@ethlete/agent-rules 0.1.0-next.37 → 0.1.0-next.39
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/CHANGELOG.md +51 -0
- package/README.md +43 -5
- package/content/hooks/away-mode.py +287 -0
- package/content/hooks/background-design-commands.py +42 -7
- package/content/hooks/context-warning.py +2 -44
- package/content/hooks/subagent-model-policy.py +90 -23
- package/content/mods/.claude-plugin/marketplace.json +5 -0
- package/content/mods/plugins/e2e-progress/.claude-plugin/plugin.json +1 -1
- 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/rules/subagent-models.md +9 -6
- package/content/skills/agent-sessions/SKILL.md +2 -2
- package/content/skills/agent-sessions/agent-sessions.mjs +30 -14
- package/content/skills/angular-patterns/SKILL.md +1 -1
- package/content/skills/codex-subagent/SKILL.md +1 -1
- package/content/skills/design-exploration/SKILL.md +5 -2
- package/content/skills/figma-export/SKILL.md +1 -1
- package/content/skills/handoff/SKILL.md +4 -187
- package/content/skills/handoff/save.md +187 -0
- package/content/skills/query/SKILL.md +1 -1
- package/content/skills/report/SKILL.md +26 -0
- package/content/skills/rxjs-signals/SKILL.md +1 -1
- package/content/skills/styleguide/SKILL.md +1 -1
- package/content/skills/styleguide/lint-rule-lookup.md +42 -41
- package/content/skills/theming/SKILL.md +1 -1
- package/content/skills/timetrack/SKILL.md +37 -1
- package/content/skills/verify-in-storybook/SKILL.md +1 -1
- package/package.json +1 -1
- package/src/index.js +13 -2
- package/src/index.js.map +1 -1
- package/src/lib/config.d.ts +13 -0
- package/src/lib/config.js +13 -3
- package/src/lib/config.js.map +1 -1
- 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/plan.js +10 -2
- package/src/lib/plan.js.map +1 -1
- package/src/lib/render.d.ts +1 -0
- package/src/lib/render.js +3 -1
- 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/targets/claude-mods.js +1 -1
- package/src/lib/targets/claude-mods.js.map +1 -1
- package/src/lib/targets/hooks-shared.js +6 -0
- package/src/lib/targets/hooks-shared.js.map +1 -1
- package/src/lib/targets/mcp.d.ts +6 -6
- package/src/lib/targets/mcp.js +9 -5
- package/src/lib/targets/mcp.js.map +1 -1
- package/src/lib/timetrack-command.js +240 -41
- package/src/lib/timetrack-command.js.map +1 -1
- package/src/lib/timetrack-snapshot.d.ts +11 -0
- package/src/lib/timetrack-snapshot.js +27 -1
- package/src/lib/timetrack-snapshot.js.map +1 -1
- package/src/lib/timetrack.d.ts +48 -2
- package/src/lib/timetrack.js +8 -2
- package/src/lib/timetrack.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @ethlete/agent-rules
|
|
2
2
|
|
|
3
|
+
## 0.1.0-next.39
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- `timetrack rows <day> --compare <file>` compares a day's rows with another machine's `rows --json` export, ignoring paths and order, and exits 1 on a difference.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- `timetrack rows` marks a row nobody was at the machine for with `unattended`, and `timetrack snapshot --help` prints usage instead of recording a snapshot.
|
|
12
|
+
- `timetrack rows <day> --compare <file>` maps a paired machine's checkout paths onto this machine's by repository key, so one repository under differently named folders compares as the same rows.
|
|
13
|
+
- An agent's night on one paired machine now reads unattended on both, and `timetrack day --received` adds the events paired machines sent.
|
|
14
|
+
- Keep the latest stand-in verdict per context and day and print it under `timetrack naming`, so a row that stays "Not yet named" can be explained.
|
|
15
|
+
- The `status-line` mod shows its band only in a session that ran the `doc-agent` skill (typed `/doc-agent` or called by the model); `builder-agent` hides it again, and every other session never shows it nor polls git and CI for it.
|
|
16
|
+
- `timetrack rules` lists the day a day-scoped attribution rule holds on, in the JSON and in the printed line.
|
|
17
|
+
|
|
18
|
+
## 0.1.0-next.38
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- Add the opt-in `away-mode` hook, which switches a tracked agent session to away mode after `awayMode.thresholdMinutes` without typed input and back on the next typed prompt.
|
|
23
|
+
- The away-mode hook appends the report table for the time away to its "user is back" message when `awayMode.reportCommand` is set.
|
|
24
|
+
- The `subagent-model-policy` hook no longer denies a subagent call that names no model: it runs it on `sonnet` and
|
|
25
|
+
returns the model table as a note. The delegating rule now says sonnet is the default.
|
|
26
|
+
- The `background-design-commands` hook no longer denies a long design command run in the foreground: it starts it with
|
|
27
|
+
`run_in_background: true` and says so in a note.
|
|
28
|
+
- The `context-warning` hook warns once per tier and no longer repeats a reminder on every later prompt. A session
|
|
29
|
+
started with the builder role gets `CLAUDE_CODE_SILENT_TURN_REMINDER=0`, so Claude Code's silent-turn reminder stays off
|
|
30
|
+
for it and its subagents.
|
|
31
|
+
- The `background-design-commands` hook also starts a wait loop in the background: a Bash call with an `until` or
|
|
32
|
+
`while` loop that sleeps runs with `run_in_background: true`, and the completion notice ends the wait.
|
|
33
|
+
- `timetrack edit --day <D> --edits <file.json>` queues many row edits of one day as one approval. The timetrack skill names the user's rules for tidying a day.
|
|
34
|
+
- Add `ethlete-agents report`, which prints a fixed progress table for a period, and a `report` skill that pastes it.
|
|
35
|
+
- Add the `status-line` Claude Code mod: a band above the prompt with the running slice and its duration, the open queue, open questions and a blocked mark when the branch's CI is red.
|
|
36
|
+
- The `subagent-model-policy` hook logs each subagent start to `.git/ethlete/subagent-starts.jsonl`: model, effort, HEAD, branch, description, prompt head and the file paths the prompt names.
|
|
37
|
+
- Add `timetrack rules --repoint --from <KEY> --to <KEY>`, which queues pointing every attribution rule that names one issue at another.
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- List the `prefer-computed-linked-signal-source` rule in the styleguide lint rule lookup.
|
|
42
|
+
- The subagent rule tells the session to stop each background subagent once its result is in.
|
|
43
|
+
- The `agent-sessions` skill no longer says that lint runs only in CI: the pre-commit hook lints the staged files.
|
|
44
|
+
- The `design-exploration` skill names one exception to "the user chooses": a role that the project gives its own picks
|
|
45
|
+
builds its recommendation and records the pick.
|
|
46
|
+
- An accepted or edited row between midnight and 6 am now carries a `night-row` day warning, and `timetrack rows` shows each row's desk events and human prompts.
|
|
47
|
+
- The builder claude launch starts with a smaller fixed context: only the repo MCP config and seven unused tools denied.
|
|
48
|
+
- A repo can set the `designMcpCommand` var to start the `ethlete-design` MCP server with its own command.
|
|
49
|
+
- Split the handoff skill: `SKILL.md` keeps the resume mode, and save mode, handoff mode and clearing on your own move to a sibling `save.md` that is read only when saving.
|
|
50
|
+
- Shorten the frontmatter descriptions of the bundled skills so they load less context into every session.
|
|
51
|
+
- `timetrack` output into a pipe is no longer cut off, `timetrack approvals` and `approval <id>` print the day, rows and issue of a waiting write, and `timetrack standins --stale [days]` lists old placeholders with no work.
|
|
52
|
+
- A prompt another program typed into a pane (mailbox wake, restart resume prompt, `/clear`) no longer counts as a person being there. The restart now ends its prompts in `[typed by agent-sessions]`.
|
|
53
|
+
|
|
3
54
|
## 0.1.0-next.37
|
|
4
55
|
|
|
5
56
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -317,7 +317,8 @@ per hook in the config:
|
|
|
317
317
|
"subagent-model-policy",
|
|
318
318
|
"background-design-commands",
|
|
319
319
|
"git-safety",
|
|
320
|
-
"builder-chat-words"
|
|
320
|
+
"builder-chat-words",
|
|
321
|
+
"away-mode"
|
|
321
322
|
]
|
|
322
323
|
}
|
|
323
324
|
```
|
|
@@ -368,17 +369,54 @@ Available hooks:
|
|
|
368
369
|
never tells the user or the main agent to hand off the root session.
|
|
369
370
|
|
|
370
371
|
- **`subagent-model-policy`** (Claude Code only) - gates every call to the subagent tool.
|
|
371
|
-
A call that names no `model`
|
|
372
|
-
a lookup,
|
|
373
|
-
it a subagent inherits the model leading the session, which is how an
|
|
374
|
-
ends up doing every grep it delegates
|
|
372
|
+
A call that names no `model` runs on sonnet, and the model table is returned with it:
|
|
373
|
+
haiku for a lookup, sonnet for scoped work, opus for hard work, fable for judgment-heavy
|
|
374
|
+
work. Without it a subagent inherits the model leading the session, which is how an
|
|
375
|
+
expensive model ends up doing every grep it delegates.
|
|
376
|
+
|
|
377
|
+
Each start appends a line to `.git/ethlete/subagent-starts.jsonl` (model, effort, HEAD,
|
|
378
|
+
description, prompt head, the file paths the prompt names), to join with later commits.
|
|
375
379
|
|
|
376
380
|
A call that names `fable` asks the user - it is the most expensive option, and only the
|
|
377
381
|
user knows whether the task is judgment-heavy. A fork and an agent type whose own
|
|
378
382
|
definition sets a model both pass untouched, because `model` would change nothing there.
|
|
379
383
|
|
|
384
|
+
- **`away-mode`** (Claude Code only) - switches an interactive session into "user is away" mode
|
|
385
|
+
on its own. Opt in with `"awayMode": { "skills": ["my-skill"], "thresholdMinutes": 15 }` in the
|
|
386
|
+
config (the local config overrides it); a session is tracked once a prompt starts with
|
|
387
|
+
`/my-skill`. When a prompt that is not typed by a human (mailbox, cross-session, task
|
|
388
|
+
notification, restart) arrives after the threshold without typed input, the hook tells the
|
|
389
|
+
agent the user is away; the next typed prompt tells it the user is back. A typed `afk` marks
|
|
390
|
+
the session away at once. With `"reportCommand": "<cli> report"` inside `awayMode`, the back
|
|
391
|
+
message also carries that command's table since the last typed input (dropped when it fails or
|
|
392
|
+
takes over 10 s). State is kept in `.git/ethlete/away/`.
|
|
393
|
+
|
|
380
394
|
Hooks can be turned off per machine - see the local config below.
|
|
381
395
|
|
|
396
|
+
## Mods (Claude Code)
|
|
397
|
+
|
|
398
|
+
`"mods": ["status-line"]` in the config enables a Claude Code mod from the `ethlete` marketplace the
|
|
399
|
+
package ships (`yarn agents:sync` writes the marketplace and `enabledPlugins` into
|
|
400
|
+
`.claude/settings.json`). A mod runs code in every session of the repo, so none is on by default.
|
|
401
|
+
|
|
402
|
+
- **`e2e-progress`** - live Playwright run progress as a status line entry and a pane.
|
|
403
|
+
- **`status-line`** - a band above the prompt, always visible: `▶ <running slice> · 42 min · 14 offen · ❓2`.
|
|
404
|
+
The slice comes from the git `slice-paths` file (`kein Slice` once it is older than 2 h), the queue
|
|
405
|
+
count from the `### Warteschlange` list of the `report.planFiles` markdown files, `❓N` from the
|
|
406
|
+
`-` lines of `<git common dir>/ethlete/open-questions.md`, and `⛔ CI rot` when the latest `gh run`
|
|
407
|
+
of the branch failed (checked every 2 minutes). A field whose source is missing is left out.
|
|
408
|
+
|
|
409
|
+
## Progress report
|
|
410
|
+
|
|
411
|
+
`ethlete-agents report [today|yesterday|week | --since <date> [--until <date>]]` prints a fixed
|
|
412
|
+
markdown table of the period: one line per row with a feature, fix or other non-docs commit (short
|
|
413
|
+
sha, result), the parked rows, and a figures line (commit counts, reverts, red CI runs via `gh`,
|
|
414
|
+
subagent starts per model, the running slice). Without config it works from the git log alone.
|
|
415
|
+
Opt in to short names and the parked section with
|
|
416
|
+
`"report": { "planFiles": ["plans/STATUS.md", "plans/queue.md", "plans/rows.md"] }`: repo-relative paths
|
|
417
|
+
of markdown files holding `| <id> | <short name> | <what> | <state> | <what is missing> | <who> |` rows
|
|
418
|
+
and `N. **<name> (<id>)**` queue lines. The `report` skill runs it and pastes the output.
|
|
419
|
+
|
|
382
420
|
## Git hooks (opt-in)
|
|
383
421
|
|
|
384
422
|
Separate from the agent hooks above, and opt-in for the same reason - a generated block
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""UserPromptSubmit hook: switch an interactive session into "user is away" mode on its own.
|
|
3
|
+
|
|
4
|
+
A session opts in through `awayMode` in ethlete-agents.config.json (the local config file
|
|
5
|
+
overrides it): {"awayMode": {"skills": ["doc-agent"], "thresholdMinutes": 15}}. Without `skills`
|
|
6
|
+
the hook does nothing. A session becomes active when a prompt starts with `/<skill>` or with
|
|
7
|
+
`/handoff resume <skill>-`.
|
|
8
|
+
|
|
9
|
+
Prompts the agent sessions send themselves (mailbox messages, cross-session messages, task
|
|
10
|
+
notifications, system reminders, the restart prompt) are not human input. The last human-typed
|
|
11
|
+
prompt is stored per session; when a non-human prompt arrives after the threshold, the hook injects
|
|
12
|
+
the away message once and a one-line reminder afterwards. The next human-typed prompt injects the
|
|
13
|
+
back message; with `awayMode.reportCommand` (e.g. `node dist/libs/agent-rules/src/index.js report`)
|
|
14
|
+
it also carries that command's table for the time away (`--since <last typed input>`), left out when the
|
|
15
|
+
command fails or takes over 10 s. A human prompt that is exactly `afk` marks the session away at once.
|
|
16
|
+
|
|
17
|
+
State lives in `<git common dir>/ethlete/away/<session_id>.json`, so it is never committed.
|
|
18
|
+
|
|
19
|
+
Can be disabled per machine via a gitignored ethlete-agents.config.local.json at the repo root:
|
|
20
|
+
{"disableHooks": true} or {"disableHooks": ["away-mode"]}.
|
|
21
|
+
|
|
22
|
+
Fail-safe: any error exits 0 with no output - the hook must never block work because it could
|
|
23
|
+
not read its own input.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
import json
|
|
27
|
+
import os
|
|
28
|
+
import re
|
|
29
|
+
import shlex
|
|
30
|
+
import subprocess
|
|
31
|
+
import sys
|
|
32
|
+
from datetime import datetime, timezone
|
|
33
|
+
|
|
34
|
+
HOOK_NAME = "away-mode"
|
|
35
|
+
CONFIG_FILE = "ethlete-agents.config.json"
|
|
36
|
+
LOCAL_CONFIG_FILE = "ethlete-agents.config.local.json"
|
|
37
|
+
DEFAULT_THRESHOLD_MINUTES = 15
|
|
38
|
+
AGENT_SESSIONS_SUFFIX = "[typed by agent-sessions]"
|
|
39
|
+
|
|
40
|
+
BACK_MESSAGE = (
|
|
41
|
+
"The user is back (typed input after {minutes} min away). Leave away mode: put every question you "
|
|
42
|
+
"collected while they were away once, in full, in your round format."
|
|
43
|
+
)
|
|
44
|
+
AWAY_MESSAGE = (
|
|
45
|
+
"The user is away (no typed input for {minutes} min). Work by your skill's away rules: collect "
|
|
46
|
+
"questions, one short line per event, no round. Typed input switches back on its own."
|
|
47
|
+
)
|
|
48
|
+
BACK_REPORT_MESSAGE = (
|
|
49
|
+
" Paste this report for the time away unchanged, then the collected questions:\n\n{report}"
|
|
50
|
+
)
|
|
51
|
+
REPORT_TIMEOUT_SECONDS = 10
|
|
52
|
+
STILL_AWAY_MESSAGE = "The user is still away (no typed input for {minutes} min)."
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def agent_name(argv):
|
|
56
|
+
"""The --agent value, defaulting to claude — older registrations pass no flag."""
|
|
57
|
+
for index, arg in enumerate(argv):
|
|
58
|
+
if arg == "--agent" and index + 1 < len(argv):
|
|
59
|
+
return argv[index + 1]
|
|
60
|
+
if arg.startswith("--agent="):
|
|
61
|
+
return arg.split("=", 1)[1]
|
|
62
|
+
return "claude"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def repo_root(data):
|
|
66
|
+
"""Repo root: the env var the agent sets, else the script's own location, else the cwd."""
|
|
67
|
+
for variable in ("CLAUDE_PROJECT_DIR", "CODEX_PROJECT_DIR"):
|
|
68
|
+
value = os.environ.get(variable)
|
|
69
|
+
if value:
|
|
70
|
+
return value
|
|
71
|
+
here = os.path.abspath(__file__)
|
|
72
|
+
derived = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(here))))
|
|
73
|
+
if os.path.isfile(os.path.join(derived, LOCAL_CONFIG_FILE)):
|
|
74
|
+
return derived
|
|
75
|
+
cwd = data.get("cwd")
|
|
76
|
+
return cwd if isinstance(cwd, str) and cwd else derived
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def load_config(root, file_name):
|
|
80
|
+
"""Parsed JSON object at the repo root, or {} if missing/unreadable."""
|
|
81
|
+
if not root:
|
|
82
|
+
return {}
|
|
83
|
+
try:
|
|
84
|
+
with open(os.path.join(root, file_name), encoding="utf-8") as f:
|
|
85
|
+
config = json.load(f)
|
|
86
|
+
except (OSError, ValueError, AttributeError):
|
|
87
|
+
return {}
|
|
88
|
+
return config if isinstance(config, dict) else {}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def load_local_config(root):
|
|
92
|
+
return load_config(root, LOCAL_CONFIG_FILE)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def disabled_locally(config):
|
|
96
|
+
"""True when the local config disables this hook (or all hooks) on this machine."""
|
|
97
|
+
disabled = config.get("disableHooks")
|
|
98
|
+
return disabled is True or (isinstance(disabled, list) and HOOK_NAME in disabled)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def away_settings(root, local_config):
|
|
102
|
+
"""(skills, threshold in minutes); the local config's `awayMode` replaces the shared one."""
|
|
103
|
+
setting = local_config.get("awayMode")
|
|
104
|
+
if not isinstance(setting, dict):
|
|
105
|
+
setting = load_config(root, CONFIG_FILE).get("awayMode")
|
|
106
|
+
if not isinstance(setting, dict):
|
|
107
|
+
return [], DEFAULT_THRESHOLD_MINUTES
|
|
108
|
+
skills = setting.get("skills")
|
|
109
|
+
skills = [s for s in skills if isinstance(s, str) and s] if isinstance(skills, list) else []
|
|
110
|
+
threshold = setting.get("thresholdMinutes")
|
|
111
|
+
if isinstance(threshold, bool) or not isinstance(threshold, (int, float)) or threshold <= 0:
|
|
112
|
+
threshold = DEFAULT_THRESHOLD_MINUTES
|
|
113
|
+
return skills, threshold
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def report_command(root, local_config):
|
|
117
|
+
"""The configured report command; the local config's `awayMode` replaces the shared one."""
|
|
118
|
+
setting = local_config.get("awayMode")
|
|
119
|
+
if not isinstance(setting, dict):
|
|
120
|
+
setting = load_config(root, CONFIG_FILE).get("awayMode")
|
|
121
|
+
command = setting.get("reportCommand") if isinstance(setting, dict) else None
|
|
122
|
+
return command.strip() if isinstance(command, str) and command.strip() else None
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def away_report(root, command, since):
|
|
126
|
+
"""The report table since `since`, or None when the command is missing, fails or is too slow."""
|
|
127
|
+
if not command or not since:
|
|
128
|
+
return None
|
|
129
|
+
try:
|
|
130
|
+
result = subprocess.run(
|
|
131
|
+
shlex.split(command) + ["--since", since],
|
|
132
|
+
cwd=root,
|
|
133
|
+
capture_output=True,
|
|
134
|
+
text=True,
|
|
135
|
+
timeout=REPORT_TIMEOUT_SECONDS,
|
|
136
|
+
)
|
|
137
|
+
except Exception:
|
|
138
|
+
return None
|
|
139
|
+
output = result.stdout.strip()
|
|
140
|
+
return output if result.returncode == 0 and output else None
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def is_human_typed(prompt):
|
|
144
|
+
stripped = prompt.strip()
|
|
145
|
+
return not (
|
|
146
|
+
stripped.startswith("Mailbox message from ")
|
|
147
|
+
or "<cross-session-message" in stripped
|
|
148
|
+
or stripped.endswith(AGENT_SESSIONS_SUFFIX)
|
|
149
|
+
or stripped.startswith("<task-notification")
|
|
150
|
+
or stripped.startswith("<system-reminder")
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def invokes_skill(prompt, skills):
|
|
155
|
+
text = prompt.strip()
|
|
156
|
+
if text.endswith(AGENT_SESSIONS_SUFFIX):
|
|
157
|
+
text = text[: -len(AGENT_SESSIONS_SUFFIX)].strip()
|
|
158
|
+
for skill in skills:
|
|
159
|
+
name = re.escape(skill)
|
|
160
|
+
if re.match(rf"/{name}(?![\w-])", text) or re.match(rf"/handoff\s+resume\s+{name}-", text):
|
|
161
|
+
return True
|
|
162
|
+
return False
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def state_path(root, session_id):
|
|
166
|
+
result = subprocess.run(
|
|
167
|
+
["git", "-C", root, "rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
168
|
+
capture_output=True,
|
|
169
|
+
text=True,
|
|
170
|
+
timeout=3,
|
|
171
|
+
)
|
|
172
|
+
common_dir = result.stdout.strip() if result.returncode == 0 else ""
|
|
173
|
+
if not common_dir:
|
|
174
|
+
return None
|
|
175
|
+
safe_id = re.sub(r"[^\w.-]", "_", str(session_id))
|
|
176
|
+
return os.path.join(common_dir, "ethlete", "away", f"{safe_id}.json")
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def read_state(path):
|
|
180
|
+
try:
|
|
181
|
+
with open(path, encoding="utf-8") as f:
|
|
182
|
+
state = json.load(f)
|
|
183
|
+
except (OSError, ValueError):
|
|
184
|
+
return None
|
|
185
|
+
return state if isinstance(state, dict) else None
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def write_state(path, state):
|
|
189
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
190
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
191
|
+
json.dump(state, f)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def minutes_since(iso, now):
|
|
195
|
+
try:
|
|
196
|
+
then = datetime.fromisoformat(iso)
|
|
197
|
+
except (TypeError, ValueError):
|
|
198
|
+
return None
|
|
199
|
+
if then.tzinfo is None:
|
|
200
|
+
then = then.replace(tzinfo=timezone.utc)
|
|
201
|
+
return max(0, int((now - then).total_seconds() // 60))
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def emit(message):
|
|
205
|
+
print(
|
|
206
|
+
json.dumps(
|
|
207
|
+
{"hookSpecificOutput": {"hookEventName": "UserPromptSubmit", "additionalContext": message}}
|
|
208
|
+
)
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def main():
|
|
213
|
+
if agent_name(sys.argv[1:]) != "claude":
|
|
214
|
+
return
|
|
215
|
+
|
|
216
|
+
data = json.load(sys.stdin)
|
|
217
|
+
prompt = data.get("prompt")
|
|
218
|
+
session_id = data.get("session_id")
|
|
219
|
+
|
|
220
|
+
if not isinstance(prompt, str) or not session_id:
|
|
221
|
+
return
|
|
222
|
+
|
|
223
|
+
root = repo_root(data)
|
|
224
|
+
local_config = load_local_config(root)
|
|
225
|
+
|
|
226
|
+
if disabled_locally(local_config):
|
|
227
|
+
return
|
|
228
|
+
|
|
229
|
+
skills, threshold = away_settings(root, local_config)
|
|
230
|
+
|
|
231
|
+
if not skills:
|
|
232
|
+
return
|
|
233
|
+
|
|
234
|
+
path = state_path(root, session_id)
|
|
235
|
+
|
|
236
|
+
if not path:
|
|
237
|
+
return
|
|
238
|
+
|
|
239
|
+
now = datetime.now(timezone.utc)
|
|
240
|
+
now_iso = now.isoformat(timespec="seconds")
|
|
241
|
+
state = read_state(path)
|
|
242
|
+
human = is_human_typed(prompt)
|
|
243
|
+
|
|
244
|
+
if not state or not state.get("active"):
|
|
245
|
+
if not invokes_skill(prompt, skills):
|
|
246
|
+
return
|
|
247
|
+
state = {"active": True, "lastHumanInput": now_iso if human else None, "away": False}
|
|
248
|
+
write_state(path, state)
|
|
249
|
+
return
|
|
250
|
+
|
|
251
|
+
if human:
|
|
252
|
+
was_away = state.get("away") is True
|
|
253
|
+
since = state.get("lastHumanInput")
|
|
254
|
+
minutes = minutes_since(since, now)
|
|
255
|
+
state["lastHumanInput"] = now_iso
|
|
256
|
+
state["away"] = prompt.strip().lower() == "afk"
|
|
257
|
+
write_state(path, state)
|
|
258
|
+
if was_away and not state["away"]:
|
|
259
|
+
message = BACK_MESSAGE.format(minutes=minutes if minutes is not None else threshold)
|
|
260
|
+
report = away_report(root, report_command(root, local_config), since)
|
|
261
|
+
if report:
|
|
262
|
+
message += BACK_REPORT_MESSAGE.format(report=report)
|
|
263
|
+
emit(message)
|
|
264
|
+
return
|
|
265
|
+
|
|
266
|
+
minutes = minutes_since(state.get("lastHumanInput"), now)
|
|
267
|
+
|
|
268
|
+
if minutes is not None and minutes < threshold:
|
|
269
|
+
return
|
|
270
|
+
|
|
271
|
+
shown = minutes if minutes is not None else int(threshold)
|
|
272
|
+
|
|
273
|
+
if state.get("away") is True:
|
|
274
|
+
emit(STILL_AWAY_MESSAGE.format(minutes=shown))
|
|
275
|
+
return
|
|
276
|
+
|
|
277
|
+
state["away"] = True
|
|
278
|
+
write_state(path, state)
|
|
279
|
+
emit(AWAY_MESSAGE.format(minutes=shown))
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
if __name__ == "__main__":
|
|
283
|
+
try:
|
|
284
|
+
main()
|
|
285
|
+
except Exception:
|
|
286
|
+
pass
|
|
287
|
+
sys.exit(0)
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""PreToolUse hook: long design commands
|
|
2
|
+
"""PreToolUse hook: long design commands and wait loops run in the background.
|
|
3
3
|
|
|
4
4
|
`design check`, `design compare`, `design ready`, `design sketch ready`, `design harness`
|
|
5
5
|
and the `studio:e2e` target each take minutes. A `--help` or `-h`
|
|
6
6
|
call of a `design` command only prints usage and passes; `studio:e2e --help` runs the suite. In the foreground
|
|
7
7
|
they block the whole session, so a Bash call that runs one without `run_in_background: true`
|
|
8
|
-
is
|
|
8
|
+
is allowed with that flag set, and the agent reads the output when the completion notice arrives.
|
|
9
|
+
|
|
10
|
+
A wait loop gets the same flag: an `until` or `while` loop whose body runs `sleep`. In the
|
|
11
|
+
foreground it holds the session for the whole wait and ends at the Bash timeout.
|
|
9
12
|
|
|
10
13
|
Matches the `yarn design ...`, `node dist/libs/cli/src/index.js design ...` and
|
|
11
14
|
`npx nx ... studio:e2e` forms at command position only. Quoted text, heredoc bodies and
|
|
@@ -45,6 +48,9 @@ SEPARATORS = re.compile(r"&&|\|\||[;&|\n(){}`]")
|
|
|
45
48
|
ASSIGNMENT = re.compile(r"^[A-Za-z_]\w*=")
|
|
46
49
|
HELP_PRINTS_USAGE = frozenset(("design check", "design compare", "design ready", "design sketch ready", "design harness"))
|
|
47
50
|
HELP_FLAG = re.compile(r"(?:^|\s)(?:--help|-h)(?=\s|$)")
|
|
51
|
+
WAIT_LOOP = "wait loop"
|
|
52
|
+
LOOP_KEYWORDS = frozenset(("until", "while"))
|
|
53
|
+
LOOP_BODY_KEYWORDS = frozenset(("do", "then", "else"))
|
|
48
54
|
|
|
49
55
|
|
|
50
56
|
def without_heredoc_bodies(command):
|
|
@@ -124,11 +130,39 @@ def long_command_in(command):
|
|
|
124
130
|
return None
|
|
125
131
|
|
|
126
132
|
|
|
133
|
+
def command_words(segment):
|
|
134
|
+
words = [word for word in segment.split() if not ASSIGNMENT.match(word)]
|
|
135
|
+
while words and words[0] in LOOP_BODY_KEYWORDS:
|
|
136
|
+
words = words[1:]
|
|
137
|
+
return words
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def wait_loop_in(command):
|
|
141
|
+
"""True when the shell string runs an `until` or `while` loop that sleeps."""
|
|
142
|
+
loop_open = False
|
|
143
|
+
for segment in command_segments(command):
|
|
144
|
+
words = command_words(segment)
|
|
145
|
+
if not words:
|
|
146
|
+
continue
|
|
147
|
+
if words[0] in LOOP_KEYWORDS:
|
|
148
|
+
loop_open = True
|
|
149
|
+
words = words[1:]
|
|
150
|
+
if loop_open and words and os.path.basename(words[0]) == "sleep":
|
|
151
|
+
return True
|
|
152
|
+
if words and words[0] == "done":
|
|
153
|
+
loop_open = False
|
|
154
|
+
return False
|
|
155
|
+
|
|
156
|
+
|
|
127
157
|
def reason_for(name):
|
|
158
|
+
if name == WAIT_LOOP:
|
|
159
|
+
return (
|
|
160
|
+
"A loop that sleeps until a condition holds blocks the session, so this call runs with "
|
|
161
|
+
"`run_in_background: true`. Go on with other work; the completion notice wakes you."
|
|
162
|
+
)
|
|
128
163
|
return (
|
|
129
|
-
f"`{name}` takes minutes
|
|
130
|
-
"
|
|
131
|
-
"when the completion notice arrives."
|
|
164
|
+
f"`{name}` takes minutes, so this call runs with `run_in_background: true`. "
|
|
165
|
+
"Read its output when the completion notice arrives; pass the flag yourself next time."
|
|
132
166
|
)
|
|
133
167
|
|
|
134
168
|
|
|
@@ -154,7 +188,7 @@ def main():
|
|
|
154
188
|
if disabled_locally(load_local_config(repo_root(data))):
|
|
155
189
|
return
|
|
156
190
|
|
|
157
|
-
name = long_command_in(command)
|
|
191
|
+
name = long_command_in(command) or (WAIT_LOOP if wait_loop_in(command) else None)
|
|
158
192
|
|
|
159
193
|
if not name:
|
|
160
194
|
return
|
|
@@ -164,8 +198,9 @@ def main():
|
|
|
164
198
|
{
|
|
165
199
|
"hookSpecificOutput": {
|
|
166
200
|
"hookEventName": "PreToolUse",
|
|
167
|
-
"permissionDecision": "
|
|
201
|
+
"permissionDecision": "allow",
|
|
168
202
|
"permissionDecisionReason": reason_for(name),
|
|
203
|
+
"updatedInput": {**tool_input, "run_in_background": True},
|
|
169
204
|
}
|
|
170
205
|
}
|
|
171
206
|
)
|
|
@@ -11,8 +11,7 @@ is not a warning:
|
|
|
11
11
|
|
|
12
12
|
* SessionStart - states the budget and how to scope work to it, before the
|
|
13
13
|
first request. Nothing else tells the model what its budget is.
|
|
14
|
-
* UserPromptSubmit - the tiered warning,
|
|
15
|
-
prompt.
|
|
14
|
+
* UserPromptSubmit - the tiered warning, once per tier.
|
|
16
15
|
* PostToolBatch - the same tiered warning, delivered mid-run. This is the only
|
|
17
16
|
event that fires between an agent's own model requests, so without it a long
|
|
18
17
|
autonomous run never learns its token count until the user types something.
|
|
@@ -74,10 +73,7 @@ choose between finishing and handing off again never ends. `resume` is not a sav
|
|
|
74
73
|
Warns once per tier per session (state kept in a temp file); re-arms itself
|
|
75
74
|
if the context shrinks again (e.g. after a compaction). The Stop event keeps its
|
|
76
75
|
own per-tier counter, so crossing a tier mid-run costs at most one notice while
|
|
77
|
-
working and one demand at the end of the turn.
|
|
78
|
-
warning carries a short reminder instead: how much budget is left, and how to
|
|
79
|
-
work so that either ending stays cheap. One warning at 70% is stale by the time
|
|
80
|
-
it matters, and the agent cannot see its own token count.
|
|
76
|
+
working and one demand at the end of the turn. Prompts between tiers get nothing.
|
|
81
77
|
|
|
82
78
|
Can be disabled per machine via a gitignored ethlete-agents.config.local.json
|
|
83
79
|
at the repo root: {"disableHooks": true} or {"disableHooks": ["context-warning"]}.
|
|
@@ -104,8 +100,6 @@ WARN_FRACTION = 0.70
|
|
|
104
100
|
CRITICAL_FRACTION = 0.85
|
|
105
101
|
FINAL_FRACTION = 0.95
|
|
106
102
|
|
|
107
|
-
# How to work once the budget is tight - repeated on every prompt from the first
|
|
108
|
-
# warning on, so it stays in view as the budget shrinks.
|
|
109
103
|
HANDOFF_MODE = (
|
|
110
104
|
"Work in slices that each end in a committable state. Send bulky reads, searches and "
|
|
111
105
|
"test runs to a sub-agent so their output stays out of this context. Write down each "
|
|
@@ -757,23 +751,6 @@ def stop_messages(profile, tier, tokens, budget, priced):
|
|
|
757
751
|
)
|
|
758
752
|
|
|
759
753
|
|
|
760
|
-
def reminder(tier, tokens, budget, priced):
|
|
761
|
-
"""The short note repeated on every prompt after a tier was already warned about.
|
|
762
|
-
|
|
763
|
-
A single warning at 70% is stale by the time the budget is actually tight, and the
|
|
764
|
-
agent has no way to read its own token count between prompts.
|
|
765
|
-
"""
|
|
766
|
-
stop = (
|
|
767
|
-
" You were already told to hand off. Do not take on new work."
|
|
768
|
-
if tier >= 2
|
|
769
|
-
else ""
|
|
770
|
-
)
|
|
771
|
-
return (
|
|
772
|
-
f"[context-warning hook] Handoff mode is active: {headroom(tokens, budget)} left of "
|
|
773
|
-
f"the {budget // 1000}k {limit_name(priced)}. {HANDOFF_MODE}{stop}"
|
|
774
|
-
)
|
|
775
|
-
|
|
776
|
-
|
|
777
754
|
SUBAGENT_HAND_BACK = (
|
|
778
755
|
"Finish only the atomic edit in flight - start nothing new. Commit what is committable, "
|
|
779
756
|
"then end your run with the hand-back report to the parent agent: what is done (with the "
|
|
@@ -811,15 +788,6 @@ def subagent_stop_message(tier, tokens, budget, priced):
|
|
|
811
788
|
)
|
|
812
789
|
|
|
813
790
|
|
|
814
|
-
def subagent_reminder(tokens, budget, priced):
|
|
815
|
-
return (
|
|
816
|
-
f"[context-warning hook] Handoff mode is active for this sub-agent thread, not the "
|
|
817
|
-
f"parent/main agent: {headroom(tokens, budget)} left of its {budget // 1000}k "
|
|
818
|
-
f"{limit_name(priced)}. Keep findings compact and send them to the parent agent "
|
|
819
|
-
f"before the budget runs out. Do not create a user-facing session handoff."
|
|
820
|
-
)
|
|
821
|
-
|
|
822
|
-
|
|
823
791
|
def emit(event, additional_context, system_message=None):
|
|
824
792
|
payload = {
|
|
825
793
|
"hookSpecificOutput": {
|
|
@@ -971,16 +939,6 @@ def main():
|
|
|
971
939
|
# Below the first threshold, or the context shrank - the state was re-armed above.
|
|
972
940
|
if tier == 0:
|
|
973
941
|
return
|
|
974
|
-
# Only a prompt repeats the reminder. On a tool batch it would be re-injected before
|
|
975
|
-
# every model request, which costs more context than it saves.
|
|
976
|
-
if event != "UserPromptSubmit":
|
|
977
|
-
return
|
|
978
|
-
emit(
|
|
979
|
-
event,
|
|
980
|
-
subagent_reminder(tokens, budget, priced)
|
|
981
|
-
if is_subagent
|
|
982
|
-
else reminder(tier, tokens, budget, priced),
|
|
983
|
-
)
|
|
984
942
|
return
|
|
985
943
|
|
|
986
944
|
if is_subagent:
|