claude-everything-workflow 0.1.4 → 0.1.6

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.
Files changed (35) hide show
  1. package/README.md +50 -19
  2. package/hooks/check-code-size.js +111 -0
  3. package/package.json +1 -1
  4. package/rules/02-code-size.md +11 -2
  5. package/rules/common/hooks.md +2 -1
  6. package/rules/common/skills-learning.md +7 -0
  7. package/scripts/install.ps1 +80 -43
  8. package/scripts/install.sh +56 -3
  9. package/scripts/verify-harness.js +156 -26
  10. package/settings.json +8 -40
  11. package/skills/brainstorming/scripts/frame-template.html +25 -26
  12. package/skills/brainstorming/scripts/helper.js +101 -22
  13. package/skills/brainstorming/scripts/server.cjs +399 -30
  14. package/skills/brainstorming/scripts/start-server.sh +70 -9
  15. package/skills/brainstorming/scripts/stop-server.sh +66 -2
  16. package/skills/brainstorming/visual-companion.md +33 -22
  17. package/skills/learn/.gitkeep +0 -0
  18. package/skills/learn/README.md +15 -0
  19. package/skills/learn/debugging/.gitkeep +0 -0
  20. package/skills/learn/pr/.gitkeep +0 -0
  21. package/skills/learn/testing/.gitkeep +0 -0
  22. package/skills/subagent-driven-development/SKILL.md +425 -0
  23. package/skills/subagent-driven-development/implementer-prompt.md +139 -0
  24. package/skills/subagent-driven-development/scripts/review-package +44 -0
  25. package/skills/subagent-driven-development/scripts/sdd-workspace +22 -0
  26. package/skills/subagent-driven-development/scripts/task-brief +40 -0
  27. package/skills/subagent-driven-development/task-reviewer-prompt.md +188 -0
  28. package/skills/using-superpowers/SKILL.md +75 -0
  29. package/skills/writing-plans/SKILL.md +25 -2
  30. package/commands/acceptance.md +0 -73
  31. package/hooks/evaluate-session.js +0 -59
  32. package/hooks/pre-compact.js +0 -92
  33. package/hooks/runtime/session-utils.js +0 -45
  34. package/hooks/session-end.js +0 -62
  35. package/hooks/session-start.js +0 -60
@@ -11,6 +11,9 @@
11
11
  # --host <bind-host> Host/interface to bind (default: 127.0.0.1).
12
12
  # Use 0.0.0.0 in remote/containerized environments.
13
13
  # --url-host <host> Hostname shown in returned URL JSON.
14
+ # --idle-timeout-minutes <n> Shut down after n minutes idle (default 240 = 4h).
15
+ # --open Auto-open the browser on the first screen (use only
16
+ # after the user approves the visual companion).
14
17
  # --foreground Run server in the current terminal (no backgrounding).
15
18
  # --background Force background mode (overrides Codex auto-foreground).
16
19
 
@@ -22,6 +25,7 @@ FOREGROUND="false"
22
25
  FORCE_BACKGROUND="false"
23
26
  BIND_HOST="127.0.0.1"
24
27
  URL_HOST=""
28
+ IDLE_TIMEOUT_MINUTES=""
25
29
  while [[ $# -gt 0 ]]; do
26
30
  case "$1" in
27
31
  --project-dir)
@@ -36,6 +40,14 @@ while [[ $# -gt 0 ]]; do
36
40
  URL_HOST="$2"
37
41
  shift 2
38
42
  ;;
43
+ --idle-timeout-minutes)
44
+ IDLE_TIMEOUT_MINUTES="$2"
45
+ shift 2
46
+ ;;
47
+ --open)
48
+ export BRAINSTORM_OPEN=1
49
+ shift
50
+ ;;
39
51
  --foreground|--no-daemon)
40
52
  FOREGROUND="true"
41
53
  shift
@@ -59,6 +71,29 @@ if [[ -z "$URL_HOST" ]]; then
59
71
  fi
60
72
  fi
61
73
 
74
+ if [[ -n "$IDLE_TIMEOUT_MINUTES" ]]; then
75
+ if ! [[ "$IDLE_TIMEOUT_MINUTES" =~ ^[0-9]+$ ]] || [[ "$IDLE_TIMEOUT_MINUTES" -lt 1 ]]; then
76
+ echo "{\"error\": \"--idle-timeout-minutes must be a positive integer\"}"
77
+ exit 1
78
+ fi
79
+ export BRAINSTORM_IDLE_TIMEOUT_MS=$(( IDLE_TIMEOUT_MINUTES * 60 * 1000 ))
80
+ fi
81
+
82
+ is_windows_like_shell() {
83
+ case "${OSTYPE:-}" in
84
+ msys*|cygwin*|mingw*) return 0 ;;
85
+ esac
86
+ if [[ -n "${MSYSTEM:-}" ]]; then
87
+ return 0
88
+ fi
89
+ local uname_s
90
+ uname_s="$(uname -s 2>/dev/null || true)"
91
+ case "$uname_s" in
92
+ MSYS*|MINGW*|CYGWIN*) return 0 ;;
93
+ esac
94
+ return 1
95
+ }
96
+
62
97
  # Some environments reap detached/background processes. Auto-foreground when detected.
63
98
  if [[ -n "${CODEX_CI:-}" && "$FOREGROUND" != "true" && "$FORCE_BACKGROUND" != "true" ]]; then
64
99
  FOREGROUND="true"
@@ -66,19 +101,24 @@ fi
66
101
 
67
102
  # Windows/Git Bash reaps nohup background processes. Auto-foreground when detected.
68
103
  if [[ "$FOREGROUND" != "true" && "$FORCE_BACKGROUND" != "true" ]]; then
69
- case "${OSTYPE:-}" in
70
- msys*|cygwin*|mingw*) FOREGROUND="true" ;;
71
- esac
72
- if [[ -n "${MSYSTEM:-}" ]]; then
104
+ if is_windows_like_shell; then
73
105
  FOREGROUND="true"
74
106
  fi
75
107
  fi
76
108
 
109
+ # Session files (server.log, server-info, .last-token) embed the session key —
110
+ # keep everything this script and the server create owner-only.
111
+ umask 077
112
+
77
113
  # Generate unique session directory
78
114
  SESSION_ID="$$-$(date +%s)"
79
115
 
80
116
  if [[ -n "$PROJECT_DIR" ]]; then
81
117
  SESSION_DIR="${PROJECT_DIR}/.superpowers/brainstorm/${SESSION_ID}"
118
+ # Persist the bound port and key per project so a restart reuses them and an
119
+ # already-open browser tab reconnects to the same URL with a valid cookie.
120
+ export BRAINSTORM_PORT_FILE="${PROJECT_DIR}/.superpowers/brainstorm/.last-port"
121
+ export BRAINSTORM_TOKEN_FILE="${PROJECT_DIR}/.superpowers/brainstorm/.last-token"
82
122
  else
83
123
  SESSION_DIR="/tmp/brainstorm-${SESSION_ID}"
84
124
  fi
@@ -86,10 +126,21 @@ fi
86
126
  STATE_DIR="${SESSION_DIR}/state"
87
127
  PID_FILE="${STATE_DIR}/server.pid"
88
128
  LOG_FILE="${STATE_DIR}/server.log"
129
+ SERVER_ID_FILE="${STATE_DIR}/server-instance-id"
89
130
 
90
131
  # Create fresh session directory with content and state peers
91
132
  mkdir -p "${SESSION_DIR}/content" "$STATE_DIR"
92
133
 
134
+ SERVER_ID=""
135
+ if [[ -r /dev/urandom ]]; then
136
+ SERVER_ID="$(od -An -N24 -tx1 /dev/urandom 2>/dev/null | tr -d ' \n' || true)"
137
+ fi
138
+ if ! [[ "$SERVER_ID" =~ ^[A-Za-z0-9_-]{32,64}$ ]]; then
139
+ SERVER_ID="$(printf '%08x%08x%08x%08x' "$$" "$(date +%s)" "${RANDOM:-0}" "${RANDOM:-0}")"
140
+ fi
141
+ printf '%s\n' "$SERVER_ID" > "$SERVER_ID_FILE"
142
+ chmod 600 "$SERVER_ID_FILE" 2>/dev/null || true
143
+
93
144
  # Kill any existing server
94
145
  if [[ -f "$PID_FILE" ]]; then
95
146
  old_pid=$(cat "$PID_FILE")
@@ -97,7 +148,7 @@ if [[ -f "$PID_FILE" ]]; then
97
148
  rm -f "$PID_FILE"
98
149
  fi
99
150
 
100
- cd "$SCRIPT_DIR"
151
+ cd "$SCRIPT_DIR" || exit 1
101
152
 
102
153
  # Resolve the harness PID (grandparent of this script).
103
154
  # $PPID is the ephemeral shell the harness spawned to run us — it dies
@@ -107,22 +158,32 @@ if [[ -z "$OWNER_PID" || "$OWNER_PID" == "1" ]]; then
107
158
  OWNER_PID="$PPID"
108
159
  fi
109
160
 
161
+ # Windows/MSYS2: Node.js cannot see POSIX PIDs from the MSYS2 namespace.
162
+ # Passing a PID node cannot verify causes server to log owner-pid-invalid
163
+ # and self-terminate at the 60-second lifecycle check. Clear it so the
164
+ # watchdog is disabled and the idle timeout becomes the only shutdown trigger.
165
+ if is_windows_like_shell; then
166
+ OWNER_PID=""
167
+ fi
168
+
110
169
  # Foreground mode for environments that reap detached/background processes.
111
170
  if [[ "$FOREGROUND" == "true" ]]; then
112
- echo "$$" > "$PID_FILE"
113
- env BRAINSTORM_DIR="$SESSION_DIR" BRAINSTORM_HOST="$BIND_HOST" BRAINSTORM_URL_HOST="$URL_HOST" BRAINSTORM_OWNER_PID="$OWNER_PID" node server.cjs
171
+ env BRAINSTORM_DIR="$SESSION_DIR" BRAINSTORM_HOST="$BIND_HOST" BRAINSTORM_URL_HOST="$URL_HOST" BRAINSTORM_OWNER_PID="$OWNER_PID" node server.cjs "--brainstorm-server-id=$SERVER_ID" &
172
+ SERVER_PID=$!
173
+ echo "$SERVER_PID" > "$PID_FILE"
174
+ wait "$SERVER_PID"
114
175
  exit $?
115
176
  fi
116
177
 
117
178
  # Start server, capturing output to log file
118
179
  # Use nohup to survive shell exit; disown to remove from job table
119
- nohup env BRAINSTORM_DIR="$SESSION_DIR" BRAINSTORM_HOST="$BIND_HOST" BRAINSTORM_URL_HOST="$URL_HOST" BRAINSTORM_OWNER_PID="$OWNER_PID" node server.cjs > "$LOG_FILE" 2>&1 &
180
+ nohup env BRAINSTORM_DIR="$SESSION_DIR" BRAINSTORM_HOST="$BIND_HOST" BRAINSTORM_URL_HOST="$URL_HOST" BRAINSTORM_OWNER_PID="$OWNER_PID" node server.cjs "--brainstorm-server-id=$SERVER_ID" > "$LOG_FILE" 2>&1 &
120
181
  SERVER_PID=$!
121
182
  disown "$SERVER_PID" 2>/dev/null
122
183
  echo "$SERVER_PID" > "$PID_FILE"
123
184
 
124
185
  # Wait for server-started message (check log file)
125
- for i in {1..50}; do
186
+ for _ in {1..50}; do
126
187
  if grep -q "server-started" "$LOG_FILE" 2>/dev/null; then
127
188
  # Verify server is still alive after a short window (catches process reapers)
128
189
  alive="true"
@@ -15,15 +15,78 @@ fi
15
15
 
16
16
  STATE_DIR="${SESSION_DIR}/state"
17
17
  PID_FILE="${STATE_DIR}/server.pid"
18
+ SERVER_ID_FILE="${STATE_DIR}/server-instance-id"
19
+
20
+ mark_stopped() {
21
+ local reason="$1"
22
+ rm -f "${STATE_DIR}/server-info"
23
+ printf '{"reason":"%s","timestamp":%s}\n' "$reason" "$(date +%s)" > "${STATE_DIR}/server-stopped"
24
+ }
25
+
26
+ read_expected_server_id() {
27
+ [[ -f "$SERVER_ID_FILE" ]] || return 1
28
+ local id
29
+ id="$(tr -d '\r\n' < "$SERVER_ID_FILE" 2>/dev/null || true)"
30
+ [[ "$id" =~ ^[A-Za-z0-9_-]{32,64}$ ]] || return 1
31
+ printf '%s\n' "$id"
32
+ }
33
+
34
+ command_line_for_pid() {
35
+ local pid="$1"
36
+ if [[ -r "/proc/$pid/cmdline" ]]; then
37
+ tr '\0' '\n' < "/proc/$pid/cmdline" 2>/dev/null || true
38
+ return 0
39
+ fi
40
+ ps -ww -p "$pid" -o command= 2>/dev/null || ps -f -p "$pid" 2>/dev/null | sed '1d' || true
41
+ }
42
+
43
+ command_has_server_id() {
44
+ local pid="$1"
45
+ local expected="$2"
46
+ local expected_arg="--brainstorm-server-id=$expected"
47
+ if [[ -r "/proc/$pid/cmdline" ]]; then
48
+ local arg
49
+ while IFS= read -r -d '' arg || [[ -n "$arg" ]]; do
50
+ [[ "$arg" == "$expected_arg" ]] && return 0
51
+ done < "/proc/$pid/cmdline"
52
+ return 1
53
+ fi
54
+ local command_line
55
+ command_line="$(command_line_for_pid "$pid")"
56
+ [[ -n "$command_line" ]] || return 1
57
+ case " $command_line " in
58
+ *" $expected_arg "*) return 0 ;;
59
+ *) return 1 ;;
60
+ esac
61
+ }
62
+
63
+ # Confirm a PID has this session's per-start instance id, not just a familiar
64
+ # process name. Ambiguous or legacy metadata fails closed as stale_pid.
65
+ is_brainstorm_server() {
66
+ kill -0 "$1" 2>/dev/null || return 1
67
+ local expected_id
68
+ expected_id="$(read_expected_server_id)" || return 1
69
+ command_has_server_id "$1" "$expected_id" || return 1
70
+ return 0
71
+ }
18
72
 
19
73
  if [[ -f "$PID_FILE" ]]; then
20
74
  pid=$(cat "$PID_FILE")
21
75
 
76
+ # Refuse to signal a PID we can't prove is our server. A stale pid file may
77
+ # point at an unrelated process after a reboot/PID wraparound.
78
+ if ! is_brainstorm_server "$pid"; then
79
+ rm -f "$PID_FILE" "$SERVER_ID_FILE"
80
+ mark_stopped "stale_pid"
81
+ echo '{"status": "stale_pid"}'
82
+ exit 0
83
+ fi
84
+
22
85
  # Try to stop gracefully, fallback to force if still alive
23
86
  kill "$pid" 2>/dev/null || true
24
87
 
25
88
  # Wait for graceful shutdown (up to ~2s)
26
- for i in {1..20}; do
89
+ for _ in {1..20}; do
27
90
  if ! kill -0 "$pid" 2>/dev/null; then
28
91
  break
29
92
  fi
@@ -43,7 +106,8 @@ if [[ -f "$PID_FILE" ]]; then
43
106
  exit 1
44
107
  fi
45
108
 
46
- rm -f "$PID_FILE" "${STATE_DIR}/server.log"
109
+ rm -f "$PID_FILE" "$SERVER_ID_FILE" "${STATE_DIR}/server.log"
110
+ mark_stopped "stop-server.sh"
47
111
 
48
112
  # Only delete ephemeral /tmp directories
49
113
  if [[ "$SESSION_DIR" == /tmp/* ]]; then
@@ -28,20 +28,30 @@ A question *about* a UI topic is not automatically a visual question. "What kind
28
28
 
29
29
  The server watches a directory for HTML files and serves the newest one to the browser. You write HTML content to `screen_dir`, the user sees it in their browser and can click to select options. Selections are recorded to `state_dir/events` that you read on your next turn.
30
30
 
31
- **Content fragments vs full documents:** If your HTML file starts with `<!DOCTYPE` or `<html`, the server serves it as-is (just injects the helper script). Otherwise, the server automatically wraps your content in the frame template — adding the header, CSS theme, selection indicator, and all interactive infrastructure. **Write content fragments by default.** Only write full documents when you need complete control over the page.
31
+ **Content fragments vs full documents:** If your HTML file starts with `<!DOCTYPE` or `<html`, the server serves it as-is (just injects the helper script). Otherwise, the server automatically wraps your content in the frame template — adding the header, CSS theme, connection status, and all interactive infrastructure. **Write content fragments by default.** Only write full documents when you need complete control over the page.
32
32
 
33
33
  ## Starting a Session
34
34
 
35
35
  ```bash
36
- # Start server with persistence (mockups saved to project)
37
- scripts/start-server.sh --project-dir /path/to/project
36
+ # Start AFTER the user approves the companion. --open auto-opens their browser on
37
+ # the first screen; --project-dir persists mockups and enables same-port restart.
38
+ scripts/start-server.sh --project-dir /path/to/project --open
38
39
 
39
- # Returns: {"type":"server-started","port":52341,"url":"http://localhost:52341",
40
+ # Returns: {"type":"server-started","port":52341,
41
+ # "url":"http://localhost:52341/?key=ab12…",
40
42
  # "screen_dir":"/path/to/project/.superpowers/brainstorm/12345-1706000000/content",
41
43
  # "state_dir":"/path/to/project/.superpowers/brainstorm/12345-1706000000/state"}
42
44
  ```
43
45
 
44
- Save `screen_dir` and `state_dir` from the response. Tell user to open the URL.
46
+ Save `screen_dir` and `state_dir` from the response. With `--open`, the browser opens itself when you push the first screen — you don't need to ask the user to open it, but still share the URL as a fallback (headless/remote setups won't auto-open).
47
+
48
+ **The URL contains a session key (`?key=…`).** The server rejects any request
49
+ without it, so always give the user the **complete** URL from the `url` field —
50
+ never strip the query string, and never hand out a bare `http://host:port`. The
51
+ key gates HTTP and WebSocket access so a stray browser tab or another machine on
52
+ the network can't read the screens or inject events. After the first load the
53
+ browser remembers the key via a cookie, so reloads and `/files/*` assets work
54
+ without repeating it.
45
55
 
46
56
  **Finding connection info:** The server writes its startup JSON to `$STATE_DIR/server-info`. If you launched the server in the background and didn't capture stdout, read that file to get the URL and port. When using `--project-dir`, check `<project>/.superpowers/brainstorm/` for the session directory.
47
57
 
@@ -49,33 +59,34 @@ Save `screen_dir` and `state_dir` from the response. Tell user to open the URL.
49
59
 
50
60
  **Launching the server by platform:**
51
61
 
52
- **Claude Code (macOS / Linux):**
62
+ **Claude Code:**
53
63
  ```bash
54
- # Default mode works — the script backgrounds the server itself
55
- scripts/start-server.sh --project-dir /path/to/project
64
+ # Default mode works — the script backgrounds the server itself.
65
+ scripts/start-server.sh --project-dir /path/to/project --open
56
66
  ```
57
67
 
58
- **Claude Code (Windows):**
59
- ```bash
60
- # Windows auto-detects and uses foreground mode, which blocks the tool call.
61
- # Use run_in_background: true on the Bash tool call so the server survives
62
- # across conversation turns.
63
- scripts/start-server.sh --project-dir /path/to/project
64
- ```
65
- When calling this via the Bash tool, set `run_in_background: true`. Then read `$STATE_DIR/server-info` on the next turn to get the URL and port.
68
+ On Windows, the script auto-detects and switches to foreground mode (which blocks the tool call). Use `run_in_background: true` on the Bash tool call so the server survives across conversation turns, then read `$STATE_DIR/server-info` on the next turn to get the URL and port.
66
69
 
67
70
  **Codex:**
68
71
  ```bash
69
72
  # Codex reaps background processes. The script auto-detects CODEX_CI and
70
73
  # switches to foreground mode. Run it normally — no extra flags needed.
71
- scripts/start-server.sh --project-dir /path/to/project
74
+ scripts/start-server.sh --project-dir /path/to/project --open
72
75
  ```
73
76
 
74
77
  **Gemini CLI:**
75
78
  ```bash
76
79
  # Use --foreground and set is_background: true on your shell tool call
77
80
  # so the process survives across turns
78
- scripts/start-server.sh --project-dir /path/to/project --foreground
81
+ scripts/start-server.sh --project-dir /path/to/project --open --foreground
82
+ ```
83
+
84
+ **Copilot CLI:**
85
+ ```bash
86
+ # Use --foreground and start the server via the bash tool with mode: "async"
87
+ # so the process survives across turns. Capture the returned shellId for
88
+ # read_bash / stop_bash if you need to interact with it later.
89
+ scripts/start-server.sh --project-dir /path/to/project --open --foreground
79
90
  ```
80
91
 
81
92
  **Other environments:** The server must keep running in the background across conversation turns. If your environment reaps detached processes, use `--foreground` and launch the command with your platform's background execution mechanism.
@@ -94,10 +105,10 @@ Use `--url-host` to control what hostname is printed in the returned URL JSON.
94
105
  ## The Loop
95
106
 
96
107
  1. **Check server is alive**, then **write HTML** to a new file in `screen_dir`:
97
- - Before each write, check that `$STATE_DIR/server-info` exists. If it doesn't (or `$STATE_DIR/server-stopped` exists), the server has shut down — restart it with `start-server.sh` before continuing. The server auto-exits after 30 minutes of inactivity.
108
+ - **Required: confirm the server is alive before referring to the URL or pushing a screen.** Check that `$STATE_DIR/server-info` exists and `$STATE_DIR/server-stopped` does not. If it has shut down, restart it with `start-server.sh` using the **same `--project-dir`** — it reuses the same port, so the user's open tab reconnects on its own (it shows a "paused" overlay while the server is down) and you don't need to send a new URL. The server auto-exits after 4 hours idle (configurable with `--idle-timeout-minutes`).
98
109
  - Use semantic filenames: `platform.html`, `visual-style.html`, `layout.html`
99
110
  - **Never reuse filenames** — each screen gets a fresh file
100
- - Use Write tool — **never use cat/heredoc** (dumps noise into terminal)
111
+ - Use your file-creation tool — **never use cat/heredoc** (dumps noise into terminal)
101
112
  - Server automatically serves the newest file
102
113
 
103
114
  2. **Tell user what to expect and end your turn:**
@@ -127,7 +138,7 @@ Use `--url-host` to control what hostname is printed in the returned URL JSON.
127
138
 
128
139
  ## Writing Content Fragments
129
140
 
130
- Write just the content that goes inside the page. The server wraps it in the frame template automatically (header, theme CSS, selection indicator, and all interactive infrastructure).
141
+ Write just the content that goes inside the page. The server wraps it in the frame template automatically (header, theme CSS, connection status, and all interactive infrastructure).
131
142
 
132
143
  **Minimal example:**
133
144
 
@@ -173,7 +184,7 @@ The frame template provides these CSS classes for your content:
173
184
  </div>
174
185
  ```
175
186
 
176
- **Multi-select:** Add `data-multiselect` to the container to let users select multiple options. Each click toggles the item. The indicator bar shows the count.
187
+ **Multi-select:** Add `data-multiselect` to the container to let users select multiple options. Each click toggles the item's selected styling.
177
188
 
178
189
  ```html
179
190
  <div class="options" data-multiselect>
File without changes
@@ -0,0 +1,15 @@
1
+ # 学习模式归档
2
+
3
+ 从 Hook 观察、project/global instinct 沉淀的可复用学习产物,按分类保存。
4
+
5
+ ## 目录结构
6
+
7
+ - `pr/` — PR 工作流相关模式
8
+ - `testing/` — 测试策略和 TDD 模式
9
+ - `debugging/` — 调试方法和问题排查模式
10
+
11
+ ## 添加流程
12
+
13
+ 1. 使用 `/learn-eval --preview` 评估是否值得保存
14
+ 2. 确认模式可复用后,运行 `/learn-eval` 保存
15
+ 3. 学习产物按分类保存到对应子目录
File without changes
File without changes
File without changes