@cristiancorreau/forge 2.9.6 → 2.9.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 (36) hide show
  1. package/dist/commands/doctor.d.ts.map +1 -1
  2. package/dist/commands/doctor.js +2 -1
  3. package/dist/commands/doctor.js.map +1 -1
  4. package/dist/commands/init.js +1 -1
  5. package/dist/lib/paths.d.ts +1 -2
  6. package/dist/lib/paths.d.ts.map +1 -1
  7. package/dist/lib/paths.js +12 -16
  8. package/dist/lib/paths.js.map +1 -1
  9. package/dist/version.d.ts +1 -1
  10. package/dist/version.js +1 -1
  11. package/package.json +1 -1
  12. package/assets/adapters/claude-code/generate-claude-md.py +0 -304
  13. package/assets/adapters/codex/generate-codex-config.py +0 -269
  14. package/assets/adapters/kiro/generate-steering.py +0 -367
  15. package/assets/adapters/opencode/generate-agents-md.py +0 -262
  16. package/assets/core/hooks/pre-bash-check.py +0 -202
  17. package/assets/core/hooks/pre-edit-check.py +0 -317
  18. package/assets/forge.py +0 -1265
  19. package/assets/requirements.txt +0 -2
  20. package/assets/scripts/aitmpl-search.py +0 -808
  21. package/assets/scripts/forge-add-opportunities.py +0 -92
  22. package/assets/scripts/forge-audit.py +0 -1061
  23. package/assets/scripts/forge-generate-all.py +0 -283
  24. package/assets/scripts/forge-init.py +0 -900
  25. package/assets/scripts/forge-migrate-project-yaml.py +0 -397
  26. package/assets/scripts/forge-scaffold-profile.py +0 -181
  27. package/assets/scripts/forge-teardown.py +0 -193
  28. package/assets/scripts/forge-validate-project-yaml.py +0 -457
  29. package/assets/scripts/forge-wizard.py +0 -1003
  30. package/assets/scripts/setup-codex.sh +0 -229
  31. package/assets/scripts/team-install.sh +0 -147
  32. package/assets/scripts/token-stats.py +0 -201
  33. package/dist/lib/python.d.ts +0 -4
  34. package/dist/lib/python.d.ts.map +0 -1
  35. package/dist/lib/python.js +0 -46
  36. package/dist/lib/python.js.map +0 -1
@@ -1,317 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Forge v2 — PreToolUse hook: pre-edit-check.py
4
- Enforces branch guard, debug detection, and secret detection before file edits.
5
- """
6
-
7
- import json
8
- import os
9
- import re
10
- import subprocess
11
- import sys
12
-
13
-
14
- DEBUG = os.environ.get("DEBUG", "") not in ("", "0", "false", "False")
15
-
16
-
17
- def dbg(msg):
18
- if DEBUG:
19
- print(f"[forge-hook-debug] {msg}", flush=True)
20
-
21
-
22
- def load_project_yaml():
23
- """Walk up from cwd to find project.yaml. Returns dict or {}."""
24
- try:
25
- import yaml
26
- path = os.getcwd()
27
- for _ in range(6):
28
- candidate = os.path.join(path, "project.yaml")
29
- if os.path.isfile(candidate):
30
- with open(candidate) as f:
31
- data = yaml.safe_load(f)
32
- return data if isinstance(data, dict) else {}
33
- parent = os.path.dirname(path)
34
- if parent == path:
35
- break
36
- path = parent
37
- except Exception as e:
38
- dbg(f"project.yaml load error: {e}")
39
- return {}
40
-
41
-
42
- # ---------------------------------------------------------------------------
43
- # File classification helpers
44
- # ---------------------------------------------------------------------------
45
-
46
- CODE_EXTENSIONS = {
47
- ".py", ".ts", ".js", ".tsx", ".jsx",
48
- ".php", ".rb", ".go", ".rs", ".java",
49
- ".cs", ".cpp", ".c", ".sh",
50
- }
51
-
52
- NON_CODE_EXTENSIONS = {
53
- ".md", ".yaml", ".yml", ".json", ".toml", ".txt", ".lock",
54
- }
55
-
56
- ROOT_PROTECTED_NAMES = {"README.md", "CLAUDE.md", "CHANGELOG.md"}
57
-
58
- PROTECTED_DIRS = ("docs/", ".claude/")
59
-
60
-
61
- def is_code_file(file_path):
62
- """Return True if the file path is considered a code file."""
63
- _, ext = os.path.splitext(file_path)
64
- if ext.lower() in CODE_EXTENSIONS:
65
- return True
66
- if ext.lower() in NON_CODE_EXTENSIONS:
67
- return False
68
- # Default: treat unknown extensions as non-code (safe)
69
- return False
70
-
71
-
72
- def is_exempt_from_branch_guard(file_path):
73
- """Return True if the file should be exempt from branch-guard blocking."""
74
- norm = file_path.replace("\\", "/")
75
- # Exempt protected dirs
76
- for d in PROTECTED_DIRS:
77
- if norm.startswith(d) or f"/{d.rstrip('/')}" in norm:
78
- return True
79
- # Exempt root-level protected names
80
- basename = os.path.basename(norm)
81
- if basename in ROOT_PROTECTED_NAMES:
82
- return True
83
- # Exempt root-level *.md files
84
- if basename.endswith(".md") and "/" not in norm.lstrip("./"):
85
- return True
86
- # Exempt root-level *.yaml / *.json config files
87
- if "/" not in norm.lstrip("./"):
88
- _, ext = os.path.splitext(basename)
89
- if ext.lower() in (".yaml", ".yml", ".json"):
90
- return True
91
- return False
92
-
93
-
94
- # ---------------------------------------------------------------------------
95
- # Check 1 — Branch guard
96
- # ---------------------------------------------------------------------------
97
-
98
- PROTECTED_BRANCHES = {"main", "master", "develop"}
99
-
100
-
101
- def check_branch_guard(file_path):
102
- """Block code edits on protected branches."""
103
- try:
104
- result = subprocess.run(
105
- ["git", "branch", "--show-current"],
106
- capture_output=True,
107
- text=True,
108
- timeout=5,
109
- )
110
- branch = result.stdout.strip()
111
- dbg(f"current branch: {branch!r}")
112
- except Exception as e:
113
- dbg(f"git branch error: {e}")
114
- return None
115
-
116
- if branch not in PROTECTED_BRANCHES:
117
- return None
118
-
119
- if not is_code_file(file_path):
120
- return None
121
-
122
- if is_exempt_from_branch_guard(file_path):
123
- return None
124
-
125
- return (
126
- f"forge: edición bloqueada en {branch}. Crea una feature branch:\n"
127
- f" git checkout -b feature/<tema>-$(date +%Y-%m-%d)"
128
- )
129
-
130
-
131
- # ---------------------------------------------------------------------------
132
- # Check 2 — Debug statements
133
- # ---------------------------------------------------------------------------
134
-
135
- def check_debug_statements(file_path, content):
136
- """Warn (not block) if debug statements are found in new content."""
137
- _, ext = os.path.splitext(file_path)
138
- ext = ext.lower()
139
-
140
- if ext not in CODE_EXTENSIONS:
141
- return None
142
-
143
- found = False
144
- basename = os.path.basename(file_path)
145
- norm = file_path.replace("\\", "/")
146
-
147
- if ext in (".ts", ".js", ".tsx", ".jsx"):
148
- if "console.log(" in content or "debugger;" in content:
149
- found = True
150
-
151
- elif ext == ".php":
152
- if "var_dump(" in content or "dd(" in content or "print_r(" in content:
153
- found = True
154
-
155
- elif ext == ".py":
156
- # Skip forge scripts and .agentic/ files
157
- is_forge_script = basename.startswith("forge") and basename.endswith(".py")
158
- in_agentic = ".agentic/" in norm
159
- if not is_forge_script and not in_agentic:
160
- if "print(" in content:
161
- found = True
162
-
163
- elif ext == ".rb":
164
- if re.search(r"^\s*(puts |pp |p )", content, re.MULTILINE):
165
- found = True
166
-
167
- if found:
168
- return (
169
- f"forge: debug statement detectado en {file_path}"
170
- " — recuerda quitarlo antes del commit"
171
- )
172
- return None
173
-
174
-
175
- # ---------------------------------------------------------------------------
176
- # Check 3 — Secret detection
177
- # ---------------------------------------------------------------------------
178
-
179
- SECRET_PATTERN = re.compile(
180
- r'(password|passwd|secret|api_key|apikey|token|private_key)\s*[=:]\s*["\'][^"\']{8,}["\']',
181
- re.IGNORECASE,
182
- )
183
-
184
- LONG_SECRET_PATTERN = re.compile(
185
- r'\b(key|secret|token|password|auth|api_key|apikey)\b\s*[=:]\s*["\'][A-Za-z0-9+/=_\-]{20,}["\']',
186
- re.IGNORECASE,
187
- )
188
-
189
- EXEMPT_EXTENSIONS = {".md"}
190
- EXEMPT_SUFFIXES = (".env.example", ".env.sample")
191
- TEST_PATTERNS = re.compile(r'\.(test|spec)\.')
192
-
193
-
194
- def is_exempt_from_secret_check(file_path):
195
- norm = file_path.replace("\\", "/")
196
- basename = os.path.basename(norm)
197
- _, ext = os.path.splitext(basename)
198
-
199
- if ext.lower() in EXEMPT_EXTENSIONS:
200
- return True
201
- for suffix in EXEMPT_SUFFIXES:
202
- if norm.endswith(suffix):
203
- return True
204
- if TEST_PATTERNS.search(basename):
205
- return True
206
- return False
207
-
208
-
209
- def check_secret_detection(file_path, content):
210
- """Block if hardcoded credentials are detected."""
211
- if is_exempt_from_secret_check(file_path):
212
- return None
213
-
214
- if SECRET_PATTERN.search(content) or LONG_SECRET_PATTERN.search(content):
215
- return (
216
- f"forge: posible credencial hardcodeada detectada en {file_path}."
217
- " Usa variables de entorno."
218
- )
219
- return None
220
-
221
-
222
- # ---------------------------------------------------------------------------
223
- # project.yaml — custom forbidden patterns + enterprise mode
224
- # ---------------------------------------------------------------------------
225
-
226
- def check_project_yaml_patterns(file_path, content, project):
227
- """Check project.yaml forbidden_patterns if present."""
228
- try:
229
- rules = project.get("rules", {})
230
- forbidden = rules.get("forbidden_patterns", [])
231
- if not isinstance(forbidden, list):
232
- return None
233
- for pattern in forbidden:
234
- if re.search(pattern, content):
235
- return (
236
- f"forge: patrón prohibido detectado en {file_path} "
237
- f"(regla: {pattern!r})"
238
- )
239
- except Exception as e:
240
- dbg(f"project.yaml patterns error: {e}")
241
- return None
242
-
243
-
244
- # ---------------------------------------------------------------------------
245
- # Main
246
- # ---------------------------------------------------------------------------
247
-
248
- def main():
249
- try:
250
- raw = sys.stdin.read()
251
- if not raw.strip():
252
- dbg("empty stdin, allowing")
253
- sys.exit(0)
254
-
255
- data = json.loads(raw)
256
- except Exception as e:
257
- dbg(f"stdin parse error: {e}")
258
- sys.exit(0)
259
-
260
- try:
261
- tool_name = data.get("tool_name", "")
262
- tool_input = data.get("tool_input", {})
263
-
264
- file_path = tool_input.get("file_path", "")
265
- if not file_path:
266
- sys.exit(0)
267
-
268
- # Determine new content being written
269
- if tool_name == "Write":
270
- new_content = tool_input.get("content", "")
271
- elif tool_name == "Edit":
272
- new_content = tool_input.get("new_string", "")
273
- else:
274
- sys.exit(0)
275
-
276
- dbg(f"tool={tool_name} file={file_path} content_len={len(new_content)}")
277
-
278
- project = load_project_yaml()
279
- enterprise_mode = project.get("mode", "") == "enterprise"
280
-
281
- # Check 1 — Branch guard
282
- block_msg = check_branch_guard(file_path)
283
- if block_msg:
284
- print(block_msg, flush=True)
285
- sys.exit(2)
286
-
287
- # Check 2 — Debug statements
288
- warn_msg = check_debug_statements(file_path, new_content)
289
- if warn_msg:
290
- if enterprise_mode:
291
- print(warn_msg, flush=True)
292
- sys.exit(2)
293
- else:
294
- print(warn_msg, flush=True)
295
- # fall through — warning only
296
-
297
- # Check 3 — Secret detection
298
- block_msg = check_secret_detection(file_path, new_content)
299
- if block_msg:
300
- print(block_msg, flush=True)
301
- sys.exit(2)
302
-
303
- # project.yaml forbidden patterns
304
- block_msg = check_project_yaml_patterns(file_path, new_content, project)
305
- if block_msg:
306
- print(block_msg, flush=True)
307
- sys.exit(2)
308
-
309
- except Exception as e:
310
- dbg(f"unexpected error: {e}")
311
- sys.exit(0)
312
-
313
- sys.exit(0)
314
-
315
-
316
- if __name__ == "__main__":
317
- main()