claude-dev-env 1.93.1 → 1.95.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/_shared/advisor/CLAUDE.md +2 -2
- package/_shared/advisor/advisor-protocol.md +35 -27
- package/_shared/advisor/scripts/config/advisor_scripts_constants/model_tier_run_validator_constants.py +3 -2
- package/_shared/advisor/scripts/model_tier_run_validator.py +23 -15
- package/_shared/advisor/scripts/tests/test_model_tier_run_validator.py +81 -17
- package/_shared/pr-loop/CLAUDE.md +1 -0
- package/_shared/pr-loop/audit-contract.md +1 -1
- package/_shared/pr-loop/gh-payloads.md +3 -3
- package/_shared/pr-loop/post-audit-thread-contract.md +51 -0
- package/_shared/pr-loop/scripts/README.md +2 -2
- package/_shared/pr-loop/scripts/fix_hookspath.py +47 -12
- package/_shared/pr-loop/scripts/tests/test_code_rules_gate.py +0 -69
- package/_shared/pr-loop/scripts/tests/test_fix_hookspath.py +497 -374
- package/_shared/pr-loop/state-schema.md +3 -22
- package/bin/CLAUDE.md +11 -2
- package/bin/ever-shipped-skills.mjs +70 -0
- package/bin/install.mjs +138 -13
- package/bin/install.prune.test.mjs +457 -0
- package/bin/install.test.mjs +10 -4
- package/docs/CODE_RULES.md +1 -1
- package/hooks/blocking/CLAUDE.md +2 -0
- package/hooks/blocking/code_rules_enforcer.py +4 -0
- package/hooks/blocking/code_rules_shared.py +82 -0
- package/hooks/blocking/code_rules_test_layout.py +9 -3
- package/hooks/blocking/pii_commit_command.py +398 -0
- package/hooks/blocking/pii_payload_scan.py +133 -0
- package/hooks/blocking/pii_prevention_blocker.py +151 -449
- package/hooks/blocking/plain_language_blocker.py +138 -4
- package/hooks/blocking/sensitive_file_protector.py +114 -48
- package/hooks/blocking/tdd_enforcer.py +9 -2
- package/hooks/blocking/test_code_rules_enforcer_scratchpad.py +105 -0
- package/hooks/blocking/test_code_rules_shared.py +181 -0
- package/hooks/blocking/test_pii_prevention_blocker.py +299 -0
- package/hooks/blocking/test_plain_language_blocker_allowlist.py +184 -0
- package/hooks/blocking/test_sensitive_file_protector.py +185 -0
- package/hooks/blocking/test_tdd_enforcer_scratchpad.py +105 -0
- package/hooks/blocking/test_verdict_directory_write_blocker.py +42 -7
- package/hooks/hooks_constants/CLAUDE.md +4 -2
- package/hooks/hooks_constants/code_rules_path_utils_constants.py +0 -2
- package/hooks/hooks_constants/harness_scratchpad_constants.py +17 -0
- package/hooks/hooks_constants/local_identity.py +65 -15
- package/hooks/hooks_constants/pii_prevention_constants.py +16 -0
- package/hooks/hooks_constants/plain_language_blocker_constants.py +5 -0
- package/hooks/hooks_constants/pr_description_enforcer_constants.py +1 -1
- package/hooks/hooks_constants/sensitive_file_protector_constants.py +42 -0
- package/hooks/hooks_constants/test_local_identity.py +68 -0
- package/hooks/pyproject.toml +75 -4
- package/hooks/validators/CLAUDE.md +1 -1
- package/hooks/validators/README.md +2 -0
- package/hooks/validators/python_style_checks.py +114 -136
- package/hooks/validators/python_style_helpers.py +95 -0
- package/hooks/validators/test_python_style_checks.py +0 -164
- package/hooks/validators/test_python_style_checks_decorator_gap.py +119 -0
- package/hooks/validators/test_python_style_fixes.py +251 -0
- package/hooks/validators/test_python_style_helpers.py +125 -0
- package/package.json +1 -1
- package/rules/CLAUDE.md +1 -0
- package/rules/anti-corollary-tests.md +69 -0
- package/rules/bdd.md +1 -3
- package/rules/code-reviews.md +1 -1
- package/rules/gh-paginate.md +1 -1
- package/rules/plain-language.md +2 -0
- package/scripts/CLAUDE.md +10 -1
- package/scripts/Get-SessionAccount.ps1 +210 -0
- package/scripts/tests/CLAUDE.md +15 -1
- package/scripts/tests/Get-SessionAccount.Tests.ps1 +350 -0
- package/skills/CLAUDE.md +6 -27
- package/skills/anthropic-plan/SKILL.md +1 -13
- package/skills/autoconverge/CLAUDE.md +5 -2
- package/skills/autoconverge/SKILL.md +112 -387
- package/skills/autoconverge/reference/CLAUDE.md +4 -1
- package/skills/autoconverge/reference/closing-report.md +9 -2
- package/skills/autoconverge/reference/convergence.md +26 -22
- package/skills/autoconverge/reference/headless-safety.md +44 -0
- package/skills/autoconverge/reference/multi-pr.md +88 -0
- package/skills/autoconverge/reference/self-closing-loop.md +84 -0
- package/skills/autoconverge/reference/stop-conditions.md +21 -13
- package/skills/autoconverge/workflow/converge.clean-audit.test.mjs +87 -27
- package/skills/autoconverge/workflow/converge.contract.test.mjs +40 -10
- package/skills/autoconverge/workflow/converge.copilot-gate.test.mjs +179 -47
- package/skills/autoconverge/workflow/converge.fix-progress.test.mjs +1 -1
- package/skills/autoconverge/workflow/converge.mjs +286 -96
- package/skills/bugteam/CLAUDE.md +1 -1
- package/skills/bugteam/CONSTRAINTS.md +3 -3
- package/skills/bugteam/PROMPTS.md +8 -19
- package/skills/bugteam/SKILL.md +13 -14
- package/skills/bugteam/reference/CLAUDE.md +1 -1
- package/skills/bugteam/reference/README.md +2 -3
- package/skills/bugteam/reference/audit-and-teammates.md +2 -2
- package/skills/bugteam/reference/copilot-gap-analysis.md +2 -0
- package/skills/bugteam/reference/github-pr-reviews.md +56 -38
- package/skills/bugteam/reference/team-setup.md +11 -11
- package/skills/bugteam/scripts/CLAUDE.md +6 -6
- package/skills/bugteam/scripts/README.md +20 -8
- package/skills/bugteam/scripts/bugteam_code_rules_gate.py +13 -1463
- package/skills/bugteam/scripts/bugteam_fix_hookspath.py +23 -358
- package/skills/bugteam/scripts/bugteam_preflight.py +13 -315
- package/skills/bugteam/scripts/bugteam_scripts_constants/CLAUDE.md +2 -3
- package/skills/bugteam/scripts/test_bugteam_code_rules_gate.py +34 -1053
- package/skills/bugteam/scripts/test_bugteam_fix_hookspath.py +30 -347
- package/skills/bugteam/scripts/test_bugteam_preflight.py +30 -305
- package/skills/closeout/SKILL.md +153 -0
- package/skills/closeout/reference/handoff-prompt-template.md +72 -0
- package/skills/closeout/reference/issue-body-templates.md +108 -0
- package/skills/closeout/reference/pii-redaction-checklist.md +36 -0
- package/skills/copilot-finding-triage/SKILL.md +80 -28
- package/skills/copilot-finding-triage/reference/tier-rubric.md +70 -11
- package/skills/copilot-finding-triage/templates/notification.md +8 -3
- package/skills/everything-search/SKILL.md +1 -2
- package/skills/grokify/SKILL.md +58 -0
- package/skills/grokify/templates/handoff-template.md +92 -0
- package/skills/orchestrator/SKILL.md +35 -25
- package/skills/orchestrator-refresh/SKILL.md +15 -11
- package/skills/pr-converge/CLAUDE.md +1 -1
- package/skills/pr-converge/SKILL.md +132 -233
- package/skills/pr-converge/reference/convergence-gates.md +102 -66
- package/skills/pr-converge/reference/examples.md +37 -25
- package/skills/pr-converge/reference/fix-protocol.md +7 -7
- package/skills/pr-converge/reference/multi-pr-orchestration.md +10 -4
- package/skills/pr-converge/reference/per-tick.md +64 -41
- package/skills/pr-converge/reference/state-schema.md +27 -2
- package/skills/pr-converge/scripts/CLAUDE.md +8 -0
- package/skills/pr-converge/scripts/README.md +4 -3
- package/skills/pr-converge/scripts/_pr_converge_path_setup.py +23 -0
- package/skills/pr-converge/scripts/check_convergence.py +189 -645
- package/skills/pr-converge/scripts/check_convergence_gates.py +235 -0
- package/skills/pr-converge/scripts/check_convergence_thread_gates.py +219 -0
- package/skills/pr-converge/scripts/conftest.py +8 -0
- package/skills/pr-converge/scripts/pr_converge_scripts_constants/CLAUDE.md +1 -0
- package/skills/pr-converge/scripts/pr_converge_scripts_constants/convergence_gate_constants.py +36 -0
- package/skills/pr-converge/scripts/test__pr_converge_path_setup.py +26 -0
- package/skills/pr-converge/scripts/test_check_convergence.py +73 -228
- package/skills/pr-converge/scripts/test_check_convergence_contract.py +321 -0
- package/skills/pr-converge/scripts/test_check_convergence_gates.py +68 -0
- package/skills/pr-converge/scripts/test_check_convergence_thread_gates.py +75 -0
- package/skills/pr-fix-protocol/SKILL.md +20 -20
- package/skills/privacy-hygiene/SKILL.md +4 -3
- package/skills/reviewer-gates/SKILL.md +26 -8
- package/skills/session-log/SKILL.md +11 -12
- package/skills/session-tidy/SKILL.md +40 -30
- package/skills/skill-builder/CLAUDE.md +13 -10
- package/skills/skill-builder/SKILL.md +31 -31
- package/skills/skill-builder/references/CLAUDE.md +10 -6
- package/skills/skill-builder/references/delegation-map.md +13 -4
- package/skills/skill-builder/references/description-field.md +113 -0
- package/skills/skill-builder/references/self-audit-checklist.md +21 -4
- package/skills/skill-builder/references/skill-modularity.md +113 -0
- package/skills/skill-builder/references/skill-types.md +4 -0
- package/skills/skill-builder/templates/CLAUDE.md +4 -4
- package/skills/skill-builder/templates/gap-analysis.md +25 -1
- package/skills/skill-builder/workflows/CLAUDE.md +6 -4
- package/skills/skill-builder/workflows/improve-skill.md +17 -16
- package/skills/skill-builder/workflows/new-skill.md +34 -10
- package/skills/skill-builder/workflows/polish-skill.md +59 -43
- package/skills/team-advisor/SKILL.md +15 -11
- package/skills/usage-pause/SKILL.md +10 -14
- package/system-prompts/software-engineer.xml +7 -6
- package/hooks/validators/test_verify_paths.py +0 -32
- package/hooks/validators/verify_paths.py +0 -57
- package/skills/bdd-protocol/CLAUDE.md +0 -26
- package/skills/bdd-protocol/SKILL.md +0 -30
- package/skills/bdd-protocol/references/CLAUDE.md +0 -10
- package/skills/bdd-protocol/references/anti-patterns.md +0 -26
- package/skills/bdd-protocol/references/example-mapping.md +0 -23
- package/skills/bg-agent/CLAUDE.md +0 -17
- package/skills/bg-agent/SKILL.md +0 -69
- package/skills/bugteam/scripts/bugteam_scripts_constants/bugteam_code_rules_gate_constants.py +0 -55
- package/skills/bugteam/scripts/bugteam_scripts_constants/bugteam_fix_hookspath_constants.py +0 -26
- package/skills/bugteam/scripts/bugteam_scripts_constants/bugteam_preflight_constants.py +0 -35
- package/skills/caveman/CLAUDE.md +0 -15
- package/skills/caveman/SKILL.md +0 -38
- package/skills/code/CLAUDE.md +0 -17
- package/skills/code/SKILL.md +0 -178
- package/skills/deep-research/CLAUDE.md +0 -17
- package/skills/deep-research/SKILL.md +0 -80
- package/skills/findbugs/CLAUDE.md +0 -20
- package/skills/findbugs/SKILL.md +0 -241
- package/skills/fixbugs/CLAUDE.md +0 -19
- package/skills/fixbugs/SKILL.md +0 -142
- package/skills/gh-paginate/CLAUDE.md +0 -18
- package/skills/gh-paginate/SKILL.md +0 -84
- package/skills/gotcha/CLAUDE.md +0 -33
- package/skills/gotcha/SKILL.md +0 -73
- package/skills/implement/CLAUDE.md +0 -27
- package/skills/implement/SKILL.md +0 -66
- package/skills/implement/scripts/CLAUDE.md +0 -22
- package/skills/implement/scripts/append_note.py +0 -133
- package/skills/implement/scripts/implement_scripts_constants/CLAUDE.md +0 -22
- package/skills/implement/scripts/implement_scripts_constants/__init__.py +0 -0
- package/skills/implement/scripts/implement_scripts_constants/notes_constants.py +0 -12
- package/skills/implement/scripts/test_append_note.py +0 -191
- package/skills/log-audit/CLAUDE.md +0 -20
- package/skills/log-audit/SKILL.md +0 -66
- package/skills/log-audit/reference/CLAUDE.md +0 -9
- package/skills/log-audit/reference/charter.md +0 -52
- package/skills/log-audit/scripts/CLAUDE.md +0 -27
- package/skills/log-audit/scripts/cluster_recurrences.py +0 -261
- package/skills/log-audit/scripts/collect_log_window.py +0 -199
- package/skills/log-audit/scripts/log_audit_constants/CLAUDE.md +0 -12
- package/skills/log-audit/scripts/log_audit_constants/__init__.py +0 -0
- package/skills/log-audit/scripts/log_audit_constants/cluster_recurrences_constants.py +0 -23
- package/skills/log-audit/scripts/log_audit_constants/collect_log_window_constants.py +0 -24
- package/skills/log-audit/scripts/log_audit_constants/mine_copilot_findings_constants.py +0 -49
- package/skills/log-audit/scripts/mine_copilot_findings.py +0 -302
- package/skills/log-audit/scripts/test_cluster_recurrences.py +0 -160
- package/skills/log-audit/scripts/test_collect_log_window.py +0 -111
- package/skills/log-audit/scripts/test_mine_copilot_findings.py +0 -126
- package/skills/logifix/CLAUDE.md +0 -36
- package/skills/logifix/SKILL.md +0 -69
- package/skills/logifix/scripts/CLAUDE.md +0 -16
- package/skills/logifix/scripts/logifix.ps1 +0 -205
- package/skills/monitor-open-prs/CLAUDE.md +0 -34
- package/skills/monitor-open-prs/SKILL.md +0 -88
- package/skills/monitor-open-prs/scripts/CLAUDE.md +0 -17
- package/skills/monitor-open-prs/scripts/discover_open_prs.py +0 -69
- package/skills/monitor-open-prs/scripts/test_discover_open_prs.py +0 -149
- package/skills/monitor-open-prs/test_skill_contract.py +0 -27
- package/skills/post-audit-findings/SKILL.md +0 -80
- package/skills/pr-consistency-audit/CLAUDE.md +0 -34
- package/skills/pr-consistency-audit/SKILL.md +0 -116
- package/skills/pr-consistency-audit/reference/CLAUDE.md +0 -16
- package/skills/pr-consistency-audit/reference/detection-rules.md +0 -96
- package/skills/pr-consistency-audit/reference/illustrations.md +0 -78
- package/skills/pr-review-responder/CLAUDE.md +0 -35
- package/skills/pr-review-responder/EXAMPLES.md +0 -590
- package/skills/pr-review-responder/PRINCIPLES.md +0 -533
- package/skills/pr-review-responder/README.md +0 -168
- package/skills/pr-review-responder/SKILL.md +0 -203
- package/skills/pr-review-responder/TESTING.md +0 -350
- package/skills/pr-scope-resolve/SKILL.md +0 -45
- package/skills/pre-compact/CLAUDE.md +0 -24
- package/skills/pre-compact/SKILL.md +0 -134
- package/skills/qbug/CLAUDE.md +0 -40
- package/skills/qbug/SKILL.md +0 -387
- package/skills/qbug/test_qbug_skill_audit_schema.py +0 -152
- package/skills/qbug/test_qbug_skill_post_fix_audit.py +0 -103
- package/skills/refine/CLAUDE.md +0 -44
- package/skills/refine/SKILL.md +0 -262
- package/skills/refine/templates/CLAUDE.md +0 -17
- package/skills/refine/templates/implementation-notes-template.html +0 -56
- package/skills/refine/templates/plan-template.md +0 -60
- package/skills/research-mode/CLAUDE.md +0 -35
- package/skills/research-mode/SKILL.md +0 -53
- package/skills/structure-prompt/CLAUDE.md +0 -42
- package/skills/structure-prompt/SKILL.md +0 -44
- package/skills/structure-prompt/reference/CLAUDE.md +0 -28
- package/skills/structure-prompt/reference/adversarial-tuning.md +0 -62
- package/skills/structure-prompt/reference/block-classification.md +0 -27
- package/skills/structure-prompt/reference/canonical-case.md +0 -48
- package/skills/structure-prompt/reference/citation-depth.md +0 -70
- package/skills/structure-prompt/reference/cleanup.md +0 -33
- package/skills/structure-prompt/reference/constraints.md +0 -33
- package/skills/structure-prompt/reference/directives.md +0 -37
- package/skills/structure-prompt/reference/examples.md +0 -72
- package/skills/structure-prompt/reference/instantiation.md +0 -51
- package/skills/structure-prompt/reference/output-contract.md +0 -72
- package/skills/structure-prompt/reference/per-category.md +0 -23
- package/skills/structure-prompt/reference/persona.md +0 -38
- package/skills/structure-prompt/reference/research.md +0 -33
- package/skills/structure-prompt/reference/structure.md +0 -28
- package/skills/verified-build/CLAUDE.md +0 -33
- package/skills/verified-build/SKILL.md +0 -33
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"""Tests for append_note.
|
|
2
|
-
|
|
3
|
-
Covers:
|
|
4
|
-
- _build_skeleton emits a four-section HTML document keyed by every slug
|
|
5
|
-
- _ensure_file creates a fresh file on first call and round-trips on subsequent calls
|
|
6
|
-
- _render_entry HTML-escapes the about label and the note body
|
|
7
|
-
- _insert_entry puts the first <li> on its own line and keeps a 6-space indent across entries
|
|
8
|
-
- _insert_entry raises a descriptive RuntimeError when the section block is missing
|
|
9
|
-
- _insert_entry raises a descriptive RuntimeError when the closing </ul> is missing
|
|
10
|
-
- main appends through the CLI surface against a real on-disk file
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
from __future__ import annotations
|
|
14
|
-
|
|
15
|
-
import importlib.util
|
|
16
|
-
import subprocess
|
|
17
|
-
import sys
|
|
18
|
-
from pathlib import Path
|
|
19
|
-
from types import ModuleType
|
|
20
|
-
|
|
21
|
-
import pytest
|
|
22
|
-
|
|
23
|
-
_SCRIPTS_DIRECTORY = Path(__file__).resolve().parent
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def _load_module() -> ModuleType:
|
|
27
|
-
if str(_SCRIPTS_DIRECTORY) not in sys.path:
|
|
28
|
-
sys.path.insert(0, str(_SCRIPTS_DIRECTORY))
|
|
29
|
-
module_path = _SCRIPTS_DIRECTORY / "append_note.py"
|
|
30
|
-
spec = importlib.util.spec_from_file_location("append_note", module_path)
|
|
31
|
-
assert spec is not None
|
|
32
|
-
assert spec.loader is not None
|
|
33
|
-
module = importlib.util.module_from_spec(spec)
|
|
34
|
-
spec.loader.exec_module(module)
|
|
35
|
-
return module
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
append_note_module = _load_module()
|
|
39
|
-
HEADING_BY_SLUG = append_note_module.HEADING_BY_SLUG
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def test_should_build_skeleton_with_every_section_slug() -> None:
|
|
43
|
-
skeleton = append_note_module._build_skeleton()
|
|
44
|
-
|
|
45
|
-
for each_slug, each_heading in HEADING_BY_SLUG.items():
|
|
46
|
-
assert f'<section id="{each_slug}">' in skeleton
|
|
47
|
-
assert f"<h2>{each_heading}</h2>" in skeleton
|
|
48
|
-
assert skeleton.count("<ul></ul>") == len(HEADING_BY_SLUG)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def test_should_create_file_with_skeleton_on_first_ensure(tmp_path: Path) -> None:
|
|
52
|
-
target = tmp_path / "subdir" / "implementation-notes.html"
|
|
53
|
-
|
|
54
|
-
document = append_note_module._ensure_file(target)
|
|
55
|
-
|
|
56
|
-
assert target.exists()
|
|
57
|
-
assert document == target.read_text(encoding="utf-8")
|
|
58
|
-
assert '<section id="decisions">' in document
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def test_should_return_existing_content_on_subsequent_ensure(tmp_path: Path) -> None:
|
|
62
|
-
target = tmp_path / "notes.html"
|
|
63
|
-
custom_content = "<!doctype html><html><body>existing</body></html>\n"
|
|
64
|
-
target.write_text(custom_content, encoding="utf-8")
|
|
65
|
-
|
|
66
|
-
returned = append_note_module._ensure_file(target)
|
|
67
|
-
|
|
68
|
-
assert returned == custom_content
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def test_should_escape_html_metacharacters_in_about_and_note() -> None:
|
|
72
|
-
entry = append_note_module._render_entry("a<b & c>d", "<script>x</script>")
|
|
73
|
-
|
|
74
|
-
assert "<script>" not in entry
|
|
75
|
-
assert "<script>" in entry
|
|
76
|
-
assert "a<b & c>d" in entry
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def test_should_put_first_entry_on_its_own_line_inside_empty_ul() -> None:
|
|
80
|
-
skeleton = append_note_module._build_skeleton()
|
|
81
|
-
entry = append_note_module._render_entry("First", "alpha")
|
|
82
|
-
|
|
83
|
-
after_first = append_note_module._insert_entry(skeleton, "decisions", entry)
|
|
84
|
-
|
|
85
|
-
assert "<ul> <li>" not in after_first
|
|
86
|
-
assert "<ul>\n <li>" in after_first
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def test_should_keep_uniform_six_space_indent_across_multiple_entries() -> None:
|
|
90
|
-
skeleton = append_note_module._build_skeleton()
|
|
91
|
-
first_entry = append_note_module._render_entry("First", "alpha")
|
|
92
|
-
second_entry = append_note_module._render_entry("Second", "beta")
|
|
93
|
-
|
|
94
|
-
after_first = append_note_module._insert_entry(skeleton, "decisions", first_entry)
|
|
95
|
-
after_second = append_note_module._insert_entry(after_first, "decisions", second_entry)
|
|
96
|
-
|
|
97
|
-
decisions_section_start = after_second.index('<section id="decisions">')
|
|
98
|
-
decisions_section_end = after_second.index("</section>", decisions_section_start)
|
|
99
|
-
decisions_section = after_second[decisions_section_start:decisions_section_end]
|
|
100
|
-
|
|
101
|
-
assert " <li>" not in decisions_section
|
|
102
|
-
assert decisions_section.count("\n <li>") == 2
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def test_should_raise_when_requested_section_is_absent() -> None:
|
|
106
|
-
document_without_section = "<html><body></body></html>\n"
|
|
107
|
-
entry = append_note_module._render_entry("x", "y")
|
|
108
|
-
|
|
109
|
-
with pytest.raises(RuntimeError, match="section 'decisions' not found"):
|
|
110
|
-
append_note_module._insert_entry(document_without_section, "decisions", entry)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def test_should_raise_when_closing_ul_is_missing() -> None:
|
|
114
|
-
truncated_section = '<section id="decisions">\n <h2>Design decisions</h2>\n <ul>\n </section>\n'
|
|
115
|
-
entry = append_note_module._render_entry("x", "y")
|
|
116
|
-
|
|
117
|
-
with pytest.raises(RuntimeError, match="missing its closing </ul>"):
|
|
118
|
-
append_note_module._insert_entry(truncated_section, "decisions", entry)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def test_should_not_borrow_closing_ul_from_a_later_section() -> None:
|
|
122
|
-
malformed_first_with_intact_second = (
|
|
123
|
-
'<section id="decisions">\n'
|
|
124
|
-
' <h2>Design decisions</h2>\n'
|
|
125
|
-
' <ul>\n'
|
|
126
|
-
' </section>\n'
|
|
127
|
-
' <section id="deviations">\n'
|
|
128
|
-
' <h2>Deviations</h2>\n'
|
|
129
|
-
' <ul></ul>\n'
|
|
130
|
-
' </section>\n'
|
|
131
|
-
)
|
|
132
|
-
entry = append_note_module._render_entry("x", "y")
|
|
133
|
-
|
|
134
|
-
with pytest.raises(RuntimeError, match="missing its closing </ul>"):
|
|
135
|
-
append_note_module._insert_entry(malformed_first_with_intact_second, "decisions", entry)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
def test_should_raise_when_closing_section_is_missing() -> None:
|
|
139
|
-
section_without_close = '<section id="decisions">\n <h2>Design decisions</h2>\n <ul></ul>\n'
|
|
140
|
-
entry = append_note_module._render_entry("x", "y")
|
|
141
|
-
|
|
142
|
-
with pytest.raises(RuntimeError, match="missing its closing </section>"):
|
|
143
|
-
append_note_module._insert_entry(section_without_close, "decisions", entry)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
def test_should_append_through_cli_against_real_file(tmp_path: Path) -> None:
|
|
147
|
-
target = tmp_path / "notes.html"
|
|
148
|
-
script_path = _SCRIPTS_DIRECTORY / "append_note.py"
|
|
149
|
-
|
|
150
|
-
first_run = subprocess.run(
|
|
151
|
-
[
|
|
152
|
-
sys.executable,
|
|
153
|
-
str(script_path),
|
|
154
|
-
"--section",
|
|
155
|
-
"decisions",
|
|
156
|
-
"--about",
|
|
157
|
-
"First",
|
|
158
|
-
"--note",
|
|
159
|
-
"alpha",
|
|
160
|
-
"--file",
|
|
161
|
-
str(target),
|
|
162
|
-
],
|
|
163
|
-
cwd=str(_SCRIPTS_DIRECTORY),
|
|
164
|
-
capture_output=True,
|
|
165
|
-
text=True,
|
|
166
|
-
check=False,
|
|
167
|
-
)
|
|
168
|
-
second_run = subprocess.run(
|
|
169
|
-
[
|
|
170
|
-
sys.executable,
|
|
171
|
-
str(script_path),
|
|
172
|
-
"--section",
|
|
173
|
-
"questions",
|
|
174
|
-
"--about",
|
|
175
|
-
"Q1",
|
|
176
|
-
"--note",
|
|
177
|
-
"<beta & gamma>",
|
|
178
|
-
"--file",
|
|
179
|
-
str(target),
|
|
180
|
-
],
|
|
181
|
-
cwd=str(_SCRIPTS_DIRECTORY),
|
|
182
|
-
capture_output=True,
|
|
183
|
-
text=True,
|
|
184
|
-
check=False,
|
|
185
|
-
)
|
|
186
|
-
|
|
187
|
-
assert first_run.returncode == 0, first_run.stderr
|
|
188
|
-
assert second_run.returncode == 0, second_run.stderr
|
|
189
|
-
output = target.read_text(encoding="utf-8")
|
|
190
|
-
assert "<li><strong>First:</strong> alpha</li>" in output
|
|
191
|
-
assert "<li><strong>Q1:</strong> <beta & gamma></li>" in output
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# log-audit
|
|
2
|
-
|
|
3
|
-
Reads this repository's own logs, finds recurring errors and timing regressions, and turns each real pattern into a tracked fix. Triggered by `/log-audit`, `audit the logs`, `what keeps failing`, or `what's getting slower`.
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
The skill runs as a background agent on a recurring schedule. Each cycle it reads the hook block log and the diagnostic extractor pipeline, clusters recurring errors and timing regressions, opens a grouped draft fix pull request or a tracked optimization issue per finding, and mines the defects Copilot and Bugbot keep catching into skill-edit proposals. Cycle state lives under `~/.claude/runtime/log-audit/`, so a restart resumes the same run.
|
|
8
|
-
|
|
9
|
-
## Key files
|
|
10
|
-
|
|
11
|
-
| File | Purpose |
|
|
12
|
-
|---|---|
|
|
13
|
-
| `SKILL.md` | Full instructions: the cycle steps, the three scripts and how to pipe them, the log sources in and out of scope, finding-filing rules, reviewer mining, cycle state, and cadence. |
|
|
14
|
-
|
|
15
|
-
## Subdirectories
|
|
16
|
-
|
|
17
|
-
| Directory | Role |
|
|
18
|
-
|---|---|
|
|
19
|
-
| `reference/` | The agent charter — the fixed contract the skill answers to. |
|
|
20
|
-
| `scripts/` | The collect, cluster, and mine scripts and their constants package. |
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: log-audit
|
|
3
|
-
description: >-
|
|
4
|
-
Watches this repo's own logs for patterns worth acting on: clusters recurring
|
|
5
|
-
errors and timing regressions, then opens a grouped fix PR or a tracked
|
|
6
|
-
optimization issue per real finding. Use for /log-audit, 'audit the logs',
|
|
7
|
-
'what keeps failing', or 'what's getting slower'.
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
# log-audit
|
|
11
|
-
|
|
12
|
-
Read the logs this repo writes about itself, find what keeps going wrong or keeps getting slower, and turn each real pattern into a tracked fix. `reference/charter.md` holds the full contract; this file is how to run a cycle.
|
|
13
|
-
|
|
14
|
-
## One cycle
|
|
15
|
-
|
|
16
|
-
1. **Collect.** Run `scripts/collect_log_window.py` to read the recent window of the hook block log into records.
|
|
17
|
-
2. **Cluster.** Pipe those records into `scripts/cluster_recurrences.py` to group them by a normalized signature and rank the loudest first. When timing samples are on hand, the same module flags operations whose recent runs have grown slower than their earlier runs.
|
|
18
|
-
3. **Mine reviewers.** Run `scripts/mine_copilot_findings.py` to sort recent reviewer-bot comments into defect classes and print a skill-edit proposal for each class.
|
|
19
|
-
4. **File findings.** For each real finding, open a grouped fix pull request as a draft, or file a tracked optimization issue for a delay.
|
|
20
|
-
5. **Report.** Write the per-cycle report: delays removed, pull requests opened, skill improvements suggested.
|
|
21
|
-
6. **Re-arm.** Save cycle state and schedule the next cycle.
|
|
22
|
-
|
|
23
|
-
## Scripts
|
|
24
|
-
|
|
25
|
-
| File | What it does |
|
|
26
|
-
|---|---|
|
|
27
|
-
| `scripts/collect_log_window.py` | Tails the JSON-lines hook block log and prints the block records inside a time window as JSON. `--hours` sets the window; `--log-path` overrides the log location. |
|
|
28
|
-
| `scripts/cluster_recurrences.py` | Reads that JSON on stdin, groups records by a normalized message signature, and prints the clusters ranked by recency-weighted count. Its `detect_timing_regressions` flags an operation whose recent runs are slower than its earliest runs. |
|
|
29
|
-
| `scripts/mine_copilot_findings.py` | Reads a repo's reviewer-bot comments through `gh`, sorts them into defect classes, and prints one skill-edit proposal per class, most frequent first. Takes `--repo owner/name`. |
|
|
30
|
-
|
|
31
|
-
Run the first two as a pipeline:
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
python scripts/collect_log_window.py --hours 24 | python scripts/cluster_recurrences.py
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## What it reads
|
|
38
|
-
|
|
39
|
-
In scope:
|
|
40
|
-
|
|
41
|
-
- The hook block log at `~/.claude/logs/hook-blocks.log`, written by `hook_block_logger`.
|
|
42
|
-
- The `hooks/diagnostic/` extractor pipeline. When Neon is set up, read through that pipeline's SQL — the shape of `queries/blocks_by_category.sql` and its siblings against the `hook_events` table, which carries `duration_ms` for timing work. When Neon is not set up, read the flat `hook-blocks.log` directly. Reuse the diagnostic pipeline's helpers; do not hold a second copy.
|
|
43
|
-
|
|
44
|
-
Out of scope: Samsung-automation logs. Read this repo's log surfaces only.
|
|
45
|
-
|
|
46
|
-
## Filing findings
|
|
47
|
-
|
|
48
|
-
- A pull request or optimization issue carries its body in a file passed by path, following the `gh-body-file` rule.
|
|
49
|
-
- Any paginated GitHub read follows the `gh-paginate` rule.
|
|
50
|
-
- Group the related fixes for one finding into a single draft pull request rather than one PR per line.
|
|
51
|
-
|
|
52
|
-
## Reviewer-defect mining
|
|
53
|
-
|
|
54
|
-
`mine_copilot_findings.py` names a skill or rule edit for each defect class the reviewers keep catching — an edit that would block that class at write time rather than at review. These are proposals. A human applies them through review; the agent does not commit them on its own.
|
|
55
|
-
|
|
56
|
-
## Cycle state and restart survival
|
|
57
|
-
|
|
58
|
-
The agent keeps its state in a JSON file under `~/.claude/runtime/log-audit/` — the last window it read, the signatures it already reported, and the open items it filed. At the start of each cycle, read that file; at the end, write it back. Because the state lives in the durable runtime directory rather than the OS temp directory, a restart reads the same file and resumes the same run.
|
|
59
|
-
|
|
60
|
-
## Cadence
|
|
61
|
-
|
|
62
|
-
The agent runs on a recurring schedule following the repository's Scheduled Task Cadence: a sub-hour interval, with a 30-minute default. Re-arm the next cycle with `ScheduleWakeup` for a self-paced loop, or register a cron routine through `/schedule` for a fixed clock cadence.
|
|
63
|
-
|
|
64
|
-
## Per-cycle report
|
|
65
|
-
|
|
66
|
-
Each cycle ends with a short report: the delays removed, the pull requests opened, and the skill improvements suggested.
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# log-audit/reference
|
|
2
|
-
|
|
3
|
-
Reference material for the `log-audit` skill.
|
|
4
|
-
|
|
5
|
-
## Key files
|
|
6
|
-
|
|
7
|
-
| File | Purpose |
|
|
8
|
-
|---|---|
|
|
9
|
-
| `charter.md` | The agent's contract: what it watches (this repo's hook-block log and diagnostic extractor pipeline), what it looks for (recurring errors and timing regressions), what it files per finding (grouped draft fix PR or tracked optimization issue), how it mines reviewer defect patterns into skill-definition proposals, and the per-cycle report it emits. Cycle state lives under `~/.claude/runtime/log-audit/`; the agent runs on a sub-hour cadence. |
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# Log-Audit Agent Charter
|
|
2
|
-
|
|
3
|
-
The contract for the log-audit agent: what it watches, what it looks for, and what it produces each cycle. The skill body (`SKILL.md`) and its scripts carry out this contract; this document is the fixed reference they answer to.
|
|
4
|
-
|
|
5
|
-
## What the agent is
|
|
6
|
-
|
|
7
|
-
A background agent that reads this repository's own log surfaces, finds patterns worth acting on, and turns each real pattern into a tracked fix. It runs on its own without a person driving it and picks up where it left off after a restart.
|
|
8
|
-
|
|
9
|
-
## Cycle state and cadence
|
|
10
|
-
|
|
11
|
-
The agent keeps its own state on disk under `~/.claude/runtime/log-audit/`. This directory holds durable cycle state — the last window it read, the signatures it already reported, and the open items it filed — so a restart resumes the same run rather than starting over. The OS temp directory is not a home for this state, because temp files can be cleared between sessions.
|
|
12
|
-
|
|
13
|
-
The agent runs on a recurring schedule. It follows the repository's Scheduled Task Cadence: a sub-hour interval, with a 30-minute default.
|
|
14
|
-
|
|
15
|
-
## Log sources it reads
|
|
16
|
-
|
|
17
|
-
In scope:
|
|
18
|
-
|
|
19
|
-
- The hook block log at `~/.claude/logs/hook-blocks.log`, written by `hook_block_logger`. Each line is one JSON record naming the hook that blocked, the event, the reason, the tool, and a short input excerpt.
|
|
20
|
-
- The `hooks/diagnostic/` extractor pipeline. When Neon is configured, the agent reads through the pipeline's SQL — the shape of `queries/blocks_by_category.sql` and its siblings against the `hook_events` table, which carries `duration_ms` for timing work. When Neon is not configured, the agent reads the flat `hook-blocks.log` directly. It reuses the diagnostic pipeline's helpers rather than holding a second copy of them.
|
|
21
|
-
|
|
22
|
-
Out of scope:
|
|
23
|
-
|
|
24
|
-
- Samsung-automation logs. The agent reads this repository's log surfaces only.
|
|
25
|
-
|
|
26
|
-
## What it looks for
|
|
27
|
-
|
|
28
|
-
Two kinds of pattern:
|
|
29
|
-
|
|
30
|
-
- Recurring errors. The same failure showing up again and again. The agent groups log records by a normalized message signature — the message with its digits, paths, and hashes stripped — so records that differ only in those details fall into one cluster. It ranks clusters by count weighted toward recent activity.
|
|
31
|
-
- Timing regressions. The same operation taking longer over time. When a repeated operation's duration climbs across cycles, the agent flags it as an unnecessary delay, separate from any error.
|
|
32
|
-
|
|
33
|
-
## What it does per finding
|
|
34
|
-
|
|
35
|
-
For each real finding, the agent takes one of two tracked actions:
|
|
36
|
-
|
|
37
|
-
- Opens a grouped fix pull request as a draft, gathering the related fixes into one branch.
|
|
38
|
-
- Files a tracked optimization issue when the finding is a delay to chase rather than a fix to write.
|
|
39
|
-
|
|
40
|
-
Both paths carry their body in a file passed by path, following the `gh-body-file` rule, and any paginated GitHub read follows the `gh-paginate` rule.
|
|
41
|
-
|
|
42
|
-
## Reviewer-defect mining
|
|
43
|
-
|
|
44
|
-
The agent also reads the defect patterns that Copilot and Bugbot catch again and again across recent pull requests. It clusters those comments into defect classes and proposes concrete edits to the skill definitions that would block each class upstream, at the point of writing, rather than at review. These are proposals: they land through review, not by the agent applying them on its own.
|
|
45
|
-
|
|
46
|
-
## Per-cycle report
|
|
47
|
-
|
|
48
|
-
Each cycle ends with a short report covering:
|
|
49
|
-
|
|
50
|
-
- Delays removed.
|
|
51
|
-
- Pull requests opened.
|
|
52
|
-
- Skill improvements suggested.
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# log-audit/scripts
|
|
2
|
-
|
|
3
|
-
The collect, cluster, and mine scripts for the `log-audit` skill, plus their constants package.
|
|
4
|
-
|
|
5
|
-
## Files
|
|
6
|
-
|
|
7
|
-
| File | Purpose |
|
|
8
|
-
|---|---|
|
|
9
|
-
| `collect_log_window.py` | Tails the JSON-lines hook block log and prints the block records inside a time window as JSON. |
|
|
10
|
-
| `test_collect_log_window.py` | Tests for `collect_log_window.py`. |
|
|
11
|
-
| `cluster_recurrences.py` | Groups block records by a normalized signature, ranks them by recency-weighted count, and flags timing regressions. |
|
|
12
|
-
| `test_cluster_recurrences.py` | Tests for `cluster_recurrences.py`. |
|
|
13
|
-
| `mine_copilot_findings.py` | Sorts reviewer-bot comments into defect classes and prints one skill-edit proposal per class. |
|
|
14
|
-
| `test_mine_copilot_findings.py` | Tests for `mine_copilot_findings.py`. |
|
|
15
|
-
|
|
16
|
-
## Subdirectories
|
|
17
|
-
|
|
18
|
-
| Directory | Role |
|
|
19
|
-
|---|---|
|
|
20
|
-
| `log_audit_constants/` | Named constants imported by the three scripts. |
|
|
21
|
-
|
|
22
|
-
## Running
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
python collect_log_window.py --hours 24 | python cluster_recurrences.py
|
|
26
|
-
python mine_copilot_findings.py --repo owner/name
|
|
27
|
-
```
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
"""Group hook-block records by a normalized signature and rank the clusters.
|
|
2
|
-
|
|
3
|
-
Two failures can read differently only because one names line 12 and the other
|
|
4
|
-
line 348. They are the same failure. This script strips the varying parts down
|
|
5
|
-
to one signature, so it counts how often each real failure recurs. It ranks the
|
|
6
|
-
loudest first and weights recent blocks over stale ones. It also reads timing
|
|
7
|
-
samples for one operation and flags that operation when its recent runs have
|
|
8
|
-
grown slower than its earlier runs.
|
|
9
|
-
|
|
10
|
-
Reads the JSON record list collect_log_window prints, on stdin.
|
|
11
|
-
|
|
12
|
-
Usage:
|
|
13
|
-
collect_log_window.py --hours 24 | cluster_recurrences.py
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
from __future__ import annotations
|
|
17
|
-
|
|
18
|
-
import json
|
|
19
|
-
import re
|
|
20
|
-
import sys
|
|
21
|
-
from collections import defaultdict
|
|
22
|
-
from dataclasses import dataclass
|
|
23
|
-
from datetime import datetime
|
|
24
|
-
from pathlib import Path
|
|
25
|
-
|
|
26
|
-
_script_directory = str(Path(__file__).resolve().parent)
|
|
27
|
-
if _script_directory not in sys.path:
|
|
28
|
-
sys.path.insert(0, _script_directory)
|
|
29
|
-
|
|
30
|
-
from log_audit_constants.cluster_recurrences_constants import ( # noqa: E402
|
|
31
|
-
DIGIT_PATTERN,
|
|
32
|
-
HASH_PATTERN,
|
|
33
|
-
MIN_TIMING_SAMPLES_PER_HALF,
|
|
34
|
-
PATH_PATTERN,
|
|
35
|
-
RECENCY_DECAY_BASE,
|
|
36
|
-
RECENCY_HALF_LIFE_HOURS,
|
|
37
|
-
SAMPLE_HALVES,
|
|
38
|
-
SECONDS_PER_HOUR,
|
|
39
|
-
SIGNATURE_PLACEHOLDER,
|
|
40
|
-
TIMING_REGRESSION_RATIO,
|
|
41
|
-
)
|
|
42
|
-
from log_audit_constants.collect_log_window_constants import ( # noqa: E402
|
|
43
|
-
RECORD_LEVEL_KEY,
|
|
44
|
-
RECORD_MESSAGE_KEY,
|
|
45
|
-
RECORD_SOURCE_KEY,
|
|
46
|
-
RECORD_TIMESTAMP_KEY,
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
from collect_log_window import LogRecord # noqa: E402
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
@dataclass(frozen=True)
|
|
53
|
-
class SignatureCluster:
|
|
54
|
-
"""A group of records that share one normalized message signature.
|
|
55
|
-
|
|
56
|
-
Attributes:
|
|
57
|
-
signature: The normalized message the grouped records share.
|
|
58
|
-
count: How many records fell into the cluster.
|
|
59
|
-
latest_timestamp: The most recent record's timestamp in the cluster.
|
|
60
|
-
score: The recency-weighted sum of the cluster's records.
|
|
61
|
-
"""
|
|
62
|
-
|
|
63
|
-
signature: str
|
|
64
|
-
count: int
|
|
65
|
-
latest_timestamp: datetime
|
|
66
|
-
score: float
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
@dataclass(frozen=True)
|
|
70
|
-
class TimingSample:
|
|
71
|
-
"""One measured run of a repeated operation.
|
|
72
|
-
|
|
73
|
-
Attributes:
|
|
74
|
-
operation: The operation's name.
|
|
75
|
-
timestamp: When the run happened.
|
|
76
|
-
duration_ms: How long the run took, in milliseconds.
|
|
77
|
-
"""
|
|
78
|
-
|
|
79
|
-
operation: str
|
|
80
|
-
timestamp: datetime
|
|
81
|
-
duration_ms: float
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
@dataclass(frozen=True)
|
|
85
|
-
class TimingRegression:
|
|
86
|
-
"""A repeated operation whose recent runs have grown slower.
|
|
87
|
-
|
|
88
|
-
Attributes:
|
|
89
|
-
operation: The operation's name.
|
|
90
|
-
baseline_ms: The mean duration of the earliest runs.
|
|
91
|
-
recent_ms: The mean duration of the latest runs.
|
|
92
|
-
ratio: The recent mean divided by the baseline mean.
|
|
93
|
-
"""
|
|
94
|
-
|
|
95
|
-
operation: str
|
|
96
|
-
baseline_ms: float
|
|
97
|
-
recent_ms: float
|
|
98
|
-
ratio: float
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def normalize_signature(message: str) -> str:
|
|
102
|
-
"""Reduce a message to a signature shared by its recurring variants.
|
|
103
|
-
|
|
104
|
-
Args:
|
|
105
|
-
message: A raw block-reason message.
|
|
106
|
-
|
|
107
|
-
Returns:
|
|
108
|
-
The message with paths, hashes, and numbers replaced by a placeholder
|
|
109
|
-
and runs of whitespace collapsed to single spaces.
|
|
110
|
-
"""
|
|
111
|
-
without_paths = re.sub(PATH_PATTERN, SIGNATURE_PLACEHOLDER, message)
|
|
112
|
-
without_hashes = re.sub(HASH_PATTERN, SIGNATURE_PLACEHOLDER, without_paths)
|
|
113
|
-
without_numbers = re.sub(DIGIT_PATTERN, SIGNATURE_PLACEHOLDER, without_hashes)
|
|
114
|
-
return re.sub(r"\s+", " ", without_numbers).strip()
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def recency_weight(record_timestamp: datetime, now: datetime) -> float:
|
|
118
|
-
"""Weight a record by how recent it is, halving each half-life of age.
|
|
119
|
-
|
|
120
|
-
Args:
|
|
121
|
-
record_timestamp: When the record was written.
|
|
122
|
-
now: The current time age is measured against.
|
|
123
|
-
|
|
124
|
-
Returns:
|
|
125
|
-
A weight near one for a fresh record, falling toward zero as it ages.
|
|
126
|
-
"""
|
|
127
|
-
age_hours = (now - record_timestamp).total_seconds() / SECONDS_PER_HOUR
|
|
128
|
-
non_negative_age_hours = max(age_hours, 0.0)
|
|
129
|
-
return RECENCY_DECAY_BASE ** (non_negative_age_hours / RECENCY_HALF_LIFE_HOURS)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def rank_signature_clusters(
|
|
133
|
-
all_records: list[LogRecord], now: datetime
|
|
134
|
-
) -> list[SignatureCluster]:
|
|
135
|
-
"""Group records by signature and rank them by recency-weighted count.
|
|
136
|
-
|
|
137
|
-
Args:
|
|
138
|
-
all_records: The block records to group.
|
|
139
|
-
now: The current time used to weight each record.
|
|
140
|
-
|
|
141
|
-
Returns:
|
|
142
|
-
One cluster per distinct signature, highest score first.
|
|
143
|
-
"""
|
|
144
|
-
records_by_signature: dict[str, list[LogRecord]] = defaultdict(list)
|
|
145
|
-
for each_record in all_records:
|
|
146
|
-
records_by_signature[normalize_signature(each_record.message)].append(
|
|
147
|
-
each_record
|
|
148
|
-
)
|
|
149
|
-
clusters: list[SignatureCluster] = []
|
|
150
|
-
for each_signature, each_signature_records in records_by_signature.items():
|
|
151
|
-
score = sum(
|
|
152
|
-
recency_weight(each_grouped.timestamp, now)
|
|
153
|
-
for each_grouped in each_signature_records
|
|
154
|
-
)
|
|
155
|
-
latest_timestamp = max(
|
|
156
|
-
each_grouped.timestamp for each_grouped in each_signature_records
|
|
157
|
-
)
|
|
158
|
-
clusters.append(
|
|
159
|
-
SignatureCluster(
|
|
160
|
-
signature=each_signature,
|
|
161
|
-
count=len(each_signature_records),
|
|
162
|
-
latest_timestamp=latest_timestamp,
|
|
163
|
-
score=score,
|
|
164
|
-
)
|
|
165
|
-
)
|
|
166
|
-
return sorted(
|
|
167
|
-
clusters,
|
|
168
|
-
key=lambda cluster: (cluster.score, cluster.count),
|
|
169
|
-
reverse=True,
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
def _mean_duration(all_samples: list[TimingSample]) -> float:
|
|
174
|
-
"""Return the mean duration in milliseconds of the given samples."""
|
|
175
|
-
return sum(each_sample.duration_ms for each_sample in all_samples) / len(
|
|
176
|
-
all_samples
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
def detect_timing_regressions(
|
|
181
|
-
all_samples: list[TimingSample],
|
|
182
|
-
) -> list[TimingRegression]:
|
|
183
|
-
"""Flag operations whose recent runs are slower than their earliest runs.
|
|
184
|
-
|
|
185
|
-
Args:
|
|
186
|
-
all_samples: Timing samples across one or more operations.
|
|
187
|
-
|
|
188
|
-
Returns:
|
|
189
|
-
One regression per operation whose recent-to-baseline duration ratio
|
|
190
|
-
reaches the regression threshold, highest ratio first.
|
|
191
|
-
"""
|
|
192
|
-
samples_by_operation: dict[str, list[TimingSample]] = defaultdict(list)
|
|
193
|
-
for each_sample in all_samples:
|
|
194
|
-
samples_by_operation[each_sample.operation].append(each_sample)
|
|
195
|
-
regressions: list[TimingRegression] = []
|
|
196
|
-
for each_operation, each_operation_samples in samples_by_operation.items():
|
|
197
|
-
if len(each_operation_samples) < MIN_TIMING_SAMPLES_PER_HALF * SAMPLE_HALVES:
|
|
198
|
-
continue
|
|
199
|
-
ordered_samples = sorted(
|
|
200
|
-
each_operation_samples, key=lambda sample: sample.timestamp
|
|
201
|
-
)
|
|
202
|
-
baseline_ms = _mean_duration(ordered_samples[:MIN_TIMING_SAMPLES_PER_HALF])
|
|
203
|
-
recent_ms = _mean_duration(ordered_samples[-MIN_TIMING_SAMPLES_PER_HALF:])
|
|
204
|
-
if baseline_ms <= 0:
|
|
205
|
-
continue
|
|
206
|
-
ratio = recent_ms / baseline_ms
|
|
207
|
-
if ratio >= TIMING_REGRESSION_RATIO:
|
|
208
|
-
regressions.append(
|
|
209
|
-
TimingRegression(
|
|
210
|
-
operation=each_operation,
|
|
211
|
-
baseline_ms=baseline_ms,
|
|
212
|
-
recent_ms=recent_ms,
|
|
213
|
-
ratio=ratio,
|
|
214
|
-
)
|
|
215
|
-
)
|
|
216
|
-
return sorted(regressions, key=lambda regression: regression.ratio, reverse=True)
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
def _record_from_json_dict(all_record_fields: dict[str, str]) -> LogRecord:
|
|
220
|
-
"""Rebuild a LogRecord from one collect_log_window JSON dict."""
|
|
221
|
-
return LogRecord(
|
|
222
|
-
timestamp=datetime.fromisoformat(all_record_fields[RECORD_TIMESTAMP_KEY]),
|
|
223
|
-
source=all_record_fields[RECORD_SOURCE_KEY],
|
|
224
|
-
level=all_record_fields[RECORD_LEVEL_KEY],
|
|
225
|
-
message=all_record_fields[RECORD_MESSAGE_KEY],
|
|
226
|
-
)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
def main() -> int:
|
|
230
|
-
"""Read records on stdin and print ranked signature clusters.
|
|
231
|
-
|
|
232
|
-
Returns:
|
|
233
|
-
The process exit code; zero on success, one when stdin is not a JSON
|
|
234
|
-
list of well-formed records.
|
|
235
|
-
"""
|
|
236
|
-
try:
|
|
237
|
-
records_payload = json.load(sys.stdin)
|
|
238
|
-
except json.JSONDecodeError as decode_error:
|
|
239
|
-
print(f"cluster_recurrences: stdin is not valid JSON: {decode_error}", file=sys.stderr)
|
|
240
|
-
return 1
|
|
241
|
-
if not isinstance(records_payload, list):
|
|
242
|
-
print("cluster_recurrences: stdin JSON must be a list of records", file=sys.stderr)
|
|
243
|
-
return 1
|
|
244
|
-
try:
|
|
245
|
-
records = [
|
|
246
|
-
_record_from_json_dict(each_record_fields)
|
|
247
|
-
for each_record_fields in records_payload
|
|
248
|
-
]
|
|
249
|
-
except (KeyError, TypeError, ValueError) as record_error:
|
|
250
|
-
print(f"cluster_recurrences: malformed record in stdin: {record_error}", file=sys.stderr)
|
|
251
|
-
return 1
|
|
252
|
-
clusters = rank_signature_clusters(records, datetime.now())
|
|
253
|
-
for each_cluster in clusters:
|
|
254
|
-
print(
|
|
255
|
-
f"{each_cluster.count}\t{each_cluster.score:.2f}\t{each_cluster.signature}"
|
|
256
|
-
)
|
|
257
|
-
return 0
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if __name__ == "__main__":
|
|
261
|
-
raise SystemExit(main())
|