claude-dev-env 1.38.1 → 1.40.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/CLAUDE.md +10 -36
- package/_shared/pr-loop/audit-reply-template.md +147 -0
- package/_shared/pr-loop/fix-protocol.md +25 -4
- package/_shared/pr-loop/gh-payloads.md +37 -50
- package/_shared/pr-loop/scripts/code_rules_gate.py +0 -60
- package/_shared/pr-loop/scripts/config/post_audit_thread_constants.py +199 -0
- package/_shared/pr-loop/scripts/config/reviews_disabled_constants.py +8 -0
- package/_shared/pr-loop/scripts/post_audit_thread.py +1242 -0
- package/_shared/pr-loop/scripts/preflight.py +129 -2
- package/_shared/pr-loop/scripts/reviews_disabled.py +59 -0
- package/_shared/pr-loop/scripts/tests/test_code_rules_gate.py +0 -19
- package/_shared/pr-loop/scripts/tests/test_post_audit_thread.py +1116 -0
- package/_shared/pr-loop/scripts/tests/test_post_audit_thread_constants.py +127 -0
- package/_shared/pr-loop/scripts/tests/test_preflight.py +41 -0
- package/_shared/pr-loop/scripts/tests/test_reviews_disabled.py +36 -0
- package/_shared/pr-loop/state-schema.md +1 -1
- package/agents/clean-coder.md +2 -2
- package/agents/pr-description-writer.md +150 -52
- package/bin/install.mjs +6 -7
- package/bin/install.test.mjs +8 -0
- package/commands/doc-gist.md +16 -0
- package/commands/plan.md +0 -2
- package/commands/review-plan.md +1 -1
- package/docs/CODE_RULES.md +122 -2
- package/docs/PR_DESCRIPTION_GUIDE.md +127 -64
- package/hooks/blocking/bot_mention_comment_blocker.py +75 -0
- package/hooks/blocking/code_rules_enforcer.py +1143 -129
- package/hooks/blocking/convergence_gate_blocker.py +130 -0
- package/hooks/blocking/destructive_command_blocker.py +74 -0
- package/hooks/blocking/gh_body_arg_blocker.py +30 -0
- package/hooks/blocking/md_to_html_blocker.py +119 -0
- package/hooks/blocking/pr_description_enforcer.py +57 -22
- package/hooks/blocking/test_bot_mention_comment_blocker.py +131 -0
- package/hooks/blocking/test_code_rules_enforcer.py +21 -0
- package/hooks/blocking/test_code_rules_enforcer_any_exempt_files.py +70 -0
- package/hooks/blocking/test_code_rules_enforcer_any_imports_and_cast.py +92 -0
- package/hooks/blocking/test_code_rules_enforcer_banned_import_alias.py +143 -0
- package/hooks/blocking/test_code_rules_enforcer_banned_prefixes.py +152 -0
- package/hooks/blocking/test_code_rules_enforcer_bare_except.py +120 -0
- package/hooks/blocking/test_code_rules_enforcer_boundary_types.py +175 -0
- package/hooks/blocking/test_code_rules_enforcer_cap_meta.py +0 -1
- package/hooks/blocking/test_code_rules_enforcer_collection_prefix.py +50 -0
- package/hooks/blocking/test_code_rules_enforcer_docstring_format.py +255 -0
- package/hooks/blocking/test_code_rules_enforcer_inline_tuple_string_magic.py +130 -0
- package/hooks/blocking/test_code_rules_enforcer_stub_implementations.py +141 -0
- package/hooks/blocking/test_code_rules_enforcer_test_branching.py +143 -0
- package/hooks/blocking/test_code_rules_enforcer_thin_wrapper_files.py +169 -0
- package/hooks/blocking/test_code_rules_enforcer_todo_markers.py +99 -0
- package/hooks/blocking/test_code_rules_enforcer_typed_dict_pairs.py +141 -0
- package/hooks/blocking/test_convergence_gate_blocker.py +63 -0
- package/hooks/blocking/test_destructive_command_blocker.py +146 -0
- package/hooks/blocking/test_destructive_command_blocker_no_verify.py +102 -0
- package/hooks/blocking/test_gh_body_arg_blocker.py +45 -0
- package/hooks/blocking/test_md_to_html_blocker.py +317 -0
- package/hooks/blocking/test_pr_description_enforcer.py +69 -8
- package/hooks/config/any_type_config.py +7 -0
- package/hooks/config/banned_identifiers_constants.py +11 -0
- package/hooks/config/blocking_check_limits.py +38 -0
- package/hooks/config/bot_mention_comment_blocker_constants.py +20 -0
- package/hooks/config/code_rules_enforcer_constants.py +53 -0
- package/hooks/config/convergence_branch_constants.py +9 -0
- package/hooks/config/doc_gist_auto_publish_constants.py +18 -0
- package/hooks/config/html_companion_constants.py +20 -0
- package/hooks/config/inline_tuple_string_magic_constants.py +22 -0
- package/hooks/config/pr_description_enforcer_constants.py +14 -0
- package/hooks/config/test_banned_identifiers_constants.py +17 -0
- package/hooks/hooks.json +28 -20
- package/hooks/pyproject.toml +69 -0
- package/hooks/validators/mypy_integration.py +47 -1
- package/hooks/validators/run_all_validators.py +3 -3
- package/hooks/validators/test_mypy_integration.py +50 -1
- package/hooks/workflow/doc_gist_auto_publish.py +144 -0
- package/hooks/workflow/md_to_html_companion.py +365 -0
- package/hooks/workflow/test_doc_gist_auto_publish.py +117 -0
- package/hooks/workflow/test_md_to_html_companion.py +452 -0
- package/package.json +1 -1
- package/rules/gh-body-file.md +2 -0
- package/scripts/Install-SweepEmptyDirs.ps1 +111 -0
- package/scripts/check.ps1 +106 -0
- package/scripts/config/timing.py +11 -0
- package/scripts/sweep_empty_dirs.py +138 -0
- package/scripts/sync_to_cursor/rules.py +1 -1
- package/scripts/test_sweep_empty_dirs.py +183 -0
- package/skills/_shared/pr-loop/prompts/pr-consistency-audit.xml +323 -0
- package/skills/_shared/pr-loop/scripts/_cli_utils.py +22 -0
- package/skills/_shared/pr-loop/scripts/_path_resolver.py +165 -0
- package/skills/_shared/pr-loop/scripts/_xml_utils.py +20 -0
- package/skills/_shared/pr-loop/scripts/build_audit_prompt.py +182 -0
- package/skills/_shared/pr-loop/scripts/build_fix_prompt.py +185 -0
- package/skills/_shared/pr-loop/scripts/config/__init__.py +0 -0
- package/skills/_shared/pr-loop/scripts/config/path_resolver_constants.py +78 -0
- package/skills/_shared/pr-loop/scripts/init_loop_state.py +135 -0
- package/skills/_shared/pr-loop/scripts/teardown_worktrees.py +175 -0
- package/skills/_shared/pr-loop/scripts/write_audit_outcomes.py +182 -0
- package/skills/_shared/pr-loop/scripts/write_fix_outcomes.py +206 -0
- package/skills/bugteam/CONSTRAINTS.md +21 -22
- package/skills/bugteam/EXAMPLES.md +3 -3
- package/skills/bugteam/PROMPTS.md +227 -67
- package/skills/bugteam/SKILL.md +132 -455
- package/skills/bugteam/reference/README.md +1 -1
- package/skills/bugteam/reference/audit-and-teammates.md +112 -39
- package/skills/bugteam/reference/audit-contract.md +4 -22
- package/skills/bugteam/reference/copilot-gap-analysis.md +8 -5
- package/skills/bugteam/reference/design-rationale.md +2 -2
- package/skills/bugteam/reference/github-pr-reviews.md +50 -57
- package/skills/bugteam/reference/obstacles/audit-assign-ids.md +13 -0
- package/skills/bugteam/reference/obstacles/audit-capture-excerpts.md +13 -0
- package/skills/bugteam/reference/obstacles/audit-walk-categories.md +13 -0
- package/skills/bugteam/reference/obstacles/audit-write-xml.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-append-summary.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-apply-fixes.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-git-add-commit.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-git-push.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-post-reply.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-publish-summary.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-py-compile.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-read-files.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-resolve-thread.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-test-suite.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-violation-count.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-write-xml.md +13 -0
- package/skills/bugteam/reference/team-setup.md +111 -9
- package/skills/bugteam/reference/teardown-publish-permissions.md +39 -8
- package/skills/bugteam/scripts/README.md +60 -0
- package/skills/bugteam/scripts/_claude_permissions_common.py +358 -0
- package/skills/bugteam/scripts/bugteam_code_rules_gate.py +976 -0
- package/skills/bugteam/scripts/bugteam_fix_hookspath.py +375 -0
- package/skills/bugteam/scripts/bugteam_preflight.py +328 -0
- package/skills/bugteam/scripts/config/bugteam_code_rules_gate_constants.py +25 -0
- package/skills/bugteam/scripts/config/bugteam_fix_hookspath_constants.py +26 -0
- package/skills/bugteam/scripts/config/bugteam_preflight_constants.py +35 -0
- package/skills/bugteam/scripts/config/claude_permissions_common_constants.py +20 -0
- package/skills/bugteam/scripts/config/probe_code_rules_enforcer_check_constants.py +12 -0
- package/skills/bugteam/scripts/config/windows_safe_rmtree_constants.py +7 -0
- package/skills/bugteam/scripts/grant_project_claude_permissions.py +175 -0
- package/skills/bugteam/scripts/probe_code_rules_enforcer_check.py +107 -0
- package/skills/bugteam/scripts/revoke_project_claude_permissions.py +220 -0
- package/skills/bugteam/scripts/test__claude_permissions_common.py +112 -0
- package/skills/bugteam/scripts/test_bugteam_code_rules_gate.py +400 -0
- package/skills/bugteam/scripts/test_bugteam_fix_hookspath.py +384 -0
- package/skills/bugteam/scripts/test_bugteam_preflight.py +309 -0
- package/skills/bugteam/scripts/test_claude_permissions_common.py +195 -0
- package/skills/bugteam/scripts/test_grant_project_claude_permissions.py +55 -0
- package/skills/bugteam/scripts/test_probe_code_rules_enforcer_check.py +76 -0
- package/skills/bugteam/scripts/test_revoke_project_claude_permissions.py +55 -0
- package/skills/bugteam/scripts/test_windows_safe_rmtree.py +108 -0
- package/skills/bugteam/scripts/windows_safe_rmtree.py +100 -0
- package/skills/bugteam/test_skill_additions.py +1 -11
- package/skills/code/SKILL.md +176 -0
- package/skills/copilot-review/SKILL.md +16 -0
- package/skills/doc-gist/SKILL.md +99 -0
- package/skills/doc-gist/references/examples/01-exploration-code-approaches.html +453 -0
- package/skills/doc-gist/references/examples/02-exploration-visual-designs.html +515 -0
- package/skills/doc-gist/references/examples/03-code-review-pr.html +638 -0
- package/skills/doc-gist/references/examples/04-code-understanding.html +491 -0
- package/skills/doc-gist/references/examples/05-design-system.html +629 -0
- package/skills/doc-gist/references/examples/06-component-variants.html +605 -0
- package/skills/doc-gist/references/examples/07-prototype-animation.html +455 -0
- package/skills/doc-gist/references/examples/08-prototype-interaction.html +396 -0
- package/skills/doc-gist/references/examples/09-slide-deck.html +592 -0
- package/skills/doc-gist/references/examples/10-svg-illustrations.html +492 -0
- package/skills/doc-gist/references/examples/11-status-report.html +528 -0
- package/skills/doc-gist/references/examples/12-incident-report.html +596 -0
- package/skills/doc-gist/references/examples/13-flowchart-diagram.html +395 -0
- package/skills/doc-gist/references/examples/14-research-feature-explainer.html +381 -0
- package/skills/doc-gist/references/examples/15-research-concept-explainer.html +368 -0
- package/skills/doc-gist/references/examples/16-implementation-plan.html +702 -0
- package/skills/doc-gist/references/examples/17-pr-writeup.html +595 -0
- package/skills/doc-gist/references/examples/18-editor-triage-board.html +573 -0
- package/skills/doc-gist/references/examples/19-editor-feature-flags.html +663 -0
- package/skills/doc-gist/references/examples/20-editor-prompt-tuner.html +722 -0
- package/skills/doc-gist/references/examples/README.md +5 -0
- package/skills/doc-gist/scripts/config/__init__.py +0 -0
- package/skills/doc-gist/scripts/config/gist_upload_constants.py +16 -0
- package/skills/doc-gist/scripts/gist_upload.py +177 -0
- package/skills/doc-gist/scripts/test_gist_upload.py +51 -0
- package/skills/findbugs/SKILL.md +96 -2
- package/skills/monitor-open-prs/SKILL.md +14 -32
- package/skills/monitor-open-prs/test_skill_contract.py +0 -11
- package/skills/pr-consistency-audit/SKILL.md +112 -0
- package/skills/pr-consistency-audit/reference/detection-rules.md +96 -0
- package/skills/pr-consistency-audit/reference/illustrations.md +78 -0
- package/skills/pr-converge/SKILL.md +229 -23
- package/skills/pr-converge/config/__init__.py +0 -0
- package/skills/pr-converge/config/constants.py +63 -0
- package/skills/pr-converge/reference/convergence-gates.md +138 -44
- package/skills/pr-converge/reference/examples.md +43 -11
- package/skills/pr-converge/reference/fix-protocol.md +6 -5
- package/skills/pr-converge/reference/ground-rules.md +5 -3
- package/skills/pr-converge/reference/multi-pr-orchestration.md +44 -19
- package/skills/pr-converge/reference/obstacles/fix-post-replies.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-publish-summary.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-push.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-read-filelines.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-reset-state.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-resolve-threads.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-spawn-clean-coder.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-stage-commit.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-trigger-bugbot.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-write-test.md +13 -0
- package/skills/pr-converge/reference/per-tick.md +107 -31
- package/skills/pr-converge/reference/state-schema.md +22 -1
- package/skills/pr-converge/reference/stop-conditions.md +9 -7
- package/skills/pr-converge/scripts/README.md +34 -46
- package/skills/pr-converge/scripts/check_bugbot_ci.py +279 -0
- package/skills/pr-converge/scripts/check_convergence.py +497 -0
- package/skills/pr-converge/scripts/check_pending_reviews.py +154 -0
- package/skills/pr-converge/scripts/config/pr_converge_constants.py +118 -0
- package/skills/pr-converge/scripts/fetch_copilot_reviews.py +134 -0
- package/skills/pr-converge/scripts/post_fix_reply.py +168 -0
- package/skills/pr-converge/scripts/test_check_bugbot_ci.py +312 -0
- package/skills/pr-converge/workflows/schedule-wakeup-loop.md +5 -12
- package/skills/qbug/SKILL.md +157 -27
- package/skills/session-log/SKILL.md +216 -114
- package/skills/session-tidy/SKILL.md +1 -1
- package/skills/skill-builder/SKILL.md +138 -56
- package/skills/skill-builder/references/delegation-map.md +72 -113
- package/skills/skill-builder/references/progressive-disclosure.md +122 -0
- package/skills/skill-builder/references/self-audit-checklist.md +92 -0
- package/skills/skill-builder/references/skill-types.md +228 -0
- package/skills/skill-builder/references/thariq-x-post-skills.json +33 -0
- package/skills/skill-builder/templates/gap-analysis.md +15 -8
- package/skills/skill-builder/workflows/improve-skill.md +86 -57
- package/skills/skill-builder/workflows/new-skill.md +80 -168
- package/skills/skill-builder/workflows/polish-skill.md +78 -54
- package/skills/structure-prompt/SKILL.md +50 -0
- package/skills/structure-prompt/reference/adversarial-tuning.md +62 -0
- package/skills/structure-prompt/reference/block-classification.md +27 -0
- package/skills/structure-prompt/reference/canonical-case.md +48 -0
- package/skills/structure-prompt/reference/citation-depth.md +70 -0
- package/skills/structure-prompt/reference/cleanup.md +33 -0
- package/skills/structure-prompt/reference/constraints.md +33 -0
- package/skills/structure-prompt/reference/directives.md +37 -0
- package/skills/structure-prompt/reference/examples.md +72 -0
- package/skills/structure-prompt/reference/instantiation.md +51 -0
- package/skills/structure-prompt/reference/output-contract.md +72 -0
- package/skills/structure-prompt/reference/per-category.md +23 -0
- package/skills/structure-prompt/reference/persona.md +38 -0
- package/skills/structure-prompt/reference/research.md +33 -0
- package/skills/structure-prompt/reference/structure.md +28 -0
- package/agents/code-standards-agent.md +0 -93
- package/agents/groq-coder.md +0 -113
- package/agents/plan-executor.md +0 -226
- package/agents/project-docs-analyzer.md +0 -53
- package/agents/project-structure-organizer-agent.md +0 -72
- package/agents/skill-to-agent-converter.md +0 -370
- package/agents/skill-writer-agent.md +0 -470
- package/agents/user-docs-writer.md +0 -67
- package/agents/workflow-visual-documenter.md +0 -82
- package/commands/readability-review.md +0 -20
- package/hooks/mypy.ini +0 -2
- package/hooks/notification/attention_needed_notify.py +0 -71
- package/hooks/notification/claude_notification_handler.py +0 -67
- package/hooks/notification/notification_utils.py +0 -267
- package/hooks/notification/subagent_complete_notify.py +0 -381
- package/hooks/notification/test_attention_needed_notify.py +0 -47
- package/hooks/notification/test_claude_notification_handler.py +0 -54
- package/hooks/notification/test_notification_utils.py +0 -91
- package/hooks/notification/test_subagent_complete_notify.py +0 -79
- package/scripts/config/groq_bugteam_config.py +0 -230
- package/scripts/config/test_groq_bugteam_config.py +0 -83
- package/scripts/config/test_spec_implementer_prompt.py +0 -32
- package/scripts/groq_bugteam.README.md +0 -131
- package/scripts/groq_bugteam.py +0 -647
- package/scripts/groq_bugteam_dotenv.py +0 -40
- package/scripts/groq_bugteam_spec.py +0 -226
- package/scripts/test_groq_bugteam.py +0 -529
- package/scripts/test_groq_bugteam_apply_fix_from_spec.py +0 -426
- package/scripts/test_groq_bugteam_dotenv.py +0 -66
- package/scripts/test_groq_bugteam_spec.py +0 -338
- package/skills/bugteam/SKILL_EVALS.md +0 -309
- package/skills/dream/SKILL.md +0 -118
- package/skills/ingest/SKILL.md +0 -40
- package/skills/npm-creator/SKILL.md +0 -187
- package/skills/readability-review/SKILL.md +0 -127
- package/skills/resume-review/SKILL.md +0 -261
- package/skills/rule-audit/SKILL.md +0 -307
- package/skills/rule-creator/SKILL.md +0 -150
- package/skills/searching-obsidian-vault/SKILL.md +0 -131
- package/skills/skill-writer/REFERENCE.md +0 -284
- package/skills/skill-writer/SKILL.md +0 -222
- package/skills/tdd-team/SKILL.md +0 -128
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""PostToolUse hook: generates a companion .html from a .md file after write.
|
|
3
|
+
|
|
4
|
+
The .md serves as a first draft; the .html is a 2nd-pass refinement with
|
|
5
|
+
dark-mode styling that also validates the .md structure.
|
|
6
|
+
See https://thariqs.github.io/html-effectiveness/
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import logging
|
|
11
|
+
import os
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
from html import escape
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from urllib.parse import urlparse
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
logging.basicConfig(stream=sys.stderr, level=logging.WARNING, format="%(message)s")
|
|
20
|
+
|
|
21
|
+
_hook_dir = str(Path(__file__).absolute().parent.parent)
|
|
22
|
+
if _hook_dir not in sys.path:
|
|
23
|
+
sys.path.insert(0, _hook_dir)
|
|
24
|
+
|
|
25
|
+
from config.html_companion_constants import ( # noqa: E402
|
|
26
|
+
BLOCKED_URL_SCHEMES,
|
|
27
|
+
CSS_ACCENT_COLOR,
|
|
28
|
+
CSS_BG_COLOR,
|
|
29
|
+
CSS_BODY_PADDING,
|
|
30
|
+
CSS_BORDER_COLOR,
|
|
31
|
+
CSS_CODE_SIZE,
|
|
32
|
+
CSS_FG_COLOR,
|
|
33
|
+
CSS_H1_SIZE,
|
|
34
|
+
CSS_H2_SIZE,
|
|
35
|
+
CSS_H3_SIZE,
|
|
36
|
+
CSS_LINE_HEIGHT,
|
|
37
|
+
CSS_MAX_WIDTH,
|
|
38
|
+
CSS_MUTED_COLOR,
|
|
39
|
+
CSS_STRONG_COLOR,
|
|
40
|
+
CSS_SURFACE_COLOR,
|
|
41
|
+
CSS_TABLE_WIDTH,
|
|
42
|
+
CSS_TH_WEIGHT,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _is_exempt_path(file_path: str) -> bool:
|
|
47
|
+
normalized = file_path.replace("\\", "/")
|
|
48
|
+
if "/.claude/" in normalized or normalized.startswith(".claude/"):
|
|
49
|
+
return True
|
|
50
|
+
if normalized.startswith("./"):
|
|
51
|
+
normalized = normalized[2:]
|
|
52
|
+
stripped = normalized.lstrip("/")
|
|
53
|
+
if "/" not in stripped:
|
|
54
|
+
return stripped.lower() in ("readme.md", "changelog.md")
|
|
55
|
+
return False
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _md_to_html(markdown_text: str) -> str:
|
|
59
|
+
text = markdown_text.strip()
|
|
60
|
+
if not text:
|
|
61
|
+
return ""
|
|
62
|
+
|
|
63
|
+
all_lines = text.split("\n")
|
|
64
|
+
all_output_lines: list[str] = []
|
|
65
|
+
is_in_code_block = False
|
|
66
|
+
is_in_unordered_list = False
|
|
67
|
+
is_in_ordered_list = False
|
|
68
|
+
paragraph_buffer: list[str] = []
|
|
69
|
+
|
|
70
|
+
def flush_paragraph() -> None:
|
|
71
|
+
if paragraph_buffer:
|
|
72
|
+
all_output_lines.append("<p>" + "\n".join(paragraph_buffer) + "</p>")
|
|
73
|
+
paragraph_buffer.clear()
|
|
74
|
+
|
|
75
|
+
def close_lists() -> None:
|
|
76
|
+
nonlocal is_in_unordered_list, is_in_ordered_list
|
|
77
|
+
if is_in_unordered_list:
|
|
78
|
+
all_output_lines.append("</ul>")
|
|
79
|
+
is_in_unordered_list = False
|
|
80
|
+
if is_in_ordered_list:
|
|
81
|
+
all_output_lines.append("</ol>")
|
|
82
|
+
is_in_ordered_list = False
|
|
83
|
+
|
|
84
|
+
for each_line in all_lines:
|
|
85
|
+
if each_line.startswith("```"):
|
|
86
|
+
if is_in_code_block:
|
|
87
|
+
all_output_lines.append("</code></pre>")
|
|
88
|
+
is_in_code_block = False
|
|
89
|
+
else:
|
|
90
|
+
flush_paragraph()
|
|
91
|
+
close_lists()
|
|
92
|
+
language = each_line[3:].strip()
|
|
93
|
+
if language and re.match(r"^[A-Za-z0-9_+#-]+$", language):
|
|
94
|
+
all_output_lines.append(
|
|
95
|
+
f'<pre><code class="language-{language}">'
|
|
96
|
+
)
|
|
97
|
+
else:
|
|
98
|
+
all_output_lines.append("<pre><code>")
|
|
99
|
+
is_in_code_block = True
|
|
100
|
+
continue
|
|
101
|
+
|
|
102
|
+
if is_in_code_block:
|
|
103
|
+
all_output_lines.append(escape(each_line))
|
|
104
|
+
continue
|
|
105
|
+
|
|
106
|
+
stripped = each_line.strip()
|
|
107
|
+
if not stripped:
|
|
108
|
+
flush_paragraph()
|
|
109
|
+
close_lists()
|
|
110
|
+
continue
|
|
111
|
+
|
|
112
|
+
if stripped.startswith("# "):
|
|
113
|
+
flush_paragraph()
|
|
114
|
+
close_lists()
|
|
115
|
+
all_output_lines.append(f"<h1>{_inline_format(stripped[2:])}</h1>")
|
|
116
|
+
elif stripped.startswith("## "):
|
|
117
|
+
flush_paragraph()
|
|
118
|
+
close_lists()
|
|
119
|
+
all_output_lines.append(f"<h2>{_inline_format(stripped[3:])}</h2>")
|
|
120
|
+
elif stripped.startswith("### "):
|
|
121
|
+
flush_paragraph()
|
|
122
|
+
close_lists()
|
|
123
|
+
all_output_lines.append(f"<h3>{_inline_format(stripped[4:])}</h3>")
|
|
124
|
+
elif stripped.startswith("#### "):
|
|
125
|
+
flush_paragraph()
|
|
126
|
+
close_lists()
|
|
127
|
+
all_output_lines.append(f"<h4>{_inline_format(stripped[5:])}</h4>")
|
|
128
|
+
elif stripped.startswith("##### "):
|
|
129
|
+
flush_paragraph()
|
|
130
|
+
close_lists()
|
|
131
|
+
all_output_lines.append(f"<h5>{_inline_format(stripped[6:])}</h5>")
|
|
132
|
+
elif stripped.startswith("###### "):
|
|
133
|
+
flush_paragraph()
|
|
134
|
+
close_lists()
|
|
135
|
+
all_output_lines.append(f"<h6>{_inline_format(stripped[7:])}</h6>")
|
|
136
|
+
elif stripped.startswith("- ") or stripped.startswith("* "):
|
|
137
|
+
flush_paragraph()
|
|
138
|
+
if is_in_ordered_list:
|
|
139
|
+
all_output_lines.append("</ol>")
|
|
140
|
+
is_in_ordered_list = False
|
|
141
|
+
if not is_in_unordered_list:
|
|
142
|
+
all_output_lines.append("<ul>")
|
|
143
|
+
is_in_unordered_list = True
|
|
144
|
+
all_output_lines.append(f"<li>{_inline_format(stripped[2:])}</li>")
|
|
145
|
+
elif re.match(r"^\d+\.\s", stripped):
|
|
146
|
+
flush_paragraph()
|
|
147
|
+
if is_in_unordered_list:
|
|
148
|
+
all_output_lines.append("</ul>")
|
|
149
|
+
is_in_unordered_list = False
|
|
150
|
+
if not is_in_ordered_list:
|
|
151
|
+
all_output_lines.append("<ol>")
|
|
152
|
+
is_in_ordered_list = True
|
|
153
|
+
content = re.sub(r"^\d+\.\s", "", stripped)
|
|
154
|
+
all_output_lines.append(f"<li>{_inline_format(content)}</li>")
|
|
155
|
+
elif stripped == "---":
|
|
156
|
+
flush_paragraph()
|
|
157
|
+
close_lists()
|
|
158
|
+
all_output_lines.append("<hr>")
|
|
159
|
+
elif stripped.startswith("> "):
|
|
160
|
+
flush_paragraph()
|
|
161
|
+
close_lists()
|
|
162
|
+
all_output_lines.append(
|
|
163
|
+
f"<blockquote>{_inline_format(stripped[2:])}</blockquote>"
|
|
164
|
+
)
|
|
165
|
+
else:
|
|
166
|
+
paragraph_buffer.append(_inline_format(stripped))
|
|
167
|
+
|
|
168
|
+
if is_in_code_block:
|
|
169
|
+
all_output_lines.append("</code></pre>")
|
|
170
|
+
close_lists()
|
|
171
|
+
flush_paragraph()
|
|
172
|
+
|
|
173
|
+
return "\n".join(all_output_lines)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _placeholder(
|
|
177
|
+
match: re.Match, storage: list, open_tag: str, close_tag: str
|
|
178
|
+
) -> str:
|
|
179
|
+
placeholder = f"\x00CODE{len(storage)}\x00"
|
|
180
|
+
storage.append((placeholder, f"{open_tag}{match.group(1)}{close_tag}"))
|
|
181
|
+
return placeholder
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _inline_format(text: str) -> str:
|
|
185
|
+
text = escape(text)
|
|
186
|
+
|
|
187
|
+
code_placeholders: list[tuple[str, str]] = []
|
|
188
|
+
text = re.sub(
|
|
189
|
+
r"`([^`]+)`",
|
|
190
|
+
lambda m: _placeholder(m, code_placeholders, "<code>", "</code>"),
|
|
191
|
+
text,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
link_placeholders: list[tuple[str, str, str]] = []
|
|
195
|
+
|
|
196
|
+
def _save_link(match: re.Match) -> str:
|
|
197
|
+
link_text = match.group("text")
|
|
198
|
+
url = match.group("url").strip()
|
|
199
|
+
parsed_url = urlparse(url)
|
|
200
|
+
if parsed_url.scheme.lower() in BLOCKED_URL_SCHEMES:
|
|
201
|
+
url = ""
|
|
202
|
+
placeholder = f"\x00LINK{len(link_placeholders)}\x00"
|
|
203
|
+
link_placeholders.append((placeholder, url, link_text))
|
|
204
|
+
return placeholder
|
|
205
|
+
|
|
206
|
+
text = re.sub(
|
|
207
|
+
r"\[(?P<text>[^\]]+)\]\((?P<url>(?:[^)(]+|\([^)(]*\))*)\)",
|
|
208
|
+
_save_link,
|
|
209
|
+
text,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
text = re.sub(r"\*\*(.+?)\*\*", r"<strong>\1</strong>", text)
|
|
213
|
+
text = re.sub(r"\*(.+?)\*", r"<em>\1</em>", text)
|
|
214
|
+
|
|
215
|
+
for placeholder, url, link_text in link_placeholders:
|
|
216
|
+
if url == "":
|
|
217
|
+
text = text.replace(placeholder, link_text)
|
|
218
|
+
else:
|
|
219
|
+
text = text.replace(placeholder, f'<a href="{url}">{link_text}</a>')
|
|
220
|
+
for placeholder, content in code_placeholders:
|
|
221
|
+
text = text.replace(placeholder, content)
|
|
222
|
+
return text
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _extract_title(markdown_text: str) -> str:
|
|
226
|
+
for each_line in markdown_text.strip().split("\n"):
|
|
227
|
+
stripped = each_line.strip()
|
|
228
|
+
if stripped.startswith("# "):
|
|
229
|
+
return stripped[2:].strip()
|
|
230
|
+
return "Document"
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _html_template(title: str, body: str) -> str:
|
|
234
|
+
return """<!DOCTYPE html>
|
|
235
|
+
<html lang="en">
|
|
236
|
+
<head>
|
|
237
|
+
<meta charset="UTF-8">
|
|
238
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
239
|
+
<title>{title}</title>
|
|
240
|
+
<style>
|
|
241
|
+
:root {{ color-scheme: dark; }}
|
|
242
|
+
* {{ box-sizing: border-box; margin: 0; padding: 0; }}
|
|
243
|
+
body {{
|
|
244
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
245
|
+
background: rgb({bg}); color: rgb({fg}); line-height: {line_height};
|
|
246
|
+
padding: {body_padding}; max-width: {max_width}; margin: 0 auto;
|
|
247
|
+
}}
|
|
248
|
+
h1 {{ font-size: {h1_size}; border-bottom: 1px solid rgb({border}); padding-bottom: 0.5rem; margin: 1.5rem 0 1rem; }}
|
|
249
|
+
h2 {{ font-size: {h2_size}; margin: 1.25rem 0 0.75rem; color: rgb({accent}); }}
|
|
250
|
+
h3 {{ font-size: {h3_size}; margin: 1rem 0 0.5rem; }}
|
|
251
|
+
p {{ margin: 0.75rem 0; }}
|
|
252
|
+
a {{ color: rgb({accent}); }}
|
|
253
|
+
code {{
|
|
254
|
+
font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: {code_size};
|
|
255
|
+
background: rgb({surface}); padding: 0.15em 0.35em; border-radius: 3px;
|
|
256
|
+
}}
|
|
257
|
+
pre {{
|
|
258
|
+
background: rgb({surface}); border: 1px solid rgb({border});
|
|
259
|
+
border-radius: 6px; padding: 1rem; overflow-x: auto; margin: 0.75rem 0;
|
|
260
|
+
}}
|
|
261
|
+
pre code {{ background: none; padding: 0; }}
|
|
262
|
+
ul, ol {{ padding-left: 1.5rem; margin: 0.5rem 0; }}
|
|
263
|
+
li {{ margin: 0.25rem 0; }}
|
|
264
|
+
strong {{ color: rgb({strong}); }}
|
|
265
|
+
table {{ width: {table_width}; border-collapse: collapse; margin: 0.75rem 0; }}
|
|
266
|
+
th, td {{ padding: 0.5rem 0.75rem; text-align: left; border: 1px solid rgb({border}); }}
|
|
267
|
+
th {{ background: rgb({surface}); font-weight: {th_weight}; }}
|
|
268
|
+
hr {{ border: none; border-top: 1px solid rgb({border}); margin: 1.5rem 0; }}
|
|
269
|
+
blockquote {{
|
|
270
|
+
border-left: 3px solid rgb({accent}); padding-left: 1rem;
|
|
271
|
+
color: rgb({muted}); margin: 0.75rem 0;
|
|
272
|
+
}}
|
|
273
|
+
</style>
|
|
274
|
+
</head>
|
|
275
|
+
<body>
|
|
276
|
+
{body}
|
|
277
|
+
</body>
|
|
278
|
+
</html>""".format(
|
|
279
|
+
title=title,
|
|
280
|
+
body=body,
|
|
281
|
+
bg=CSS_BG_COLOR,
|
|
282
|
+
fg=CSS_FG_COLOR,
|
|
283
|
+
border=CSS_BORDER_COLOR,
|
|
284
|
+
accent=CSS_ACCENT_COLOR,
|
|
285
|
+
muted=CSS_MUTED_COLOR,
|
|
286
|
+
surface=CSS_SURFACE_COLOR,
|
|
287
|
+
strong=CSS_STRONG_COLOR,
|
|
288
|
+
line_height=CSS_LINE_HEIGHT,
|
|
289
|
+
body_padding=CSS_BODY_PADDING,
|
|
290
|
+
max_width=CSS_MAX_WIDTH,
|
|
291
|
+
h1_size=CSS_H1_SIZE,
|
|
292
|
+
h2_size=CSS_H2_SIZE,
|
|
293
|
+
h3_size=CSS_H3_SIZE,
|
|
294
|
+
code_size=CSS_CODE_SIZE,
|
|
295
|
+
table_width=CSS_TABLE_WIDTH,
|
|
296
|
+
th_weight=CSS_TH_WEIGHT,
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def main() -> None:
|
|
301
|
+
"""Process a PostToolUse hook payload from stdin.
|
|
302
|
+
|
|
303
|
+
Reads JSON with tool_name and tool_input.file_path from stdin.
|
|
304
|
+
When file_path is a .md file outside .claude/, generates a companion
|
|
305
|
+
.html file alongside it.
|
|
306
|
+
|
|
307
|
+
Args:
|
|
308
|
+
(reads from sys.stdin — no function arguments)
|
|
309
|
+
|
|
310
|
+
Returns:
|
|
311
|
+
None — exits 0 on success or when no action is needed.
|
|
312
|
+
"""
|
|
313
|
+
try:
|
|
314
|
+
input_data = json.load(sys.stdin)
|
|
315
|
+
except json.JSONDecodeError:
|
|
316
|
+
sys.exit(0)
|
|
317
|
+
|
|
318
|
+
if not isinstance(input_data, dict):
|
|
319
|
+
sys.exit(0)
|
|
320
|
+
|
|
321
|
+
tool_name = input_data.get("tool_name", "")
|
|
322
|
+
if tool_name not in ("Write", "Edit"):
|
|
323
|
+
sys.exit(0)
|
|
324
|
+
|
|
325
|
+
tool_input = input_data.get("tool_input", {})
|
|
326
|
+
if not isinstance(tool_input, dict):
|
|
327
|
+
sys.exit(0)
|
|
328
|
+
|
|
329
|
+
file_path = tool_input.get("file_path", "")
|
|
330
|
+
if not file_path or not file_path.lower().endswith(".md"):
|
|
331
|
+
sys.exit(0)
|
|
332
|
+
|
|
333
|
+
if _is_exempt_path(file_path):
|
|
334
|
+
sys.exit(0)
|
|
335
|
+
|
|
336
|
+
if not os.path.exists(file_path):
|
|
337
|
+
sys.exit(0)
|
|
338
|
+
|
|
339
|
+
try:
|
|
340
|
+
with open(file_path, encoding="utf-8") as f:
|
|
341
|
+
md_content = f.read()
|
|
342
|
+
except OSError:
|
|
343
|
+
sys.exit(0)
|
|
344
|
+
|
|
345
|
+
if not md_content.strip():
|
|
346
|
+
sys.exit(0)
|
|
347
|
+
|
|
348
|
+
title = escape(_extract_title(md_content))
|
|
349
|
+
html_body = _md_to_html(md_content)
|
|
350
|
+
html_content = _html_template(title=title, body=html_body)
|
|
351
|
+
|
|
352
|
+
html_path = os.path.splitext(file_path)[0] + ".html"
|
|
353
|
+
try:
|
|
354
|
+
with open(html_path, "w", encoding="utf-8") as f:
|
|
355
|
+
f.write(html_content)
|
|
356
|
+
except OSError:
|
|
357
|
+
logging.warning(
|
|
358
|
+
"md_to_html_companion: failed to write %s", html_path
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
sys.exit(0)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
if __name__ == "__main__":
|
|
365
|
+
main()
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Tests for doc_gist_auto_publish hook.
|
|
2
|
+
|
|
3
|
+
Validates payload parsing, target-path resolution, sentinel detection,
|
|
4
|
+
and the always-exit-0 contract without needing `gh` authentication.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import tempfile
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
HOOK_SCRIPT_PATH = os.path.join(os.path.dirname(__file__), "doc_gist_auto_publish.py")
|
|
16
|
+
SENTINEL = "<!-- @publish-as-gist -->"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
STUB_PREVIEW_URL = "https://htmlpreview.github.io/?stub"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class _RunHook:
|
|
23
|
+
def __call__(self, tool_name: str, tool_input: dict) -> subprocess.CompletedProcess:
|
|
24
|
+
payload = json.dumps({"tool_name": tool_name, "tool_input": tool_input})
|
|
25
|
+
with tempfile.TemporaryDirectory() as isolation_root:
|
|
26
|
+
stub_dir = Path(isolation_root) / "skills" / "doc-gist" / "scripts"
|
|
27
|
+
stub_dir.mkdir(parents=True)
|
|
28
|
+
(stub_dir / "gist_upload.py").write_text(
|
|
29
|
+
f"import sys; print({STUB_PREVIEW_URL!r}); "
|
|
30
|
+
f"print('Gist: stub', file=sys.stderr); "
|
|
31
|
+
f"print('Preview: stub', file=sys.stderr)",
|
|
32
|
+
encoding="utf-8",
|
|
33
|
+
)
|
|
34
|
+
return subprocess.run(
|
|
35
|
+
[sys.executable, HOOK_SCRIPT_PATH, isolation_root],
|
|
36
|
+
input=payload,
|
|
37
|
+
capture_output=True,
|
|
38
|
+
text=True,
|
|
39
|
+
check=False,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
_run_hook = _RunHook()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_exits_zero_on_invalid_json():
|
|
47
|
+
result = subprocess.run(
|
|
48
|
+
[sys.executable, HOOK_SCRIPT_PATH],
|
|
49
|
+
input="not json",
|
|
50
|
+
capture_output=True,
|
|
51
|
+
text=True,
|
|
52
|
+
check=False,
|
|
53
|
+
)
|
|
54
|
+
assert result.returncode == 0
|
|
55
|
+
assert "invalid json" in result.stderr.lower()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_exits_zero_on_non_dict_payload():
|
|
59
|
+
result = subprocess.run(
|
|
60
|
+
[sys.executable, HOOK_SCRIPT_PATH],
|
|
61
|
+
input="[]",
|
|
62
|
+
capture_output=True,
|
|
63
|
+
text=True,
|
|
64
|
+
check=False,
|
|
65
|
+
)
|
|
66
|
+
assert result.returncode == 0
|
|
67
|
+
assert result.stderr == ""
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_skips_non_html_files():
|
|
71
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
72
|
+
txt_path = os.path.join(tmp, "notes.txt")
|
|
73
|
+
with open(txt_path, "w", encoding="utf-8") as f:
|
|
74
|
+
f.write("plain text")
|
|
75
|
+
|
|
76
|
+
result = _run_hook("Write", {"file_path": txt_path, "content": "plain text"})
|
|
77
|
+
assert result.returncode == 0
|
|
78
|
+
assert result.stderr == ""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_skips_html_without_sentinel():
|
|
82
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
83
|
+
html_path = os.path.join(tmp, "page.html")
|
|
84
|
+
with open(html_path, "w", encoding="utf-8") as f:
|
|
85
|
+
f.write("<html><body>No marker</body></html>")
|
|
86
|
+
|
|
87
|
+
result = _run_hook("Write", {"file_path": html_path, "content": "<html>"})
|
|
88
|
+
assert result.returncode == 0
|
|
89
|
+
assert result.stderr == ""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_exits_zero_when_html_has_sentinel():
|
|
93
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
94
|
+
html_path = os.path.join(tmp, "report.html")
|
|
95
|
+
with open(html_path, "w", encoding="utf-8") as f:
|
|
96
|
+
f.write(f"<html>{SENTINEL}<body>Report</body></html>")
|
|
97
|
+
|
|
98
|
+
result = _run_hook("Write", {"file_path": html_path, "content": "<html>"})
|
|
99
|
+
assert result.returncode == 0
|
|
100
|
+
assert STUB_PREVIEW_URL in result.stdout
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_skips_non_write_tool():
|
|
104
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
105
|
+
html_path = os.path.join(tmp, "page.html")
|
|
106
|
+
with open(html_path, "w", encoding="utf-8") as f:
|
|
107
|
+
f.write(f"<html>{SENTINEL}</html>")
|
|
108
|
+
|
|
109
|
+
result = _run_hook("Read", {"file_path": html_path})
|
|
110
|
+
assert result.returncode == 0
|
|
111
|
+
assert result.stderr == ""
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_exits_zero_when_file_missing():
|
|
115
|
+
result = _run_hook("Write", {"file_path": "/nonexistent/path/page.html"})
|
|
116
|
+
assert result.returncode == 0
|
|
117
|
+
assert result.stderr == ""
|