@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.
- package/AGENTS.md +28 -0
- package/CHANGELOG.md +620 -0
- package/CLAUDE.md +1 -0
- package/README.md +406 -29
- package/THIRD-PARTY-LICENSES.md +35 -0
- package/content/defaults.json +1 -1
- package/content/git-hooks/post-checkout.sh +10 -0
- package/content/git-hooks/pre-push.sh +5 -0
- package/content/hooks/away-mode.py +287 -0
- package/content/hooks/background-design-commands.py +215 -0
- package/content/hooks/builder-chat-words.py +269 -0
- package/content/hooks/context-warning.py +836 -142
- package/content/hooks/git-safety.py +213 -0
- package/content/hooks/subagent-model-policy.py +261 -0
- package/content/mods/.claude-plugin/marketplace.json +16 -0
- package/content/mods/plugins/e2e-progress/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/e2e-progress/hooks/hooks.json +1 -0
- package/content/mods/plugins/e2e-progress/hooks/register.tsx +442 -0
- package/content/mods/plugins/e2e-progress/tsconfig.json +3 -0
- package/content/mods/plugins/e2e-progress/types/index.d.ts +23 -0
- package/content/mods/plugins/status-line/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/status-line/hooks/hooks.json +1 -0
- package/content/mods/plugins/status-line/hooks/line.ts +73 -0
- package/content/mods/plugins/status-line/hooks/register.tsx +141 -0
- package/content/mods/plugins/status-line/types/index.d.ts +5 -0
- package/content/output-styles/ste-clarity.md +131 -0
- package/content/rules/agent-sessions-wake-up.md +11 -0
- package/content/rules/app-styling.md +66 -0
- package/content/rules/comments.md +4 -1
- package/content/rules/lint-and-format.md +7 -5
- package/content/rules/nx-layout.md +53 -0
- package/content/rules/reactive-state.md +1 -1
- package/content/rules/styling.md +19 -10
- package/content/rules/subagent-models.md +42 -0
- package/content/skills/agent-sessions/SKILL.md +94 -0
- package/content/skills/agent-sessions/agent-sessions.mjs +1079 -0
- package/content/skills/angular-patterns/SKILL.md +31 -7
- package/content/skills/api-source/SKILL.md +156 -0
- package/content/skills/app-testing/SKILL.md +141 -0
- package/content/skills/codex-subagent/SKILL.md +90 -0
- package/content/skills/codex-subagent/codex-agent.mjs +229 -0
- package/content/skills/design-exploration/SKILL.md +190 -0
- package/content/skills/design-exploration/check-story.mjs +139 -0
- package/content/skills/design-exploration/reference-check-and-notes.md +92 -0
- package/content/skills/design-exploration/reference-flows-and-wireframes.md +78 -0
- package/content/skills/design-exploration/reference-inbox-and-mcp.md +54 -0
- package/content/skills/design-exploration/reference-order-and-design-system.md +124 -0
- package/content/skills/design-exploration/reference-products-and-sketches.md +211 -0
- package/content/skills/design-exploration/reference-shots.md +25 -0
- package/content/skills/design-exploration/shoot-template.mjs +61 -0
- package/content/skills/domain-modeling/ADR-FORMAT.md +47 -0
- package/content/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
- package/content/skills/domain-modeling/SKILL.md +80 -0
- package/content/skills/e2e-triage/SKILL.md +80 -0
- package/content/skills/figma-export/SKILL.md +191 -0
- package/content/skills/figma-export/dump-figma-layers.py +83 -0
- package/content/skills/figma-export/dump-figma-svg.py +235 -0
- package/content/skills/figma-export/measure-template.mjs +87 -0
- package/content/skills/git-commit/SKILL.md +21 -7
- package/content/skills/git-flow/SKILL.md +87 -0
- package/content/skills/grill-with-docs/SKILL.md +13 -0
- package/content/skills/grilling/SKILL.md +52 -0
- package/content/skills/handoff/SKILL.md +29 -69
- package/content/skills/handoff/save.md +187 -0
- package/content/skills/query/SKILL.md +165 -64
- package/content/skills/report/SKILL.md +26 -0
- package/content/skills/rxjs-signals/SKILL.md +33 -4
- package/content/skills/sdk-docs/SKILL.md +50 -14
- package/content/skills/sdk-local-build/SKILL.md +26 -8
- package/content/skills/sdk-local-build/sdk-local-baseline.mjs +64 -0
- package/content/skills/sdk-source/SKILL.md +37 -34
- package/content/skills/sdk-update/SKILL.md +103 -0
- package/content/skills/story-styling/SKILL.md +10 -8
- package/content/skills/styleguide/SKILL.md +13 -8
- package/content/skills/styleguide/assets.md +54 -0
- package/content/skills/styleguide/changesets.md +17 -0
- package/content/skills/styleguide/file-structure.md +73 -0
- package/content/skills/styleguide/lint-rule-lookup.md +52 -0
- package/content/skills/styleguide/storybook-structure.md +25 -0
- package/content/skills/theming/SKILL.md +56 -28
- package/content/skills/timetrack/SKILL.md +324 -0
- package/content/skills/verify-in-app/SKILL.md +107 -0
- package/content/skills/verify-in-storybook/SKILL.md +1 -1
- package/migrations/list-state-query-form.md +20 -0
- package/migrations/nx-layout.md +29 -0
- package/migrations/sdk-components-over-hand-built-ui.md +27 -0
- package/migrations/search-query-field.md +52 -0
- package/migrations.json +39 -0
- package/package.json +19 -3
- package/src/index.js +99 -32
- package/src/index.js.map +1 -1
- package/src/lib/cli-args.d.ts +9 -0
- package/src/lib/cli-args.js +48 -0
- package/src/lib/cli-args.js.map +1 -0
- package/src/lib/commitlint.d.ts +10 -0
- package/src/lib/commitlint.js +51 -0
- package/src/lib/commitlint.js.map +1 -0
- package/src/lib/config.d.ts +51 -6
- package/src/lib/config.js +127 -10
- package/src/lib/config.js.map +1 -1
- package/src/lib/filter.d.ts +2 -0
- package/src/lib/filter.js +4 -4
- package/src/lib/filter.js.map +1 -1
- package/src/lib/frontmatter.d.ts +2 -0
- package/src/lib/frontmatter.js +33 -5
- package/src/lib/frontmatter.js.map +1 -1
- package/src/lib/git-flow/build.d.ts +35 -0
- package/src/lib/git-flow/build.js +24 -0
- package/src/lib/git-flow/build.js.map +1 -0
- package/src/lib/git-flow/config.d.ts +59 -0
- package/src/lib/git-flow/config.js +50 -0
- package/src/lib/git-flow/config.js.map +1 -0
- package/src/lib/git-flow/index.d.ts +6 -0
- package/src/lib/git-flow/index.js +23 -0
- package/src/lib/git-flow/index.js.map +1 -0
- package/src/lib/git-flow/parse.d.ts +49 -0
- package/src/lib/git-flow/parse.js +300 -0
- package/src/lib/git-flow/parse.js.map +1 -0
- package/src/lib/git-flow/rename.d.ts +24 -0
- package/src/lib/git-flow/rename.js +70 -0
- package/src/lib/git-flow/rename.js.map +1 -0
- package/src/lib/git-flow/start.d.ts +49 -0
- package/src/lib/git-flow/start.js +57 -0
- package/src/lib/git-flow/start.js.map +1 -0
- package/src/lib/git-flow/validate.d.ts +34 -0
- package/src/lib/git-flow/validate.js +72 -0
- package/src/lib/git-flow/validate.js.map +1 -0
- package/src/lib/git-flow-command.d.ts +4 -0
- package/src/lib/git-flow-command.js +165 -0
- package/src/lib/git-flow-command.js.map +1 -0
- package/src/lib/git-flow-repair.d.ts +17 -0
- package/src/lib/git-flow-repair.js +165 -0
- package/src/lib/git-flow-repair.js.map +1 -0
- package/src/lib/git-flow-start.d.ts +20 -0
- package/src/lib/git-flow-start.js +140 -0
- package/src/lib/git-flow-start.js.map +1 -0
- package/src/lib/git-test-env.fixtures.d.ts +11 -0
- package/src/lib/git-test-env.fixtures.js +31 -0
- package/src/lib/git-test-env.fixtures.js.map +1 -0
- package/src/lib/git.d.ts +64 -0
- package/src/lib/git.js +131 -0
- package/src/lib/git.js.map +1 -0
- package/src/lib/gitlab.d.ts +35 -0
- package/src/lib/gitlab.js +116 -0
- package/src/lib/gitlab.js.map +1 -0
- package/src/lib/index.d.ts +2 -0
- package/src/lib/index.js +26 -11
- package/src/lib/index.js.map +1 -1
- package/src/lib/migrate.js +8 -2
- package/src/lib/migrate.js.map +1 -1
- package/src/lib/output-style-command.d.ts +3 -0
- package/src/lib/output-style-command.js +69 -0
- package/src/lib/output-style-command.js.map +1 -0
- package/src/lib/output-style.d.ts +38 -0
- package/src/lib/output-style.js +134 -0
- package/src/lib/output-style.js.map +1 -0
- package/src/lib/owned-paths.js +27 -3
- package/src/lib/owned-paths.js.map +1 -1
- package/src/lib/package-runner.d.ts +4 -0
- package/src/lib/package-runner.js +86 -0
- package/src/lib/package-runner.js.map +1 -0
- package/src/lib/peer-path.d.ts +12 -0
- package/src/lib/peer-path.js +39 -0
- package/src/lib/peer-path.js.map +1 -0
- package/src/lib/plain-text.d.ts +9 -0
- package/src/lib/plain-text.js +22 -0
- package/src/lib/plain-text.js.map +1 -0
- package/src/lib/plan.d.ts +6 -6
- package/src/lib/plan.js +168 -40
- package/src/lib/plan.js.map +1 -1
- package/src/lib/prettier.d.ts +21 -0
- package/src/lib/prettier.js +51 -0
- package/src/lib/prettier.js.map +1 -0
- package/src/lib/prompt.d.ts +8 -0
- package/src/lib/prompt.js +35 -0
- package/src/lib/prompt.js.map +1 -0
- package/src/lib/render.d.ts +26 -2
- package/src/lib/render.js +45 -10
- package/src/lib/render.js.map +1 -1
- package/src/lib/report-command.d.ts +33 -0
- package/src/lib/report-command.js +312 -0
- package/src/lib/report-command.js.map +1 -0
- package/src/lib/sessions-command.d.ts +4 -0
- package/src/lib/sessions-command.js +16 -0
- package/src/lib/sessions-command.js.map +1 -0
- package/src/lib/sync.d.ts +1 -2
- package/src/lib/sync.js +37 -17
- package/src/lib/sync.js.map +1 -1
- package/src/lib/targets/agents-skills.js +1 -1
- package/src/lib/targets/agents-skills.js.map +1 -1
- package/src/lib/targets/claude-hooks.d.ts +3 -23
- package/src/lib/targets/claude-hooks.js +22 -86
- package/src/lib/targets/claude-hooks.js.map +1 -1
- package/src/lib/targets/claude-mods.d.ts +20 -0
- package/src/lib/targets/claude-mods.js +47 -0
- package/src/lib/targets/claude-mods.js.map +1 -0
- package/src/lib/targets/claude.js +2 -3
- package/src/lib/targets/claude.js.map +1 -1
- package/src/lib/targets/codex-hooks.d.ts +12 -0
- package/src/lib/targets/codex-hooks.js +35 -0
- package/src/lib/targets/codex-hooks.js.map +1 -0
- package/src/lib/targets/codex.js +4 -4
- package/src/lib/targets/codex.js.map +1 -1
- package/src/lib/targets/copilot.js +4 -4
- package/src/lib/targets/copilot.js.map +1 -1
- package/src/lib/targets/cursor.js +3 -3
- package/src/lib/targets/cursor.js.map +1 -1
- package/src/lib/targets/git-hooks.d.ts +25 -0
- package/src/lib/targets/git-hooks.js +71 -0
- package/src/lib/targets/git-hooks.js.map +1 -0
- package/src/lib/targets/hooks-shared.d.ts +60 -0
- package/src/lib/targets/hooks-shared.js +174 -0
- package/src/lib/targets/hooks-shared.js.map +1 -0
- package/src/lib/targets/mcp.d.ts +16 -0
- package/src/lib/targets/mcp.js +72 -0
- package/src/lib/targets/mcp.js.map +1 -0
- package/src/lib/targets/shared.d.ts +1 -9
- package/src/lib/targets/shared.js +4 -8
- package/src/lib/targets/shared.js.map +1 -1
- package/src/lib/timetrack-command.d.ts +11 -0
- package/src/lib/timetrack-command.js +1262 -0
- package/src/lib/timetrack-command.js.map +1 -0
- package/src/lib/timetrack-snapshot.d.ts +66 -0
- package/src/lib/timetrack-snapshot.js +146 -0
- package/src/lib/timetrack-snapshot.js.map +1 -0
- package/src/lib/timetrack.d.ts +607 -0
- package/src/lib/timetrack.js +285 -0
- package/src/lib/timetrack.js.map +1 -0
- package/content/skills/styleguide/STYLEGUIDE.md +0 -520
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Stop hook: logs the chat text of a builder turn and blocks a turn that ends with more than one line.
|
|
3
|
+
|
|
4
|
+
Only runs in a session started with `--role builder` (ETHLETE_AGENT_ROLE=builder). Appends one
|
|
5
|
+
JSON line to .claude/builder-chat-words.jsonl: timestamp, session_id, words, lines, committed, reported, blocked.
|
|
6
|
+
It blocks the stop once (not again while stop_hook_active is set) when the turn's text blocks and
|
|
7
|
+
last_assistant_message hold more than one non-empty line, or when the turn ran `git commit` or `git push` and sent
|
|
8
|
+
no report (no SendMessage, no `agent-sessions send`). It always exits 0.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
from datetime import datetime, timezone
|
|
15
|
+
|
|
16
|
+
LOG_FILE = os.path.join(".claude", "builder-chat-words.jsonl")
|
|
17
|
+
BLOCK_REASON = (
|
|
18
|
+
"builder: no chat text. Send the report with SendMessage to the grill session; "
|
|
19
|
+
"end the turn with at most one line."
|
|
20
|
+
)
|
|
21
|
+
REPORT_REASON = (
|
|
22
|
+
"builder: this turn committed or pushed and sent no report. Send it to the grill session with SendMessage "
|
|
23
|
+
"or `agent-sessions.mjs send`, then end the turn."
|
|
24
|
+
)
|
|
25
|
+
SEPARATORS = ";&|()\n"
|
|
26
|
+
GIT_OPTIONS_WITH_VALUE = {"-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path"}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def is_prompt(entry):
|
|
30
|
+
if entry.get("type") != "user":
|
|
31
|
+
return False
|
|
32
|
+
content = (entry.get("message") or {}).get("content")
|
|
33
|
+
if isinstance(content, str):
|
|
34
|
+
return True
|
|
35
|
+
return isinstance(content, list) and not any(
|
|
36
|
+
isinstance(block, dict) and block.get("type") == "tool_result" for block in content
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def turn_entries(path):
|
|
41
|
+
texts = []
|
|
42
|
+
tools = []
|
|
43
|
+
with open(path, encoding="utf-8") as handle:
|
|
44
|
+
for line in handle:
|
|
45
|
+
try:
|
|
46
|
+
entry = json.loads(line)
|
|
47
|
+
except ValueError:
|
|
48
|
+
continue
|
|
49
|
+
if not isinstance(entry, dict):
|
|
50
|
+
continue
|
|
51
|
+
if is_prompt(entry):
|
|
52
|
+
texts = []
|
|
53
|
+
tools = []
|
|
54
|
+
elif entry.get("type") == "assistant":
|
|
55
|
+
content = (entry.get("message") or {}).get("content")
|
|
56
|
+
if isinstance(content, str):
|
|
57
|
+
texts.append(content)
|
|
58
|
+
elif isinstance(content, list):
|
|
59
|
+
for block in content:
|
|
60
|
+
if not isinstance(block, dict):
|
|
61
|
+
continue
|
|
62
|
+
if block.get("type") == "text":
|
|
63
|
+
texts.append(str(block.get("text", "")))
|
|
64
|
+
elif block.get("type") == "tool_use":
|
|
65
|
+
tools.append(block)
|
|
66
|
+
return texts, tools
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def bash_commands(tools):
|
|
70
|
+
for tool in tools:
|
|
71
|
+
if tool.get("name") == "Bash":
|
|
72
|
+
command = (tool.get("input") or {}).get("command")
|
|
73
|
+
if isinstance(command, str):
|
|
74
|
+
yield command
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def read_heredoc_delimiter(command, index):
|
|
78
|
+
strip_tabs = command.startswith("-", index)
|
|
79
|
+
if strip_tabs:
|
|
80
|
+
index += 1
|
|
81
|
+
while index < len(command) and command[index] in " \t":
|
|
82
|
+
index += 1
|
|
83
|
+
delimiter = []
|
|
84
|
+
while index < len(command) and command[index] not in " \t" + SEPARATORS + "<>":
|
|
85
|
+
char = command[index]
|
|
86
|
+
if char in "'\"":
|
|
87
|
+
end = command.find(char, index + 1)
|
|
88
|
+
end = len(command) if end == -1 else end
|
|
89
|
+
delimiter.append(command[index + 1 : end])
|
|
90
|
+
index = end + 1
|
|
91
|
+
else:
|
|
92
|
+
if char != "\\":
|
|
93
|
+
delimiter.append(char)
|
|
94
|
+
index += 1
|
|
95
|
+
return "".join(delimiter), strip_tabs, index
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def skip_heredoc_bodies(command, index, heredocs):
|
|
99
|
+
for delimiter, strip_tabs in heredocs:
|
|
100
|
+
while index < len(command):
|
|
101
|
+
end = command.find("\n", index)
|
|
102
|
+
end = len(command) if end == -1 else end
|
|
103
|
+
row = command[index:end]
|
|
104
|
+
index = end + 1
|
|
105
|
+
if (row.lstrip("\t") if strip_tabs else row) == delimiter:
|
|
106
|
+
break
|
|
107
|
+
return index
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def simple_commands(command):
|
|
111
|
+
commands = [[]]
|
|
112
|
+
word = None
|
|
113
|
+
heredocs = []
|
|
114
|
+
index = 0
|
|
115
|
+
|
|
116
|
+
def end_word():
|
|
117
|
+
nonlocal word
|
|
118
|
+
if word is not None:
|
|
119
|
+
commands[-1].append(word)
|
|
120
|
+
word = None
|
|
121
|
+
|
|
122
|
+
def end_command():
|
|
123
|
+
end_word()
|
|
124
|
+
if commands[-1]:
|
|
125
|
+
commands.append([])
|
|
126
|
+
|
|
127
|
+
while index < len(command):
|
|
128
|
+
char = command[index]
|
|
129
|
+
if char == "\\":
|
|
130
|
+
if command.startswith("\n", index + 1):
|
|
131
|
+
index += 2
|
|
132
|
+
continue
|
|
133
|
+
word = (word or "") + command[index + 1 : index + 2]
|
|
134
|
+
index += 2
|
|
135
|
+
elif char == "'":
|
|
136
|
+
end = command.find("'", index + 1)
|
|
137
|
+
end = len(command) if end == -1 else end
|
|
138
|
+
word = (word or "") + command[index + 1 : end]
|
|
139
|
+
index = end + 1
|
|
140
|
+
elif char == '"':
|
|
141
|
+
index += 1
|
|
142
|
+
chars = []
|
|
143
|
+
while index < len(command) and command[index] != '"':
|
|
144
|
+
if command[index] == "\\" and index + 1 < len(command):
|
|
145
|
+
index += 1
|
|
146
|
+
chars.append(command[index])
|
|
147
|
+
index += 1
|
|
148
|
+
word = (word or "") + "".join(chars)
|
|
149
|
+
index += 1
|
|
150
|
+
elif char == "#" and word is None:
|
|
151
|
+
end = command.find("\n", index)
|
|
152
|
+
index = len(command) if end == -1 else end
|
|
153
|
+
elif command.startswith("<<<", index):
|
|
154
|
+
end_word()
|
|
155
|
+
index += 3
|
|
156
|
+
elif command.startswith("<<", index):
|
|
157
|
+
end_word()
|
|
158
|
+
delimiter, strip_tabs, index = read_heredoc_delimiter(command, index + 2)
|
|
159
|
+
heredocs.append((delimiter, strip_tabs))
|
|
160
|
+
elif char == "\n":
|
|
161
|
+
end_command()
|
|
162
|
+
index = skip_heredoc_bodies(command, index + 1, heredocs)
|
|
163
|
+
heredocs = []
|
|
164
|
+
elif char in SEPARATORS:
|
|
165
|
+
end_command()
|
|
166
|
+
index += 1
|
|
167
|
+
elif char in " \t":
|
|
168
|
+
end_word()
|
|
169
|
+
index += 1
|
|
170
|
+
else:
|
|
171
|
+
word = (word or "") + char
|
|
172
|
+
index += 1
|
|
173
|
+
end_command()
|
|
174
|
+
return [words for words in commands if words]
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def command_words(words):
|
|
178
|
+
index = 0
|
|
179
|
+
while index < len(words) and "=" in words[index] and not words[index].startswith("-"):
|
|
180
|
+
index += 1
|
|
181
|
+
return words[index:]
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def is_git_commit(words):
|
|
185
|
+
words = command_words(words)
|
|
186
|
+
if not words or os.path.basename(words[0]) != "git":
|
|
187
|
+
return False
|
|
188
|
+
index = 1
|
|
189
|
+
while index < len(words) and words[index].startswith("-"):
|
|
190
|
+
index += 2 if words[index] in GIT_OPTIONS_WITH_VALUE else 1
|
|
191
|
+
return index < len(words) and words[index] in ("commit", "push")
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def is_report_send(words):
|
|
195
|
+
words = command_words(words)
|
|
196
|
+
if len(words) < 3:
|
|
197
|
+
return False
|
|
198
|
+
if words[0] == "yarn":
|
|
199
|
+
return words[1:3] == ["agents:sessions", "send"]
|
|
200
|
+
if os.path.basename(words[0]) != "node":
|
|
201
|
+
return False
|
|
202
|
+
scripts = [word for word in words[1:] if not word.startswith("-")]
|
|
203
|
+
return len(scripts) >= 2 and os.path.basename(scripts[0]) == "agent-sessions.mjs" and scripts[1] == "send"
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def bash_simple_commands(tools):
|
|
207
|
+
for command in bash_commands(tools):
|
|
208
|
+
yield from simple_commands(command)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def has_commit(tools):
|
|
212
|
+
return any(is_git_commit(words) for words in bash_simple_commands(tools))
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def has_report(tools):
|
|
216
|
+
return any(tool.get("name") == "SendMessage" for tool in tools) or any(
|
|
217
|
+
is_report_send(words) for words in bash_simple_commands(tools)
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def with_final(texts, final):
|
|
222
|
+
if not isinstance(final, str) or not final.strip():
|
|
223
|
+
return texts
|
|
224
|
+
if texts and texts[-1].strip() == final.strip():
|
|
225
|
+
return texts
|
|
226
|
+
return [*texts, final]
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def main():
|
|
230
|
+
if os.environ.get("ETHLETE_AGENT_ROLE") != "builder":
|
|
231
|
+
return
|
|
232
|
+
payload = json.load(sys.stdin)
|
|
233
|
+
path = payload.get("transcript_path")
|
|
234
|
+
final = payload.get("last_assistant_message")
|
|
235
|
+
has_transcript = bool(path) and os.path.isfile(path)
|
|
236
|
+
if not has_transcript and not isinstance(final, str):
|
|
237
|
+
return
|
|
238
|
+
root = os.environ.get("CLAUDE_PROJECT_DIR") or payload.get("cwd") or os.getcwd()
|
|
239
|
+
log = os.path.join(root, LOG_FILE)
|
|
240
|
+
os.makedirs(os.path.dirname(log), exist_ok=True)
|
|
241
|
+
# Claude Code calls the Stop hook before the final text block reaches the transcript.
|
|
242
|
+
texts, tools = turn_entries(path) if has_transcript else ([], [])
|
|
243
|
+
texts = with_final(texts, final)
|
|
244
|
+
lines = sum(1 for text in texts for row in text.splitlines() if row.strip())
|
|
245
|
+
committed = has_commit(tools)
|
|
246
|
+
reported = has_report(tools)
|
|
247
|
+
unreported = committed and not reported
|
|
248
|
+
blocked = (lines > 1 or unreported) and not payload.get("stop_hook_active")
|
|
249
|
+
record = {
|
|
250
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
251
|
+
"session_id": payload.get("session_id"),
|
|
252
|
+
"words": sum(len(text.split()) for text in texts),
|
|
253
|
+
"lines": lines,
|
|
254
|
+
"committed": committed,
|
|
255
|
+
"reported": reported,
|
|
256
|
+
"blocked": blocked,
|
|
257
|
+
}
|
|
258
|
+
with open(log, "a", encoding="utf-8") as handle:
|
|
259
|
+
handle.write(json.dumps(record) + "\n")
|
|
260
|
+
if blocked:
|
|
261
|
+
reason = REPORT_REASON if unreported else BLOCK_REASON
|
|
262
|
+
print(json.dumps({"decision": "block", "reason": reason}))
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
try:
|
|
266
|
+
main()
|
|
267
|
+
except Exception:
|
|
268
|
+
pass
|
|
269
|
+
sys.exit(0)
|