claude-dev-env 8.117.4 → 8.118.0
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/bin/ever-registered-hooks.mjs +1 -0
- package/docs/agents-guidance/asks.md +4 -0
- package/docs/references/advisor-tool.md +2 -0
- package/hooks/blocking/task_subject_outcome_gate.py +110 -0
- package/hooks/blocking/test_task_subject_outcome_gate.py +129 -0
- package/hooks/features/conduct-gates.md +3 -0
- package/hooks/features/session-context.md +3 -3
- package/hooks/hooks.json +5 -0
- package/hooks/hooks_constants/advisor_rules_prompt_constants.py +14 -6
- package/hooks/hooks_constants/task_subject_outcome_constants.py +37 -0
- package/hooks/session/advisor_rules_prompt.py +53 -9
- package/hooks/session/test_advisor_rules_prompt.py +70 -4
- package/package.json +1 -1
- package/scripts/policy_lint/adapter_configuration.py +5 -0
- package/scripts/policy_lint/config/constants.py +1 -0
- package/scripts/tests/test_adapter_configuration.py +8 -0
|
@@ -100,6 +100,7 @@ export const EVER_REGISTERED_HOOK_RELATIVE_PATHS = new Set([
|
|
|
100
100
|
'blocking/subagent_model_routing.mjs',
|
|
101
101
|
'blocking/subprocess_budget_completeness.py',
|
|
102
102
|
'blocking/task_subject_length_gate.py',
|
|
103
|
+
'blocking/task_subject_outcome_gate.py',
|
|
103
104
|
'blocking/tdd-enforcer.py',
|
|
104
105
|
'blocking/tdd_enforcer.py',
|
|
105
106
|
'blocking/test-preflight-check.py',
|
|
@@ -14,6 +14,8 @@ Work every ask from the user now, without pause, until it is done with proof you
|
|
|
14
14
|
- Record each ask as one item in the session tracker: `TaskCreate`, `TodoWrite`, or the Codex `update_plan` tool. The user follows your work there.
|
|
15
15
|
- Keep each item's status current as the work moves: in progress when you start it, completed only after you saw the proof. A long turn updates the list at each step, so the list never lags the work.
|
|
16
16
|
- An item blocked on the user stays open, and the reply says what the user must give.
|
|
17
|
+
- Name each item by its outcome in the user's words, so the user sees at a glance where the work stands and what is left. Keep internal procedure steps, playbook step names, and skill names out of the list the user follows. Put them in a private checklist file, such as `todo.md` in the work folder.
|
|
18
|
+
- When the user asks where things stand, answer with what is done, what is being built, what is left, and what needs the user.
|
|
17
19
|
|
|
18
20
|
## Completion reports
|
|
19
21
|
|
|
@@ -45,6 +47,8 @@ The gate holds a turn once when all three hold:
|
|
|
45
47
|
|
|
46
48
|
The gate never reads the reply text. A held turn passes, so the gate adds at most one step to a turn.
|
|
47
49
|
|
|
50
|
+
In Claude Code, `task_subject_outcome_gate.py` denies a task list item named as a procedure step. [Conduct gates](../../hooks/features/conduct-gates.md) lists what it matches.
|
|
51
|
+
|
|
48
52
|
In Claude Code, `tracking_nudge.py` runs on `UserPromptSubmit`. For the session's first prompt that asks for work, and the first after each compaction, it adds one note that asks for an item in the session's task list tool, so the agent tracks the ask before it starts. The note never blocks.
|
|
49
53
|
|
|
50
54
|
## Cursor
|
|
@@ -26,6 +26,8 @@ On tasks longer than a few steps, aim for an early approach consult and a comple
|
|
|
26
26
|
|
|
27
27
|
Call for design, architecture, and risk questions where you will not touch a file. If the response would be analysis or a recommendation with no other tool calls, call first. That judgment is where a second opinion is highest value. Simple factual lookups and arithmetic do not need a call.
|
|
28
28
|
|
|
29
|
+
A session that runs on the advisor model itself plans no advisor consults. A consult there would ask the same model for a second opinion. The rules on this page, the hard rule included, apply only to a session on another model. [Session context hooks](../../hooks/features/session-context.md) covers how the SessionStart prompt tells the two apart.
|
|
30
|
+
|
|
29
31
|
## Hard rule
|
|
30
32
|
|
|
31
33
|
Your first write, edit, or state-changing shell call on a task must be preceded by an advisor call in the same or an earlier turn. Read-only orientation (`ls`, `cat`, `grep`, `find`, and harness equivalents) is not state-changing. This is a checkpoint, not a difficulty judgment. It applies to one-line edits too.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""PreToolUse hook that keeps procedure steps out of the task list the user follows.
|
|
3
|
+
|
|
4
|
+
The gate reads each subject a TaskCreate or TaskUpdate call sets, and the
|
|
5
|
+
content of each item a TodoWrite call writes. It denies the call when a subject
|
|
6
|
+
carries one of these markers:
|
|
7
|
+
|
|
8
|
+
- It starts with a procedure step label: step, phase, stage, part, feature,
|
|
9
|
+
bug fix, refactoring, or playbook, then a number or a range of one or two
|
|
10
|
+
digits, then a colon, a closing parenthesis, or a period that no digit
|
|
11
|
+
follows, so a version such as 2.0 passes.
|
|
12
|
+
- It holds a backtick, the mark of a code-formatted name.
|
|
13
|
+
|
|
14
|
+
A call with no string subject passes, so a status-only TaskUpdate keeps working.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import sys
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
hooks_root_directory = str(Path(__file__).resolve().parent.parent)
|
|
23
|
+
if hooks_root_directory not in sys.path:
|
|
24
|
+
sys.path.insert(0, hooks_root_directory)
|
|
25
|
+
|
|
26
|
+
from hooks_constants.hook_block_logger import log_hook_block
|
|
27
|
+
from hooks_constants.pre_tool_use_stdin import read_hook_input_dictionary_from_stdin
|
|
28
|
+
from hooks_constants.task_subject_outcome_constants import (
|
|
29
|
+
ALL_SUBJECT_TOOL_NAMES,
|
|
30
|
+
ALLOW_EXIT_CODE,
|
|
31
|
+
BLOCK_EXIT_CODE,
|
|
32
|
+
CODE_SPAN_MARKER,
|
|
33
|
+
CODE_SPAN_MESSAGE,
|
|
34
|
+
GATE_EVENT_NAME,
|
|
35
|
+
PROCEDURE_STEP_MESSAGE,
|
|
36
|
+
PROCEDURE_STEP_PREFIX_PATTERN,
|
|
37
|
+
RETRY_INSTRUCTION,
|
|
38
|
+
TASK_SUBJECT_KEY,
|
|
39
|
+
TODO_CONTENT_KEY,
|
|
40
|
+
TODO_WRITE_TOOL_NAME,
|
|
41
|
+
TODOS_KEY,
|
|
42
|
+
TOOL_INPUT_KEY,
|
|
43
|
+
TOOL_NAME_KEY,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def task_subject_violation(subject: str) -> str | None:
|
|
48
|
+
"""Return the message for the marker a task subject carries, or None when it reads as an outcome.
|
|
49
|
+
|
|
50
|
+
>>> task_subject_violation("PR 2347 merged with checks green") is None
|
|
51
|
+
True
|
|
52
|
+
>>> task_subject_violation("Feature 3: Write the checkpoint").startswith("The task subject")
|
|
53
|
+
True
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
subject: The wording the task list would show the user.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
The message for the marker, or None.
|
|
60
|
+
"""
|
|
61
|
+
if PROCEDURE_STEP_PREFIX_PATTERN.match(subject):
|
|
62
|
+
return PROCEDURE_STEP_MESSAGE.format(subject=subject)
|
|
63
|
+
if CODE_SPAN_MARKER in subject:
|
|
64
|
+
return CODE_SPAN_MESSAGE.format(subject=subject)
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _subjects_in_call(tool_name: str, all_tool_input_fields: dict[str, object]) -> list[str]:
|
|
69
|
+
if tool_name in ALL_SUBJECT_TOOL_NAMES:
|
|
70
|
+
subject = all_tool_input_fields.get(TASK_SUBJECT_KEY)
|
|
71
|
+
return [subject] if isinstance(subject, str) else []
|
|
72
|
+
if tool_name != TODO_WRITE_TOOL_NAME:
|
|
73
|
+
return []
|
|
74
|
+
all_todo_entries = all_tool_input_fields.get(TODOS_KEY)
|
|
75
|
+
if not isinstance(all_todo_entries, list):
|
|
76
|
+
return []
|
|
77
|
+
return [
|
|
78
|
+
each_entry[TODO_CONTENT_KEY]
|
|
79
|
+
for each_entry in all_todo_entries
|
|
80
|
+
if isinstance(each_entry, dict) and isinstance(each_entry.get(TODO_CONTENT_KEY), str)
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def main() -> int:
|
|
85
|
+
hook_input = read_hook_input_dictionary_from_stdin()
|
|
86
|
+
if hook_input is None:
|
|
87
|
+
return ALLOW_EXIT_CODE
|
|
88
|
+
tool_name = hook_input.get(TOOL_NAME_KEY)
|
|
89
|
+
tool_input = hook_input.get(TOOL_INPUT_KEY)
|
|
90
|
+
if not isinstance(tool_name, str) or not isinstance(tool_input, dict):
|
|
91
|
+
return ALLOW_EXIT_CODE
|
|
92
|
+
for each_subject in _subjects_in_call(tool_name, tool_input):
|
|
93
|
+
violation = task_subject_violation(each_subject)
|
|
94
|
+
if violation is None:
|
|
95
|
+
continue
|
|
96
|
+
block_reason = violation + RETRY_INSTRUCTION
|
|
97
|
+
log_hook_block(
|
|
98
|
+
Path(__file__).name,
|
|
99
|
+
GATE_EVENT_NAME,
|
|
100
|
+
block_reason,
|
|
101
|
+
tool_name=tool_name,
|
|
102
|
+
offending_input_preview=each_subject,
|
|
103
|
+
)
|
|
104
|
+
sys.stderr.write(block_reason)
|
|
105
|
+
return BLOCK_EXIT_CODE
|
|
106
|
+
return ALLOW_EXIT_CODE
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
sys.exit(main())
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
import task_subject_outcome_gate
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def run_gate(
|
|
11
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
12
|
+
capsys: pytest.CaptureFixture[str],
|
|
13
|
+
tool_name: str,
|
|
14
|
+
tool_input: object,
|
|
15
|
+
) -> tuple[int, str]:
|
|
16
|
+
hook_input = {"hook_event_name": "PreToolUse", "tool_name": tool_name, "tool_input": tool_input}
|
|
17
|
+
monkeypatch.setattr(
|
|
18
|
+
"sys.stdin", io.TextIOWrapper(io.BytesIO(json.dumps(hook_input).encode("utf-8")))
|
|
19
|
+
)
|
|
20
|
+
exit_code = task_subject_outcome_gate.main()
|
|
21
|
+
return exit_code, capsys.readouterr().err
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@pytest.fixture(autouse=True)
|
|
25
|
+
def isolated_home(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
|
26
|
+
monkeypatch.setenv("HOME", str(tmp_path))
|
|
27
|
+
monkeypatch.setenv("USERPROFILE", str(tmp_path))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.mark.parametrize("tool_name", ["TaskCreate", "TaskUpdate"])
|
|
31
|
+
@pytest.mark.parametrize(
|
|
32
|
+
"subject",
|
|
33
|
+
[
|
|
34
|
+
"Task names in the list read as outcomes",
|
|
35
|
+
"PR 2347 merged with checks green",
|
|
36
|
+
"PR 12: checks green",
|
|
37
|
+
"Issue 7: closed with the fix linked",
|
|
38
|
+
"Merge PR #2347 once review is clean",
|
|
39
|
+
"Feature flag removed from the settings page",
|
|
40
|
+
"Step notes turn off when the user asks",
|
|
41
|
+
"Phase 2.0 released to all users",
|
|
42
|
+
],
|
|
43
|
+
)
|
|
44
|
+
def test_should_allow_a_plain_outcome_subject(
|
|
45
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
46
|
+
capsys: pytest.CaptureFixture[str],
|
|
47
|
+
tool_name: str,
|
|
48
|
+
subject: str,
|
|
49
|
+
) -> None:
|
|
50
|
+
assert run_gate(monkeypatch, capsys, tool_name, {"subject": subject}) == (0, "")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@pytest.mark.parametrize(
|
|
54
|
+
"subject",
|
|
55
|
+
[
|
|
56
|
+
"Feature 1: Investigate the affected subsystem",
|
|
57
|
+
"Feature 3: Write the throughput checkpoint",
|
|
58
|
+
"Feature 6-8: Rebase into small ordered commits, run Opening a PR",
|
|
59
|
+
"Step 3: run the tests",
|
|
60
|
+
"phase 2) migrate callers",
|
|
61
|
+
"Bug fix 4. Reproduce first",
|
|
62
|
+
"Bug fix 5: Reproduce first",
|
|
63
|
+
],
|
|
64
|
+
)
|
|
65
|
+
def test_should_deny_a_subject_that_starts_with_a_procedure_step_label(
|
|
66
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], subject: str
|
|
67
|
+
) -> None:
|
|
68
|
+
exit_code, stderr_text = run_gate(monkeypatch, capsys, "TaskCreate", {"subject": subject})
|
|
69
|
+
assert exit_code == 2
|
|
70
|
+
assert "procedure step label" in stderr_text
|
|
71
|
+
assert "by its outcome in the user's words" in stderr_text
|
|
72
|
+
assert "private checklist" in stderr_text
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_should_deny_a_subject_with_a_code_formatted_name(
|
|
76
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
77
|
+
) -> None:
|
|
78
|
+
exit_code, stderr_text = run_gate(
|
|
79
|
+
monkeypatch, capsys, "TaskUpdate", {"taskId": "3", "subject": "Run `how` over the hooks"}
|
|
80
|
+
)
|
|
81
|
+
assert exit_code == 2
|
|
82
|
+
assert "code-formatted name" in stderr_text
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_should_deny_a_todo_write_item_that_carries_a_marker(
|
|
86
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
87
|
+
) -> None:
|
|
88
|
+
all_todos = [
|
|
89
|
+
{"content": "Hook refuses procedure step names", "status": "completed"},
|
|
90
|
+
{"content": "Step 2: push the branch", "status": "pending"},
|
|
91
|
+
]
|
|
92
|
+
exit_code, stderr_text = run_gate(monkeypatch, capsys, "TodoWrite", {"todos": all_todos})
|
|
93
|
+
assert exit_code == 2
|
|
94
|
+
assert "Step 2: push the branch" in stderr_text
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_should_allow_todo_write_items_that_read_as_outcomes(
|
|
98
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
99
|
+
) -> None:
|
|
100
|
+
all_todos = [{"content": "Hook refuses procedure step names", "status": "in_progress"}]
|
|
101
|
+
assert run_gate(monkeypatch, capsys, "TodoWrite", {"todos": all_todos}) == (0, "")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@pytest.mark.parametrize(
|
|
105
|
+
("tool_name", "tool_input"),
|
|
106
|
+
[
|
|
107
|
+
("TaskUpdate", {"taskId": "3", "status": "completed"}),
|
|
108
|
+
("TaskCreate", "Step 1: not a dictionary"),
|
|
109
|
+
("Bash", {"subject": "Step 1: run"}),
|
|
110
|
+
("TodoWrite", {"todos": "Step 1: run"}),
|
|
111
|
+
],
|
|
112
|
+
)
|
|
113
|
+
def test_should_leave_other_tools_and_schemas_alone(
|
|
114
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
115
|
+
capsys: pytest.CaptureFixture[str],
|
|
116
|
+
tool_name: str,
|
|
117
|
+
tool_input: object,
|
|
118
|
+
) -> None:
|
|
119
|
+
assert run_gate(monkeypatch, capsys, tool_name, tool_input) == (0, "")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_task_subject_violation_should_return_none_for_an_outcome() -> None:
|
|
123
|
+
assert task_subject_outcome_gate.task_subject_violation("Hook refuses step names") is None
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_task_subject_violation_should_name_the_backtick_marker() -> None:
|
|
127
|
+
violation = task_subject_outcome_gate.task_subject_violation("Fix `gate.py`")
|
|
128
|
+
assert violation is not None
|
|
129
|
+
assert "code-formatted name" in violation
|
|
@@ -12,6 +12,7 @@ This family stops a chat reply, edited message, or tool call when its payload br
|
|
|
12
12
|
- `blocking/edit_marker_gate.py` rejects strikethrough and edit-note markers in replacement chat text or cards.
|
|
13
13
|
- `blocking/issue_close_handoff_gate.py` denies an issue comment or issue write that closes the issue and routes a found defect to another issue or epic.
|
|
14
14
|
- `blocking/session_title_format_gate.py` denies a session title that breaks the `<emoji> <name>` shape or has a name longer than 25 characters.
|
|
15
|
+
- `blocking/task_subject_outcome_gate.py` denies a TaskCreate or TaskUpdate subject, or a TodoWrite item, that starts with a procedure step label (step, phase, stage, part, feature, bug fix, refactoring, or playbook, then a one- or two-digit number or range, then `:`, `)`, or a `.` that no digit follows) or holds a backtick. The reason says to name the item by its outcome in the user's words and keep procedure steps in a private checklist file. A status-only TaskUpdate passes.
|
|
15
16
|
- `blocking/task_subject_length_gate.py` denies a `TaskCreate` or `TaskUpdate` whose `subject` is over 80 characters, and a `TodoWrite` whose list holds an item `content` over 80 characters, naming the first such item. The reason gives the length and the limit and says to start with who acts (Me, You, or Handed off), say what is left, and put detail in the description.
|
|
16
17
|
- `blocking/step_note_gate.py` requires a status line before a tool call while its opt-in flag is on.
|
|
17
18
|
- `blocking/wakeup_cap_gate.py` keeps a self-wakeup inside the 1-hour prompt cache. A wake over the step-down (57 minutes for `send_later` and Routines, 3480 seconds for `ScheduleWakeup`) and at most 60 minutes away runs with its delay rewritten to the step-down. A wake over 60 minutes away, or a cron with more than 57 minutes between wakes, is denied with a reason that says to stack wakes under the cap. A Routine that starts a fresh session on each firing passes.
|
|
@@ -36,6 +37,7 @@ This family stops a chat reply, edited message, or tool call when its payload br
|
|
|
36
37
|
- `blocking/edit_marker_gate.py` runs on `PreToolUse`, matcher `mcp__.*__update_message`, timeout `10` seconds in `hooks.json`.
|
|
37
38
|
- `blocking/issue_close_handoff_gate.py` runs on `PreToolUse`, matcher `mcp__.*__(add_issue_comment|issue_write|update_issue_comment)`, timeout `10` seconds in `hooks.json`.
|
|
38
39
|
- `blocking/session_title_format_gate.py` runs on `PreToolUse`, matcher `mcp__.*__set_session_title`, timeout `10` seconds in `hooks.json`.
|
|
40
|
+
- `blocking/task_subject_outcome_gate.py` runs on `PreToolUse`, matcher `TaskCreate|TaskUpdate|TodoWrite`, timeout `10` seconds in `hooks.json`, after the length gate in the same group. Like the length gate, it runs in Claude Code only.
|
|
39
41
|
- `blocking/task_subject_length_gate.py` runs on `PreToolUse`, matcher `TaskCreate|TaskUpdate|TodoWrite`, timeout `10` seconds in `hooks.json`. It runs in Claude Code only: the installer gives Codex only the PreToolUse group whose matcher is `multi_agent_v1__spawn_agent`, and gives Cursor only the hooks `bin/install-constants.mjs` names.
|
|
40
42
|
- `blocking/step_note_gate.py` runs on `PreToolUse`, matcher `*`, timeout `15` seconds in `hooks.json`.
|
|
41
43
|
- `blocking/question_brief_gate.py` runs on `PreToolUse`, matcher `AskUserQuestion`, timeout `10` seconds in `hooks.json`. Its transcript poll stops at 3 seconds.
|
|
@@ -65,6 +67,7 @@ Preconditions:
|
|
|
65
67
|
- **Edit marker.** Input is an update message with strikethrough or an edit note. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_edit_marker_gate.py -q`. The adjacent test observes a denial; clean replacement text passes.
|
|
66
68
|
- **Handoff close.** Input is an issue comment that says the issue is closed and that the found defect belongs to another issue. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_issue_close_handoff_gate.py -q`. The adjacent test observes a denial; a close with a plain cross-reference and a routing comment on an open issue both pass.
|
|
67
69
|
- **Session title.** Input is a set session title call with no leading emoji or a name over 25 characters. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_session_title_format_gate.py -q`. The adjacent test observes a denial that names the broken rule; a well-formed title passes.
|
|
70
|
+
- **Procedure step names.** Input is a TaskCreate subject `Feature 3: Write the throughput checkpoint`, a TaskUpdate subject with a backtick, and a TodoWrite item `Step 2: push the branch`. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_task_subject_outcome_gate.py -q`. The adjacent test observes a denial for each; `PR 12: checks green`, `PR 2347 merged with checks green`, and a status-only TaskUpdate pass.
|
|
68
71
|
- **Task subject.** Input is a `TaskCreate` call whose subject is a 229-character status sentence, then three short subjects that start with Me, You, and Handed off. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_task_subject_length_gate.py -q`. The adjacent test observes a denial that gives the status sentence's length and the limit, the short ones passing, 80 characters passing and 81 denied, a status-only `TaskUpdate` passing, and a `TodoWrite` denial that names its long item.
|
|
69
72
|
- **First title.** Input is a `UserPromptSubmit` payload with a work prompt, after a transcript that lists the title tool and holds no title call. Run `python -m pytest packages/claude-dev-env/hooks/session/test_tracking_nudge.py -q`. The adjacent test observes one note that names the tool and `⏳ <name>`, exit 0 and empty stderr. A second ask and an ask after a compaction get no such note. A session without the title tool, and a title that shows the hourglass, get no title note.
|
|
70
73
|
- **Step note.** Input is a tool call after a transcript message without a status line while the flag is on. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_step_note_gate.py -q`. The adjacent test observes a block until a status line appears.
|
|
@@ -8,7 +8,7 @@ This family injects reminders and task guidance when an agent starts, resumes, s
|
|
|
8
8
|
- `session/compaction_recall_prompt.py` returns every message the user typed after a compaction. `session/compaction_user_messages.py` reads them from a Claude Code transcript or a Codex rollout. `session/compaction_trim.py` trims each one in Python: it drops filler, articles, and gratitude, keeps approvals, continuation requests, backtick spans, and paths as typed, and marks a reversed message `(overruled by #N)`. No model runs, so the hook works on Claude Code and Codex with no account.
|
|
9
9
|
- `session/task_tool_prompt.py` injects a task tracking directive at session start.
|
|
10
10
|
- `session/working_style_prompt.py` injects the session's working style at session start.
|
|
11
|
-
- `session/advisor_rules_prompt.py` injects advisor guidance when the built-in advisor is enabled. For evidence on when an advisor pays, see [Subagents and fan-out](../../docs/model-choice/subagents-and-fan-out.md).
|
|
11
|
+
- `session/advisor_rules_prompt.py` injects advisor guidance when the built-in advisor is enabled. It stays silent when the SessionStart payload's `model` is the `advisorModel` value or is in its family, such as `claude-fable-5-2` against `fable`. When the payload has no `model`, the guidance names the advisor model and tells a session on that model to plan no consults. For evidence on when an advisor pays, see [Subagents and fan-out](../../docs/model-choice/subagents-and-fan-out.md).
|
|
12
12
|
- `session/orchestrator_auto_starter.py` injects an orchestrator directive when its environment flag is enabled.
|
|
13
13
|
- `session/plugin_session_baseline_writer.py` records each plugin's `version` and `installPath` from `installed_plugins.json` to a per-session file in the system temp folder. It writes on `startup`, or when the session has no baseline yet, and leaves an existing baseline alone on `resume`, `clear`, and `compact`.
|
|
14
14
|
- `session/plugin_change_warning.py` compares `installed_plugins.json` with that baseline before each prompt. It names each plugin whose version or install path changed, or that the baseline lacks, once per session, and tells the user to restart Claude Code.
|
|
@@ -38,7 +38,7 @@ Preconditions:
|
|
|
38
38
|
- **Compaction recall.** Input is a Claude Code transcript or a Codex rollout with typed, meta, sidechain, peer, and harness entries across a compaction. Run `python -m pytest packages/claude-dev-env/hooks/session/test_compaction_user_messages.py packages/claude-dev-env/hooks/session/test_compaction_trim.py packages/claude-dev-env/hooks/session/test_compaction_recall_prompt.py packages/claude-dev-env/hooks/session/test_compaction_trim_eval.py -q`. The tests observe only typed messages, a stable result across a second compaction, the trim rules, the recall budget, and the trimmed lines in the hook's `additionalContext`. `python packages/claude-dev-env/hooks/session/compaction_trim_eval.py` trims each fixture transcript with planted facts, prints the share of facts that survive, the reversals marked, and the compression ratio, and exits 1 on any loss.
|
|
39
39
|
- **Task tracking.** Input is a SessionStart event. Run `python -m pytest packages/claude-dev-env/hooks/session/test_task_tool_prompt.py -q`. The adjacent test observes a `SessionStart` context directive that names the task tool.
|
|
40
40
|
- **Working style.** Input is a SessionStart event. Run `python -m pytest packages/claude-dev-env/hooks/session/test_working_style_prompt.py -q`. The adjacent test observes the fixed context text.
|
|
41
|
-
- **Advisor guidance.** Input is SessionStart with `advisorModel` set. Run `python -m pytest packages/claude-dev-env/hooks/session/test_advisor_rules_prompt.py -q`. The adjacent test observes guidance only when the advisor setting is enabled.
|
|
41
|
+
- **Advisor guidance.** Input is SessionStart with `advisorModel` set. Run `python -m pytest packages/claude-dev-env/hooks/session/test_advisor_rules_prompt.py -q`. The adjacent test observes guidance only when the advisor setting is enabled and the payload's model is in another family or absent, and silence when the payload's model is the advisor model or shares its family.
|
|
42
42
|
- **Orchestrator start.** Input is SessionStart with its opt-in flag set. Run `python -m pytest packages/claude-dev-env/hooks/session/test_orchestrator_auto_starter.py -q`. The adjacent test observes an orchestrator directive.
|
|
43
43
|
- **Plugin restart warning.** Input is a SessionStart event, an `installed_plugins.json` change, and a prompt. Run `python -m pytest packages/claude-dev-env/hooks/session/test_plugin_session_baseline_writer.py packages/claude-dev-env/hooks/session/test_plugin_change_warning.py packages/claude-dev-env/hooks/test_plugin_session_baseline.py -q`. The tests observe one warning for a changed version, a changed install path, and a plugin new since start, silence on a `lastUpdated` refresh and on a second prompt, and a warning that still fires after a `compact` SessionStart.
|
|
44
44
|
- **Artifact template pointer.** Input is an `Artifact` quickstart call. Run `python -m pytest packages/claude-dev-env/hooks/session/test_artifact_template_pointer.py -q`. The adjacent test observes the status flowchart path first, the html-plan path ahead of the template path in `additionalContext`, and silence on a publish call or another skill.
|
|
@@ -51,6 +51,6 @@ Preconditions:
|
|
|
51
51
|
- The recall keeps the first message and the newest that fit in 6,000 characters, under the 2,500 token preview limit Codex applies to hook context. A message over 1,500 characters is cut, and the line says how much was left out.
|
|
52
52
|
- The overruled mark comes from cue phrases such as `instead` or `change of plan` and shared words. A reversal with no cue phrase gets no mark, and the later line still overrides by its place. A cue in a message that agrees with an earlier one, such as `dont use haiku` after `use Python trim instead of Haiku`, marks that earlier line too, so the context tells the agent to follow the later message where the two differ.
|
|
53
53
|
- `session/skill_loaded_reminder.py` has three registration points. An `Agent` or `Task` helper gets no poteto-mode line from it; a brief that needs the skill names it, or spawns `pstack:poteto-agent`. Its tests cover the compaction restore, the workflow helper reminder, silence on a user turn while the skill stays loaded, silence on a spawn payload, and no `PreToolUse` registration in `hooks.json`.
|
|
54
|
-
- The advisor prompt depends on settings
|
|
54
|
+
- The advisor prompt depends on settings, an environment disable flag, and the payload's `model`. Claude Code 2.1.325 sends `model` on an interactive `claude` start and leaves it out under `claude -p` and the desktop app's stream-json launch, so those sessions get the guidance with the advisor model named. The two starter scripts each use separate opt-in checks.
|
|
55
55
|
- The issue tracker starter requires the checkout to appear in the project path registry.
|
|
56
56
|
- `advisory/auto_mode_denial_quick_fix.py` lives under `advisory/` but belongs here because its only output is agent context and a one-line user message.
|
package/hooks/hooks.json
CHANGED
|
@@ -236,6 +236,11 @@
|
|
|
236
236
|
"type": "command",
|
|
237
237
|
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/task_subject_length_gate.py",
|
|
238
238
|
"timeout": 10
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"type": "command",
|
|
242
|
+
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/task_subject_outcome_gate.py",
|
|
243
|
+
"timeout": 10
|
|
239
244
|
}
|
|
240
245
|
]
|
|
241
246
|
},
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Each sentence in ``ALL_ADVISOR_RULE_SENTENCES`` is copied word for word from
|
|
4
4
|
``docs/references/advisor-tool.md``, which stays the one source. A
|
|
5
5
|
synchronization test fails when a sentence drifts from that document.
|
|
6
|
+
``ADVISOR_RULES_PROMPT_TEMPLATE`` takes the configured advisor model as
|
|
7
|
+
``advisor_model``.
|
|
6
8
|
"""
|
|
7
9
|
|
|
8
10
|
from __future__ import annotations
|
|
@@ -10,28 +12,34 @@ from __future__ import annotations
|
|
|
10
12
|
__all__ = [
|
|
11
13
|
"ADVISOR_DISABLE_ENV_VAR",
|
|
12
14
|
"ADVISOR_MODEL_SETTINGS_KEY",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
+
"ADVISOR_RULES_HEADER_TEMPLATE",
|
|
16
|
+
"ADVISOR_RULES_PROMPT_TEMPLATE",
|
|
15
17
|
"ALL_ADVISOR_RULE_SENTENCES",
|
|
16
18
|
"ALL_ADVISOR_DISABLE_ENV_TRUE_VALUES",
|
|
19
|
+
"ALL_MODEL_FAMILY_NAMES",
|
|
17
20
|
"CLAUDE_CONFIG_DIR_ENV_VAR",
|
|
18
21
|
"DEFAULT_CLAUDE_CONFIG_DIRECTORY_NAME",
|
|
22
|
+
"SESSION_MODEL_PAYLOAD_KEY",
|
|
19
23
|
"USER_SETTINGS_FILE_NAME",
|
|
20
24
|
]
|
|
21
25
|
|
|
22
26
|
ADVISOR_MODEL_SETTINGS_KEY = "advisorModel"
|
|
27
|
+
SESSION_MODEL_PAYLOAD_KEY = "model"
|
|
28
|
+
ALL_MODEL_FAMILY_NAMES = ("fable", "opus", "sonnet", "haiku")
|
|
23
29
|
ADVISOR_DISABLE_ENV_VAR = "CLAUDE_CODE_DISABLE_ADVISOR_TOOL"
|
|
24
30
|
ALL_ADVISOR_DISABLE_ENV_TRUE_VALUES = frozenset({"1", "true", "yes", "on"})
|
|
25
31
|
CLAUDE_CONFIG_DIR_ENV_VAR = "CLAUDE_CONFIG_DIR"
|
|
26
32
|
DEFAULT_CLAUDE_CONFIG_DIRECTORY_NAME = ".claude"
|
|
27
33
|
USER_SETTINGS_FILE_NAME = "settings.json"
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
"ADVISOR, when `advisor` is in your tool list.
|
|
31
|
-
"
|
|
35
|
+
ADVISOR_RULES_HEADER_TEMPLATE = (
|
|
36
|
+
"ADVISOR, when `advisor` is in your tool list. The advisor runs on `{advisor_model}`."
|
|
37
|
+
" Use your own judgment on when a consult helps."
|
|
38
|
+
" Starting points from ~/.claude/docs/references/advisor-tool.md:"
|
|
32
39
|
)
|
|
33
40
|
|
|
34
41
|
ALL_ADVISOR_RULE_SENTENCES = (
|
|
42
|
+
"A session that runs on the advisor model itself plans no advisor consults.",
|
|
35
43
|
"Call for design, architecture, and risk questions where you will not touch a file.",
|
|
36
44
|
"On tasks longer than a few steps, aim for an early approach consult and a completion review.",
|
|
37
45
|
"This cadence guides planning and leaves the task free to follow its evidence.",
|
|
@@ -41,4 +49,4 @@ ALL_ADVISOR_RULE_SENTENCES = (
|
|
|
41
49
|
"Give the advice serious weight.",
|
|
42
50
|
)
|
|
43
51
|
|
|
44
|
-
|
|
52
|
+
ADVISOR_RULES_PROMPT_TEMPLATE = " ".join((ADVISOR_RULES_HEADER_TEMPLATE, *ALL_ADVISOR_RULE_SENTENCES))
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Constants for task_subject_outcome_gate.py."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
TOOL_NAME_KEY = "tool_name"
|
|
6
|
+
TOOL_INPUT_KEY = "tool_input"
|
|
7
|
+
GATE_EVENT_NAME = "PreToolUse"
|
|
8
|
+
ALLOW_EXIT_CODE = 0
|
|
9
|
+
BLOCK_EXIT_CODE = 2
|
|
10
|
+
|
|
11
|
+
TASK_CREATE_TOOL_NAME = "TaskCreate"
|
|
12
|
+
TASK_UPDATE_TOOL_NAME = "TaskUpdate"
|
|
13
|
+
TODO_WRITE_TOOL_NAME = "TodoWrite"
|
|
14
|
+
ALL_SUBJECT_TOOL_NAMES = frozenset({TASK_CREATE_TOOL_NAME, TASK_UPDATE_TOOL_NAME})
|
|
15
|
+
TASK_SUBJECT_KEY = "subject"
|
|
16
|
+
TODOS_KEY = "todos"
|
|
17
|
+
TODO_CONTENT_KEY = "content"
|
|
18
|
+
|
|
19
|
+
PROCEDURE_STEP_PREFIX_PATTERN = re.compile(
|
|
20
|
+
r"^\s*(?:step|phase|stage|part|feature|bug\s+fix|refactoring|playbook)"
|
|
21
|
+
r"\s*\d{1,2}(?:\s*[-–]\s*\d{1,2})?\s*(?:[:)]|\.(?!\d))",
|
|
22
|
+
re.IGNORECASE,
|
|
23
|
+
)
|
|
24
|
+
CODE_SPAN_MARKER = "`"
|
|
25
|
+
|
|
26
|
+
PROCEDURE_STEP_MESSAGE = (
|
|
27
|
+
"The task subject '{subject}' starts with a procedure step label such as 'Step 3:' or"
|
|
28
|
+
" 'Feature 6-8:'."
|
|
29
|
+
)
|
|
30
|
+
CODE_SPAN_MESSAGE = "The task subject '{subject}' holds a code-formatted name in backticks."
|
|
31
|
+
RETRY_INSTRUCTION = (
|
|
32
|
+
" The user follows the task list to see where the work stands and what is left."
|
|
33
|
+
" Name the item by its outcome in the user's words, such as"
|
|
34
|
+
" 'Task names in the list read as outcomes'."
|
|
35
|
+
" Keep playbook steps, skill names, and other procedure steps in a private checklist"
|
|
36
|
+
" file such as todo.md in the work folder, and call the tool again."
|
|
37
|
+
)
|
|
@@ -6,6 +6,10 @@ adds the team-advisor starting points, such as a consult on a design question,
|
|
|
6
6
|
and leaves each call to the session's judgment. It emits them only when the user settings carry an
|
|
7
7
|
``advisorModel`` value and ``CLAUDE_CODE_DISABLE_ADVISOR_TOOL`` is not set, so a
|
|
8
8
|
session without the advisor is never told to call it.
|
|
9
|
+
It also stays silent when the SessionStart payload's ``model`` is the
|
|
10
|
+
``advisorModel`` value or belongs to its model family, so a session is never
|
|
11
|
+
told to consult itself. When the payload has no ``model``, the guidance names the advisor model
|
|
12
|
+
so the session can tell for itself.
|
|
9
13
|
The hook writes nothing and runs no tools itself.
|
|
10
14
|
"""
|
|
11
15
|
|
|
@@ -23,14 +27,17 @@ if _hooks_directory not in sys.path:
|
|
|
23
27
|
from hooks_constants.advisor_rules_prompt_constants import (
|
|
24
28
|
ADVISOR_DISABLE_ENV_VAR,
|
|
25
29
|
ADVISOR_MODEL_SETTINGS_KEY,
|
|
26
|
-
|
|
30
|
+
ADVISOR_RULES_PROMPT_TEMPLATE,
|
|
27
31
|
ALL_ADVISOR_DISABLE_ENV_TRUE_VALUES,
|
|
32
|
+
ALL_MODEL_FAMILY_NAMES,
|
|
28
33
|
CLAUDE_CONFIG_DIR_ENV_VAR,
|
|
29
34
|
DEFAULT_CLAUDE_CONFIG_DIRECTORY_NAME,
|
|
35
|
+
SESSION_MODEL_PAYLOAD_KEY,
|
|
30
36
|
USER_SETTINGS_FILE_NAME,
|
|
31
37
|
)
|
|
32
38
|
from hooks_constants.mod_handoff import is_mod_plugin_enabled
|
|
33
39
|
from hooks_constants.mod_handoff_constants import SESSION_PROMPTS_PLUGIN_NAME
|
|
40
|
+
from hooks_constants.pre_tool_use_stdin import read_hook_input_dictionary_from_stdin
|
|
34
41
|
|
|
35
42
|
|
|
36
43
|
def user_settings_path() -> Path:
|
|
@@ -47,30 +54,67 @@ def is_advisor_disabled_by_environment() -> bool:
|
|
|
47
54
|
return raw_value in ALL_ADVISOR_DISABLE_ENV_TRUE_VALUES
|
|
48
55
|
|
|
49
56
|
|
|
50
|
-
def
|
|
51
|
-
"""Return
|
|
57
|
+
def configured_advisor_model(settings_path: Path) -> str | None:
|
|
58
|
+
"""Return the settings file's non-empty advisor model, or None."""
|
|
52
59
|
try:
|
|
53
60
|
settings = json.loads(settings_path.read_text(encoding="utf-8"))
|
|
54
61
|
except (OSError, ValueError):
|
|
55
|
-
return
|
|
62
|
+
return None
|
|
56
63
|
if not isinstance(settings, dict):
|
|
57
|
-
return
|
|
64
|
+
return None
|
|
58
65
|
advisor_model = settings.get(ADVISOR_MODEL_SETTINGS_KEY)
|
|
59
|
-
|
|
66
|
+
if not isinstance(advisor_model, str) or not advisor_model.strip():
|
|
67
|
+
return None
|
|
68
|
+
return advisor_model.strip()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def model_family(model_name: str) -> str | None:
|
|
72
|
+
"""Return the family an alias or full model id names, or None.
|
|
73
|
+
|
|
74
|
+
::
|
|
75
|
+
|
|
76
|
+
"fable" -> "fable" "claude-fable-5-2" -> "fable"
|
|
77
|
+
"claude-mythos-1" -> None
|
|
78
|
+
"""
|
|
79
|
+
lowered_model_name = model_name.lower()
|
|
80
|
+
for each_family_name in ALL_MODEL_FAMILY_NAMES:
|
|
81
|
+
if each_family_name in lowered_model_name:
|
|
82
|
+
return each_family_name
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def runs_on_advisor_model(session_model: object, advisor_model: str) -> bool:
|
|
87
|
+
"""Return True when the session model is the advisor model or shares its known family.
|
|
88
|
+
|
|
89
|
+
::
|
|
90
|
+
|
|
91
|
+
"claude-fable-5-2", "fable" -> True "claude-mythos-1", "claude-mythos-1" -> True
|
|
92
|
+
"claude-opus-5-5", "fable" -> False "claude-mythos-1", "custom-advisor" -> False
|
|
93
|
+
"""
|
|
94
|
+
if not isinstance(session_model, str):
|
|
95
|
+
return False
|
|
96
|
+
if session_model.strip().lower() == advisor_model.lower():
|
|
97
|
+
return True
|
|
98
|
+
session_family = model_family(session_model)
|
|
99
|
+
return session_family is not None and session_family == model_family(advisor_model)
|
|
60
100
|
|
|
61
101
|
|
|
62
102
|
def main() -> None:
|
|
63
|
-
"""Emit the advisor guidance as SessionStart additionalContext when the advisor is on and the session-prompts mod is off."""
|
|
103
|
+
"""Emit the advisor guidance as SessionStart additionalContext when the advisor is on, the session runs on another model, and the session-prompts mod is off."""
|
|
64
104
|
if is_mod_plugin_enabled(SESSION_PROMPTS_PLUGIN_NAME):
|
|
65
105
|
return
|
|
66
106
|
if is_advisor_disabled_by_environment():
|
|
67
107
|
return
|
|
68
|
-
|
|
108
|
+
advisor_model = configured_advisor_model(user_settings_path())
|
|
109
|
+
if advisor_model is None:
|
|
110
|
+
return
|
|
111
|
+
session_start_payload = read_hook_input_dictionary_from_stdin() or {}
|
|
112
|
+
if runs_on_advisor_model(session_start_payload.get(SESSION_MODEL_PAYLOAD_KEY), advisor_model):
|
|
69
113
|
return
|
|
70
114
|
session_start_output = {
|
|
71
115
|
"hookSpecificOutput": {
|
|
72
116
|
"hookEventName": "SessionStart",
|
|
73
|
-
"additionalContext":
|
|
117
|
+
"additionalContext": ADVISOR_RULES_PROMPT_TEMPLATE.format(advisor_model=advisor_model),
|
|
74
118
|
}
|
|
75
119
|
}
|
|
76
120
|
sys.stdout.write(json.dumps(session_start_output) + "\n")
|
|
@@ -19,19 +19,30 @@ import advisor_rules_prompt as starter
|
|
|
19
19
|
|
|
20
20
|
from hooks_constants.advisor_rules_prompt_constants import (
|
|
21
21
|
ADVISOR_DISABLE_ENV_VAR,
|
|
22
|
-
ADVISOR_RULES_PROMPT,
|
|
23
22
|
ALL_ADVISOR_RULE_SENTENCES,
|
|
24
23
|
CLAUDE_CONFIG_DIR_ENV_VAR,
|
|
25
24
|
)
|
|
26
25
|
|
|
27
26
|
|
|
28
|
-
def _run_main() -> str:
|
|
27
|
+
def _run_main(session_start_payload: object = "") -> str:
|
|
28
|
+
stdin_text = (
|
|
29
|
+
session_start_payload
|
|
30
|
+
if isinstance(session_start_payload, str)
|
|
31
|
+
else json.dumps(session_start_payload)
|
|
32
|
+
)
|
|
29
33
|
captured_stdout = StringIO()
|
|
30
|
-
with patch("sys.stdout", captured_stdout):
|
|
34
|
+
with patch("sys.stdin", StringIO(stdin_text)), patch("sys.stdout", captured_stdout):
|
|
31
35
|
starter.main()
|
|
32
36
|
return captured_stdout.getvalue()
|
|
33
37
|
|
|
34
38
|
|
|
39
|
+
def _session_start_payload(session_model: str | None) -> dict[str, str]:
|
|
40
|
+
payload = {"hook_event_name": "SessionStart", "source": "startup"}
|
|
41
|
+
if session_model is not None:
|
|
42
|
+
payload["model"] = session_model
|
|
43
|
+
return payload
|
|
44
|
+
|
|
45
|
+
|
|
35
46
|
@pytest.fixture
|
|
36
47
|
def config_directory(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
|
37
48
|
monkeypatch.setenv(CLAUDE_CONFIG_DIR_ENV_VAR, str(tmp_path))
|
|
@@ -49,7 +60,62 @@ class TestAdvisorRulesPrompt:
|
|
|
49
60
|
_write_settings(config_directory, {"advisorModel": "fable"})
|
|
50
61
|
hook_output = json.loads(_run_main())["hookSpecificOutput"]
|
|
51
62
|
assert hook_output["hookEventName"] == "SessionStart"
|
|
52
|
-
|
|
63
|
+
for each_rule_sentence in ALL_ADVISOR_RULE_SENTENCES:
|
|
64
|
+
assert each_rule_sentence in hook_output["additionalContext"]
|
|
65
|
+
|
|
66
|
+
def test_should_name_the_configured_advisor_model(self, config_directory: Path) -> None:
|
|
67
|
+
_write_settings(config_directory, {"advisorModel": "fable"})
|
|
68
|
+
hook_output = json.loads(_run_main())["hookSpecificOutput"]
|
|
69
|
+
assert "The advisor runs on `fable`." in hook_output["additionalContext"]
|
|
70
|
+
|
|
71
|
+
@pytest.mark.parametrize(
|
|
72
|
+
("advisor_model", "session_model"),
|
|
73
|
+
[
|
|
74
|
+
("fable", "claude-fable-5-2"),
|
|
75
|
+
("claude-fable-5-2", "claude-fable-5-2"),
|
|
76
|
+
("opus", "claude-opus-5-5[1m]"),
|
|
77
|
+
("claude-opus-4-7", "claude-opus-5"),
|
|
78
|
+
("claude-mythos-1", "claude-mythos-1"),
|
|
79
|
+
("Custom-Advisor", "custom-advisor"),
|
|
80
|
+
],
|
|
81
|
+
)
|
|
82
|
+
def test_should_emit_nothing_when_session_runs_on_the_advisor_model(
|
|
83
|
+
self, config_directory: Path, advisor_model: str, session_model: str
|
|
84
|
+
) -> None:
|
|
85
|
+
_write_settings(config_directory, {"advisorModel": advisor_model})
|
|
86
|
+
assert _run_main(_session_start_payload(session_model)) == ""
|
|
87
|
+
|
|
88
|
+
@pytest.mark.parametrize(
|
|
89
|
+
("advisor_model", "session_model"),
|
|
90
|
+
[
|
|
91
|
+
("fable", "claude-opus-5-5"),
|
|
92
|
+
("opus", "claude-sonnet-5-5"),
|
|
93
|
+
("fable", "claude-mythos-1"),
|
|
94
|
+
("custom-advisor", "claude-fable-5-2"),
|
|
95
|
+
("custom-advisor", "claude-mythos-1"),
|
|
96
|
+
],
|
|
97
|
+
)
|
|
98
|
+
def test_should_emit_rules_when_session_runs_on_another_model(
|
|
99
|
+
self, config_directory: Path, advisor_model: str, session_model: str
|
|
100
|
+
) -> None:
|
|
101
|
+
_write_settings(config_directory, {"advisorModel": advisor_model})
|
|
102
|
+
hook_output = json.loads(_run_main(_session_start_payload(session_model)))
|
|
103
|
+
assert hook_output["hookSpecificOutput"]["hookEventName"] == "SessionStart"
|
|
104
|
+
|
|
105
|
+
@pytest.mark.parametrize("session_start_payload", [_session_start_payload(None), "", "{not json", "[]"])
|
|
106
|
+
def test_should_emit_rules_when_payload_names_no_model(
|
|
107
|
+
self, config_directory: Path, session_start_payload: object
|
|
108
|
+
) -> None:
|
|
109
|
+
_write_settings(config_directory, {"advisorModel": "fable"})
|
|
110
|
+
hook_output = json.loads(_run_main(session_start_payload))
|
|
111
|
+
assert hook_output["hookSpecificOutput"]["hookEventName"] == "SessionStart"
|
|
112
|
+
|
|
113
|
+
def test_should_emit_rules_when_payload_model_is_not_a_string(
|
|
114
|
+
self, config_directory: Path
|
|
115
|
+
) -> None:
|
|
116
|
+
_write_settings(config_directory, {"advisorModel": "fable"})
|
|
117
|
+
hook_output = json.loads(_run_main({"hook_event_name": "SessionStart", "model": 5}))
|
|
118
|
+
assert hook_output["hookSpecificOutput"]["hookEventName"] == "SessionStart"
|
|
53
119
|
|
|
54
120
|
def test_should_emit_nothing_when_advisor_model_is_missing(
|
|
55
121
|
self, config_directory: Path
|
package/package.json
CHANGED
|
@@ -134,6 +134,7 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
134
134
|
hooks/blocking/issue_close_handoff_gate.py -> exempt
|
|
135
135
|
hooks/blocking/verify_before_acting.py -> exempt
|
|
136
136
|
hooks/blocking/session_title_format_gate.py -> exempt
|
|
137
|
+
hooks/blocking/task_subject_outcome_gate.py -> exempt
|
|
137
138
|
hooks/blocking/artifact_dark_mode_gate.py -> exempt
|
|
138
139
|
hooks/blocking/send_user_file_worktree_root_gate.py -> exempt
|
|
139
140
|
hooks/blocking/question_brief_gate.py -> exempt
|
|
@@ -176,6 +177,10 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
176
177
|
The session title format gate denies a malformed title. It decides the
|
|
177
178
|
shape of a title and no code or safety policy.
|
|
178
179
|
|
|
180
|
+
The task subject gate denies a task list subject that starts with a
|
|
181
|
+
procedure step label or holds a code-formatted name. It decides the
|
|
182
|
+
wording the user reads and no code or safety policy.
|
|
183
|
+
|
|
179
184
|
The artifact page gate denies a page publish whose text is unreadable in
|
|
180
185
|
dark mode. It decides how a page renders and no code or safety policy.
|
|
181
186
|
|
|
@@ -71,6 +71,7 @@ ALL_ACTION_BOUNDARY_EXEMPT_REGISTRATION_PATHS = (
|
|
|
71
71
|
"blocking/issue_close_handoff_gate.py",
|
|
72
72
|
"blocking/verify_before_acting.py",
|
|
73
73
|
"blocking/session_title_format_gate.py",
|
|
74
|
+
"blocking/task_subject_outcome_gate.py",
|
|
74
75
|
"blocking/image_read_size_gate.py",
|
|
75
76
|
"blocking/artifact_dark_mode_gate.py",
|
|
76
77
|
"blocking/send_user_file_worktree_root_gate.py",
|
|
@@ -130,6 +130,14 @@ def test_new_session_title_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
|
130
130
|
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
131
131
|
|
|
132
132
|
|
|
133
|
+
def test_new_task_subject_outcome_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
134
|
+
current_document = _hook_document(
|
|
135
|
+
["hooks/blocking/task_subject_outcome_gate.py"],
|
|
136
|
+
'{"hooks": {}}',
|
|
137
|
+
)
|
|
138
|
+
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
139
|
+
|
|
140
|
+
|
|
133
141
|
def test_new_task_subject_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
134
142
|
current_document = _hook_document(
|
|
135
143
|
["hooks/blocking/task_subject_length_gate.py"],
|