claude-dev-env 8.122.0 → 8.124.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 +2 -0
- package/bin/ever-registered-hooks.test.mjs +5 -0
- package/docs/templates/artifact-page/README.md +14 -1
- package/docs/templates/artifact-page/review-rounds.md +1 -1
- package/docs/templates/artifact-page/template.html +26 -18
- package/docs/templates/html-plan/README.md +4 -0
- package/hooks/blocking/artifact_current_page_fixtures/piled_review_page.html +399 -0
- package/hooks/blocking/artifact_current_page_fixtures/rebuilt_review_page.html +403 -0
- package/hooks/blocking/artifact_current_page_gate.py +418 -0
- package/hooks/blocking/artifact_repeated_item_render.cjs +112 -0
- package/hooks/blocking/closing_question_round_gate.py +387 -0
- package/hooks/blocking/closing_question_round_lines.py +109 -0
- package/hooks/blocking/closing_question_round_open_items.py +348 -0
- package/hooks/blocking/closing_question_round_transcript.py +344 -0
- package/hooks/blocking/open_tasks_stop_gate.py +12 -1
- package/hooks/blocking/open_tasks_transcript.py +30 -0
- package/hooks/blocking/open_tasks_transcript_records.py +57 -1
- package/hooks/blocking/test_artifact_current_page_gate.py +415 -0
- package/hooks/blocking/test_closing_question_round_gate.py +983 -0
- package/hooks/blocking/test_closing_question_round_gate_declaration.py +307 -0
- package/hooks/blocking/test_closing_question_round_gate_work.py +349 -0
- package/hooks/blocking/test_closing_question_round_lines.py +70 -0
- package/hooks/blocking/test_closing_question_round_open_items.py +238 -0
- package/hooks/blocking/test_closing_question_round_transcript.py +236 -0
- package/hooks/blocking/test_open_tasks_stop_gate.py +64 -0
- package/hooks/blocking/test_open_tasks_transcript.py +34 -0
- package/hooks/blocking/test_open_tasks_transcript_records.py +34 -0
- package/hooks/features/conduct-gates.md +6 -0
- package/hooks/hooks.json +15 -0
- package/hooks/hooks_constants/artifact_current_page_gate_constants.py +91 -0
- package/hooks/hooks_constants/artifact_dark_mode_gate_constants.py +3 -3
- package/hooks/hooks_constants/closing_question_round_gate_constants.py +167 -0
- package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +8 -0
- package/hooks/hooks_constants/test_artifact_current_page_gate_constants.py +53 -0
- package/hooks/hooks_constants/test_artifact_dark_mode_gate_constants.py +6 -0
- package/hooks/hooks_constants/test_closing_question_round_gate_constants.py +92 -0
- package/hooks/session/artifact_link_record.py +109 -0
- package/hooks/session/test_artifact_link_record.py +101 -0
- package/hooks/test_context_budget_hooks.py +2 -0
- package/package.json +1 -1
- package/scripts/policy_lint/adapter_configuration.py +6 -0
- package/scripts/policy_lint/config/constants.py +1 -0
- package/scripts/tests/test_adapter_configuration.py +8 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""PostToolUse hook that records the link of a published page beside the page file.
|
|
3
|
+
|
|
4
|
+
An agent that republishes a page must pass the page's link, or the publish
|
|
5
|
+
opens a second copy. An agent that lost its context has no other place to
|
|
6
|
+
find the link. This hook writes it down after each page publish::
|
|
7
|
+
|
|
8
|
+
Artifact {"file_path": "/work/first-look.html"} -> result names https://claude.ai/artifact/abc
|
|
9
|
+
writes /work/first-look.html.artifact-link.json {"url": "...", "title": "..."}
|
|
10
|
+
Artifact {"file_path": "...", "url": "<link>"} -> records <link>
|
|
11
|
+
Artifact {"action": "read", ...} -> no record
|
|
12
|
+
|
|
13
|
+
``blocking/artifact_current_page_gate.py`` reads the record on the next
|
|
14
|
+
publish. The hook never blocks and prints nothing.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import sys
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
hooks_root_directory = str(Path(__file__).resolve().parent.parent)
|
|
24
|
+
if hooks_root_directory not in sys.path:
|
|
25
|
+
sys.path.insert(0, hooks_root_directory)
|
|
26
|
+
|
|
27
|
+
from blocking.artifact_current_page_gate import is_artifact_link, link_record_path, page_title
|
|
28
|
+
from blocking.artifact_dark_mode_gate import published_page_path
|
|
29
|
+
from hooks_constants.artifact_current_page_gate_constants import (
|
|
30
|
+
ARTIFACT_LINK_PATTERN,
|
|
31
|
+
ARTIFACT_URL_INPUT_KEY,
|
|
32
|
+
LINK_RECORD_TITLE_KEY,
|
|
33
|
+
LINK_RECORD_URL_KEY,
|
|
34
|
+
TOOL_RESPONSE_KEY,
|
|
35
|
+
)
|
|
36
|
+
from hooks_constants.pre_tool_use_stdin import read_hook_input_dictionary_from_stdin
|
|
37
|
+
from hooks_constants.spawn_readiness_hook_constants import TOOL_INPUT_KEY, TOOL_NAME_KEY
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def published_link(all_tool_input: dict[str, object], tool_response: object) -> str:
|
|
41
|
+
"""Return the link a page publish went to, or an empty string.
|
|
42
|
+
|
|
43
|
+
A publish that passes ``url`` went to that link. A first publish names its
|
|
44
|
+
new link in the tool result, under ``url`` or in its text::
|
|
45
|
+
|
|
46
|
+
{"url": "https://claude.ai/artifact/abc"}, <any result> -> https://claude.ai/artifact/abc
|
|
47
|
+
{}, {"url": "https://claude.ai/artifact/xyz", ...} -> https://claude.ai/artifact/xyz
|
|
48
|
+
{}, "Published to https://claude.ai/artifact/xyz" -> https://claude.ai/artifact/xyz
|
|
49
|
+
{}, "Copied from <link a> to <link b>" -> ""
|
|
50
|
+
{}, "The publish was refused" -> ""
|
|
51
|
+
|
|
52
|
+
Result text that names two different links does not say which one is the
|
|
53
|
+
page, so it gives no link. A call ``url`` that is no artifact link is
|
|
54
|
+
skipped.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
all_tool_input: The input of the publish call.
|
|
58
|
+
tool_response: The tool result, as text or as a parsed object.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
The link, or an empty string when neither place names one.
|
|
62
|
+
"""
|
|
63
|
+
link_in_call = all_tool_input.get(ARTIFACT_URL_INPUT_KEY)
|
|
64
|
+
if isinstance(link_in_call, str) and is_artifact_link(link_in_call):
|
|
65
|
+
return link_in_call
|
|
66
|
+
if isinstance(tool_response, dict):
|
|
67
|
+
link_in_result = tool_response.get(ARTIFACT_URL_INPUT_KEY)
|
|
68
|
+
if isinstance(link_in_result, str) and is_artifact_link(link_in_result):
|
|
69
|
+
return link_in_result
|
|
70
|
+
response_text = (
|
|
71
|
+
tool_response if isinstance(tool_response, str) else json.dumps(tool_response, default=str)
|
|
72
|
+
)
|
|
73
|
+
all_links_in_text = set(ARTIFACT_LINK_PATTERN.findall(response_text))
|
|
74
|
+
return all_links_in_text.pop() if len(all_links_in_text) == 1 else ""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def record_page_link(page_path: Path, link: str) -> None:
|
|
78
|
+
"""Write the link record beside the page, and skip a page file that cannot be read.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
page_path: The local page file that was published.
|
|
82
|
+
link: The link the page was published at.
|
|
83
|
+
"""
|
|
84
|
+
try:
|
|
85
|
+
title = page_title(page_path.read_text(encoding="utf-8", errors="replace"))
|
|
86
|
+
link_record_path(page_path).write_text(
|
|
87
|
+
json.dumps({LINK_RECORD_URL_KEY: link, LINK_RECORD_TITLE_KEY: title}) + "\n",
|
|
88
|
+
encoding="utf-8",
|
|
89
|
+
)
|
|
90
|
+
except OSError:
|
|
91
|
+
return
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def main() -> int:
|
|
95
|
+
hook_input = read_hook_input_dictionary_from_stdin()
|
|
96
|
+
if hook_input is None:
|
|
97
|
+
return 0
|
|
98
|
+
tool_input = hook_input.get(TOOL_INPUT_KEY)
|
|
99
|
+
page_path = published_page_path(hook_input.get(TOOL_NAME_KEY), tool_input)
|
|
100
|
+
if page_path is None or not page_path.is_file() or not isinstance(tool_input, dict):
|
|
101
|
+
return 0
|
|
102
|
+
link = published_link(tool_input, hook_input.get(TOOL_RESPONSE_KEY))
|
|
103
|
+
if link:
|
|
104
|
+
record_page_link(page_path, link)
|
|
105
|
+
return 0
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
if __name__ == "__main__":
|
|
109
|
+
sys.exit(main())
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Behavior tests for the hook that records a published page's link beside the page."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
11
|
+
|
|
12
|
+
from blocking.artifact_current_page_gate import link_record_path, recorded_page_link
|
|
13
|
+
from session.artifact_link_record import published_link, record_page_link
|
|
14
|
+
|
|
15
|
+
RECORD_SCRIPT_PATH = Path(__file__).resolve().parent / "artifact_link_record.py"
|
|
16
|
+
PAGE_LINK = "https://claude.ai/artifact/SamplePageLink01"
|
|
17
|
+
PAGE_SOURCE = "<title>Sample Run</title><p>One screen.</p>"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _run_record(tool_input: dict[str, object], tool_response: object) -> int:
|
|
21
|
+
completed_run = subprocess.run(
|
|
22
|
+
[sys.executable, str(RECORD_SCRIPT_PATH)],
|
|
23
|
+
input=json.dumps(
|
|
24
|
+
{"tool_name": "Artifact", "tool_input": tool_input, "tool_response": tool_response}
|
|
25
|
+
),
|
|
26
|
+
capture_output=True,
|
|
27
|
+
text=True,
|
|
28
|
+
check=False,
|
|
29
|
+
)
|
|
30
|
+
assert completed_run.stdout == ""
|
|
31
|
+
return completed_run.returncode
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_should_take_the_link_the_call_passed() -> None:
|
|
35
|
+
assert published_link({"url": PAGE_LINK}, "Updated the page.") == PAGE_LINK
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_should_skip_a_call_url_that_is_no_artifact_link() -> None:
|
|
39
|
+
assert published_link({"url": "<link>"}, "The publish was refused.") == ""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_should_take_the_link_the_result_names() -> None:
|
|
43
|
+
assert published_link({}, f"Published to {PAGE_LINK} (private).") == PAGE_LINK
|
|
44
|
+
code_link = "https://claude.ai/code/artifact/0e557edc-f0c7-4382-8568-aee7ab02950b"
|
|
45
|
+
assert published_link({}, [{"type": "text", "text": f"Live at {code_link}."}]) == code_link
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_should_take_the_url_field_of_a_publish_result_over_another_link_in_it() -> None:
|
|
49
|
+
publish_result = {
|
|
50
|
+
"note": "Started from https://claude.ai/artifact/SomeOtherPage01",
|
|
51
|
+
"url": PAGE_LINK,
|
|
52
|
+
"title": "Sample Run",
|
|
53
|
+
"seq": 1,
|
|
54
|
+
}
|
|
55
|
+
assert published_link({}, publish_result) == PAGE_LINK
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_should_find_no_link_in_a_result_that_names_none() -> None:
|
|
59
|
+
assert published_link({}, "The publish was refused.") == ""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_should_take_a_link_whose_id_holds_an_underscore() -> None:
|
|
63
|
+
underscore_link = "https://claude.ai/artifact/Ab_12Cd"
|
|
64
|
+
assert published_link({}, f"Published to {underscore_link}.") == underscore_link
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_should_record_nothing_when_the_result_text_names_two_links() -> None:
|
|
68
|
+
result_text = f"Copied from https://claude.ai/artifact/SourcePage01 to {PAGE_LINK}."
|
|
69
|
+
assert published_link({}, result_text) == ""
|
|
70
|
+
assert published_link({}, f"Published to {PAGE_LINK}. Open {PAGE_LINK}.") == PAGE_LINK
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_should_write_the_link_and_title_beside_the_page(tmp_path: Path) -> None:
|
|
74
|
+
page_path = tmp_path / "first-look.html"
|
|
75
|
+
page_path.write_text(PAGE_SOURCE, encoding="utf-8")
|
|
76
|
+
record_page_link(page_path, PAGE_LINK)
|
|
77
|
+
assert json.loads(link_record_path(page_path).read_text(encoding="utf-8")) == {
|
|
78
|
+
"url": PAGE_LINK,
|
|
79
|
+
"title": "Sample Run",
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_should_write_no_record_for_a_page_that_is_gone(tmp_path: Path) -> None:
|
|
84
|
+
missing_page_path = tmp_path / "missing.html"
|
|
85
|
+
record_page_link(missing_page_path, PAGE_LINK)
|
|
86
|
+
assert not link_record_path(missing_page_path).exists()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_should_record_a_first_publish_so_the_gate_finds_its_link(tmp_path: Path) -> None:
|
|
90
|
+
page_path = tmp_path / "first-look.html"
|
|
91
|
+
page_path.write_text(PAGE_SOURCE, encoding="utf-8")
|
|
92
|
+
assert _run_record({"file_path": str(page_path)}, f"Published: {PAGE_LINK}") == 0
|
|
93
|
+
assert recorded_page_link(page_path, PAGE_SOURCE) == PAGE_LINK
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_should_write_no_record_for_a_read_or_a_result_with_no_link(tmp_path: Path) -> None:
|
|
97
|
+
page_path = tmp_path / "first-look.html"
|
|
98
|
+
page_path.write_text(PAGE_SOURCE, encoding="utf-8")
|
|
99
|
+
assert _run_record({"action": "read", "url": PAGE_LINK}, PAGE_SOURCE) == 0
|
|
100
|
+
assert _run_record({"file_path": str(page_path)}, "The publish was refused.") == 0
|
|
101
|
+
assert not link_record_path(page_path).exists()
|
|
@@ -31,6 +31,8 @@ UNMEASURED_REASON_BY_SCRIPT = {
|
|
|
31
31
|
"session/plugin_change_warning.py": "emits only after a plugin changes on disk mid-session, "
|
|
32
32
|
"once per plugin, naming plugin ids",
|
|
33
33
|
"blocking/wakeup_cap_gate.py": "emits one fixed-template line only when it rewrites a wake delay",
|
|
34
|
+
"blocking/artifact_current_page_gate.py": "emits one fixed republish note only after a "
|
|
35
|
+
"Playwright render of the page, which the measuring run has no browser for",
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
|
package/package.json
CHANGED
|
@@ -136,6 +136,7 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
136
136
|
hooks/blocking/session_title_format_gate.py -> exempt
|
|
137
137
|
hooks/blocking/task_subject_outcome_gate.py -> exempt
|
|
138
138
|
hooks/blocking/artifact_dark_mode_gate.py -> exempt
|
|
139
|
+
hooks/blocking/artifact_current_page_gate.py -> exempt
|
|
139
140
|
hooks/blocking/send_user_file_worktree_root_gate.py -> exempt
|
|
140
141
|
hooks/blocking/sent_file_question_gate.py -> exempt
|
|
141
142
|
hooks/blocking/question_brief_gate.py -> exempt
|
|
@@ -227,6 +228,11 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
227
228
|
characters. It decides the shape of a task subject and no code or safety
|
|
228
229
|
policy.
|
|
229
230
|
|
|
231
|
+
The artifact current page gate denies a page publish that draws one item
|
|
232
|
+
more than once, or that would open a second link for a page with a
|
|
233
|
+
recorded link. It decides what a published page shows and no code or
|
|
234
|
+
safety policy.
|
|
235
|
+
|
|
230
236
|
Args:
|
|
231
237
|
registered_string: One command, path, script, or entrypoint string.
|
|
232
238
|
"""
|
|
@@ -74,6 +74,7 @@ ALL_ACTION_BOUNDARY_EXEMPT_REGISTRATION_PATHS = (
|
|
|
74
74
|
"blocking/task_subject_outcome_gate.py",
|
|
75
75
|
"blocking/image_read_size_gate.py",
|
|
76
76
|
"blocking/artifact_dark_mode_gate.py",
|
|
77
|
+
"blocking/artifact_current_page_gate.py",
|
|
77
78
|
"blocking/send_user_file_worktree_root_gate.py",
|
|
78
79
|
"blocking/sent_file_question_gate.py",
|
|
79
80
|
"blocking/question_brief_gate.py",
|
|
@@ -162,6 +162,14 @@ def test_new_artifact_page_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
|
162
162
|
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
163
163
|
|
|
164
164
|
|
|
165
|
+
def test_new_artifact_current_page_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
166
|
+
current_document = _hook_document(
|
|
167
|
+
["hooks/blocking/artifact_current_page_gate.py"],
|
|
168
|
+
'{"hooks": {}}',
|
|
169
|
+
)
|
|
170
|
+
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
171
|
+
|
|
172
|
+
|
|
165
173
|
def test_new_send_user_file_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
166
174
|
current_document = _hook_document(
|
|
167
175
|
["hooks/blocking/send_user_file_worktree_root_gate.py"],
|