@leocm/flowcraft 2.2.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 +7 -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 -162
  25. package/setup/.claude/hooks/permission-request.py +132 -132
  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 -186
  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 -91
  37. package/setup/.claude/settings.json +233 -233
  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 -199
  96. package/setup/tests/test_task_manager.py +148 -148
@@ -1,287 +1,287 @@
1
- #!/usr/bin/env python3
2
- """SDLC cross-model review key setup (cross-platform).
3
-
4
- Auto-discovers providers from ~/.claude/settings.json / settings.local.json /
5
- ~/.codex/config.toml / env ANTHROPIC_*, lists model-catalog.json alternatives,
6
- lets the user complete missing info (key/base_url/model/context), then writes to
7
- BOTH ~/.claude/api-keys.json and ~/.codex/api-keys.json (per-directory, no
8
- cross-use).
9
-
10
- Usage:
11
- python .codex/hooks/setup-keys.py
12
- """
13
- import json
14
- import os
15
- import re
16
- import sys
17
- import urllib.parse
18
- from pathlib import Path
19
-
20
- # R2 UTF-8 stdio 双保险(消除 Windows GBK 乱码)
21
- for _s in (sys.stdout, sys.stderr):
22
- try:
23
- _s.reconfigure(encoding="utf-8", errors="replace")
24
- except Exception:
25
- pass
26
-
27
- SCRIPT_DIR = Path(__file__).resolve().parent
28
- if SCRIPT_DIR.name == "hooks":
29
- REPO = SCRIPT_DIR.parent.parent
30
- else:
31
- REPO = SCRIPT_DIR.parent
32
- os.environ.setdefault("SDLC_CATALOG", str(REPO / ".codex" / "model-catalog.json"))
33
-
34
- HOME = os.path.expanduser("~")
35
- CATALOG = os.environ.get("SDLC_CATALOG", "")
36
- CLAUDE_SETTINGS = os.path.join(HOME, ".claude", "settings.json")
37
- CLAUDE_SETTINGS_LOCAL = os.path.join(HOME, ".claude", "settings.local.json")
38
- CODEX_CONFIG = os.path.join(HOME, ".codex", "config.toml")
39
- KEY_CLAUDE = os.path.join(HOME, ".claude", "api-keys.json")
40
- KEY_CODEX = os.path.join(HOME, ".codex", "api-keys.json")
41
-
42
-
43
- def host_of(url):
44
- try:
45
- return urllib.parse.urlparse(url).netloc.lower()
46
- except Exception:
47
- return ""
48
-
49
-
50
- # --- 0) catalog ---
51
- cat = {}
52
- if os.path.exists(CATALOG):
53
- try:
54
- for p in json.load(open(CATALOG, encoding="utf-8")).get("providers", []):
55
- cat[p["id"]] = {
56
- "name": p.get("name", p["id"]),
57
- "base_url": p.get("base_url", ""),
58
- "key_env": p.get("key_env", p["id"].upper() + "_API_KEY"),
59
- "default_model": p.get("default_model", ""),
60
- "default_context": p.get("default_context", ""),
61
- "models": p.get("models", []),
62
- }
63
- except Exception as e:
64
- print("catalog parse failed: %s" % e, file=sys.stderr)
65
-
66
-
67
- def find_cat_id(url):
68
- h = host_of(url)
69
- if not h:
70
- return ""
71
- for k, c in cat.items():
72
- if host_of(c["base_url"]) == h:
73
- return k
74
- return h.split(".")[0]
75
-
76
-
77
- def ctx_for(model, entry):
78
- for m in entry.get("models", []):
79
- if m.get("name") == model:
80
- return str(m.get("context", ""))
81
- return str(entry.get("default_context", ""))
82
-
83
-
84
- def main() -> int:
85
- # --- 1) discovery ---
86
- discovered = [] # (id, name, base_url, model, key, source)
87
-
88
- def add_disc(pid, base, model, key, source):
89
- if not base:
90
- return
91
- name = cat.get(pid, {}).get("name", pid) if pid in cat else pid
92
- discovered.append({
93
- "id": pid, "name": name, "base_url": base,
94
- "model": model or "", "key": key or "", "source": source,
95
- })
96
-
97
- for sf in (CLAUDE_SETTINGS, CLAUDE_SETTINGS_LOCAL):
98
- if not os.path.exists(sf):
99
- continue
100
- try:
101
- j = json.load(open(sf, encoding="utf-8"))
102
- base = j.get("env", {}).get("ANTHROPIC_BASE_URL", "")
103
- if base:
104
- model = (j.get("env", {}).get("ANTHROPIC_MODEL", "") or
105
- j.get("env", {}).get("ANTHROPIC_DEFAULT_SONNET_MODEL", ""))
106
- key = (j.get("env", {}).get("ANTHROPIC_AUTH_TOKEN", "") or
107
- j.get("env", {}).get("ANTHROPIC_API_KEY", ""))
108
- add_disc(find_cat_id(base), base, model, key, sf)
109
- except Exception:
110
- pass
111
-
112
- if os.path.exists(CODEX_CONFIG):
113
- try:
114
- t = open(CODEX_CONFIG, encoding="utf-8").read()
115
- for mb in re.finditer(r"\[model_providers\.([^\]]+)\](.*?)(?=\n\[|\Z)", t, re.S):
116
- pname = mb.group(1).strip()
117
- block = mb.group(2)
118
- b = re.search(r'base_url\s*=\s*"([^"]+)"', block)
119
- if not b:
120
- continue
121
- b = b.group(1)
122
- if "anthropic" not in b:
123
- b = b.rstrip("/") + "/anthropic"
124
- m = re.search(r'^\s*model\s*=\s*"([^"]+)"', t, re.M)
125
- add_disc(find_cat_id(b), b, m.group(1) if m else "", "", CODEX_CONFIG)
126
- except Exception:
127
- pass
128
-
129
- env_base = os.environ.get("ANTHROPIC_BASE_URL", "")
130
- if env_base:
131
- env_model = (os.environ.get("ANTHROPIC_MODEL", "") or
132
- os.environ.get("ANTHROPIC_DEFAULT_SONNET_MODEL", ""))
133
- env_key = (os.environ.get("ANTHROPIC_AUTH_TOKEN", "") or
134
- os.environ.get("ANTHROPIC_API_KEY", ""))
135
- add_disc(find_cat_id(env_base), env_base, env_model, env_key, "env ANTHROPIC_*")
136
-
137
- # dedup by id (first wins: claude settings > codex config > env)
138
- seen = set()
139
- deduped = []
140
- for d in discovered:
141
- if d["id"] and d["id"] not in seen:
142
- seen.add(d["id"])
143
- deduped.append(d)
144
- discovered = deduped
145
-
146
- # --- 2) existing data ---
147
- data = {}
148
- if os.path.exists(KEY_CODEX):
149
- try:
150
- data = json.load(open(KEY_CODEX, encoding="utf-8"))
151
- except Exception:
152
- pass
153
-
154
- # merge discovered into data (fill missing)
155
- for d in discovered:
156
- pid = d["id"]
157
- if not pid:
158
- continue
159
- e = data.setdefault(pid, {})
160
- e.setdefault("name", d["name"])
161
- e.setdefault("base_url", d["base_url"])
162
- e.setdefault("model", d["model"])
163
- e.setdefault("key", d["key"])
164
- if d["model"] and pid in cat:
165
- ctx = ctx_for(d["model"], cat[pid])
166
- if ctx:
167
- e.setdefault("context", ctx)
168
-
169
- print("== 自动发现 ==")
170
- if discovered:
171
- for d in discovered:
172
- print(" [%s] %s base=%s model=%s key=%s source=%s" % (
173
- d["id"], d["name"], d["base_url"], d["model"] or "-",
174
- "已填" if d["key"] else "缺失", d["source"]))
175
- else:
176
- print(" (未发现已配置 provider)")
177
-
178
- # --- 3) catalog options not complete ---
179
- options = []
180
- for k, c in sorted(cat.items()):
181
- if any(d["id"] == k for d in discovered):
182
- continue
183
- e = data.get(k, {})
184
- complete = bool(e.get("key")) and bool(e.get("base_url")) and bool(e.get("model"))
185
- if complete:
186
- continue
187
- options.append((k, c, bool(e)))
188
- if options:
189
- print("== 清单可选项(未发现或信息不全,选中后补缺失项)==")
190
- for i, (k, c, has) in enumerate(options, 1):
191
- st = "已存在(待补)" if has else "未配置"
192
- models = ", ".join(m["name"] + "(" + str(m.get("context", "")) + ")" for m in c.get("models", []))
193
- print(" [%d] %s (%s) %s 默认=%s(%s) key_env=%s [%s]" % (
194
- i, c["name"], k, c["base_url"], c["default_model"],
195
- c["default_context"], c["key_env"], st))
196
- if models:
197
- print(" 可选: %s" % models)
198
- sel = input(" 选择要添加/补全的编号(逗号分隔,回车跳过): ").strip()
199
- for part in sel.split(","):
200
- part = part.strip()
201
- if not part.isdigit():
202
- continue
203
- n = int(part)
204
- if n < 1 or n > len(options):
205
- continue
206
- k, c, _ = options[n - 1]
207
- e = data.setdefault(k, {})
208
- e.setdefault("name", c["name"])
209
- e.setdefault("base_url", c["base_url"])
210
- e.setdefault("model", c["default_model"])
211
- e.setdefault("context", c["default_context"])
212
- if not e.get("key"):
213
- inp = input(" API key(%s,必填): " % c["key_env"]).strip()
214
- if inp:
215
- e["key"] = inp
216
- if not e.get("base_url"):
217
- inp = input(" base_url(Anthropic 兼容,必填): ").strip()
218
- if inp:
219
- e["base_url"] = inp
220
- models = [m["name"] for m in c.get("models", [])]
221
- inp = input(" 模型 [默认 %s;可选: %s;留空用默认]: " % (e.get("model"), ", ".join(models))).strip()
222
- if inp:
223
- e["model"] = inp
224
- ctx = ctx_for(inp, c)
225
- if ctx:
226
- e["context"] = ctx
227
- inp = input(" 上下文大小 [当前 %s,留空保留]: " % e.get("context", "")).strip()
228
- if inp:
229
- e["context"] = inp
230
- else:
231
- print("== 清单中无待配置项 ==")
232
-
233
- # --- 4) custom provider ---
234
- inp = input("添加/更新自定义 provider?(y/n,默认 n): ").strip().lower()
235
- if inp in ("y", "yes"):
236
- pid = input(" provider id(如 mygw): ").strip()
237
- if pid:
238
- e = data.setdefault(pid, {})
239
- e.setdefault("name", input(" 名称: ").strip() or pid)
240
- inp = input(" base_url(Anthropic 兼容)[现有 %s,留空保留]: " % e.get("base_url", "")).strip()
241
- if inp:
242
- e["base_url"] = inp
243
- inp = input(" model [现有 %s,留空保留]: " % e.get("model", "")).strip()
244
- if inp:
245
- e["model"] = inp
246
- inp = input(" 上下文大小 [现有 %s,留空保留]: " % e.get("context", "")).strip()
247
- if inp:
248
- e["context"] = inp
249
- if not e.get("key"):
250
- inp = input(" API key: ").strip()
251
- if inp:
252
- e["key"] = inp
253
-
254
- # --- 5) fill defaults from catalog ---
255
- for k, c in cat.items():
256
- e = data.get(k)
257
- if not e:
258
- continue
259
- e.setdefault("name", c["name"])
260
- e.setdefault("base_url", c["base_url"])
261
- e.setdefault("model", c["default_model"])
262
- e.setdefault("context", c["default_context"])
263
-
264
- # --- 6) write both files ---
265
- os.makedirs(os.path.dirname(KEY_CLAUDE), exist_ok=True)
266
- os.makedirs(os.path.dirname(KEY_CODEX), exist_ok=True)
267
- s = json.dumps(data, ensure_ascii=False, indent=4)
268
- for kf in (KEY_CLAUDE, KEY_CODEX):
269
- with open(kf, "w", encoding="utf-8") as fh:
270
- fh.write(s)
271
- if os.name != "nt":
272
- try:
273
- os.chmod(kf, 0o600)
274
- except Exception:
275
- pass
276
- print("已保存: %s" % KEY_CLAUDE)
277
- print("已保存: %s" % KEY_CODEX)
278
- print("配置摘要:")
279
- for pid, c in sorted(data.items()):
280
- print(" [%s] %s base=%s model=%s context=%s key=%s" % (
281
- pid, c.get("name", ""), c.get("base_url", ""), c.get("model", ""),
282
- c.get("context", ""), "已填" if c.get("key") else "缺失"))
283
- return 0
284
-
285
-
286
- if __name__ == "__main__":
287
- sys.exit(main())
1
+ #!/usr/bin/env python3
2
+ """SDLC cross-model review key setup (cross-platform).
3
+
4
+ Auto-discovers providers from ~/.claude/settings.json / settings.local.json /
5
+ ~/.codex/config.toml / env ANTHROPIC_*, lists model-catalog.json alternatives,
6
+ lets the user complete missing info (key/base_url/model/context), then writes to
7
+ BOTH ~/.claude/api-keys.json and ~/.codex/api-keys.json (per-directory, no
8
+ cross-use).
9
+
10
+ Usage:
11
+ python .codex/hooks/setup-keys.py
12
+ """
13
+ import json
14
+ import os
15
+ import re
16
+ import sys
17
+ import urllib.parse
18
+ from pathlib import Path
19
+
20
+ # R2 UTF-8 stdio 双保险(消除 Windows GBK 乱码)
21
+ for _s in (sys.stdout, sys.stderr):
22
+ try:
23
+ _s.reconfigure(encoding="utf-8", errors="replace")
24
+ except Exception:
25
+ pass
26
+
27
+ SCRIPT_DIR = Path(__file__).resolve().parent
28
+ if SCRIPT_DIR.name == "hooks":
29
+ REPO = SCRIPT_DIR.parent.parent
30
+ else:
31
+ REPO = SCRIPT_DIR.parent
32
+ os.environ.setdefault("SDLC_CATALOG", str(REPO / ".codex" / "model-catalog.json"))
33
+
34
+ HOME = os.path.expanduser("~")
35
+ CATALOG = os.environ.get("SDLC_CATALOG", "")
36
+ CLAUDE_SETTINGS = os.path.join(HOME, ".claude", "settings.json")
37
+ CLAUDE_SETTINGS_LOCAL = os.path.join(HOME, ".claude", "settings.local.json")
38
+ CODEX_CONFIG = os.path.join(HOME, ".codex", "config.toml")
39
+ KEY_CLAUDE = os.path.join(HOME, ".claude", "api-keys.json")
40
+ KEY_CODEX = os.path.join(HOME, ".codex", "api-keys.json")
41
+
42
+
43
+ def host_of(url):
44
+ try:
45
+ return urllib.parse.urlparse(url).netloc.lower()
46
+ except Exception:
47
+ return ""
48
+
49
+
50
+ # --- 0) catalog ---
51
+ cat = {}
52
+ if os.path.exists(CATALOG):
53
+ try:
54
+ for p in json.load(open(CATALOG, encoding="utf-8")).get("providers", []):
55
+ cat[p["id"]] = {
56
+ "name": p.get("name", p["id"]),
57
+ "base_url": p.get("base_url", ""),
58
+ "key_env": p.get("key_env", p["id"].upper() + "_API_KEY"),
59
+ "default_model": p.get("default_model", ""),
60
+ "default_context": p.get("default_context", ""),
61
+ "models": p.get("models", []),
62
+ }
63
+ except Exception as e:
64
+ print("catalog parse failed: %s" % e, file=sys.stderr)
65
+
66
+
67
+ def find_cat_id(url):
68
+ h = host_of(url)
69
+ if not h:
70
+ return ""
71
+ for k, c in cat.items():
72
+ if host_of(c["base_url"]) == h:
73
+ return k
74
+ return h.split(".")[0]
75
+
76
+
77
+ def ctx_for(model, entry):
78
+ for m in entry.get("models", []):
79
+ if m.get("name") == model:
80
+ return str(m.get("context", ""))
81
+ return str(entry.get("default_context", ""))
82
+
83
+
84
+ def main() -> int:
85
+ # --- 1) discovery ---
86
+ discovered = [] # (id, name, base_url, model, key, source)
87
+
88
+ def add_disc(pid, base, model, key, source):
89
+ if not base:
90
+ return
91
+ name = cat.get(pid, {}).get("name", pid) if pid in cat else pid
92
+ discovered.append({
93
+ "id": pid, "name": name, "base_url": base,
94
+ "model": model or "", "key": key or "", "source": source,
95
+ })
96
+
97
+ for sf in (CLAUDE_SETTINGS, CLAUDE_SETTINGS_LOCAL):
98
+ if not os.path.exists(sf):
99
+ continue
100
+ try:
101
+ j = json.load(open(sf, encoding="utf-8"))
102
+ base = j.get("env", {}).get("ANTHROPIC_BASE_URL", "")
103
+ if base:
104
+ model = (j.get("env", {}).get("ANTHROPIC_MODEL", "") or
105
+ j.get("env", {}).get("ANTHROPIC_DEFAULT_SONNET_MODEL", ""))
106
+ key = (j.get("env", {}).get("ANTHROPIC_AUTH_TOKEN", "") or
107
+ j.get("env", {}).get("ANTHROPIC_API_KEY", ""))
108
+ add_disc(find_cat_id(base), base, model, key, sf)
109
+ except Exception:
110
+ pass
111
+
112
+ if os.path.exists(CODEX_CONFIG):
113
+ try:
114
+ t = open(CODEX_CONFIG, encoding="utf-8").read()
115
+ for mb in re.finditer(r"\[model_providers\.([^\]]+)\](.*?)(?=\n\[|\Z)", t, re.S):
116
+ pname = mb.group(1).strip()
117
+ block = mb.group(2)
118
+ b = re.search(r'base_url\s*=\s*"([^"]+)"', block)
119
+ if not b:
120
+ continue
121
+ b = b.group(1)
122
+ if "anthropic" not in b:
123
+ b = b.rstrip("/") + "/anthropic"
124
+ m = re.search(r'^\s*model\s*=\s*"([^"]+)"', t, re.M)
125
+ add_disc(find_cat_id(b), b, m.group(1) if m else "", "", CODEX_CONFIG)
126
+ except Exception:
127
+ pass
128
+
129
+ env_base = os.environ.get("ANTHROPIC_BASE_URL", "")
130
+ if env_base:
131
+ env_model = (os.environ.get("ANTHROPIC_MODEL", "") or
132
+ os.environ.get("ANTHROPIC_DEFAULT_SONNET_MODEL", ""))
133
+ env_key = (os.environ.get("ANTHROPIC_AUTH_TOKEN", "") or
134
+ os.environ.get("ANTHROPIC_API_KEY", ""))
135
+ add_disc(find_cat_id(env_base), env_base, env_model, env_key, "env ANTHROPIC_*")
136
+
137
+ # dedup by id (first wins: claude settings > codex config > env)
138
+ seen = set()
139
+ deduped = []
140
+ for d in discovered:
141
+ if d["id"] and d["id"] not in seen:
142
+ seen.add(d["id"])
143
+ deduped.append(d)
144
+ discovered = deduped
145
+
146
+ # --- 2) existing data ---
147
+ data = {}
148
+ if os.path.exists(KEY_CODEX):
149
+ try:
150
+ data = json.load(open(KEY_CODEX, encoding="utf-8"))
151
+ except Exception:
152
+ pass
153
+
154
+ # merge discovered into data (fill missing)
155
+ for d in discovered:
156
+ pid = d["id"]
157
+ if not pid:
158
+ continue
159
+ e = data.setdefault(pid, {})
160
+ e.setdefault("name", d["name"])
161
+ e.setdefault("base_url", d["base_url"])
162
+ e.setdefault("model", d["model"])
163
+ e.setdefault("key", d["key"])
164
+ if d["model"] and pid in cat:
165
+ ctx = ctx_for(d["model"], cat[pid])
166
+ if ctx:
167
+ e.setdefault("context", ctx)
168
+
169
+ print("== 自动发现 ==")
170
+ if discovered:
171
+ for d in discovered:
172
+ print(" [%s] %s base=%s model=%s key=%s source=%s" % (
173
+ d["id"], d["name"], d["base_url"], d["model"] or "-",
174
+ "已填" if d["key"] else "缺失", d["source"]))
175
+ else:
176
+ print(" (未发现已配置 provider)")
177
+
178
+ # --- 3) catalog options not complete ---
179
+ options = []
180
+ for k, c in sorted(cat.items()):
181
+ if any(d["id"] == k for d in discovered):
182
+ continue
183
+ e = data.get(k, {})
184
+ complete = bool(e.get("key")) and bool(e.get("base_url")) and bool(e.get("model"))
185
+ if complete:
186
+ continue
187
+ options.append((k, c, bool(e)))
188
+ if options:
189
+ print("== 清单可选项(未发现或信息不全,选中后补缺失项)==")
190
+ for i, (k, c, has) in enumerate(options, 1):
191
+ st = "已存在(待补)" if has else "未配置"
192
+ models = ", ".join(m["name"] + "(" + str(m.get("context", "")) + ")" for m in c.get("models", []))
193
+ print(" [%d] %s (%s) %s 默认=%s(%s) key_env=%s [%s]" % (
194
+ i, c["name"], k, c["base_url"], c["default_model"],
195
+ c["default_context"], c["key_env"], st))
196
+ if models:
197
+ print(" 可选: %s" % models)
198
+ sel = input(" 选择要添加/补全的编号(逗号分隔,回车跳过): ").strip()
199
+ for part in sel.split(","):
200
+ part = part.strip()
201
+ if not part.isdigit():
202
+ continue
203
+ n = int(part)
204
+ if n < 1 or n > len(options):
205
+ continue
206
+ k, c, _ = options[n - 1]
207
+ e = data.setdefault(k, {})
208
+ e.setdefault("name", c["name"])
209
+ e.setdefault("base_url", c["base_url"])
210
+ e.setdefault("model", c["default_model"])
211
+ e.setdefault("context", c["default_context"])
212
+ if not e.get("key"):
213
+ inp = input(" API key(%s,必填): " % c["key_env"]).strip()
214
+ if inp:
215
+ e["key"] = inp
216
+ if not e.get("base_url"):
217
+ inp = input(" base_url(Anthropic 兼容,必填): ").strip()
218
+ if inp:
219
+ e["base_url"] = inp
220
+ models = [m["name"] for m in c.get("models", [])]
221
+ inp = input(" 模型 [默认 %s;可选: %s;留空用默认]: " % (e.get("model"), ", ".join(models))).strip()
222
+ if inp:
223
+ e["model"] = inp
224
+ ctx = ctx_for(inp, c)
225
+ if ctx:
226
+ e["context"] = ctx
227
+ inp = input(" 上下文大小 [当前 %s,留空保留]: " % e.get("context", "")).strip()
228
+ if inp:
229
+ e["context"] = inp
230
+ else:
231
+ print("== 清单中无待配置项 ==")
232
+
233
+ # --- 4) custom provider ---
234
+ inp = input("添加/更新自定义 provider?(y/n,默认 n): ").strip().lower()
235
+ if inp in ("y", "yes"):
236
+ pid = input(" provider id(如 mygw): ").strip()
237
+ if pid:
238
+ e = data.setdefault(pid, {})
239
+ e.setdefault("name", input(" 名称: ").strip() or pid)
240
+ inp = input(" base_url(Anthropic 兼容)[现有 %s,留空保留]: " % e.get("base_url", "")).strip()
241
+ if inp:
242
+ e["base_url"] = inp
243
+ inp = input(" model [现有 %s,留空保留]: " % e.get("model", "")).strip()
244
+ if inp:
245
+ e["model"] = inp
246
+ inp = input(" 上下文大小 [现有 %s,留空保留]: " % e.get("context", "")).strip()
247
+ if inp:
248
+ e["context"] = inp
249
+ if not e.get("key"):
250
+ inp = input(" API key: ").strip()
251
+ if inp:
252
+ e["key"] = inp
253
+
254
+ # --- 5) fill defaults from catalog ---
255
+ for k, c in cat.items():
256
+ e = data.get(k)
257
+ if not e:
258
+ continue
259
+ e.setdefault("name", c["name"])
260
+ e.setdefault("base_url", c["base_url"])
261
+ e.setdefault("model", c["default_model"])
262
+ e.setdefault("context", c["default_context"])
263
+
264
+ # --- 6) write both files ---
265
+ os.makedirs(os.path.dirname(KEY_CLAUDE), exist_ok=True)
266
+ os.makedirs(os.path.dirname(KEY_CODEX), exist_ok=True)
267
+ s = json.dumps(data, ensure_ascii=False, indent=4)
268
+ for kf in (KEY_CLAUDE, KEY_CODEX):
269
+ with open(kf, "w", encoding="utf-8") as fh:
270
+ fh.write(s)
271
+ if os.name != "nt":
272
+ try:
273
+ os.chmod(kf, 0o600)
274
+ except Exception:
275
+ pass
276
+ print("已保存: %s" % KEY_CLAUDE)
277
+ print("已保存: %s" % KEY_CODEX)
278
+ print("配置摘要:")
279
+ for pid, c in sorted(data.items()):
280
+ print(" [%s] %s base=%s model=%s context=%s key=%s" % (
281
+ pid, c.get("name", ""), c.get("base_url", ""), c.get("model", ""),
282
+ c.get("context", ""), "已填" if c.get("key") else "缺失"))
283
+ return 0
284
+
285
+
286
+ if __name__ == "__main__":
287
+ sys.exit(main())
package/setup/AGENTS.md CHANGED
@@ -141,6 +141,13 @@ Stage behavior is controlled by `flowcraft.yaml` in the project root:
141
141
  - **Automatic task identification**: "implement / fix / refactor / what changes / add / modify" → **modification task** → automatically enter P1. "analyze / explain / view / why / how" → **consultation task** → answer directly in P0, do not enter P1. After an old task completes, a new request → archive to `completed_tasks` + reset task fields + new P1. **`project_roadmap` / `completed_tasks` / `global_architecture` are never reset**
142
142
  - **Problem rollback**: when an issue is found in completed functionality → enter P0.5, do not modify code casually
143
143
  - **Version selection must be user-confirmed**: when adding new dependencies/components, the P1 phase must first run `/oss-version-check` to verify the real latest stable version and known vulnerabilities (Maven Central / GitHub Releases / OSV), then provide version suggestions (current stable / latest / LTS) with a version verification table, and **wait for user confirmation before use**. Choosing a version on your own is forbidden. If the network is unavailable, mark the suggestion as "unverified" and re-verify after the network recovers.
144
+ - **Criterion first (判据先行)**: before acting, define a decidable success criterion (number/state/diff). If you cannot answer "how do I know it worked", do not start.
145
+ - **Single variable (单变量)**: change one variable at a time, keep everything else unchanged, and record it.
146
+ - **Enumerate candidates (枚举候选)**: when the target is uncertain, enumerate all candidates and verify one by one; inferring a single candidate is forbidden.
147
+ - **Switch dimension after 3 failures (三次换维度)**: 3 consecutive failures in the same dimension force a dimension switch (object/channel/coordinate/timing/permission); stuck = 3 rounds with no real progress.
148
+ - **No conclusion escalation (结论不升级)**: one failure only yields "this method failed", never "impossible". Reports use four parts: conclusion / done / not done & why (facts only) / next action.
149
+
150
+ > Full methodology (applies to every requirement, not only debugging): `methodology` skill.
144
151
 
145
152
  ## Wiki Cross-Validation Rules (Mandatory)
146
153
 
@@ -224,6 +231,7 @@ Before declaring a coding task complete (and before AI code review), answer thre
224
231
  1. **Correctness (正确性)** — does the change actually solve the problem? Any typos, missing imports, wrong paths, off-by-one errors?
225
232
  2. **Side effects (副作用)** — does it break callers/tests? Have you traced every caller of every function you modified?
226
233
  3. **Closure (收尾)** — have you met every PRD acceptance criterion? What is still not done?
234
+ 4. **Criterion (判据)** — does every PRD acceptance criterion have a decidable, machine-checkable verdict? (methodology: criterion first)
227
235
  If any answer is "not sure", go back and verify — never declare completion without the self-review.
228
236
  Completion marker:
229
237
  ```
@@ -255,6 +263,7 @@ Completion marker:
255
263
  ## P0.5 Problem Rollback (on demand)
256
264
 
257
265
  Receive issue report → record symptom → root-cause analysis (requirement ambiguity / design flaw / implementation bug) → A/B/C decision → wait for user choice, then execute:
266
+ Apply the `methodology` skill before deciding: state the criterion, enumerate candidates, and switch dimension if the same fix already failed 3 times.
258
267
  - **A** Optimize on original approach → P1 (approach has direction but has flaws)
259
268
  - **B** Redo requirements → P1 (requirements themselves are problematic)
260
269
  - **C** Fix code directly (not recommended, only when error is clear and does not affect approach)
@@ -284,6 +293,7 @@ At P1 start, ask the user to choose the requirement clarification method:
284
293
 
285
294
  ### 1. brainstorming requirement clarification
286
295
  Use the brainstorming skill to systematically clarify requirements; output the requirement list and design doc.
296
+ Every requirement must carry a decidable criterion ("how will we know it works"); a requirement without one goes back for clarification (see `methodology` skill).
287
297
 
288
298
  **【Decision Point 1: requirement confirmation】**
289
299
 
@@ -319,7 +329,7 @@ Flow: ask user if needed → scan HTTP/HTTPS calls in `modified_files` → choos
319
329
  - Wiki directory does not exist: skip
320
330
 
321
331
  ### 3. Generate report
322
- Auto-run `/P5report` to generate the task summary report.
332
+ Auto-run `/P5report` to generate the task summary report. The report follows the four-part format: 结论 / 已完成 / 未完成及原因 / 下一步 (see `methodology` skill).
323
333
 
324
334
  ### 4. Delivery confirmation
325
335
  Show the user the deliverable list and report summary; confirm completion.