autoforge-ai 0.1.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 (84) hide show
  1. package/.claude/commands/check-code.md +32 -0
  2. package/.claude/commands/checkpoint.md +40 -0
  3. package/.claude/commands/create-spec.md +613 -0
  4. package/.claude/commands/expand-project.md +234 -0
  5. package/.claude/commands/gsd-to-autoforge-spec.md +10 -0
  6. package/.claude/commands/review-pr.md +75 -0
  7. package/.claude/templates/app_spec.template.txt +331 -0
  8. package/.claude/templates/coding_prompt.template.md +265 -0
  9. package/.claude/templates/initializer_prompt.template.md +354 -0
  10. package/.claude/templates/testing_prompt.template.md +146 -0
  11. package/.env.example +64 -0
  12. package/LICENSE.md +676 -0
  13. package/README.md +423 -0
  14. package/agent.py +444 -0
  15. package/api/__init__.py +10 -0
  16. package/api/database.py +536 -0
  17. package/api/dependency_resolver.py +449 -0
  18. package/api/migration.py +156 -0
  19. package/auth.py +83 -0
  20. package/autoforge_paths.py +315 -0
  21. package/autonomous_agent_demo.py +293 -0
  22. package/bin/autoforge.js +3 -0
  23. package/client.py +607 -0
  24. package/env_constants.py +27 -0
  25. package/examples/OPTIMIZE_CONFIG.md +230 -0
  26. package/examples/README.md +531 -0
  27. package/examples/org_config.yaml +172 -0
  28. package/examples/project_allowed_commands.yaml +139 -0
  29. package/lib/cli.js +791 -0
  30. package/mcp_server/__init__.py +1 -0
  31. package/mcp_server/feature_mcp.py +988 -0
  32. package/package.json +53 -0
  33. package/parallel_orchestrator.py +1800 -0
  34. package/progress.py +247 -0
  35. package/prompts.py +427 -0
  36. package/pyproject.toml +17 -0
  37. package/rate_limit_utils.py +132 -0
  38. package/registry.py +614 -0
  39. package/requirements-prod.txt +14 -0
  40. package/security.py +959 -0
  41. package/server/__init__.py +17 -0
  42. package/server/main.py +261 -0
  43. package/server/routers/__init__.py +32 -0
  44. package/server/routers/agent.py +177 -0
  45. package/server/routers/assistant_chat.py +327 -0
  46. package/server/routers/devserver.py +309 -0
  47. package/server/routers/expand_project.py +239 -0
  48. package/server/routers/features.py +746 -0
  49. package/server/routers/filesystem.py +514 -0
  50. package/server/routers/projects.py +524 -0
  51. package/server/routers/schedules.py +356 -0
  52. package/server/routers/settings.py +127 -0
  53. package/server/routers/spec_creation.py +357 -0
  54. package/server/routers/terminal.py +453 -0
  55. package/server/schemas.py +593 -0
  56. package/server/services/__init__.py +36 -0
  57. package/server/services/assistant_chat_session.py +496 -0
  58. package/server/services/assistant_database.py +304 -0
  59. package/server/services/chat_constants.py +57 -0
  60. package/server/services/dev_server_manager.py +557 -0
  61. package/server/services/expand_chat_session.py +399 -0
  62. package/server/services/process_manager.py +657 -0
  63. package/server/services/project_config.py +475 -0
  64. package/server/services/scheduler_service.py +683 -0
  65. package/server/services/spec_chat_session.py +502 -0
  66. package/server/services/terminal_manager.py +756 -0
  67. package/server/utils/__init__.py +1 -0
  68. package/server/utils/process_utils.py +134 -0
  69. package/server/utils/project_helpers.py +32 -0
  70. package/server/utils/validation.py +54 -0
  71. package/server/websocket.py +903 -0
  72. package/start.py +456 -0
  73. package/ui/dist/assets/index-8W_wmZzz.js +168 -0
  74. package/ui/dist/assets/index-B47Ubhox.css +1 -0
  75. package/ui/dist/assets/vendor-flow-CVNK-_lx.js +7 -0
  76. package/ui/dist/assets/vendor-query-BUABzP5o.js +1 -0
  77. package/ui/dist/assets/vendor-radix-DTNNCg2d.js +45 -0
  78. package/ui/dist/assets/vendor-react-qkC6yhPU.js +1 -0
  79. package/ui/dist/assets/vendor-utils-COeKbHgx.js +2 -0
  80. package/ui/dist/assets/vendor-xterm-DP_gxef0.js +16 -0
  81. package/ui/dist/index.html +23 -0
  82. package/ui/dist/ollama.png +0 -0
  83. package/ui/dist/vite.svg +6 -0
  84. package/ui/package.json +57 -0
package/start.py ADDED
@@ -0,0 +1,456 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Simple CLI launcher for the Autonomous Coding Agent.
4
+ Provides an interactive menu to create new projects or continue existing ones.
5
+
6
+ Supports two paths for new projects:
7
+ 1. Claude path: Use /create-spec to generate spec interactively
8
+ 2. Manual path: Edit template files directly, then continue
9
+ """
10
+
11
+ import os
12
+ import subprocess
13
+ import sys
14
+ from pathlib import Path
15
+
16
+ from dotenv import load_dotenv
17
+
18
+ from auth import is_auth_error, print_auth_error_help
19
+
20
+ # Load environment variables from .env file if present
21
+ load_dotenv()
22
+
23
+ from prompts import (
24
+ get_project_prompts_dir,
25
+ has_project_prompts,
26
+ scaffold_project_prompts,
27
+ )
28
+ from registry import (
29
+ get_project_path,
30
+ list_registered_projects,
31
+ register_project,
32
+ )
33
+
34
+
35
+ def check_spec_exists(project_dir: Path) -> bool:
36
+ """
37
+ Check if valid spec files exist for a project.
38
+
39
+ Checks in order:
40
+ 1. Project prompts directory: {project_dir}/prompts/app_spec.txt
41
+ 2. Project root (legacy): {project_dir}/app_spec.txt
42
+ """
43
+ # Check project prompts directory first
44
+ project_prompts = get_project_prompts_dir(project_dir)
45
+ spec_file = project_prompts / "app_spec.txt"
46
+ if spec_file.exists():
47
+ try:
48
+ content = spec_file.read_text(encoding="utf-8")
49
+ return "<project_specification>" in content
50
+ except (OSError, PermissionError):
51
+ return False
52
+
53
+ # Check legacy location in project root
54
+ legacy_spec = project_dir / "app_spec.txt"
55
+ if legacy_spec.exists():
56
+ try:
57
+ content = legacy_spec.read_text(encoding="utf-8")
58
+ return "<project_specification>" in content
59
+ except (OSError, PermissionError):
60
+ return False
61
+
62
+ return False
63
+
64
+
65
+ def get_existing_projects() -> list[tuple[str, Path]]:
66
+ """Get list of existing projects from registry.
67
+
68
+ Returns:
69
+ List of (name, path) tuples for registered projects that still exist.
70
+ """
71
+ registry = list_registered_projects()
72
+ projects = []
73
+
74
+ for name, info in registry.items():
75
+ path = Path(info["path"])
76
+ if path.exists():
77
+ projects.append((name, path))
78
+
79
+ return sorted(projects, key=lambda x: x[0])
80
+
81
+
82
+ def display_menu(projects: list[tuple[str, Path]]) -> None:
83
+ """Display the main menu."""
84
+ print("\n" + "=" * 50)
85
+ print(" AutoForge - Autonomous Coding Agent")
86
+ print("=" * 50)
87
+ print("\n[1] Create new project")
88
+
89
+ if projects:
90
+ print("[2] Continue existing project")
91
+
92
+ print("[q] Quit")
93
+ print()
94
+
95
+
96
+ def display_projects(projects: list[tuple[str, Path]]) -> None:
97
+ """Display list of existing projects."""
98
+ print("\n" + "-" * 40)
99
+ print(" Existing Projects")
100
+ print("-" * 40)
101
+
102
+ for i, (name, path) in enumerate(projects, 1):
103
+ print(f" [{i}] {name}")
104
+ print(f" {path}")
105
+
106
+ print("\n [b] Back to main menu")
107
+ print()
108
+
109
+
110
+ def get_project_choice(projects: list[tuple[str, Path]]) -> tuple[str, Path] | None:
111
+ """Get user's project selection.
112
+
113
+ Returns:
114
+ Tuple of (name, path) for the selected project, or None if cancelled.
115
+ """
116
+ while True:
117
+ choice = input("Select project number: ").strip().lower()
118
+
119
+ if choice == 'b':
120
+ return None
121
+
122
+ try:
123
+ idx = int(choice) - 1
124
+ if 0 <= idx < len(projects):
125
+ return projects[idx]
126
+ print(f"Please enter a number between 1 and {len(projects)}")
127
+ except ValueError:
128
+ print("Invalid input. Enter a number or 'b' to go back.")
129
+
130
+
131
+ def get_new_project_info() -> tuple[str, Path] | None:
132
+ """Get name and path for new project.
133
+
134
+ Returns:
135
+ Tuple of (name, path) for the new project, or None if cancelled.
136
+ """
137
+ print("\n" + "-" * 40)
138
+ print(" Create New Project")
139
+ print("-" * 40)
140
+ print("\nEnter project name (e.g., my-awesome-app)")
141
+ print("Leave empty to cancel.\n")
142
+
143
+ name = input("Project name: ").strip()
144
+
145
+ if not name:
146
+ return None
147
+
148
+ # Basic validation - OS-aware invalid characters
149
+ # Windows has more restrictions than Unix
150
+ if sys.platform == "win32":
151
+ invalid_chars = '<>:"/\\|?*'
152
+ else:
153
+ # Unix only restricts / and null
154
+ invalid_chars = '/'
155
+
156
+ for char in invalid_chars:
157
+ if char in name:
158
+ print(f"Invalid character '{char}' in project name")
159
+ return None
160
+
161
+ # Check if name already registered
162
+ existing = get_project_path(name)
163
+ if existing:
164
+ print(f"Project '{name}' already exists at {existing}")
165
+ return None
166
+
167
+ # Get project path
168
+ print("\nEnter the full path for the project directory")
169
+ print("(e.g., C:/Projects/my-app or /home/user/projects/my-app)")
170
+ print("Leave empty to cancel.\n")
171
+
172
+ path_str = input("Project path: ").strip()
173
+ if not path_str:
174
+ return None
175
+
176
+ project_path = Path(path_str).resolve()
177
+
178
+ return name, project_path
179
+
180
+
181
+ def ensure_project_scaffolded(project_name: str, project_dir: Path) -> Path:
182
+ """
183
+ Ensure project directory exists with prompt templates and is registered.
184
+
185
+ Creates the project directory, copies template files, and registers in registry.
186
+
187
+ Args:
188
+ project_name: Name of the project
189
+ project_dir: Absolute path to the project directory
190
+
191
+ Returns:
192
+ The project directory path
193
+ """
194
+ # Create project directory if it doesn't exist
195
+ project_dir.mkdir(parents=True, exist_ok=True)
196
+
197
+ # Scaffold prompts (copies templates if they don't exist)
198
+ print(f"\nSetting up project: {project_name}")
199
+ print(f"Location: {project_dir}")
200
+ scaffold_project_prompts(project_dir)
201
+
202
+ # Register in registry
203
+ register_project(project_name, project_dir)
204
+
205
+ return project_dir
206
+
207
+
208
+ def run_spec_creation(project_dir: Path) -> bool:
209
+ """
210
+ Run Claude Code with /create-spec command to create project specification.
211
+
212
+ The project path is passed as an argument so create-spec knows where to write files.
213
+ Captures stderr to detect authentication errors and provide helpful guidance.
214
+ """
215
+ print("\n" + "=" * 50)
216
+ print(" Project Specification Setup")
217
+ print("=" * 50)
218
+ print(f"\nProject directory: {project_dir}")
219
+ print(f"Prompts will be saved to: {get_project_prompts_dir(project_dir)}")
220
+ print("\nLaunching Claude Code for interactive spec creation...")
221
+ print("Answer the questions to define your project.")
222
+ print("When done, Claude will generate the spec files.")
223
+ print("Exit Claude Code (Ctrl+C or /exit) when finished.\n")
224
+
225
+ try:
226
+ # Launch CLI with /create-spec command
227
+ # Project path included in command string so it populates $ARGUMENTS
228
+ # Capture stderr to detect auth errors while letting stdout flow to terminal
229
+ result = subprocess.run(
230
+ ["claude", f"/create-spec {project_dir}"],
231
+ check=False, # Don't raise on non-zero exit
232
+ cwd=str(Path(__file__).parent), # Run from project root
233
+ stderr=subprocess.PIPE,
234
+ text=True
235
+ )
236
+
237
+ # Check for authentication errors in stderr
238
+ stderr_output = result.stderr or ""
239
+ if result.returncode != 0 and is_auth_error(stderr_output):
240
+ print_auth_error_help()
241
+ return False
242
+
243
+ # If there was stderr output but not an auth error, show it
244
+ if stderr_output.strip() and result.returncode != 0:
245
+ print(f"\nClaude CLI error: {stderr_output.strip()}")
246
+
247
+ # Check if spec was created in project prompts directory
248
+ if check_spec_exists(project_dir):
249
+ print("\n" + "-" * 50)
250
+ print("Spec files created successfully!")
251
+ return True
252
+ else:
253
+ print("\n" + "-" * 50)
254
+ print("Spec creation incomplete.")
255
+ print(f"Please ensure app_spec.txt exists in: {get_project_prompts_dir(project_dir)}")
256
+ # If failed with non-zero exit and no spec, might be auth issue
257
+ if result.returncode != 0:
258
+ print("\nIf you're having authentication issues, try running: claude login")
259
+ return False
260
+
261
+ except FileNotFoundError:
262
+ print("\nError: 'claude' command not found.")
263
+ print("Make sure Claude Code CLI is installed:")
264
+ print(" npm install -g @anthropic-ai/claude-code")
265
+ return False
266
+ except KeyboardInterrupt:
267
+ print("\n\nSpec creation cancelled.")
268
+ return False
269
+
270
+
271
+ def run_manual_spec_flow(project_dir: Path) -> bool:
272
+ """
273
+ Guide user through manual spec editing flow.
274
+
275
+ Shows the paths to edit and waits for user to press Enter when ready.
276
+ """
277
+ prompts_dir = get_project_prompts_dir(project_dir)
278
+
279
+ print("\n" + "-" * 50)
280
+ print(" Manual Specification Setup")
281
+ print("-" * 50)
282
+ print("\nTemplate files have been created. Edit these files in your editor:")
283
+ print("\n Required:")
284
+ print(f" {prompts_dir / 'app_spec.txt'}")
285
+ print("\n Optional (customize agent behavior):")
286
+ print(f" {prompts_dir / 'initializer_prompt.md'}")
287
+ print(f" {prompts_dir / 'coding_prompt.md'}")
288
+ print("\n" + "-" * 50)
289
+ print("\nThe app_spec.txt file contains a template with placeholders.")
290
+ print("Replace the placeholders with your actual project specification.")
291
+ print("\nWhen you're done editing, press Enter to continue...")
292
+
293
+ try:
294
+ input()
295
+ except KeyboardInterrupt:
296
+ print("\n\nCancelled.")
297
+ return False
298
+
299
+ # Validate that spec was edited
300
+ if check_spec_exists(project_dir):
301
+ print("\nSpec file validated successfully!")
302
+ return True
303
+ else:
304
+ print("\nWarning: The app_spec.txt file still contains the template placeholder.")
305
+ print("The agent may not work correctly without a proper specification.")
306
+ confirm = input("Continue anyway? [y/N]: ").strip().lower()
307
+ return confirm == 'y'
308
+
309
+
310
+ def ask_spec_creation_choice() -> str | None:
311
+ """Ask user whether to create spec with Claude or manually."""
312
+ print("\n" + "-" * 40)
313
+ print(" Specification Setup")
314
+ print("-" * 40)
315
+ print("\nHow would you like to define your project?")
316
+ print("\n[1] Create spec with Claude (recommended)")
317
+ print(" Interactive conversation to define your project")
318
+ print("\n[2] Edit templates manually")
319
+ print(" Edit the template files directly in your editor")
320
+ print("\n[b] Back to main menu")
321
+ print()
322
+
323
+ while True:
324
+ choice = input("Select [1/2/b]: ").strip().lower()
325
+ if choice in ['1', '2', 'b']:
326
+ return choice
327
+ print("Invalid choice. Please enter 1, 2, or b.")
328
+
329
+
330
+ def create_new_project_flow() -> tuple[str, Path] | None:
331
+ """
332
+ Complete flow for creating a new project.
333
+
334
+ 1. Get project name and path
335
+ 2. Create project directory and scaffold prompts
336
+ 3. Ask: Claude or Manual?
337
+ 4. If Claude: Run /create-spec with project path
338
+ 5. If Manual: Show paths, wait for Enter
339
+ 6. Return (name, path) tuple if successful
340
+ """
341
+ project_info = get_new_project_info()
342
+ if not project_info:
343
+ return None
344
+
345
+ project_name, project_path = project_info
346
+
347
+ # Create project directory and scaffold prompts FIRST
348
+ project_dir = ensure_project_scaffolded(project_name, project_path)
349
+
350
+ # Ask user how they want to handle spec creation
351
+ choice = ask_spec_creation_choice()
352
+
353
+ if choice == 'b':
354
+ return None
355
+ elif choice == '1':
356
+ # Create spec with Claude
357
+ success = run_spec_creation(project_dir)
358
+ if not success:
359
+ print("\nYou can try again later or edit the templates manually.")
360
+ retry = input("Start agent anyway? [y/N]: ").strip().lower()
361
+ if retry != 'y':
362
+ return None
363
+ elif choice == '2':
364
+ # Manual mode - guide user through editing
365
+ success = run_manual_spec_flow(project_dir)
366
+ if not success:
367
+ return None
368
+
369
+ return project_name, project_dir
370
+
371
+
372
+ def run_agent(project_name: str, project_dir: Path) -> None:
373
+ """Run the autonomous agent with the given project.
374
+
375
+ Captures stderr to detect authentication errors and provide helpful guidance.
376
+
377
+ Args:
378
+ project_name: Name of the project
379
+ project_dir: Absolute path to the project directory
380
+ """
381
+ # Final validation before running
382
+ if not has_project_prompts(project_dir):
383
+ print(f"\nWarning: No valid spec found for project '{project_name}'")
384
+ print("The agent may not work correctly.")
385
+ confirm = input("Continue anyway? [y/N]: ").strip().lower()
386
+ if confirm != 'y':
387
+ return
388
+
389
+ print(f"\nStarting agent for project: {project_name}")
390
+ print(f"Location: {project_dir}")
391
+ print("-" * 50)
392
+
393
+ # Build the command - pass absolute path
394
+ cmd = [sys.executable, "autonomous_agent_demo.py", "--project-dir", str(project_dir.resolve())]
395
+
396
+ # Run the agent with stderr capture to detect auth errors
397
+ # stdout goes directly to terminal for real-time output
398
+ try:
399
+ result = subprocess.run(
400
+ cmd,
401
+ check=False,
402
+ stderr=subprocess.PIPE,
403
+ text=True
404
+ )
405
+
406
+ # Check for authentication errors
407
+ stderr_output = result.stderr or ""
408
+ if result.returncode != 0:
409
+ if is_auth_error(stderr_output):
410
+ print_auth_error_help()
411
+ elif stderr_output.strip():
412
+ # Show any other errors
413
+ print(f"\nAgent error:\n{stderr_output.strip()}")
414
+ # Still hint about auth if exit was unexpected
415
+ if "error" in stderr_output.lower() or "exception" in stderr_output.lower():
416
+ print("\nIf this is an authentication issue, try running: claude login")
417
+
418
+ except KeyboardInterrupt:
419
+ print("\n\nAgent interrupted. Run again to resume.")
420
+
421
+
422
+ def main() -> None:
423
+ """Main entry point."""
424
+ # Ensure we're in the right directory
425
+ script_dir = Path(__file__).parent.absolute()
426
+ os.chdir(script_dir)
427
+
428
+ while True:
429
+ projects = get_existing_projects()
430
+ display_menu(projects)
431
+
432
+ choice = input("Select option: ").strip().lower()
433
+
434
+ if choice == 'q':
435
+ print("\nGoodbye!")
436
+ break
437
+
438
+ elif choice == '1':
439
+ result = create_new_project_flow()
440
+ if result:
441
+ project_name, project_dir = result
442
+ run_agent(project_name, project_dir)
443
+
444
+ elif choice == '2' and projects:
445
+ display_projects(projects)
446
+ selected = get_project_choice(projects)
447
+ if selected:
448
+ project_name, project_dir = selected
449
+ run_agent(project_name, project_dir)
450
+
451
+ else:
452
+ print("Invalid option. Please try again.")
453
+
454
+
455
+ if __name__ == "__main__":
456
+ main()