@leocm/flowcraft 2.1.0 → 2.3.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.
Files changed (96) hide show
  1. package/README.md +19 -2
  2. package/bin/cli.js +108 -108
  3. package/flowcraft.yaml +30 -30
  4. package/install.sh +24 -24
  5. package/lib/args.js +38 -38
  6. package/lib/config.js +20 -20
  7. package/lib/copy.js +131 -131
  8. package/lib/fix.js +110 -110
  9. package/lib/fsutil.js +104 -104
  10. package/lib/global.js +229 -229
  11. package/lib/init.js +43 -43
  12. package/lib/runtime.js +84 -84
  13. package/lib/version.js +55 -55
  14. package/lib/wizard.js +125 -125
  15. package/package.json +33 -33
  16. package/presets/backend.yaml +20 -20
  17. package/presets/default.yaml +15 -15
  18. package/presets/frontend.yaml +20 -20
  19. package/presets/quick-fix.yaml +15 -15
  20. package/setup/.claude/hooks/check-phase-test.py +152 -152
  21. package/setup/.claude/hooks/check-phase-write.py +235 -235
  22. package/setup/.claude/hooks/dispatch.py +67 -67
  23. package/setup/.claude/hooks/file-suggestion.py +45 -45
  24. package/setup/.claude/hooks/flowcraft_env.py +162 -137
  25. package/setup/.claude/hooks/permission-request.py +132 -125
  26. package/setup/.claude/hooks/post-tool-failure.py +36 -36
  27. package/setup/.claude/hooks/pre-compact.py +66 -66
  28. package/setup/.claude/hooks/review-runner.py +846 -846
  29. package/setup/.claude/hooks/setup-keys.py +282 -282
  30. package/setup/.claude/hooks/statusline.py +63 -63
  31. package/setup/.claude/hooks/stop-check.py +186 -171
  32. package/setup/.claude/hooks/subagent-start.py +50 -50
  33. package/setup/.claude/hooks/subagent-stop.py +63 -63
  34. package/setup/.claude/hooks/task-completed.py +57 -57
  35. package/setup/.claude/hooks/task_manager.py +592 -592
  36. package/setup/.claude/hooks/user-prompt-submit.py +91 -85
  37. package/setup/.claude/settings.json +233 -237
  38. package/setup/.claude/skills/Pstatus/SKILL.md +68 -68
  39. package/setup/.claude/skills/archive/SKILL.md +195 -195
  40. package/setup/.claude/skills/brainstorming/SKILL.md +5 -5
  41. package/setup/.claude/skills/brainstorming/scripts/server.cjs +723 -723
  42. package/setup/.claude/skills/brainstorming/scripts/start-server.py +245 -245
  43. package/setup/.claude/skills/brainstorming/scripts/stop-server.py +178 -178
  44. package/setup/.claude/skills/brainstorming/visual-companion.md +298 -298
  45. package/setup/.claude/skills/chrome-integration/SKILL.md +66 -66
  46. package/setup/.claude/skills/code-review/SKILL.md +264 -264
  47. package/setup/.claude/skills/executing-plans/SKILL.md +1 -1
  48. package/setup/.claude/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
  49. package/setup/.claude/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
  50. package/setup/.claude/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
  51. package/setup/.claude/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
  52. package/setup/.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
  53. package/setup/.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
  54. package/setup/.claude/skills/methodology/SKILL.md +124 -0
  55. package/setup/.claude/skills/phase/SKILL.md +62 -62
  56. package/setup/.claude/skills/playwright/SKILL.md +85 -85
  57. package/setup/.claude/skills/review/SKILL.md +97 -97
  58. package/setup/.claude/skills/task/SKILL.md +26 -26
  59. package/setup/.claude/skills/test-driven-development/SKILL.md +1 -1
  60. package/setup/.claude/skills/ui-ux-pro-max/SKILL.md +1 -1
  61. package/setup/.claude/skills/verification-before-completion/SKILL.md +1 -1
  62. package/setup/.claude/skills/writing-plans/SKILL.md +1 -1
  63. package/setup/.codex/.agents/skills/archive/SKILL.md +195 -195
  64. package/setup/.codex/.agents/skills/brainstorming/SKILL.md +5 -5
  65. package/setup/.codex/.agents/skills/brainstorming/scripts/server.cjs +723 -723
  66. package/setup/.codex/.agents/skills/brainstorming/scripts/start-server.py +245 -245
  67. package/setup/.codex/.agents/skills/brainstorming/scripts/stop-server.py +178 -178
  68. package/setup/.codex/.agents/skills/brainstorming/visual-companion.md +298 -298
  69. package/setup/.codex/.agents/skills/chrome-integration/SKILL.md +66 -66
  70. package/setup/.codex/.agents/skills/code-review/SKILL.md +264 -264
  71. package/setup/.codex/.agents/skills/executing-plans/SKILL.md +1 -1
  72. package/setup/.codex/.agents/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
  73. package/setup/.codex/.agents/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
  74. package/setup/.codex/.agents/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
  75. package/setup/.codex/.agents/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
  76. package/setup/.codex/.agents/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
  77. package/setup/.codex/.agents/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
  78. package/setup/.codex/.agents/skills/methodology/SKILL.md +124 -0
  79. package/setup/.codex/.agents/skills/phase/SKILL.md +62 -62
  80. package/setup/.codex/.agents/skills/playwright/SKILL.md +85 -85
  81. package/setup/.codex/.agents/skills/review/SKILL.md +97 -97
  82. package/setup/.codex/.agents/skills/task/SKILL.md +27 -27
  83. package/setup/.codex/.agents/skills/test-driven-development/SKILL.md +1 -1
  84. package/setup/.codex/.agents/skills/ui-ux-pro-max/SKILL.md +1 -1
  85. package/setup/.codex/.agents/skills/verification-before-completion/SKILL.md +1 -1
  86. package/setup/.codex/.agents/skills/writing-plans/SKILL.md +1 -1
  87. package/setup/.codex/hooks/review-runner.py +851 -851
  88. package/setup/.codex/hooks/setup-keys.py +287 -287
  89. package/setup/AGENTS.md +11 -1
  90. package/setup/CLAUDE.md +11 -1
  91. package/setup/install.sh +24 -24
  92. package/setup/tests/test_decision_timeout.py +241 -241
  93. package/setup/tests/test_hook_guards.py +357 -357
  94. package/setup/tests/test_sdlc_bootstrap.py +167 -167
  95. package/setup/tests/test_sessionlog_switch.py +199 -0
  96. package/setup/tests/test_task_manager.py +148 -148
@@ -1,178 +1,178 @@
1
- #!/usr/bin/env python3
2
- """Stop the brainstorm server and clean up.
3
-
4
- Usage: stop-server.py <session_dir>
5
-
6
- Kills the server process. Only deletes the session directory if it is
7
- ephemeral (under the temp dir). Persistent directories (.superpowers/) are
8
- kept so mockups can be reviewed later.
9
- """
10
- import json
11
- import os
12
- import re
13
- import signal
14
- import subprocess
15
- import sys
16
- import tempfile
17
- import time
18
- from pathlib import Path
19
-
20
-
21
- def mark_stopped(state_dir: Path, reason: str) -> None:
22
- info = state_dir / "server-info"
23
- try:
24
- info.unlink()
25
- except OSError:
26
- pass
27
- stopped = state_dir / "server-stopped"
28
- stopped.write_text(json.dumps({"reason": reason, "timestamp": int(time.time())}) + "\n", encoding="utf-8")
29
-
30
-
31
- def read_expected_server_id(server_id_file: Path) -> str:
32
- if not server_id_file.is_file():
33
- return ""
34
- try:
35
- sid = server_id_file.read_text(encoding="utf-8").strip("\r\n")
36
- except Exception:
37
- return ""
38
- if re.fullmatch(r"[A-Za-z0-9_-]{32,64}", sid):
39
- return sid
40
- return ""
41
-
42
-
43
- def command_has_server_id(pid: int, expected: str) -> bool:
44
- expected_arg = f"--brainstorm-server-id={expected}"
45
- if os.name != "nt":
46
- try:
47
- with open(f"/proc/{pid}/cmdline", "rb") as f:
48
- args = f.read().split(b"\0")
49
- return expected_arg.encode("utf-8") in args
50
- except Exception:
51
- pass
52
- try:
53
- r = subprocess.run(
54
- ["ps", "-ww", "-p", str(pid), "-o", "command="],
55
- capture_output=True, text=True, timeout=5,
56
- )
57
- return expected_arg in r.stdout
58
- except Exception:
59
- return False
60
- # Windows: query the command line via PowerShell, fall back to wmic
61
- for cmdline in (
62
- ["powershell", "-NoProfile", "-Command",
63
- f"(Get-CimInstance Win32_Process -Filter \"ProcessId={pid}\").CommandLine"],
64
- ["wmic", "process", "where", f"processid={pid}", "get", "commandline"],
65
- ):
66
- try:
67
- r = subprocess.run(cmdline, capture_output=True, text=True, timeout=10)
68
- if expected_arg in r.stdout:
69
- return True
70
- except Exception:
71
- continue
72
- return False
73
-
74
-
75
- def is_brainstorm_server(pid: int, server_id_file: Path) -> bool:
76
- if not is_alive(pid):
77
- return False
78
- expected = read_expected_server_id(server_id_file)
79
- if not expected:
80
- return False
81
- return command_has_server_id(pid, expected)
82
-
83
-
84
- def is_alive(pid: int) -> bool:
85
- try:
86
- os.kill(pid, 0)
87
- return True
88
- except OSError:
89
- return False
90
-
91
-
92
- def main(argv=None) -> int:
93
- argv = sys.argv[1:] if argv is None else argv
94
- if not argv:
95
- print(json_dumps({"error": "Usage: stop-server.py <session_dir>"}))
96
- return 1
97
- session_dir = Path(argv[0])
98
-
99
- state_dir = session_dir / "state"
100
- pid_file = state_dir / "server.pid"
101
- server_id_file = state_dir / "server-instance-id"
102
-
103
- if not pid_file.is_file():
104
- print(json_dumps({"status": "not_running"}))
105
- return 0
106
-
107
- try:
108
- pid = int(pid_file.read_text(encoding="utf-8").strip() or "0")
109
- except Exception:
110
- pid = 0
111
-
112
- # Refuse to signal a PID we cannot prove is our server.
113
- if pid <= 0 or not is_brainstorm_server(pid, server_id_file):
114
- for f in (pid_file, server_id_file):
115
- try:
116
- f.unlink()
117
- except OSError:
118
- pass
119
- mark_stopped(state_dir, "stale_pid")
120
- print(json_dumps({"status": "stale_pid"}))
121
- return 0
122
-
123
- # Try to stop gracefully, fall back to force if still alive
124
- try:
125
- os.kill(pid, signal.SIGTERM)
126
- except Exception:
127
- pass
128
-
129
- for _ in range(20):
130
- if not is_alive(pid):
131
- break
132
- time.sleep(0.1)
133
-
134
- if is_alive(pid):
135
- try:
136
- os.kill(pid, getattr(signal, "SIGKILL", signal.SIGTERM))
137
- except Exception:
138
- pass
139
- time.sleep(0.1)
140
-
141
- if is_alive(pid):
142
- print(json_dumps({"status": "failed", "error": "process still running"}))
143
- return 1
144
-
145
- log_file = state_dir / "server.log"
146
- for f in (pid_file, server_id_file, log_file):
147
- try:
148
- f.unlink()
149
- except OSError:
150
- pass
151
- mark_stopped(state_dir, "stop-server.py")
152
-
153
- # Only delete ephemeral temp directories
154
- tmp_base = Path(tempfile.gettempdir()).resolve()
155
- try:
156
- is_ephemeral = (
157
- str(session_dir).startswith("/tmp/")
158
- or session_dir.resolve().is_relative_to(tmp_base)
159
- )
160
- except Exception:
161
- is_ephemeral = str(session_dir).startswith("/tmp/")
162
- if is_ephemeral and session_dir.exists():
163
- try:
164
- import shutil
165
- shutil.rmtree(session_dir)
166
- except Exception:
167
- pass
168
-
169
- print(json_dumps({"status": "stopped"}))
170
- return 0
171
-
172
-
173
- def json_dumps(obj) -> str:
174
- return json.dumps(obj, ensure_ascii=False)
175
-
176
-
177
- if __name__ == "__main__":
178
- sys.exit(main())
1
+ #!/usr/bin/env python3
2
+ """Stop the brainstorm server and clean up.
3
+
4
+ Usage: stop-server.py <session_dir>
5
+
6
+ Kills the server process. Only deletes the session directory if it is
7
+ ephemeral (under the temp dir). Persistent directories (.superpowers/) are
8
+ kept so mockups can be reviewed later.
9
+ """
10
+ import json
11
+ import os
12
+ import re
13
+ import signal
14
+ import subprocess
15
+ import sys
16
+ import tempfile
17
+ import time
18
+ from pathlib import Path
19
+
20
+
21
+ def mark_stopped(state_dir: Path, reason: str) -> None:
22
+ info = state_dir / "server-info"
23
+ try:
24
+ info.unlink()
25
+ except OSError:
26
+ pass
27
+ stopped = state_dir / "server-stopped"
28
+ stopped.write_text(json.dumps({"reason": reason, "timestamp": int(time.time())}) + "\n", encoding="utf-8")
29
+
30
+
31
+ def read_expected_server_id(server_id_file: Path) -> str:
32
+ if not server_id_file.is_file():
33
+ return ""
34
+ try:
35
+ sid = server_id_file.read_text(encoding="utf-8").strip("\r\n")
36
+ except Exception:
37
+ return ""
38
+ if re.fullmatch(r"[A-Za-z0-9_-]{32,64}", sid):
39
+ return sid
40
+ return ""
41
+
42
+
43
+ def command_has_server_id(pid: int, expected: str) -> bool:
44
+ expected_arg = f"--brainstorm-server-id={expected}"
45
+ if os.name != "nt":
46
+ try:
47
+ with open(f"/proc/{pid}/cmdline", "rb") as f:
48
+ args = f.read().split(b"\0")
49
+ return expected_arg.encode("utf-8") in args
50
+ except Exception:
51
+ pass
52
+ try:
53
+ r = subprocess.run(
54
+ ["ps", "-ww", "-p", str(pid), "-o", "command="],
55
+ capture_output=True, text=True, timeout=5,
56
+ )
57
+ return expected_arg in r.stdout
58
+ except Exception:
59
+ return False
60
+ # Windows: query the command line via PowerShell, fall back to wmic
61
+ for cmdline in (
62
+ ["powershell", "-NoProfile", "-Command",
63
+ f"(Get-CimInstance Win32_Process -Filter \"ProcessId={pid}\").CommandLine"],
64
+ ["wmic", "process", "where", f"processid={pid}", "get", "commandline"],
65
+ ):
66
+ try:
67
+ r = subprocess.run(cmdline, capture_output=True, text=True, timeout=10)
68
+ if expected_arg in r.stdout:
69
+ return True
70
+ except Exception:
71
+ continue
72
+ return False
73
+
74
+
75
+ def is_brainstorm_server(pid: int, server_id_file: Path) -> bool:
76
+ if not is_alive(pid):
77
+ return False
78
+ expected = read_expected_server_id(server_id_file)
79
+ if not expected:
80
+ return False
81
+ return command_has_server_id(pid, expected)
82
+
83
+
84
+ def is_alive(pid: int) -> bool:
85
+ try:
86
+ os.kill(pid, 0)
87
+ return True
88
+ except OSError:
89
+ return False
90
+
91
+
92
+ def main(argv=None) -> int:
93
+ argv = sys.argv[1:] if argv is None else argv
94
+ if not argv:
95
+ print(json_dumps({"error": "Usage: stop-server.py <session_dir>"}))
96
+ return 1
97
+ session_dir = Path(argv[0])
98
+
99
+ state_dir = session_dir / "state"
100
+ pid_file = state_dir / "server.pid"
101
+ server_id_file = state_dir / "server-instance-id"
102
+
103
+ if not pid_file.is_file():
104
+ print(json_dumps({"status": "not_running"}))
105
+ return 0
106
+
107
+ try:
108
+ pid = int(pid_file.read_text(encoding="utf-8").strip() or "0")
109
+ except Exception:
110
+ pid = 0
111
+
112
+ # Refuse to signal a PID we cannot prove is our server.
113
+ if pid <= 0 or not is_brainstorm_server(pid, server_id_file):
114
+ for f in (pid_file, server_id_file):
115
+ try:
116
+ f.unlink()
117
+ except OSError:
118
+ pass
119
+ mark_stopped(state_dir, "stale_pid")
120
+ print(json_dumps({"status": "stale_pid"}))
121
+ return 0
122
+
123
+ # Try to stop gracefully, fall back to force if still alive
124
+ try:
125
+ os.kill(pid, signal.SIGTERM)
126
+ except Exception:
127
+ pass
128
+
129
+ for _ in range(20):
130
+ if not is_alive(pid):
131
+ break
132
+ time.sleep(0.1)
133
+
134
+ if is_alive(pid):
135
+ try:
136
+ os.kill(pid, getattr(signal, "SIGKILL", signal.SIGTERM))
137
+ except Exception:
138
+ pass
139
+ time.sleep(0.1)
140
+
141
+ if is_alive(pid):
142
+ print(json_dumps({"status": "failed", "error": "process still running"}))
143
+ return 1
144
+
145
+ log_file = state_dir / "server.log"
146
+ for f in (pid_file, server_id_file, log_file):
147
+ try:
148
+ f.unlink()
149
+ except OSError:
150
+ pass
151
+ mark_stopped(state_dir, "stop-server.py")
152
+
153
+ # Only delete ephemeral temp directories
154
+ tmp_base = Path(tempfile.gettempdir()).resolve()
155
+ try:
156
+ is_ephemeral = (
157
+ str(session_dir).startswith("/tmp/")
158
+ or session_dir.resolve().is_relative_to(tmp_base)
159
+ )
160
+ except Exception:
161
+ is_ephemeral = str(session_dir).startswith("/tmp/")
162
+ if is_ephemeral and session_dir.exists():
163
+ try:
164
+ import shutil
165
+ shutil.rmtree(session_dir)
166
+ except Exception:
167
+ pass
168
+
169
+ print(json_dumps({"status": "stopped"}))
170
+ return 0
171
+
172
+
173
+ def json_dumps(obj) -> str:
174
+ return json.dumps(obj, ensure_ascii=False)
175
+
176
+
177
+ if __name__ == "__main__":
178
+ sys.exit(main())