@windyroad/style-guide 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "wr-style-guide",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Style guide enforcement for Claude Code"
5
5
  }
package/README.md CHANGED
@@ -39,7 +39,7 @@ This examines your existing CSS, components, and design patterns, then asks abou
39
39
  |------|---------|-------------|
40
40
  | `style-guide-eval.sh` | Every prompt | Evaluates whether the task involves visual styling |
41
41
  | `style-guide-enforce-edit.sh` | Edit or Write | Blocks edits until the style-guide agent has reviewed |
42
- | `style-guide-mark-reviewed.sh` | Agent completes | Marks the review as done (TTL: 1800s) |
42
+ | `style-guide-mark-reviewed.sh` | Agent completes | Marks the review as done (TTL: 3600s) |
43
43
 
44
44
  ## Agent
45
45
 
package/hooks/hooks.json CHANGED
@@ -7,7 +7,8 @@
7
7
  { "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/hooks/style-guide-enforce-edit.sh" }] }
8
8
  ],
9
9
  "PostToolUse": [
10
- { "matcher": "Agent", "hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/hooks/style-guide-mark-reviewed.sh" }] }
10
+ { "matcher": "Agent", "hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/hooks/style-guide-mark-reviewed.sh" }] },
11
+ { "matcher": "Agent|Bash", "hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/hooks/style-guide-slide-marker.sh" }] }
11
12
  ]
12
13
  }
13
14
  }
@@ -153,6 +153,56 @@ _risk_dir() {
153
153
  echo "$dir"
154
154
  }
155
155
 
156
+ # ---------------------------------------------------------------------------
157
+ # Subprocess-completion marker slide (P111, ADR-009 amendment)
158
+ # ---------------------------------------------------------------------------
159
+
160
+ # Slides an existing session-review marker forward on subprocess return,
161
+ # treating subprocess wall-clock as continuous parent-session work for TTL
162
+ # purposes. Intended for PostToolUse hooks on Agent / Bash that may have
163
+ # been long-running subprocesses (Agent-tool delegations, `claude -p`
164
+ # iteration subprocesses, run_in_background completions).
165
+ #
166
+ # Contract:
167
+ # - Touches the marker ONLY if it already exists. NEVER creates a marker
168
+ # (creating requires a real gate review with verdict parsing).
169
+ # - Skips the touch if tool_response.is_error == true. A failed
170
+ # subprocess MUST NOT extend the parent's trust window.
171
+ # - Fail-safe on parse error: if _HOOK_INPUT cannot be parsed, treat as
172
+ # error and skip the touch.
173
+ # - No-op when marker path is empty or marker file does not exist.
174
+ #
175
+ # Why this is NOT cross-process marker sharing (ADR-032 line 123 invariant):
176
+ # the parent's PostToolUse hook touches the parent's OWN marker. The
177
+ # subprocess's session id, marker, and gate state are never read or shared.
178
+ # This is identical in shape to the existing PreToolUse:Edit slide; only
179
+ # the trigger expands to subprocess return.
180
+ #
181
+ # Usage: slide_marker_on_subprocess_return "/tmp/architect-reviewed-${SESSION_ID}"
182
+ slide_marker_on_subprocess_return() {
183
+ local MARKER="$1"
184
+ [ -n "$MARKER" ] || return 0
185
+ [ -f "$MARKER" ] || return 0
186
+
187
+ local IS_ERROR
188
+ IS_ERROR=$(echo "$_HOOK_INPUT" | python3 -c "
189
+ import sys, json
190
+ try:
191
+ data = json.load(sys.stdin)
192
+ tr = data.get('tool_response', {})
193
+ if isinstance(tr, dict):
194
+ print('true' if tr.get('is_error') is True else 'false')
195
+ else:
196
+ print('false')
197
+ except Exception:
198
+ print('true')
199
+ " 2>/dev/null || echo "true")
200
+
201
+ if [ "$IS_ERROR" = "false" ]; then
202
+ touch "$MARKER"
203
+ fi
204
+ }
205
+
156
206
  # ---------------------------------------------------------------------------
157
207
  # Non-doc file detection for WIP gating
158
208
  # ---------------------------------------------------------------------------
@@ -16,7 +16,7 @@ check_review_gate() {
16
16
  local POLICY_FILE="$3" # e.g., "docs/STYLE-GUIDE.md"
17
17
  local MARKER="/tmp/${SYSTEM}-reviewed-${SESSION_ID}"
18
18
  local HASH_FILE="/tmp/${SYSTEM}-reviewed-${SESSION_ID}.hash"
19
- local TTL_SECONDS="${REVIEW_TTL:-1800}"
19
+ local TTL_SECONDS="${REVIEW_TTL:-3600}"
20
20
 
21
21
  # 1. Marker must exist
22
22
  if [ ! -f "$MARKER" ]; then
@@ -0,0 +1,24 @@
1
+ #!/bin/bash
2
+ # Style Guide - PostToolUse:Agent|Bash slide-marker hook (P111).
3
+ # Slides the parent session's existing style-guide-reviewed marker forward
4
+ # on subprocess return, treating subprocess wall-clock as continuous parent-
5
+ # session work for TTL purposes. Only TOUCHES an existing marker — never
6
+ # creates one (creation requires a real style-guide review parsed from the
7
+ # agent's verdict file in style-guide-mark-reviewed.sh).
8
+ #
9
+ # See ADR-009 "Subprocess-boundary refresh" and P111 for context. Failed
10
+ # subprocesses (tool_response.is_error=true) do NOT extend the trust window
11
+ # — see slide_marker_on_subprocess_return in lib/gate-helpers.sh.
12
+
13
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
14
+ source "$SCRIPT_DIR/lib/review-gate.sh"
15
+
16
+ _parse_input
17
+
18
+ SESSION_ID=$(_get_session_id)
19
+ [ -n "$SESSION_ID" ] || exit 0
20
+
21
+ slide_marker_on_subprocess_return "/tmp/style-guide-reviewed-${SESSION_ID}"
22
+ slide_marker_on_subprocess_return "/tmp/style-guide-plan-reviewed-${SESSION_ID}"
23
+
24
+ exit 0
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env bats
2
+
3
+ # Tests for slide_marker_on_subprocess_return helper (P111).
4
+ #
5
+ # Behavioural contract:
6
+ # - Slides an existing marker forward (touch) on PostToolUse:Agent|Bash
7
+ # completion, treating subprocess wall-clock as continuous parent-session
8
+ # work for TTL purposes.
9
+ # - Never CREATES a marker (creating requires a real gate review).
10
+ # - Skips slide on subprocess error (tool_response.is_error=true) so a failed
11
+ # subprocess does NOT extend the parent's trust window (ADR-009 amendment).
12
+ # - No-op when no marker exists or session_id is empty (fail-safe).
13
+
14
+ setup() {
15
+ HOOKS_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
16
+ source "$HOOKS_DIR/lib/gate-helpers.sh"
17
+
18
+ TEST_SESSION="bats-slide-$$-${BATS_TEST_NUMBER}"
19
+ MARKER="/tmp/architect-reviewed-${TEST_SESSION}"
20
+ rm -f "$MARKER"
21
+ }
22
+
23
+ teardown() {
24
+ rm -f "$MARKER"
25
+ }
26
+
27
+ # Helper: backdate file mtime by N seconds (portable between macOS and Linux)
28
+ _backdate() {
29
+ local file="$1" seconds="$2"
30
+ local stamp
31
+ stamp=$(date -v-${seconds}S +%Y%m%d%H%M.%S 2>/dev/null \
32
+ || date -d "${seconds} seconds ago" +%Y%m%d%H%M.%S 2>/dev/null)
33
+ touch -t "$stamp" "$file"
34
+ }
35
+
36
+ @test "slide: existing marker is touched on success response" {
37
+ touch "$MARKER"
38
+ _backdate "$MARKER" 60
39
+ BEFORE=$(_mtime "$MARKER")
40
+ _HOOK_INPUT='{"tool_response":{"content":[]}}'
41
+ slide_marker_on_subprocess_return "$MARKER"
42
+ AFTER=$(_mtime "$MARKER")
43
+ [ "$AFTER" -gt "$BEFORE" ]
44
+ }
45
+
46
+ @test "slide: long-running subprocess does NOT cause parent marker expiry on return (P111 reproduction)" {
47
+ # Simulate the P111 failure mode: parent's marker is set, then a long
48
+ # subprocess runs (we backdate the marker to simulate elapsed wall-clock),
49
+ # then PostToolUse fires with a successful tool_response. The marker mtime
50
+ # must be refreshed so the parent's NEXT PreToolUse gate check (which
51
+ # compares NOW - mtime against TTL) sees a fresh marker.
52
+ touch "$MARKER"
53
+ # Marker is 50 minutes old — under default 60-min TTL but close to expiry.
54
+ # Without the slide on subprocess return, a subsequent 15-min subprocess
55
+ # would push the mtime past TTL and the next PreToolUse would deny.
56
+ _backdate "$MARKER" 3000
57
+ BEFORE=$(_mtime "$MARKER")
58
+ _HOOK_INPUT='{"tool_response":{"content":[{"type":"text","text":"OK"}]}}'
59
+ slide_marker_on_subprocess_return "$MARKER"
60
+ AFTER=$(_mtime "$MARKER")
61
+ NOW=$(date +%s)
62
+ [ "$AFTER" -gt "$BEFORE" ]
63
+ # And the new mtime is approximately NOW (within 5 seconds of slide call)
64
+ AGE=$((NOW - AFTER))
65
+ [ "$AGE" -lt 5 ]
66
+ }
67
+
68
+ @test "slide: does NOT touch marker when tool_response.is_error=true" {
69
+ touch "$MARKER"
70
+ _backdate "$MARKER" 60
71
+ BEFORE=$(_mtime "$MARKER")
72
+ _HOOK_INPUT='{"tool_response":{"is_error":true,"content":[]}}'
73
+ slide_marker_on_subprocess_return "$MARKER"
74
+ AFTER=$(_mtime "$MARKER")
75
+ [ "$BEFORE" = "$AFTER" ]
76
+ }
77
+
78
+ @test "slide: no-op when marker does not exist (never creates)" {
79
+ [ ! -f "$MARKER" ]
80
+ _HOOK_INPUT='{"tool_response":{"content":[]}}'
81
+ slide_marker_on_subprocess_return "$MARKER"
82
+ [ ! -f "$MARKER" ]
83
+ }
84
+
85
+ @test "slide: no-op when marker path argument is empty" {
86
+ _HOOK_INPUT='{"tool_response":{"content":[]}}'
87
+ run slide_marker_on_subprocess_return ""
88
+ [ "$status" -eq 0 ]
89
+ }
90
+
91
+ @test "slide: malformed hook input is fail-safe (no slide)" {
92
+ touch "$MARKER"
93
+ _backdate "$MARKER" 60
94
+ BEFORE=$(_mtime "$MARKER")
95
+ _HOOK_INPUT='not valid json'
96
+ slide_marker_on_subprocess_return "$MARKER"
97
+ AFTER=$(_mtime "$MARKER")
98
+ # Fail-safe: when the hook input cannot be parsed, treat as error and skip
99
+ [ "$BEFORE" = "$AFTER" ]
100
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windyroad/style-guide",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Style guide enforcement for CSS and UI components",
5
5
  "bin": {
6
6
  "windyroad-style-guide": "./bin/install.mjs"