claude-dev-env 8.22.0 → 8.23.1
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/eli5/SKILL.md +7 -3
- package/.agents/skills/eli5/reference/task-seeds.md +5 -4
- package/hooks/hooks.json +5 -0
- package/hooks/hooks_constants/advisor_rules_prompt_constants.py +43 -0
- package/hooks/hooks_constants/skill_loaded_reminder_constants.py +13 -10
- package/hooks/session/advisor_rules_prompt.py +76 -0
- package/hooks/session/skill_loaded_reminder.py +16 -16
- package/hooks/session/test_advisor_rules_prompt.py +86 -0
- package/hooks/session/test_skill_loaded_reminder.py +19 -11
- package/package.json +1 -1
|
@@ -90,11 +90,15 @@ Process steps in order.
|
|
|
90
90
|
artifact, preserve an explicit user path, or create a clear self-contained
|
|
91
91
|
browser-ready HTML artifact when no path exists. Keep the chosen path for the
|
|
92
92
|
rest of the active task or conversation.
|
|
93
|
-
2. **
|
|
93
|
+
2. **Deterministic — list the cases the user named.** When the request lists
|
|
94
|
+
cases, count each variant as its own case and keep the user's numbering,
|
|
95
|
+
such as 3a and 3b for a case that holds a draft and a ready variant. Give
|
|
96
|
+
each case its own card and its own visual.
|
|
97
|
+
3. **Borderline — add the current explanation to that artifact.** Read and apply
|
|
94
98
|
`~/.claude/rules/asd-ste100-language.md` to every sentence. Frame the topic
|
|
95
99
|
for a beginner, use a large useful visual, keep the text minimal, and update
|
|
96
100
|
the same artifact in place.
|
|
97
|
-
|
|
101
|
+
4. **Deterministic — run the digest check on a summary of many changes.** A
|
|
98
102
|
summary of a set of changes, such as the pull requests merged in a day, is a
|
|
99
103
|
digest. Give each change one card marked `data-digest-card="<id>"` that holds
|
|
100
104
|
its picture and its one-line change. Pass every source id to the check:
|
|
@@ -106,7 +110,7 @@ Process steps in order.
|
|
|
106
110
|
The check reports each source id with no card, each card over 25 words, each
|
|
107
111
|
card without a picture, and more than 40 words outside the cards. Fix every
|
|
108
112
|
finding and run it again until it prints `CLEAN`.
|
|
109
|
-
|
|
113
|
+
5. **Judgment — share the updated artifact with the user.**
|
|
110
114
|
|
|
111
115
|
### Examples
|
|
112
116
|
|
|
@@ -5,8 +5,9 @@ the start of the ELI5 process.
|
|
|
5
5
|
|
|
6
6
|
1. Resolve the active HTML artifact path and preserve the stable path.
|
|
7
7
|
2. Create the artifact when no active path exists and keep it self-contained.
|
|
8
|
-
3.
|
|
9
|
-
4.
|
|
10
|
-
5.
|
|
8
|
+
3. List each case the user named, with each variant as its own case.
|
|
9
|
+
4. Apply the ASD-STE100 rule to page and response sentences.
|
|
10
|
+
5. Add the concise beginner explanation and useful large visual in place.
|
|
11
|
+
6. Run `digest_check.py` on a digest with every source id until it prints
|
|
11
12
|
`CLEAN`.
|
|
12
|
-
|
|
13
|
+
7. Share the updated artifact with the user.
|
package/hooks/hooks.json
CHANGED
|
@@ -129,6 +129,11 @@
|
|
|
129
129
|
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/session/working_style_prompt.py",
|
|
130
130
|
"timeout": 10
|
|
131
131
|
},
|
|
132
|
+
{
|
|
133
|
+
"type": "command",
|
|
134
|
+
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/session/advisor_rules_prompt.py",
|
|
135
|
+
"timeout": 10
|
|
136
|
+
},
|
|
132
137
|
{
|
|
133
138
|
"type": "command",
|
|
134
139
|
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/session/orchestrator_auto_starter.py",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Advisor consult guidance for the SessionStart advisor_rules_prompt hook.
|
|
2
|
+
|
|
3
|
+
Each sentence in ``ALL_ADVISOR_RULE_SENTENCES`` is copied word for word from
|
|
4
|
+
``docs/references/advisor-tool.md``, which stays the one source. A
|
|
5
|
+
synchronization test fails when a sentence drifts from that document.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"ADVISOR_DISABLE_ENV_VAR",
|
|
12
|
+
"ADVISOR_MODEL_SETTINGS_KEY",
|
|
13
|
+
"ADVISOR_RULES_HEADER",
|
|
14
|
+
"ADVISOR_RULES_PROMPT",
|
|
15
|
+
"ALL_ADVISOR_RULE_SENTENCES",
|
|
16
|
+
"ALL_ADVISOR_DISABLE_ENV_TRUE_VALUES",
|
|
17
|
+
"CLAUDE_CONFIG_DIR_ENV_VAR",
|
|
18
|
+
"DEFAULT_CLAUDE_CONFIG_DIRECTORY_NAME",
|
|
19
|
+
"USER_SETTINGS_FILE_NAME",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
ADVISOR_MODEL_SETTINGS_KEY = "advisorModel"
|
|
23
|
+
ADVISOR_DISABLE_ENV_VAR = "CLAUDE_CODE_DISABLE_ADVISOR_TOOL"
|
|
24
|
+
ALL_ADVISOR_DISABLE_ENV_TRUE_VALUES = frozenset({"1", "true", "yes", "on"})
|
|
25
|
+
CLAUDE_CONFIG_DIR_ENV_VAR = "CLAUDE_CONFIG_DIR"
|
|
26
|
+
DEFAULT_CLAUDE_CONFIG_DIRECTORY_NAME = ".claude"
|
|
27
|
+
USER_SETTINGS_FILE_NAME = "settings.json"
|
|
28
|
+
|
|
29
|
+
ADVISOR_RULES_HEADER = (
|
|
30
|
+
"ADVISOR, when `advisor` is in your tool list. Use your own judgment on when a"
|
|
31
|
+
" consult helps. Starting points from ~/.claude/docs/references/advisor-tool.md:"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
ALL_ADVISOR_RULE_SENTENCES = (
|
|
35
|
+
"Call for design, architecture, and risk questions where you will not touch a file.",
|
|
36
|
+
"On tasks longer than a few steps, aim for an early approach consult and a completion review.",
|
|
37
|
+
"This cadence guides planning and leaves the task free to follow its evidence.",
|
|
38
|
+
"Short reactive tasks may use the single consult that best fits the live decision.",
|
|
39
|
+
"Ask the advisor to hunt for missing requirements, untested behavior, wrong assumptions, unhandled edge cases, evidence gaps, and early completion claims.",
|
|
40
|
+
"Give the advice serious weight.",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
ADVISOR_RULES_PROMPT = " ".join((ADVISOR_RULES_HEADER, *ALL_ADVISOR_RULE_SENTENCES))
|
|
@@ -9,12 +9,12 @@ __all__ = [
|
|
|
9
9
|
"COMPACTION_REMINDER",
|
|
10
10
|
"COMPACTION_SOURCE",
|
|
11
11
|
"NOT_LOADED_REMINDER",
|
|
12
|
-
"
|
|
12
|
+
"ALL_POTETO_MODE_SKILL_NAMES",
|
|
13
13
|
"PRE_TOOL_USE_EVENT_NAME",
|
|
14
14
|
"PROMPT_SEPARATOR",
|
|
15
15
|
"SESSION_START_EVENT_NAME",
|
|
16
16
|
"SKILL_TOOL_NAME",
|
|
17
|
-
"
|
|
17
|
+
"ALL_SLASH_COMMAND_MARKERS",
|
|
18
18
|
"SUBAGENT_START_EVENT_NAME",
|
|
19
19
|
"CLAUDE_SUBAGENT_PROMPT_PREFIX",
|
|
20
20
|
"CODEX_SUBAGENT_PROMPT_PREFIX",
|
|
@@ -34,9 +34,12 @@ WORKFLOW_SUBAGENT_TYPE = "workflow-subagent"
|
|
|
34
34
|
|
|
35
35
|
ALL_SELF_LOADING_SUBAGENT_TYPES = frozenset({"pstack:poteto-agent", "poteto-agent"})
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
ALL_POTETO_MODE_SKILL_NAMES = ("poteto-mode", "pstack:poteto-mode")
|
|
38
38
|
SKILL_TOOL_NAME = "Skill"
|
|
39
|
-
|
|
39
|
+
ALL_SLASH_COMMAND_MARKERS = (
|
|
40
|
+
"<command-name>/poteto-mode</command-name>",
|
|
41
|
+
"<command-name>/pstack:poteto-mode</command-name>",
|
|
42
|
+
)
|
|
40
43
|
PROMPT_SEPARATOR = "\n\n"
|
|
41
44
|
|
|
42
45
|
ASSISTANT_ENTRY_TYPE = "assistant"
|
|
@@ -45,11 +48,11 @@ TOOL_USE_BLOCK_TYPE = "tool_use"
|
|
|
45
48
|
COMPACT_BOUNDARY_SUBTYPE = "compact_boundary"
|
|
46
49
|
|
|
47
50
|
CLAUDE_SUBAGENT_PROMPT_PREFIX = (
|
|
48
|
-
"Before any other work, invoke the
|
|
51
|
+
"Before any other work, invoke the poteto-mode skill with the Skill tool. "
|
|
49
52
|
"Every prompt you write for a subagent opens with the same instruction."
|
|
50
53
|
)
|
|
51
54
|
|
|
52
|
-
CODEX_SUBAGENT_PROMPT_PREFIX = "$
|
|
55
|
+
CODEX_SUBAGENT_PROMPT_PREFIX = "$poteto-mode"
|
|
53
56
|
|
|
54
57
|
ALL_SPAWN_PROMPT_FIELDS_AND_PREFIXES_BY_TOOL_NAME = {
|
|
55
58
|
"Agent": ("prompt", CLAUDE_SUBAGENT_PROMPT_PREFIX),
|
|
@@ -58,13 +61,13 @@ ALL_SPAWN_PROMPT_FIELDS_AND_PREFIXES_BY_TOOL_NAME = {
|
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
NOT_LOADED_REMINDER = (
|
|
61
|
-
"The
|
|
62
|
-
"Your next tool call is the Skill tool with skill
|
|
64
|
+
"The poteto-mode skill is not loaded in this context. "
|
|
65
|
+
"Your next tool call is the Skill tool with skill poteto-mode, before any other "
|
|
63
66
|
"tool call."
|
|
64
67
|
)
|
|
65
68
|
|
|
66
69
|
COMPACTION_REMINDER = (
|
|
67
|
-
"The context was just compacted and the
|
|
68
|
-
"Your next tool call is the Skill tool with skill
|
|
70
|
+
"The context was just compacted and the poteto-mode skill rules may have been dropped. "
|
|
71
|
+
"Your next tool call is the Skill tool with skill poteto-mode, before any other "
|
|
69
72
|
"tool call. Then re-read the request that started this session and continue."
|
|
70
73
|
)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""SessionStart hook: inject open advisor consult guidance when the advisor is on.
|
|
3
|
+
|
|
4
|
+
The built-in advisor tool brings its own guidance on when to call it. This hook
|
|
5
|
+
adds the team-advisor starting points, such as a consult on a design question,
|
|
6
|
+
and leaves each call to the session's judgment. It emits them only when the user settings carry an
|
|
7
|
+
``advisorModel`` value and ``CLAUDE_CODE_DISABLE_ADVISOR_TOOL`` is not set, so a
|
|
8
|
+
session without the advisor is never told to call it.
|
|
9
|
+
The hook writes nothing and runs no tools itself.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
_hooks_directory = str(Path(__file__).resolve().parent.parent)
|
|
20
|
+
if _hooks_directory not in sys.path:
|
|
21
|
+
sys.path.insert(0, _hooks_directory)
|
|
22
|
+
|
|
23
|
+
from hooks_constants.advisor_rules_prompt_constants import (
|
|
24
|
+
ADVISOR_DISABLE_ENV_VAR,
|
|
25
|
+
ADVISOR_MODEL_SETTINGS_KEY,
|
|
26
|
+
ADVISOR_RULES_PROMPT,
|
|
27
|
+
ALL_ADVISOR_DISABLE_ENV_TRUE_VALUES,
|
|
28
|
+
CLAUDE_CONFIG_DIR_ENV_VAR,
|
|
29
|
+
DEFAULT_CLAUDE_CONFIG_DIRECTORY_NAME,
|
|
30
|
+
USER_SETTINGS_FILE_NAME,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def user_settings_path() -> Path:
|
|
35
|
+
"""Return the user settings file under the active Claude config directory."""
|
|
36
|
+
configured_directory = os.environ.get(CLAUDE_CONFIG_DIR_ENV_VAR, "").strip()
|
|
37
|
+
if configured_directory:
|
|
38
|
+
return Path(configured_directory) / USER_SETTINGS_FILE_NAME
|
|
39
|
+
return Path.home() / DEFAULT_CLAUDE_CONFIG_DIRECTORY_NAME / USER_SETTINGS_FILE_NAME
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def is_advisor_disabled_by_environment() -> bool:
|
|
43
|
+
"""Return True when the environment turns the advisor tool off."""
|
|
44
|
+
raw_value = os.environ.get(ADVISOR_DISABLE_ENV_VAR, "").strip().lower()
|
|
45
|
+
return raw_value in ALL_ADVISOR_DISABLE_ENV_TRUE_VALUES
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def is_advisor_configured(settings_path: Path) -> bool:
|
|
49
|
+
"""Return True when the settings file names a non-empty advisor model."""
|
|
50
|
+
try:
|
|
51
|
+
settings = json.loads(settings_path.read_text(encoding="utf-8"))
|
|
52
|
+
except (OSError, ValueError):
|
|
53
|
+
return False
|
|
54
|
+
if not isinstance(settings, dict):
|
|
55
|
+
return False
|
|
56
|
+
advisor_model = settings.get(ADVISOR_MODEL_SETTINGS_KEY)
|
|
57
|
+
return isinstance(advisor_model, str) and advisor_model.strip() != ""
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def main() -> None:
|
|
61
|
+
"""Emit the advisor guidance as SessionStart additionalContext when the advisor is on."""
|
|
62
|
+
if is_advisor_disabled_by_environment():
|
|
63
|
+
return
|
|
64
|
+
if not is_advisor_configured(user_settings_path()):
|
|
65
|
+
return
|
|
66
|
+
session_start_output = {
|
|
67
|
+
"hookSpecificOutput": {
|
|
68
|
+
"hookEventName": "SessionStart",
|
|
69
|
+
"additionalContext": ADVISOR_RULES_PROMPT,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
sys.stdout.write(json.dumps(session_start_output) + "\n")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
main()
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
::
|
|
5
5
|
|
|
6
|
-
Agent or Codex spawn_agent, skill not named -> prompt opens with "invoke
|
|
7
|
-
Workflow script helper starts -> "invoke
|
|
8
|
-
context compacted mid-run -> "invoke
|
|
9
|
-
user turn, skill not loaded since compacting -> "invoke
|
|
6
|
+
Agent or Codex spawn_agent, skill not named -> prompt opens with "invoke poteto-mode"
|
|
7
|
+
Workflow script helper starts -> "invoke poteto-mode now"
|
|
8
|
+
context compacted mid-run -> "invoke poteto-mode again"
|
|
9
|
+
user turn, skill not loaded since compacting -> "invoke poteto-mode now"
|
|
10
10
|
user turn, skill already loaded -> nothing
|
|
11
11
|
|
|
12
12
|
A session that loaded the skill hears nothing more until a compaction drops it.
|
|
@@ -31,12 +31,12 @@ from hooks_constants.skill_loaded_reminder_constants import (
|
|
|
31
31
|
COMPACTION_REMINDER,
|
|
32
32
|
COMPACTION_SOURCE,
|
|
33
33
|
NOT_LOADED_REMINDER,
|
|
34
|
-
|
|
34
|
+
ALL_POTETO_MODE_SKILL_NAMES,
|
|
35
35
|
PRE_TOOL_USE_EVENT_NAME,
|
|
36
36
|
PROMPT_SEPARATOR,
|
|
37
37
|
SESSION_START_EVENT_NAME,
|
|
38
38
|
SKILL_TOOL_NAME,
|
|
39
|
-
|
|
39
|
+
ALL_SLASH_COMMAND_MARKERS,
|
|
40
40
|
SUBAGENT_START_EVENT_NAME,
|
|
41
41
|
ALL_SPAWN_PROMPT_FIELDS_AND_PREFIXES_BY_TOOL_NAME,
|
|
42
42
|
TOOL_USE_BLOCK_TYPE,
|
|
@@ -58,9 +58,9 @@ def subagent_input_with_poteto_mode(
|
|
|
58
58
|
::
|
|
59
59
|
|
|
60
60
|
Agent {"prompt": "Reply leaf."} -> {"prompt": "Before any ...\\n\\nReply leaf."}
|
|
61
|
-
spawn_agent {"message": "Fix it."} -> {"message": "$
|
|
62
|
-
Agent {"prompt": "Invoke
|
|
63
|
-
Agent {"subagent_type": "
|
|
61
|
+
spawn_agent {"message": "Fix it."} -> {"message": "$poteto-mode\\n\\nFix it."}
|
|
62
|
+
Agent {"prompt": "Invoke poteto-mode, then ..."} -> None
|
|
63
|
+
Agent {"subagent_type": "poteto-agent", ...} -> None, it loads the skill
|
|
64
64
|
|
|
65
65
|
Claude Code spawns through Agent or Task and Codex through spawn_agent, so
|
|
66
66
|
each tool name carries its own prompt field and invocation text.
|
|
@@ -71,7 +71,7 @@ def subagent_input_with_poteto_mode(
|
|
|
71
71
|
"""
|
|
72
72
|
field_name, invocation_prefix = ALL_SPAWN_PROMPT_FIELDS_AND_PREFIXES_BY_TOOL_NAME[tool_name]
|
|
73
73
|
prompt = all_tool_input_fields.get(field_name)
|
|
74
|
-
if not isinstance(prompt, str) or
|
|
74
|
+
if not isinstance(prompt, str) or ALL_POTETO_MODE_SKILL_NAMES[0] in prompt:
|
|
75
75
|
return None
|
|
76
76
|
if all_tool_input_fields.get("subagent_type") in ALL_SELF_LOADING_SUBAGENT_TYPES:
|
|
77
77
|
return None
|
|
@@ -84,7 +84,7 @@ def _invokes_poteto_mode(all_entry_fields: dict[str, object]) -> bool:
|
|
|
84
84
|
return False
|
|
85
85
|
content_blocks = message.get("content")
|
|
86
86
|
if all_entry_fields.get("type") == USER_ENTRY_TYPE and isinstance(content_blocks, str):
|
|
87
|
-
return
|
|
87
|
+
return any(each_marker in content_blocks for each_marker in ALL_SLASH_COMMAND_MARKERS)
|
|
88
88
|
if all_entry_fields.get("type") != ASSISTANT_ENTRY_TYPE or not isinstance(content_blocks, list):
|
|
89
89
|
return False
|
|
90
90
|
return any(
|
|
@@ -92,7 +92,7 @@ def _invokes_poteto_mode(all_entry_fields: dict[str, object]) -> bool:
|
|
|
92
92
|
and each_block.get("type") == TOOL_USE_BLOCK_TYPE
|
|
93
93
|
and each_block.get("name") == SKILL_TOOL_NAME
|
|
94
94
|
and isinstance(each_block.get("input"), dict)
|
|
95
|
-
and each_block["input"].get("skill")
|
|
95
|
+
and each_block["input"].get("skill") in ALL_POTETO_MODE_SKILL_NAMES
|
|
96
96
|
for each_block in content_blocks
|
|
97
97
|
)
|
|
98
98
|
|
|
@@ -100,7 +100,7 @@ def _invokes_poteto_mode(all_entry_fields: dict[str, object]) -> bool:
|
|
|
100
100
|
def _marker_entry(transcript_line: str) -> dict[str, object] | None:
|
|
101
101
|
if (
|
|
102
102
|
COMPACT_BOUNDARY_SUBTYPE not in transcript_line
|
|
103
|
-
and
|
|
103
|
+
and ALL_POTETO_MODE_SKILL_NAMES[0] not in transcript_line
|
|
104
104
|
):
|
|
105
105
|
return None
|
|
106
106
|
try:
|
|
@@ -121,9 +121,9 @@ def is_poteto_mode_loaded(all_transcript_lines: Iterable[str]) -> bool:
|
|
|
121
121
|
|
|
122
122
|
::
|
|
123
123
|
|
|
124
|
-
Skill(
|
|
125
|
-
/
|
|
126
|
-
Skill(
|
|
124
|
+
Skill(poteto-mode) ... Read ... Edit -> True
|
|
125
|
+
/poteto-mode typed as a command ... Read -> True
|
|
126
|
+
Skill(poteto-mode) ... compact_boundary ... Read -> False
|
|
127
127
|
Read ... Edit -> False
|
|
128
128
|
|
|
129
129
|
Only lines naming the skill or a compaction are parsed, so a long transcript
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Tests for advisor_rules_prompt: SessionStart hook that injects advisor consult rules."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
from io import StringIO
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from unittest.mock import patch
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
_SESSION_DIR = Path(__file__).resolve().parent
|
|
12
|
+
_HOOKS_ROOT = _SESSION_DIR.parent
|
|
13
|
+
_ADVISOR_TOOL_DOC = _HOOKS_ROOT.parent / "docs" / "references" / "advisor-tool.md"
|
|
14
|
+
for each_sys_path_entry in (str(_SESSION_DIR), str(_HOOKS_ROOT)):
|
|
15
|
+
if each_sys_path_entry not in sys.path:
|
|
16
|
+
sys.path.insert(0, each_sys_path_entry)
|
|
17
|
+
|
|
18
|
+
import advisor_rules_prompt as starter
|
|
19
|
+
|
|
20
|
+
from hooks_constants.advisor_rules_prompt_constants import (
|
|
21
|
+
ADVISOR_DISABLE_ENV_VAR,
|
|
22
|
+
ADVISOR_RULES_PROMPT,
|
|
23
|
+
ALL_ADVISOR_RULE_SENTENCES,
|
|
24
|
+
CLAUDE_CONFIG_DIR_ENV_VAR,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _run_main() -> str:
|
|
29
|
+
captured_stdout = StringIO()
|
|
30
|
+
with patch("sys.stdout", captured_stdout):
|
|
31
|
+
starter.main()
|
|
32
|
+
return captured_stdout.getvalue()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.fixture
|
|
36
|
+
def config_directory(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
|
37
|
+
monkeypatch.setenv(CLAUDE_CONFIG_DIR_ENV_VAR, str(tmp_path))
|
|
38
|
+
monkeypatch.delenv(ADVISOR_DISABLE_ENV_VAR, raising=False)
|
|
39
|
+
return tmp_path
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _write_settings(config_directory: Path, settings: object) -> None:
|
|
43
|
+
(config_directory / "settings.json").write_text(json.dumps(settings), encoding="utf-8")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class TestAdvisorRulesPrompt:
|
|
47
|
+
def test_should_emit_rules_when_advisor_model_is_set(self, config_directory: Path) -> None:
|
|
48
|
+
_write_settings(config_directory, {"advisorModel": "fable"})
|
|
49
|
+
hook_output = json.loads(_run_main())["hookSpecificOutput"]
|
|
50
|
+
assert hook_output["hookEventName"] == "SessionStart"
|
|
51
|
+
assert hook_output["additionalContext"] == ADVISOR_RULES_PROMPT
|
|
52
|
+
|
|
53
|
+
def test_should_emit_nothing_when_advisor_model_is_missing(
|
|
54
|
+
self, config_directory: Path
|
|
55
|
+
) -> None:
|
|
56
|
+
_write_settings(config_directory, {"permissions": {}})
|
|
57
|
+
assert _run_main() == ""
|
|
58
|
+
|
|
59
|
+
def test_should_emit_nothing_when_advisor_model_is_blank(self, config_directory: Path) -> None:
|
|
60
|
+
_write_settings(config_directory, {"advisorModel": " "})
|
|
61
|
+
assert _run_main() == ""
|
|
62
|
+
|
|
63
|
+
def test_should_emit_nothing_when_settings_file_is_absent(self, config_directory: Path) -> None:
|
|
64
|
+
assert _run_main() == ""
|
|
65
|
+
|
|
66
|
+
def test_should_emit_nothing_when_settings_file_is_not_json(
|
|
67
|
+
self, config_directory: Path
|
|
68
|
+
) -> None:
|
|
69
|
+
(config_directory / "settings.json").write_text("{not json", encoding="utf-8")
|
|
70
|
+
assert _run_main() == ""
|
|
71
|
+
|
|
72
|
+
def test_should_emit_nothing_when_environment_disables_the_advisor(
|
|
73
|
+
self, config_directory: Path, monkeypatch: pytest.MonkeyPatch
|
|
74
|
+
) -> None:
|
|
75
|
+
_write_settings(config_directory, {"advisorModel": "fable"})
|
|
76
|
+
monkeypatch.setenv(ADVISOR_DISABLE_ENV_VAR, "1")
|
|
77
|
+
assert _run_main() == ""
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class TestAdvisorRulesMatchTheDoc:
|
|
81
|
+
@pytest.mark.parametrize("each_rule_sentence", ALL_ADVISOR_RULE_SENTENCES)
|
|
82
|
+
def test_should_quote_each_sentence_from_advisor_tool_doc(
|
|
83
|
+
self, each_rule_sentence: str
|
|
84
|
+
) -> None:
|
|
85
|
+
doc_text = " ".join(_ADVISOR_TOOL_DOC.read_text(encoding="utf-8").split())
|
|
86
|
+
assert each_rule_sentence in doc_text
|
|
@@ -27,7 +27,7 @@ SKILL_CALL_LINE = json.dumps(
|
|
|
27
27
|
{
|
|
28
28
|
"type": "tool_use",
|
|
29
29
|
"name": "Skill",
|
|
30
|
-
"input": {"skill": "
|
|
30
|
+
"input": {"skill": "poteto-mode"},
|
|
31
31
|
}
|
|
32
32
|
],
|
|
33
33
|
},
|
|
@@ -38,7 +38,7 @@ TYPED_COMMAND_LINE = json.dumps(
|
|
|
38
38
|
"type": "user",
|
|
39
39
|
"message": {
|
|
40
40
|
"role": "user",
|
|
41
|
-
"content": "<command-name>/
|
|
41
|
+
"content": "<command-name>/poteto-mode</command-name>",
|
|
42
42
|
},
|
|
43
43
|
}
|
|
44
44
|
)
|
|
@@ -58,7 +58,7 @@ TOOL_RESULT_QUOTING_THE_SKILL_LINE = json.dumps(
|
|
|
58
58
|
"content": [
|
|
59
59
|
{
|
|
60
60
|
"type": "tool_result",
|
|
61
|
-
"content": 'SKILL = "
|
|
61
|
+
"content": 'SKILL = "poteto-mode" and <command-name>/poteto-mode</command-name>',
|
|
62
62
|
}
|
|
63
63
|
]
|
|
64
64
|
},
|
|
@@ -107,7 +107,7 @@ class TestSubagentSpawn:
|
|
|
107
107
|
rewritten_input = hook_output["updatedInput"]
|
|
108
108
|
assert hook_output["permissionDecision"] == "allow"
|
|
109
109
|
assert rewritten_input["prompt"].startswith(
|
|
110
|
-
"Before any other work, invoke the
|
|
110
|
+
"Before any other work, invoke the poteto-mode skill with the Skill tool."
|
|
111
111
|
)
|
|
112
112
|
assert rewritten_input["prompt"].endswith("\n\nList every caller of main.")
|
|
113
113
|
assert rewritten_input["subagent_type"] == "Explore"
|
|
@@ -115,10 +115,10 @@ class TestSubagentSpawn:
|
|
|
115
115
|
|
|
116
116
|
def test_the_legacy_task_tool_name_is_rewritten_too(self) -> None:
|
|
117
117
|
emitted = json.loads(_run_main(_agent_call({"prompt": "Go."}, tool_name="Task")))
|
|
118
|
-
assert "
|
|
118
|
+
assert "poteto-mode" in emitted["hookSpecificOutput"]["updatedInput"]["prompt"]
|
|
119
119
|
|
|
120
120
|
def test_a_prompt_that_already_names_the_skill_is_left_alone(self) -> None:
|
|
121
|
-
assert _run_main(_agent_call({"prompt": "Invoke
|
|
121
|
+
assert _run_main(_agent_call({"prompt": "Invoke poteto-mode first. Then go."})) == ""
|
|
122
122
|
|
|
123
123
|
def test_a_poteto_agent_is_left_alone_because_it_loads_the_skill_itself(self) -> None:
|
|
124
124
|
assert (
|
|
@@ -161,14 +161,14 @@ class TestCodexSpawn:
|
|
|
161
161
|
)
|
|
162
162
|
)
|
|
163
163
|
rewritten_input = emitted["hookSpecificOutput"]["updatedInput"]
|
|
164
|
-
assert rewritten_input["message"] == "$
|
|
164
|
+
assert rewritten_input["message"] == "$poteto-mode\n\nFix the failing test."
|
|
165
165
|
assert rewritten_input["model"] == "gpt-6-luna"
|
|
166
166
|
assert "prompt" not in rewritten_input
|
|
167
167
|
|
|
168
168
|
def test_a_codex_spawn_message_that_already_mentions_the_skill_is_left_alone(self) -> None:
|
|
169
169
|
assert (
|
|
170
170
|
_run_main(
|
|
171
|
-
_agent_call({"message": "$
|
|
171
|
+
_agent_call({"message": "$poteto-mode\n\nFix it."}, tool_name="spawn_agent")
|
|
172
172
|
)
|
|
173
173
|
== ""
|
|
174
174
|
)
|
|
@@ -181,6 +181,14 @@ class TestIsPotetoModeLoaded:
|
|
|
181
181
|
def test_a_typed_slash_command_loads_it(self) -> None:
|
|
182
182
|
assert reminder.is_poteto_mode_loaded([TYPED_COMMAND_LINE, READ_CALL_LINE])
|
|
183
183
|
|
|
184
|
+
def test_a_prefixed_skill_call_loads_it(self) -> None:
|
|
185
|
+
prefixed_skill_call_line = SKILL_CALL_LINE.replace("poteto-mode", "pstack:poteto-mode")
|
|
186
|
+
assert reminder.is_poteto_mode_loaded([prefixed_skill_call_line])
|
|
187
|
+
|
|
188
|
+
def test_a_prefixed_typed_command_loads_it(self) -> None:
|
|
189
|
+
prefixed_command_line = TYPED_COMMAND_LINE.replace("/poteto-mode", "/pstack:poteto-mode")
|
|
190
|
+
assert reminder.is_poteto_mode_loaded([prefixed_command_line])
|
|
191
|
+
|
|
184
192
|
def test_a_compaction_after_the_skill_call_drops_it(self) -> None:
|
|
185
193
|
assert not reminder.is_poteto_mode_loaded(
|
|
186
194
|
[SKILL_CALL_LINE, COMPACT_BOUNDARY_LINE, READ_CALL_LINE]
|
|
@@ -193,7 +201,7 @@ class TestIsPotetoModeLoaded:
|
|
|
193
201
|
|
|
194
202
|
def test_a_plain_user_prompt_does_not_load_it(self) -> None:
|
|
195
203
|
plain_prompt_line = json.dumps(
|
|
196
|
-
{"type": "user", "message": {"content": "Read
|
|
204
|
+
{"type": "user", "message": {"content": "Read poteto-mode docs."}}
|
|
197
205
|
)
|
|
198
206
|
assert not reminder.is_poteto_mode_loaded([plain_prompt_line])
|
|
199
207
|
|
|
@@ -210,7 +218,7 @@ class TestReminderFor:
|
|
|
210
218
|
hook_output = emitted["hookSpecificOutput"]
|
|
211
219
|
assert hook_output["hookEventName"] == "UserPromptSubmit"
|
|
212
220
|
assert hook_output["additionalContext"] == NOT_LOADED_REMINDER
|
|
213
|
-
assert "
|
|
221
|
+
assert "poteto-mode" in NOT_LOADED_REMINDER
|
|
214
222
|
|
|
215
223
|
def test_a_user_turn_in_a_session_that_loaded_the_skill_prints_nothing(
|
|
216
224
|
self, tmp_path: Path
|
|
@@ -229,7 +237,7 @@ class TestReminderFor:
|
|
|
229
237
|
hook_output = emitted["hookSpecificOutput"]
|
|
230
238
|
assert hook_output["hookEventName"] == "SessionStart"
|
|
231
239
|
assert hook_output["additionalContext"] == COMPACTION_REMINDER
|
|
232
|
-
assert "
|
|
240
|
+
assert "poteto-mode" in COMPACTION_REMINDER
|
|
233
241
|
|
|
234
242
|
def test_a_resumed_session_keeps_its_context_and_prints_nothing(self) -> None:
|
|
235
243
|
assert _run_main({"hook_event_name": "SessionStart", "source": "resume"}) == ""
|