claude-everything-workflow 0.1.5 → 0.1.7

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 +56 -9
  2. package/package.json +1 -1
  3. package/rules/common/hooks.md +2 -1
  4. package/rules/common/skills-learning.md +9 -0
  5. package/scripts/install.ps1 +80 -43
  6. package/scripts/install.sh +56 -3
  7. package/scripts/verify-harness.js +225 -5
  8. package/settings.json +3 -40
  9. package/skills/README.md +35 -0
  10. package/skills/brainstorming/scripts/frame-template.html +25 -26
  11. package/skills/brainstorming/scripts/helper.js +101 -22
  12. package/skills/brainstorming/scripts/server.cjs +399 -30
  13. package/skills/brainstorming/scripts/start-server.sh +70 -9
  14. package/skills/brainstorming/scripts/stop-server.sh +66 -2
  15. package/skills/brainstorming/visual-companion.md +33 -22
  16. package/skills/context-budget/SKILL.md +59 -0
  17. package/skills/iterative-retrieval/SKILL.md +75 -0
  18. package/skills/learn/.gitkeep +0 -0
  19. package/skills/learn/README.md +15 -0
  20. package/skills/learn/debugging/.gitkeep +0 -0
  21. package/skills/learn/pr/.gitkeep +0 -0
  22. package/skills/learn/testing/.gitkeep +0 -0
  23. package/skills/subagent-driven-development/SKILL.md +425 -0
  24. package/skills/subagent-driven-development/implementer-prompt.md +139 -0
  25. package/skills/subagent-driven-development/scripts/review-package +44 -0
  26. package/skills/subagent-driven-development/scripts/sdd-workspace +22 -0
  27. package/skills/subagent-driven-development/scripts/task-brief +40 -0
  28. package/skills/subagent-driven-development/task-reviewer-prompt.md +188 -0
  29. package/skills/using-superpowers/SKILL.md +75 -0
  30. package/skills/writing-plans/SKILL.md +25 -2
  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>
@@ -0,0 +1,59 @@
1
+ ---
2
+ name: context-budget
3
+ description: "审计 Agent Harness 的上下文开销、MCP 连接器、常驻规则、skills 和 agents。用于会话变慢、工具过多、准备新增 MCP/skill/agent、或需要按 ECC 最新策略压缩默认上下文时;输出按节省 Token 和风险排序的整改建议。"
4
+ ---
5
+
6
+ # Context Budget
7
+
8
+ 用这个 skill 找出“模型能力被上下文噪音吃掉”的来源。目标不是把能力砍少,而是让默认上下文只保留高频、通用、状态性强的内容,把其余能力改为按需 skill、CLI、脚本或浏览器原生能力。
9
+
10
+ ## 工作流
11
+
12
+ 1. 盘点常驻面:入口文件、规则索引、默认 MCP、agent 描述、自动加载 skill、hooks 配置。
13
+ 2. 估算开销:Markdown 用 `words * 1.3` 粗估;代码和 JSON 用 `chars / 4` 粗估;MCP tool schema 按每个工具约 `500 tokens` 粗估。
14
+ 3. 分类保留级别:
15
+ - **默认保留**:几乎每个任务都要用,且按需加载成本更高。
16
+ - **按需加载**:只在明确触发时读取,例如专项规则、技能说明、长参考。
17
+ - **外移为 CLI/API**:无会话状态、一次请求即可完成,例如 GitHub、文档查询、包搜索。
18
+ - **删除或合并**:与现有规则重复、描述太宽、没有明确触发或退出条件。
19
+ 4. 输出整改建议:先列最大 Token 节省,再列误删风险和替代入口。
20
+
21
+ ## MCP 默认策略
22
+
23
+ 默认 MCP 必须同时满足两个条件:
24
+
25
+ - **通用**:几乎每个编码 agent、每个项目都会用。
26
+ - **MCP 明显优于 CLI/API/原生能力**:任务需要会话状态、交互式连接、流式上下文或结构化浏览;纯请求/响应工作不应作为默认 MCP 常驻。
27
+
28
+ 不满足这两个条件时,优先改成:
29
+
30
+ - skill 调用本地 CLI,例如 `gh`、`git`、`npm`;
31
+ - skill 调用 REST/API,例如文档查询;
32
+ - harness 原生能力,例如内置 web search、memory、extended thinking;
33
+ - 可选 MCP 文档项,而不是默认启用项。
34
+
35
+ ## 报告格式
36
+
37
+ ```markdown
38
+ ## Context Budget
39
+ - 估算常驻开销:
40
+ - 最大噪音来源:
41
+ - 建议默认保留:
42
+ - 建议按需加载:
43
+ - 建议外移为 CLI/API:
44
+ - 不建议修改:
45
+
46
+ ## 优先整改
47
+ 1. [路径/配置]:[动作] -> 预计节省 [tokens/原因],风险:[低/中/高]
48
+ 2. ...
49
+
50
+ ## 验证
51
+ - [命令或人工检查]:
52
+ - 剩余风险:
53
+ ```
54
+
55
+ ## 注意事项
56
+
57
+ - 不要为了“省 Token”删除用户硬规则、安全边界或验证门。
58
+ - 不要把所有外部能力都降级成手写脚本;如果任务需要交互式浏览、调试会话或持久连接,MCP 仍可能是正确选择。
59
+ - 给出建议时必须说明替代入口,否则只是减配。
@@ -0,0 +1,75 @@
1
+ ---
2
+ name: iterative-retrieval
3
+ description: "为 subagent、代码探索、RAG 式检索和大仓库上下文收集设计迭代检索闭环。用于初始上下文不明确、一次性读全仓会污染上下文、子代理不知道该读哪些文件、或搜索结果需要逐轮收敛时。"
4
+ ---
5
+
6
+ # Iterative Retrieval
7
+
8
+ 这个 skill 解决子代理和大仓库探索的核心问题:开始时不知道要读什么,但把所有内容都塞进上下文会让模型变差。
9
+
10
+ ## 四阶段闭环
11
+
12
+ 最多跑 3 轮,每轮都要缩小范围。
13
+
14
+ 1. **Dispatch**:用当前任务生成第一批搜索条件,包括路径 glob、关键词、排除目录和已知入口。
15
+ 2. **Evaluate**:按相关性给候选文件分级,并记录为什么相关、还缺什么上下文。
16
+ 3. **Refine**:从高相关文件里提取项目术语、调用链、类型名和目录模式,更新下一轮搜索条件。
17
+ 4. **Loop / Stop**:如果已有足够高相关上下文,停止;否则进入下一轮。三轮后仍不足时,带着最佳证据继续,并明确缺口。
18
+
19
+ ## 相关性分级
20
+
21
+ | 等级 | 判断 | 动作 |
22
+ | --- | --- | --- |
23
+ | 高 | 直接实现目标行为、核心调用链或关键配置 | 读细节并保留路径 |
24
+ | 中 | 提供同类模式、类型、测试或接口契约 | 只抽取模式或术语 |
25
+ | 低 | 只是同名或旁路引用 | 记录后排除 |
26
+ | 无 | 与任务无关 | 加入排除条件 |
27
+
28
+ ## 子代理任务模板
29
+
30
+ ```markdown
31
+ 目标:[一句话说明要找什么]
32
+ 范围:[允许搜索的目录/文件]
33
+ 排除:[node_modules、dist、生成物、无关目录]
34
+ 初始关键词:[3-8 个]
35
+
36
+ 请最多执行 3 轮检索:
37
+ 1. 每轮列出查询条件。
38
+ 2. 对候选文件标注高/中/低/无相关性和理由。
39
+ 3. 根据发现更新下一轮关键词或路径。
40
+ 4. 最后只回传:关键文件、证据、缺失上下文、建议下一步。
41
+
42
+ 不要回传完整 grep 输出、目录树或长日志。
43
+ ```
44
+
45
+ ## 回传格式
46
+
47
+ ```markdown
48
+ ## 结论
49
+ [是否已找到足够上下文]
50
+
51
+ ## 关键文件
52
+ - `path/to/file`:[为什么高相关]
53
+
54
+ ## 证据
55
+ - `path/to/file:line`:[可复核事实]
56
+
57
+ ## 缺口
58
+ - [仍缺的文件/术语/接口]
59
+
60
+ ## 下一步
61
+ - [最小可执行动作]
62
+ ```
63
+
64
+ ## 停止条件
65
+
66
+ - 已找到 2-5 个高相关文件,且缺口不影响当前决策。
67
+ - 下一轮搜索只会扩大噪音,没有新的术语或路径线索。
68
+ - 任务需要用户或外部系统信息,继续本地检索无法推进。
69
+
70
+ ## 反模式
71
+
72
+ - 一开始就读取全仓、完整日志或完整搜索结果。
73
+ - 只按关键词命中数排序,不解释相关性。
74
+ - 子代理返回探索过程而不是压缩后的证据。
75
+ - 明明缺关键上下文,却假装已经足够。
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