claude-dev-env 8.114.4 → 8.114.6
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/skills/orchestrator/reference/oversee-delegated-work.md +1 -1
- package/bin/ever-registered-hooks.mjs +189 -0
- package/bin/ever-registered-hooks.test.mjs +28 -0
- package/bin/install.mjs +80 -26
- package/bin/install.prune.test.mjs +152 -0
- package/bin/install.test.mjs +52 -0
- package/docs/agents-guidance/asks.md +1 -1
- package/docs/rule-guides/verified-work.md +1 -1
- package/hooks/blocking/chat_reply_gate.py +25 -11
- package/hooks/blocking/test_chat_reply_gate.py +78 -4
- package/hooks/features/conduct-gates.md +4 -4
- package/hooks/features/spawn-routing.md +2 -2
- package/hooks/hooks_constants/chat_reply_gate_constants.py +2 -0
- package/hooks/hooks_constants/once_per_session_constants.py +29 -0
- package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +3 -2
- package/hooks/hooks_constants/spawn_oversight_hook_constants.py +1 -0
- package/hooks/once_per_session.py +107 -0
- package/hooks/routing/spawn_oversight_hook.py +17 -7
- package/hooks/routing/test_spawn_oversight_hook.py +89 -0
- package/hooks/session/test_tracking_nudge.py +79 -5
- package/hooks/session/tracking_nudge.py +25 -7
- package/hooks/test_once_per_session.py +109 -0
- package/package.json +1 -1
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import importlib
|
|
2
2
|
import io
|
|
3
3
|
import json
|
|
4
|
+
import os
|
|
4
5
|
import subprocess
|
|
5
6
|
import sys
|
|
7
|
+
import tempfile
|
|
6
8
|
from pathlib import Path
|
|
7
9
|
|
|
8
10
|
import pytest
|
|
9
11
|
|
|
12
|
+
from hooks_constants.open_tasks_stop_gate_constants import TASK_LIST_NUDGE
|
|
13
|
+
|
|
10
14
|
_SESSION_DIR = Path(__file__).resolve().parent
|
|
11
15
|
if str(_SESSION_DIR) not in sys.path:
|
|
12
16
|
sys.path.insert(0, str(_SESSION_DIR))
|
|
@@ -34,16 +38,19 @@ def run_nudge(
|
|
|
34
38
|
tmp_path: Path,
|
|
35
39
|
prompt_text: str,
|
|
36
40
|
all_entries: list[dict[str, object]],
|
|
41
|
+
session_id: str | None = None,
|
|
37
42
|
) -> str:
|
|
38
43
|
transcript_path = tmp_path / "s.jsonl"
|
|
39
44
|
transcript_path.write_text(
|
|
40
45
|
"\n".join(json.dumps(each) for each in all_entries), encoding="utf-8"
|
|
41
46
|
)
|
|
42
|
-
hook_input = {
|
|
47
|
+
hook_input: dict[str, object] = {
|
|
43
48
|
"hook_event_name": "UserPromptSubmit",
|
|
44
49
|
"prompt": prompt_text,
|
|
45
50
|
"transcript_path": str(transcript_path),
|
|
46
51
|
}
|
|
52
|
+
if session_id is not None:
|
|
53
|
+
hook_input["session_id"] = session_id
|
|
47
54
|
monkeypatch.setattr(
|
|
48
55
|
"sys.stdin", io.TextIOWrapper(io.BytesIO(json.dumps(hook_input).encode("utf-8")))
|
|
49
56
|
)
|
|
@@ -62,10 +69,43 @@ def test_should_remind_a_work_prompt_to_use_the_task_list(
|
|
|
62
69
|
context_text = run_nudge(
|
|
63
70
|
monkeypatch, capsys, tmp_path, "Export the APKs", titled_entries("⏳ Export")
|
|
64
71
|
)
|
|
65
|
-
assert "
|
|
72
|
+
assert "the session's task list tool" in context_text
|
|
73
|
+
assert "TaskCreate" not in context_text
|
|
66
74
|
assert "⏳ Export" not in context_text
|
|
67
75
|
|
|
68
76
|
|
|
77
|
+
COMPACTION_ENTRY = {"type": "system", "subtype": "compact_boundary"}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_should_add_the_task_list_note_once_per_session_and_again_after_a_compaction(
|
|
81
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
82
|
+
) -> None:
|
|
83
|
+
monkeypatch.setattr(tempfile, "gettempdir", lambda: str(tmp_path))
|
|
84
|
+
entries = titled_entries("⏳ Export")
|
|
85
|
+
|
|
86
|
+
def nudge(prompt_text: str, all_entries: list[dict[str, object]]) -> str:
|
|
87
|
+
return run_nudge(monkeypatch, capsys, tmp_path, prompt_text, all_entries, "session_one")
|
|
88
|
+
|
|
89
|
+
assert nudge("thanks!", entries) == ""
|
|
90
|
+
assert TASK_LIST_NUDGE in nudge("Export the APKs", entries)
|
|
91
|
+
assert nudge("Now sign the APKs", entries) == ""
|
|
92
|
+
assert TASK_LIST_NUDGE in nudge("Upload the APKs", [*entries, COMPACTION_ENTRY])
|
|
93
|
+
assert nudge("Tag the release", [*entries, COMPACTION_ENTRY]) == ""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_should_keep_the_title_note_on_each_ask_after_the_task_list_note_shows(
|
|
97
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
98
|
+
) -> None:
|
|
99
|
+
monkeypatch.setattr(tempfile, "gettempdir", lambda: str(tmp_path))
|
|
100
|
+
entries = titled_entries("\U0001f6a9 Merge approval")
|
|
101
|
+
run_nudge(monkeypatch, capsys, tmp_path, "Export the APKs", entries, "session_one")
|
|
102
|
+
second_text = run_nudge(
|
|
103
|
+
monkeypatch, capsys, tmp_path, "Now sign the APKs", entries, "session_one"
|
|
104
|
+
)
|
|
105
|
+
assert TASK_LIST_NUDGE not in second_text
|
|
106
|
+
assert "\U0001f6a9 Merge approval" in second_text
|
|
107
|
+
|
|
108
|
+
|
|
69
109
|
@pytest.mark.parametrize("earlier_title", ["\U0001f6a9 Merge approval", "✅ Gate"])
|
|
70
110
|
def test_should_ask_to_refresh_a_title_that_says_the_session_waits_or_is_done(
|
|
71
111
|
monkeypatch: pytest.MonkeyPatch,
|
|
@@ -104,8 +144,8 @@ def test_should_skip_the_title_note_in_a_session_without_the_title_tool() -> Non
|
|
|
104
144
|
|
|
105
145
|
|
|
106
146
|
def test_should_build_the_note_only_for_a_work_prompt() -> None:
|
|
107
|
-
assert tracking_nudge.ask_tracking_context("did it fail?", []) is None
|
|
108
|
-
assert "task list" in (tracking_nudge.ask_tracking_context("Export the APKs", []) or "")
|
|
147
|
+
assert tracking_nudge.ask_tracking_context("did it fail?", [], {}) is None
|
|
148
|
+
assert "task list" in (tracking_nudge.ask_tracking_context("Export the APKs", [], {}) or "")
|
|
109
149
|
|
|
110
150
|
|
|
111
151
|
def test_should_print_the_documented_output_through_a_subprocess(tmp_path: Path) -> None:
|
|
@@ -121,4 +161,38 @@ def test_should_print_the_documented_output_through_a_subprocess(tmp_path: Path)
|
|
|
121
161
|
assert completed_process.returncode == 0
|
|
122
162
|
hook_output = json.loads(completed_process.stdout)["hookSpecificOutput"]
|
|
123
163
|
assert hook_output["hookEventName"] == "UserPromptSubmit"
|
|
124
|
-
assert "
|
|
164
|
+
assert "the session's task list tool" in hook_output["additionalContext"]
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_replay_of_two_asks_and_a_compaction_through_the_script(tmp_path: Path) -> None:
|
|
168
|
+
transcript_path = tmp_path / "session.jsonl"
|
|
169
|
+
transcript_path.write_text(json.dumps({"type": "user"}) + "\n", encoding="utf-8")
|
|
170
|
+
environment = {**os.environ, "TMP": str(tmp_path), "TEMP": str(tmp_path), "TMPDIR": str(tmp_path)}
|
|
171
|
+
|
|
172
|
+
def replay_ask(prompt_text: str) -> str:
|
|
173
|
+
hook_input = {
|
|
174
|
+
"hook_event_name": "UserPromptSubmit",
|
|
175
|
+
"session_id": "session_one",
|
|
176
|
+
"prompt": prompt_text,
|
|
177
|
+
"transcript_path": str(transcript_path),
|
|
178
|
+
}
|
|
179
|
+
return subprocess.run(
|
|
180
|
+
[sys.executable, str(NUDGE_PATH)],
|
|
181
|
+
input=json.dumps(hook_input),
|
|
182
|
+
capture_output=True,
|
|
183
|
+
text=True,
|
|
184
|
+
env=environment,
|
|
185
|
+
check=True,
|
|
186
|
+
).stdout
|
|
187
|
+
|
|
188
|
+
first_stdout = replay_ask("Export the APKs")
|
|
189
|
+
second_stdout = replay_ask("Now sign the APKs")
|
|
190
|
+
with transcript_path.open("a", encoding="utf-8") as transcript:
|
|
191
|
+
transcript.write(json.dumps(COMPACTION_ENTRY) + "\n")
|
|
192
|
+
after_compaction_stdout = replay_ask("Upload the APKs")
|
|
193
|
+
assert TASK_LIST_NUDGE in json.loads(first_stdout)["hookSpecificOutput"]["additionalContext"]
|
|
194
|
+
assert second_stdout == ""
|
|
195
|
+
assert (
|
|
196
|
+
TASK_LIST_NUDGE
|
|
197
|
+
in json.loads(after_compaction_stdout)["hookSpecificOutput"]["additionalContext"]
|
|
198
|
+
)
|
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
The user follows a session in two places: the task list shows what the agent
|
|
5
5
|
does, and the title's status emoji shows whether the session needs them. A new
|
|
6
6
|
ask changes both, so the hook adds one short ``additionalContext`` note when the
|
|
7
|
-
prompt asks for work
|
|
7
|
+
prompt asks for work. The task list note shows on the session's first ask and
|
|
8
|
+
on the first ask after each compaction::
|
|
8
9
|
|
|
9
|
-
"Export the APKs"
|
|
10
|
+
"Export the APKs", first ask -> task list note
|
|
10
11
|
"Export the APKs", title shows a red flag or a check mark
|
|
11
12
|
-> task list note + title note
|
|
13
|
+
"Sign the APKs", a later ask -> nothing, or the title note
|
|
12
14
|
"did the export fail?" -> nothing
|
|
13
15
|
"<task-notification>...</task-notification>"
|
|
14
16
|
-> nothing
|
|
@@ -22,6 +24,7 @@ from __future__ import annotations
|
|
|
22
24
|
|
|
23
25
|
import json
|
|
24
26
|
import sys
|
|
27
|
+
from collections.abc import Mapping
|
|
25
28
|
from pathlib import Path
|
|
26
29
|
|
|
27
30
|
hooks_root_directory = str(Path(__file__).resolve().parent.parent)
|
|
@@ -36,6 +39,7 @@ from hooks_constants.open_tasks_stop_gate_constants import (
|
|
|
36
39
|
PROMPT_KEY,
|
|
37
40
|
PROMPT_SUBMIT_EVENT_NAME,
|
|
38
41
|
TASK_LIST_NUDGE,
|
|
42
|
+
TASK_LIST_NUDGE_ONCE_MARKER_NAME,
|
|
39
43
|
TRANSCRIPT_PATH_KEY,
|
|
40
44
|
WORD_SEPARATOR,
|
|
41
45
|
)
|
|
@@ -45,6 +49,7 @@ from hooks_constants.session_title_constants import (
|
|
|
45
49
|
TITLE_NUDGE_TEMPLATE,
|
|
46
50
|
TITLE_TOOL_DISPLAY_SEPARATOR,
|
|
47
51
|
)
|
|
52
|
+
from once_per_session import claim_first_showing
|
|
48
53
|
from open_task_asks import is_ask
|
|
49
54
|
from session_title_turn_gate import (
|
|
50
55
|
available_title_tools,
|
|
@@ -82,12 +87,25 @@ def title_nudge(all_entries: list[dict[str, object]]) -> str | None:
|
|
|
82
87
|
)
|
|
83
88
|
|
|
84
89
|
|
|
85
|
-
def ask_tracking_context(
|
|
86
|
-
|
|
90
|
+
def ask_tracking_context(
|
|
91
|
+
prompt_text: str,
|
|
92
|
+
all_entries: list[dict[str, object]],
|
|
93
|
+
all_hook_fields: Mapping[str, object],
|
|
94
|
+
) -> str | None:
|
|
95
|
+
"""Return the note for a prompt that asks for work, or None for any other prompt.
|
|
96
|
+
|
|
97
|
+
The task list note shows on the session's first ask and on the first ask
|
|
98
|
+
after each compaction. The title note shows on every ask while the title is stale.
|
|
99
|
+
"""
|
|
87
100
|
if not is_ask(prompt_text):
|
|
88
101
|
return None
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
tracker_note = (
|
|
103
|
+
TASK_LIST_NUDGE
|
|
104
|
+
if claim_first_showing(TASK_LIST_NUDGE_ONCE_MARKER_NAME, all_hook_fields)
|
|
105
|
+
else None
|
|
106
|
+
)
|
|
107
|
+
all_notes = [tracker_note, title_nudge(all_entries)]
|
|
108
|
+
return WORD_SEPARATOR.join(each_note for each_note in all_notes if each_note) or None
|
|
91
109
|
|
|
92
110
|
|
|
93
111
|
def main() -> int:
|
|
@@ -96,7 +114,7 @@ def main() -> int:
|
|
|
96
114
|
if hook_input is None or not isinstance(prompt_value, str):
|
|
97
115
|
return ALLOW_EXIT_CODE
|
|
98
116
|
context_text = ask_tracking_context(
|
|
99
|
-
prompt_value, read_transcript_entries(hook_input.get(TRANSCRIPT_PATH_KEY))
|
|
117
|
+
prompt_value, read_transcript_entries(hook_input.get(TRANSCRIPT_PATH_KEY)), hook_input
|
|
100
118
|
)
|
|
101
119
|
if context_text:
|
|
102
120
|
hook_output = {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import tempfile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from once_per_session import (
|
|
8
|
+
claim_first_showing,
|
|
9
|
+
clear_showings,
|
|
10
|
+
compaction_count,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
CLAUDE_COMPACTION_LINE = json.dumps({"type": "system", "subtype": "compact_boundary"})
|
|
14
|
+
CODEX_COMPACTION_LINE = json.dumps({"type": "compacted", "payload": {"message": ""}})
|
|
15
|
+
QUOTED_COMPACTION_LINE = json.dumps(
|
|
16
|
+
{"type": "user", "message": {"content": 'grep output: {"subtype": "compact_boundary"}'}}
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.fixture
|
|
21
|
+
def transcript_path(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path:
|
|
22
|
+
monkeypatch.setattr(tempfile, "gettempdir", lambda: str(tmp_path))
|
|
23
|
+
session_transcript = tmp_path / "session.jsonl"
|
|
24
|
+
session_transcript.write_text(json.dumps({"type": "user"}) + "\n", encoding="utf-8")
|
|
25
|
+
return session_transcript
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _append(transcript_path: Path, transcript_line: str) -> None:
|
|
29
|
+
with transcript_path.open("a", encoding="utf-8") as transcript:
|
|
30
|
+
transcript.write(transcript_line + "\n")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _fields(transcript_path: Path, **all_extra_fields: object) -> dict[str, object]:
|
|
34
|
+
return {"session_id": "s1", "transcript_path": str(transcript_path), **all_extra_fields}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_should_show_once_per_session(transcript_path: Path) -> None:
|
|
38
|
+
assert claim_first_showing("hook", _fields(transcript_path)) is True
|
|
39
|
+
assert claim_first_showing("hook", _fields(transcript_path)) is False
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_should_keep_each_hook_and_session_apart(transcript_path: Path) -> None:
|
|
43
|
+
assert claim_first_showing("hook", _fields(transcript_path)) is True
|
|
44
|
+
assert claim_first_showing("other_hook", _fields(transcript_path)) is True
|
|
45
|
+
assert claim_first_showing("hook", _fields(transcript_path, session_id="s2")) is True
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_should_give_a_subagent_its_own_showing(transcript_path: Path) -> None:
|
|
49
|
+
assert claim_first_showing("hook", _fields(transcript_path)) is True
|
|
50
|
+
assert claim_first_showing("hook", _fields(transcript_path, agent_id="a1")) is True
|
|
51
|
+
assert claim_first_showing("hook", _fields(transcript_path, agent_id="a1")) is False
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@pytest.mark.parametrize("compaction_line", [CLAUDE_COMPACTION_LINE, CODEX_COMPACTION_LINE])
|
|
55
|
+
def test_should_show_again_after_a_compaction(transcript_path: Path, compaction_line: str) -> None:
|
|
56
|
+
assert claim_first_showing("hook", _fields(transcript_path)) is True
|
|
57
|
+
_append(transcript_path, compaction_line)
|
|
58
|
+
assert claim_first_showing("hook", _fields(transcript_path)) is True
|
|
59
|
+
assert claim_first_showing("hook", _fields(transcript_path)) is False
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_should_not_count_a_quoted_compaction_marker(transcript_path: Path) -> None:
|
|
63
|
+
_append(transcript_path, QUOTED_COMPACTION_LINE)
|
|
64
|
+
_append(transcript_path, "not json compact_boundary")
|
|
65
|
+
assert compaction_count(str(transcript_path)) == 0
|
|
66
|
+
_append(transcript_path, CLAUDE_COMPACTION_LINE)
|
|
67
|
+
assert compaction_count(str(transcript_path)) == 1
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_should_skip_a_line_that_is_not_utf8(transcript_path: Path) -> None:
|
|
71
|
+
with transcript_path.open("ab") as transcript:
|
|
72
|
+
transcript.write(b'{"subtype": "compact_boundary\xff"}\n')
|
|
73
|
+
_append(transcript_path, CLAUDE_COMPACTION_LINE)
|
|
74
|
+
assert compaction_count(str(transcript_path)) == 1
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@pytest.mark.parametrize("transcript_value", [None, "", 7])
|
|
78
|
+
def test_should_count_no_compaction_without_a_readable_transcript(
|
|
79
|
+
tmp_path: Path, transcript_value: object
|
|
80
|
+
) -> None:
|
|
81
|
+
assert compaction_count(transcript_value) == 0
|
|
82
|
+
assert compaction_count(str(tmp_path / "absent.jsonl")) == 0
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@pytest.mark.parametrize("session_value", [None, "", 7])
|
|
86
|
+
def test_should_show_every_time_without_a_session_id(
|
|
87
|
+
transcript_path: Path, session_value: object
|
|
88
|
+
) -> None:
|
|
89
|
+
all_fields = _fields(transcript_path, session_id=session_value)
|
|
90
|
+
assert claim_first_showing("hook", all_fields) is True
|
|
91
|
+
assert claim_first_showing("hook", all_fields) is True
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_should_clear_only_the_ended_session_markers(transcript_path: Path) -> None:
|
|
95
|
+
claim_first_showing("hook", _fields(transcript_path))
|
|
96
|
+
claim_first_showing("other_hook", _fields(transcript_path, agent_id="a1"))
|
|
97
|
+
claim_first_showing("hook", _fields(transcript_path, session_id="s2"))
|
|
98
|
+
clear_showings("s1")
|
|
99
|
+
assert claim_first_showing("hook", _fields(transcript_path)) is True
|
|
100
|
+
assert claim_first_showing("other_hook", _fields(transcript_path, agent_id="a1")) is True
|
|
101
|
+
assert claim_first_showing("hook", _fields(transcript_path, session_id="s2")) is False
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_should_show_every_time_when_the_marker_cannot_be_written(
|
|
105
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
106
|
+
) -> None:
|
|
107
|
+
monkeypatch.setattr(tempfile, "gettempdir", lambda: str(tmp_path / "absent_directory"))
|
|
108
|
+
assert claim_first_showing("hook", {"session_id": "s1"}) is True
|
|
109
|
+
assert claim_first_showing("hook", {"session_id": "s1"}) is True
|