alpiecode 10.7.4__tar.gz → 10.8.0__tar.gz
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.
- {alpiecode-10.7.4 → alpiecode-10.8.0}/PKG-INFO +1 -1
- {alpiecode-10.7.4 → alpiecode-10.8.0}/pyproject.toml +1 -1
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/alpiecode.egg-info/PKG-INFO +1 -1
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/alpiecode.egg-info/SOURCES.txt +12 -1
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/__init__.py +1 -1
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/agent.py +34 -61
- alpiecode-10.8.0/src/codeagent/blueprints.py +187 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/cache.py +7 -4
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/cli.py +26 -2
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/compaction.py +9 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/config.py +45 -29
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/context.py +76 -21
- alpiecode-10.8.0/src/codeagent/diff_preview.py +77 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/discovery.py +42 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/guardrails.py +118 -60
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/memory.py +166 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/orchestrator.py +168 -75
- alpiecode-10.8.0/src/codeagent/project_template.py +538 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/prompt.py +107 -42
- alpiecode-10.8.0/src/codeagent/slash.py +237 -0
- alpiecode-10.8.0/src/codeagent/subagent.py +269 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/system1.py +75 -33
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/tools.py +44 -4
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/verifier.py +44 -0
- alpiecode-10.8.0/src/codeagent/walkthrough.py +295 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/test/test_non_thinking_and_local_stream.py +3 -3
- alpiecode-10.8.0/test/test_project_templates.py +181 -0
- alpiecode-10.8.0/test/test_slash_and_diff.py +78 -0
- alpiecode-10.8.0/test/test_subagents.py +93 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/test/test_verifier.py +16 -1
- alpiecode-10.8.0/test/test_walkthrough.py +130 -0
- alpiecode-10.8.0/test/test_web_resilience_and_guardrails.py +203 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/README.md +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/setup.cfg +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/alpiecode/__init__.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/alpiecode.egg-info/dependency_links.txt +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/alpiecode.egg-info/entry_points.txt +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/alpiecode.egg-info/requires.txt +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/alpiecode.egg-info/top_level.txt +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/assessment.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/backends/__init__.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/backends/base.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/backends/local_backend.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/backends/openai_backend.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/client.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/doctor.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/dream_rsi.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/executor.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/extension/alpiecode.vsix +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/git_ops.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/github.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/guardian.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/ipython_ext.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/local_model.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/media.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/metrics.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/paths.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/progress.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/rephraser.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/server.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/session.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/updater.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/src/codeagent/vscode_installer.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/test/test_adaptive_resilience.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/test/test_cli_ui.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/test/test_context_and_trajectory.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/test/test_dream_rsi.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/test/test_local_model_download.py +0 -0
- {alpiecode-10.7.4 → alpiecode-10.8.0}/test/test_task_assessment.py +0 -0
|
@@ -10,12 +10,14 @@ src/alpiecode.egg-info/top_level.txt
|
|
|
10
10
|
src/codeagent/__init__.py
|
|
11
11
|
src/codeagent/agent.py
|
|
12
12
|
src/codeagent/assessment.py
|
|
13
|
+
src/codeagent/blueprints.py
|
|
13
14
|
src/codeagent/cache.py
|
|
14
15
|
src/codeagent/cli.py
|
|
15
16
|
src/codeagent/client.py
|
|
16
17
|
src/codeagent/compaction.py
|
|
17
18
|
src/codeagent/config.py
|
|
18
19
|
src/codeagent/context.py
|
|
20
|
+
src/codeagent/diff_preview.py
|
|
19
21
|
src/codeagent/discovery.py
|
|
20
22
|
src/codeagent/doctor.py
|
|
21
23
|
src/codeagent/dream_rsi.py
|
|
@@ -32,15 +34,19 @@ src/codeagent/metrics.py
|
|
|
32
34
|
src/codeagent/orchestrator.py
|
|
33
35
|
src/codeagent/paths.py
|
|
34
36
|
src/codeagent/progress.py
|
|
37
|
+
src/codeagent/project_template.py
|
|
35
38
|
src/codeagent/prompt.py
|
|
36
39
|
src/codeagent/rephraser.py
|
|
37
40
|
src/codeagent/server.py
|
|
38
41
|
src/codeagent/session.py
|
|
42
|
+
src/codeagent/slash.py
|
|
43
|
+
src/codeagent/subagent.py
|
|
39
44
|
src/codeagent/system1.py
|
|
40
45
|
src/codeagent/tools.py
|
|
41
46
|
src/codeagent/updater.py
|
|
42
47
|
src/codeagent/verifier.py
|
|
43
48
|
src/codeagent/vscode_installer.py
|
|
49
|
+
src/codeagent/walkthrough.py
|
|
44
50
|
src/codeagent/backends/__init__.py
|
|
45
51
|
src/codeagent/backends/base.py
|
|
46
52
|
src/codeagent/backends/local_backend.py
|
|
@@ -52,5 +58,10 @@ test/test_context_and_trajectory.py
|
|
|
52
58
|
test/test_dream_rsi.py
|
|
53
59
|
test/test_local_model_download.py
|
|
54
60
|
test/test_non_thinking_and_local_stream.py
|
|
61
|
+
test/test_project_templates.py
|
|
62
|
+
test/test_slash_and_diff.py
|
|
63
|
+
test/test_subagents.py
|
|
55
64
|
test/test_task_assessment.py
|
|
56
|
-
test/test_verifier.py
|
|
65
|
+
test/test_verifier.py
|
|
66
|
+
test/test_walkthrough.py
|
|
67
|
+
test/test_web_resilience_and_guardrails.py
|
|
@@ -17,7 +17,7 @@ Supports:
|
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
from typing import Optional, Any, Dict
|
|
19
19
|
|
|
20
|
-
__version__ = "10.
|
|
20
|
+
__version__ = "10.8.0"
|
|
21
21
|
|
|
22
22
|
def run(task: str, workdir: str = ".", reasoning_level: str = "thinking", **kwargs):
|
|
23
23
|
"""Run an autonomous coding task programmatically."""
|
|
@@ -73,28 +73,38 @@ def _print_reasoning(reasoning: str):
|
|
|
73
73
|
console.print(f"💭 {clean}")
|
|
74
74
|
|
|
75
75
|
|
|
76
|
+
def _format_bash_summary(args: dict) -> str:
|
|
77
|
+
cmd = args.get("command", "").strip()
|
|
78
|
+
return f"$ {cmd[:80]}..." if len(cmd) > 80 else f"$ {cmd}"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _format_file_summary(args: dict, name: str) -> str:
|
|
82
|
+
path = args.get("path", "")
|
|
83
|
+
extra = f" ({len(str(args['content']).splitlines())} lines)" if name == "write_file" and "content" in args else ""
|
|
84
|
+
return f"{path}{extra}"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
TOOL_SUMMARY_FORMATTERS = {
|
|
88
|
+
"bash": _format_bash_summary,
|
|
89
|
+
"write_file": lambda a: _format_file_summary(a, "write_file"),
|
|
90
|
+
"edit_file": lambda a: _format_file_summary(a, "edit_file"),
|
|
91
|
+
"read_file": lambda a: _format_file_summary(a, "read_file"),
|
|
92
|
+
"list_files": lambda a: a.get("path", "."),
|
|
93
|
+
"search": lambda a: f"'{a.get('query', '')}'",
|
|
94
|
+
"web_search": lambda a: f"'{a.get('query', '')}'",
|
|
95
|
+
"fetch_web_page": lambda a: a.get("url", ""),
|
|
96
|
+
"invoke_subagent": lambda a: f"🤖 {a.get('subagent', 'agent')}: '{a.get('prompt', '')[:50]}'",
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
76
100
|
def _format_tool_summary(name: str, args: dict) -> str:
|
|
77
101
|
if not isinstance(args, dict):
|
|
78
102
|
return ""
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
extra = ""
|
|
85
|
-
if name == "write_file" and "content" in args:
|
|
86
|
-
lines = len(str(args["content"]).splitlines())
|
|
87
|
-
extra = f" ({lines} lines)"
|
|
88
|
-
return f"{path}{extra}"
|
|
89
|
-
elif name == "list_files":
|
|
90
|
-
return args.get("path", ".")
|
|
91
|
-
elif name in ("search", "web_search"):
|
|
92
|
-
return f"'{args.get('query', '')}'"
|
|
93
|
-
elif name == "fetch_web_page":
|
|
94
|
-
return args.get("url", "")
|
|
95
|
-
else:
|
|
96
|
-
parts = [f"{k}={repr(v)[:30]}" for k, v in args.items() if k != "content"]
|
|
97
|
-
return " ".join(parts)
|
|
103
|
+
formatter = TOOL_SUMMARY_FORMATTERS.get(name)
|
|
104
|
+
if formatter:
|
|
105
|
+
return formatter(args)
|
|
106
|
+
parts = [f"{k}={repr(v)[:30]}" for k, v in args.items() if k != "content"]
|
|
107
|
+
return " ".join(parts)
|
|
98
108
|
|
|
99
109
|
|
|
100
110
|
def _print_tool_call(turn: int, name: str, args: dict):
|
|
@@ -772,50 +782,13 @@ def run_chat(workdir: Path, cfg: Config, verbose: bool = True, debug: bool = Fal
|
|
|
772
782
|
|
|
773
783
|
if not user_input:
|
|
774
784
|
continue
|
|
775
|
-
|
|
785
|
+
# In-chat slash commands (/help, /status, /diff, /undo, /doctor, /research, /review, /test, /clear, /subagents)
|
|
786
|
+
from .slash import handle_slash_command
|
|
787
|
+
slash_res = handle_slash_command(user_input, session, orchestrator, cfg, console, has_rich=HAS_RICH)
|
|
788
|
+
if slash_res is False:
|
|
776
789
|
console.print("Goodbye! 👋")
|
|
777
790
|
break
|
|
778
|
-
|
|
779
|
-
# In-chat slash commands
|
|
780
|
-
if user_input.lower() in ("/clear", "/reset"):
|
|
781
|
-
session = session_mgr.create_session(
|
|
782
|
-
workdir,
|
|
783
|
-
max_tokens=backend.context_window if hasattr(backend, 'context_window') and backend.context_window else (cfg.n_ctx if cfg.base_url == 'offline' else 262_144)
|
|
784
|
-
)
|
|
785
|
-
if HAS_RICH:
|
|
786
|
-
console.print("[bold green]✨ Conversation context reset.[/bold green]")
|
|
787
|
-
else:
|
|
788
|
-
print("✨ Conversation context reset.")
|
|
789
|
-
continue
|
|
790
|
-
|
|
791
|
-
if user_input.lower() in ("/info", "/status"):
|
|
792
|
-
mode_str = "OFFLINE (Local GGUF)" if is_offline else "ONLINE (Cloud API)"
|
|
793
|
-
ctx_tokens = backend.context_window if hasattr(backend, 'context_window') and backend.context_window else cfg.n_ctx
|
|
794
|
-
user_turns = len([m for m in session.context.messages if m.get("role") == "user"])
|
|
795
|
-
info_msg = (
|
|
796
|
-
f"[bold]AlpieCode Session Info[/bold]\n"
|
|
797
|
-
f" • Mode: {mode_str}\n"
|
|
798
|
-
f" • Working Dir: {workdir}\n"
|
|
799
|
-
f" • Context Window: {ctx_tokens} tokens\n"
|
|
800
|
-
f" • Session Turns: {user_turns}"
|
|
801
|
-
)
|
|
802
|
-
if HAS_RICH:
|
|
803
|
-
console.print(Panel(info_msg, border_style="cyan", title="ℹ️ Status"))
|
|
804
|
-
else:
|
|
805
|
-
print(info_msg)
|
|
806
|
-
continue
|
|
807
|
-
|
|
808
|
-
if user_input.lower() in ("/help", "/?"):
|
|
809
|
-
help_msg = (
|
|
810
|
-
"Available commands:\n"
|
|
811
|
-
" • /clear, /reset - Reset conversation memory\n"
|
|
812
|
-
" • /info, /status - View current model and session diagnostics\n"
|
|
813
|
-
" • exit, quit, q - Exit interactive chat"
|
|
814
|
-
)
|
|
815
|
-
if HAS_RICH:
|
|
816
|
-
console.print(Panel(help_msg, border_style="dim", title="Help"))
|
|
817
|
-
else:
|
|
818
|
-
print(help_msg)
|
|
791
|
+
elif slash_res is True:
|
|
819
792
|
continue
|
|
820
793
|
|
|
821
794
|
has_streamed_chat = False
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pre-Flight Domain Blueprint Engine for AlpieCode.
|
|
3
|
+
|
|
4
|
+
Binds concrete, unambiguous engineering blueprints to user tasks:
|
|
5
|
+
- WEB_APP : Browser-first HTML5, CSS Grid/Flexbox, Vanilla JS, python3 http.server
|
|
6
|
+
- CLI_SCRIPT : Self-contained, standard library, argparse, zero bloat
|
|
7
|
+
- REST_API : FastAPI / Flask with in-process TestClient verification
|
|
8
|
+
- NATIVE_CPP : POSIX sockets/HTTP UI, const-correct mutexes, standard algorithms
|
|
9
|
+
- GAME : Complete loop, collision, input, rendering, game over/restart
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from enum import Enum
|
|
14
|
+
from typing import Dict, List, Optional
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BlueprintType(str, Enum):
|
|
18
|
+
WEB_APP = "web_app"
|
|
19
|
+
CLI_SCRIPT = "cli_script"
|
|
20
|
+
REST_API = "rest_api"
|
|
21
|
+
NATIVE_CPP = "native_cpp"
|
|
22
|
+
GAME = "game"
|
|
23
|
+
GENERAL = "general"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class DomainBlueprint:
|
|
28
|
+
name: str
|
|
29
|
+
blueprint_type: BlueprintType
|
|
30
|
+
target_files: List[str]
|
|
31
|
+
entry_point: str
|
|
32
|
+
execution_runner: str
|
|
33
|
+
prohibitions: List[str] = field(default_factory=list)
|
|
34
|
+
architecture_rules: List[str] = field(default_factory=list)
|
|
35
|
+
|
|
36
|
+
def render_contract(self) -> str:
|
|
37
|
+
"""Render strict execution contract markdown for prompt injection."""
|
|
38
|
+
files_str = ", ".join(f"`{f}`" for f in self.target_files) if self.target_files else "Application files"
|
|
39
|
+
prohib_md = "\n".join(f"- ⛔ {p}" for p in self.prohibitions)
|
|
40
|
+
rules_md = "\n".join(f"- ✅ {r}" for r in self.architecture_rules)
|
|
41
|
+
|
|
42
|
+
return f"""## Pre-Flight Domain Blueprint: {self.name.upper()}
|
|
43
|
+
- **Primary Deliverables**: {files_str}
|
|
44
|
+
- **Entry Point**: `{self.entry_point}`
|
|
45
|
+
- **Execution / Runner**: `{self.execution_runner}`
|
|
46
|
+
|
|
47
|
+
### Architecture Rules
|
|
48
|
+
{rules_md}
|
|
49
|
+
|
|
50
|
+
### Strict Prohibitions
|
|
51
|
+
{prohib_md}
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# ── Specialized Domain Blueprint Definitions ───────────────────────────
|
|
56
|
+
|
|
57
|
+
def get_web_app_blueprint(task: str) -> DomainBlueprint:
|
|
58
|
+
return DomainBlueprint(
|
|
59
|
+
name="Browser-First Web Application",
|
|
60
|
+
blueprint_type=BlueprintType.WEB_APP,
|
|
61
|
+
target_files=["index.html", "styles.css", "app.js"],
|
|
62
|
+
entry_point="index.html",
|
|
63
|
+
execution_runner="python3 -m http.server 8000 (view at http://localhost:8000)",
|
|
64
|
+
architecture_rules=[
|
|
65
|
+
"Write `index.html` FIRST: Semantic HTML5 layout, clear container IDs, linked styles.css and app.js.",
|
|
66
|
+
"Write `styles.css` SECOND: Modern responsive styling using CSS Flexbox and Grid, clean typography.",
|
|
67
|
+
"Write `app.js` THIRD: Vanilla ES6 JavaScript for client-side state, item rendering, and interactive modals.",
|
|
68
|
+
"Write EXACTLY ONE complete file per turn in order (Turn 1: index.html, Turn 2: styles.css, Turn 3: app.js).",
|
|
69
|
+
"Verify all files exist and validate JavaScript with `node --check app.js` before completing.",
|
|
70
|
+
],
|
|
71
|
+
prohibitions=[
|
|
72
|
+
"NEVER write standalone `.jsx` files without a build tool like Vite -- Node cannot execute raw JSX.",
|
|
73
|
+
"NEVER write utility files like `utils/formatPrice.js` before `index.html` exists.",
|
|
74
|
+
"NEVER start blocking daemon servers with `&` or real `sleep` in terminal commands.",
|
|
75
|
+
],
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def get_cli_script_blueprint(task: str) -> DomainBlueprint:
|
|
80
|
+
return DomainBlueprint(
|
|
81
|
+
name="Self-Contained CLI / Utility",
|
|
82
|
+
blueprint_type=BlueprintType.CLI_SCRIPT,
|
|
83
|
+
target_files=["main.py"],
|
|
84
|
+
entry_point="main.py",
|
|
85
|
+
execution_runner="python3 main.py",
|
|
86
|
+
architecture_rules=[
|
|
87
|
+
"Implement complete, working logic in Turn 1 with zero stubs or placeholders.",
|
|
88
|
+
"Use standard library `argparse` for flexible command-line argument parsing.",
|
|
89
|
+
"Handle edge cases and invalid inputs gracefully with clear error messages.",
|
|
90
|
+
"Verify by running `python3 main.py` or writing a quick hermetic unit test.",
|
|
91
|
+
],
|
|
92
|
+
prohibitions=[
|
|
93
|
+
"NEVER split simple utility scripts across multiple unnecessary files.",
|
|
94
|
+
"NEVER leave placeholder functions (`pass` or `...`). Implement real working code.",
|
|
95
|
+
],
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def get_rest_api_blueprint(task: str) -> DomainBlueprint:
|
|
100
|
+
return DomainBlueprint(
|
|
101
|
+
name="REST API Service",
|
|
102
|
+
blueprint_type=BlueprintType.REST_API,
|
|
103
|
+
target_files=["app.py", "test_app.py"],
|
|
104
|
+
entry_point="app.py",
|
|
105
|
+
execution_runner="pytest test_app.py",
|
|
106
|
+
architecture_rules=[
|
|
107
|
+
"Define modular endpoints with input validation, proper HTTP status codes, and JSON responses.",
|
|
108
|
+
"ALWAYS test endpoints using in-process test clients (`TestClient(app)` for FastAPI or `app.test_client()` for Flask).",
|
|
109
|
+
"Verify with `pytest` in under 0.1 seconds.",
|
|
110
|
+
],
|
|
111
|
+
prohibitions=[
|
|
112
|
+
"NEVER start background servers with `uvicorn &` or `flask run &` and curl -- use TestClient.",
|
|
113
|
+
"NEVER leave unhandled exceptions in request routes.",
|
|
114
|
+
],
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def get_native_cpp_blueprint(task: str) -> DomainBlueprint:
|
|
119
|
+
return DomainBlueprint(
|
|
120
|
+
name="Native C/C++ System",
|
|
121
|
+
blueprint_type=BlueprintType.NATIVE_CPP,
|
|
122
|
+
target_files=["main.cpp"],
|
|
123
|
+
entry_point="main.cpp",
|
|
124
|
+
execution_runner="g++ -std=c++17 -O2 -o app main.cpp && ./app",
|
|
125
|
+
architecture_rules=[
|
|
126
|
+
"Always include required standard headers: `<algorithm>`, `<memory>`, `<mutex>`, `<thread>`.",
|
|
127
|
+
"Mutexes locked in `const` methods MUST be declared `mutable std::mutex mtx;`.",
|
|
128
|
+
"Never use the same identifier for member variables and accessor functions (e.g. `m_isPaused` vs `isPaused()`).",
|
|
129
|
+
"If the user asked for a website in C++, serve an HTML5/Canvas UI from a C++ HTTP server, never an ASCII terminal app.",
|
|
130
|
+
"Verify compilation with `g++ -std=c++17 -O2` with exit code 0.",
|
|
131
|
+
],
|
|
132
|
+
prohibitions=[
|
|
133
|
+
"NEVER claim completion if compilation fails with exit code != 0.",
|
|
134
|
+
"NEVER access private class members from helper functions without accessors.",
|
|
135
|
+
],
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def get_game_blueprint(task: str) -> DomainBlueprint:
|
|
140
|
+
return DomainBlueprint(
|
|
141
|
+
name="Interactive Game",
|
|
142
|
+
blueprint_type=BlueprintType.GAME,
|
|
143
|
+
target_files=["index.html", "game.js", "styles.css"],
|
|
144
|
+
entry_point="index.html",
|
|
145
|
+
execution_runner="python3 -m http.server 8000",
|
|
146
|
+
architecture_rules=[
|
|
147
|
+
"Implement complete game loop (update, render, event handling) using HTML5 Canvas or Pygame.",
|
|
148
|
+
"Include ALL game mechanics: player controls, obstacle/enemy spawning, collision physics, score tracking, win/loss states.",
|
|
149
|
+
"Add smooth keyboard/touch input listeners and an interactive restart button.",
|
|
150
|
+
"Deliver complete, runnable code with zero TODOs or missing game states.",
|
|
151
|
+
],
|
|
152
|
+
prohibitions=[
|
|
153
|
+
"NEVER deliver a game with missing collision or non-functional controls.",
|
|
154
|
+
],
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# ── Blueprint Router ───────────────────────────────────────────────────
|
|
159
|
+
|
|
160
|
+
def resolve_domain_blueprint(task: str, repo: Optional[Dict] = None, intent: str = "create") -> Optional[DomainBlueprint]:
|
|
161
|
+
"""
|
|
162
|
+
Route task intent to the optimal Domain Blueprint.
|
|
163
|
+
Runs deterministically in < 1ms.
|
|
164
|
+
"""
|
|
165
|
+
task_lower = task.lower().strip()
|
|
166
|
+
|
|
167
|
+
# 1. C / C++ Tasks
|
|
168
|
+
if any(kw in task_lower for kw in ("c++", "cpp", "g++", "gcc", "clang", "in c", "in c++")):
|
|
169
|
+
return get_native_cpp_blueprint(task)
|
|
170
|
+
|
|
171
|
+
# 2. Interactive Games
|
|
172
|
+
if any(kw in task_lower for kw in ("game", "snake", "pong", "tetris", "arcade", "flappy", "chess", "sudoku")):
|
|
173
|
+
return get_game_blueprint(task)
|
|
174
|
+
|
|
175
|
+
# 3. Web Applications / E-Commerce / Frontend
|
|
176
|
+
if any(kw in task_lower for kw in ("website", "web app", "webapp", "e-commerce", "ecommerce", "store", "dashboard", "frontend", "html", "landing page")):
|
|
177
|
+
return get_web_app_blueprint(task)
|
|
178
|
+
|
|
179
|
+
# 4. REST APIs / Microservices
|
|
180
|
+
if any(kw in task_lower for kw in ("api", "rest api", "fastapi", "flask", "endpoint", "microservice", "crud")):
|
|
181
|
+
return get_rest_api_blueprint(task)
|
|
182
|
+
|
|
183
|
+
# 5. CLI Scripts / Utilities
|
|
184
|
+
if any(kw in task_lower for kw in ("script", "cli", "command-line", "utility", "tool", "parse", "convert", "calculator")):
|
|
185
|
+
return get_cli_script_blueprint(task)
|
|
186
|
+
|
|
187
|
+
return None
|
|
@@ -289,10 +289,13 @@ class TestResultCache:
|
|
|
289
289
|
def _get_workspace_fingerprint(self, workdir: Path) -> str:
|
|
290
290
|
try:
|
|
291
291
|
mtimes = []
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
292
|
+
valid_exts = {".py", ".js", ".ts", ".json"}
|
|
293
|
+
with os.scandir(workdir) as it:
|
|
294
|
+
for entry in it:
|
|
295
|
+
if entry.is_file() and not entry.name.startswith("."):
|
|
296
|
+
dot_idx = entry.name.rfind(".")
|
|
297
|
+
if dot_idx != -1 and entry.name[dot_idx:] in valid_exts:
|
|
298
|
+
mtimes.append(f"{entry.name}:{entry.stat().st_mtime_ns}")
|
|
296
299
|
return hashlib.md5("".join(sorted(mtimes)).encode()).hexdigest()[:12]
|
|
297
300
|
except Exception:
|
|
298
301
|
return "0"
|
|
@@ -29,7 +29,7 @@ def _show_banner():
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def _normalize_args():
|
|
32
|
-
known_commands = {"init", "serve", "run", "chat", "plan", "diff", "undo", "doctor", "explain", "dream", "version", "-h", "--help", "-v", "--version"}
|
|
32
|
+
known_commands = {"init", "scaffold", "serve", "run", "chat", "plan", "diff", "undo", "doctor", "explain", "dream", "version", "-h", "--help", "-v", "--version"}
|
|
33
33
|
subcommand = None
|
|
34
34
|
|
|
35
35
|
# Normalize common flag typos / aliases before parsing
|
|
@@ -121,7 +121,13 @@ def main():
|
|
|
121
121
|
sub.add_parser("version", help="Show current version")
|
|
122
122
|
|
|
123
123
|
# ── init ──
|
|
124
|
-
sub.add_parser("init", help="Configure
|
|
124
|
+
init_p = sub.add_parser("init", help="Configure endpoint or initialize project documentation")
|
|
125
|
+
init_p.add_argument("--project", action="store_true", help="Initialize project documentation and persistent memory")
|
|
126
|
+
init_p.add_argument("--profile", choices=["basic", "standard", "advanced"], default="standard", help="Documentation profile (basic, standard, advanced)")
|
|
127
|
+
|
|
128
|
+
# ── scaffold ──
|
|
129
|
+
scaffold_p = sub.add_parser("scaffold", help="Scaffold project-level documentation, rules, and memory store")
|
|
130
|
+
scaffold_p.add_argument("--profile", choices=["basic", "standard", "advanced"], default="standard", help="Documentation profile (basic, standard, advanced)")
|
|
125
131
|
|
|
126
132
|
# ── serve ──
|
|
127
133
|
serve_p = sub.add_parser("serve", help="Start the AlpieCode API server", parents=[common])
|
|
@@ -168,6 +174,24 @@ def main():
|
|
|
168
174
|
print(f"alpiecode {__version__}")
|
|
169
175
|
return
|
|
170
176
|
|
|
177
|
+
if args.command in ("scaffold",) or (args.command == "init" and getattr(args, "project", False)):
|
|
178
|
+
from .project_template import initialize_project_structure, ProjectProfile, ProjectMetadata
|
|
179
|
+
profile_map = {
|
|
180
|
+
"basic": ProjectProfile.BASIC,
|
|
181
|
+
"standard": ProjectProfile.STANDARD,
|
|
182
|
+
"advanced": ProjectProfile.ADVANCED,
|
|
183
|
+
}
|
|
184
|
+
prof = profile_map.get(getattr(args, "profile", "standard") or "standard", ProjectProfile.STANDARD)
|
|
185
|
+
meta = ProjectMetadata(name=Path.cwd().name or "Project")
|
|
186
|
+
created = initialize_project_structure(Path.cwd(), profile=prof, meta=meta)
|
|
187
|
+
if created:
|
|
188
|
+
print(f"✅ Initialized project documentation ({prof.value.upper()} profile):")
|
|
189
|
+
for f in created:
|
|
190
|
+
print(f" • {f}")
|
|
191
|
+
else:
|
|
192
|
+
print("ℹ️ Project documentation already exists. No files were overwritten.")
|
|
193
|
+
return
|
|
194
|
+
|
|
171
195
|
if args.command == "init":
|
|
172
196
|
interactive_init()
|
|
173
197
|
return
|
|
@@ -61,6 +61,15 @@ def _summarize_tool_result(tool_name: str, content: str) -> str:
|
|
|
61
61
|
if tool_name == "update_plan":
|
|
62
62
|
return content
|
|
63
63
|
|
|
64
|
+
c_lower = content.lower()
|
|
65
|
+
if "error:" in c_lower or "syntax" in c_lower or "failed" in c_lower:
|
|
66
|
+
first_line = content.strip().splitlines()[0][:90]
|
|
67
|
+
return f"[Historical tool result (addressed in subsequent turns): {first_line}]"
|
|
68
|
+
|
|
69
|
+
if tool_name == "write_file" or "wrote " in c_lower or "successfully wrote" in c_lower:
|
|
70
|
+
first_line = content.strip().splitlines()[0][:90]
|
|
71
|
+
return f"[Completed: {first_line}]"
|
|
72
|
+
|
|
64
73
|
if len(content) <= 300:
|
|
65
74
|
return content
|
|
66
75
|
|
|
@@ -12,7 +12,8 @@ import os
|
|
|
12
12
|
import socket
|
|
13
13
|
from dataclasses import dataclass, asdict, fields
|
|
14
14
|
from pathlib import Path
|
|
15
|
-
|
|
15
|
+
import time
|
|
16
|
+
from typing import Optional, Dict, Tuple
|
|
16
17
|
|
|
17
18
|
from .paths import ensure_dir, get_alpiecode_dir, is_android, is_ios, load_dotenv_if_present
|
|
18
19
|
|
|
@@ -88,42 +89,57 @@ KNOWN_PRESETS = {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
|
|
92
|
+
_SERVER_REACHABLE_CACHE: Dict[Tuple[str, float], Tuple[float, bool]] = {}
|
|
93
|
+
|
|
94
|
+
|
|
91
95
|
def is_server_reachable(base_url: Optional[str], timeout: float = 0.5) -> bool:
|
|
92
|
-
"""Fast network ping check to see if server endpoint is online with DNS fallback."""
|
|
96
|
+
"""Fast network ping check to see if server endpoint is online with DNS fallback (5s TTL cache)."""
|
|
93
97
|
if not base_url:
|
|
94
98
|
return False
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
now = time.time()
|
|
100
|
+
cache_key = (base_url, timeout)
|
|
101
|
+
if cache_key in _SERVER_REACHABLE_CACHE:
|
|
102
|
+
cached_time, cached_res = _SERVER_REACHABLE_CACHE[cache_key]
|
|
103
|
+
if now - cached_time < 5.0:
|
|
104
|
+
return cached_res
|
|
105
|
+
|
|
106
|
+
def _check() -> bool:
|
|
102
107
|
try:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
from urllib.parse import urlparse
|
|
109
|
+
parsed = urlparse(base_url)
|
|
110
|
+
host = parsed.hostname
|
|
111
|
+
port = parsed.port or (443 if parsed.scheme == "https" else 80)
|
|
112
|
+
if not host:
|
|
113
|
+
return False
|
|
114
|
+
try:
|
|
115
|
+
with socket.create_connection((host, port), timeout=timeout):
|
|
116
|
+
return True
|
|
117
|
+
except (socket.gaierror, OSError):
|
|
118
|
+
# Resilient IP fallback for AWS EC2 / test.169pi.ai on mobile/iOS where DNS might fail ([Errno 8])
|
|
119
|
+
if host and "ec2-18-222-121-38" in host:
|
|
120
|
+
try:
|
|
121
|
+
with socket.create_connection(("18.222.121.38", port), timeout=timeout):
|
|
122
|
+
return True
|
|
123
|
+
except Exception:
|
|
124
|
+
pass
|
|
125
|
+
elif host == "test.169pi.ai":
|
|
126
|
+
try:
|
|
127
|
+
with socket.create_connection(("20.245.200.125", port), timeout=timeout):
|
|
128
|
+
return True
|
|
129
|
+
except Exception:
|
|
130
|
+
pass
|
|
131
|
+
return False
|
|
132
|
+
except Exception:
|
|
119
133
|
return False
|
|
120
|
-
|
|
121
|
-
|
|
134
|
+
|
|
135
|
+
res = _check()
|
|
136
|
+
_SERVER_REACHABLE_CACHE[cache_key] = (now, res)
|
|
137
|
+
return res
|
|
122
138
|
|
|
123
139
|
|
|
124
140
|
def is_internet_available(timeout: float = 1.0) -> bool:
|
|
125
|
-
"""Quick check if general internet is available (tries DNS and
|
|
126
|
-
for host, port in [("8.8.8.8", 53), ("1.1.1.1", 53), ("
|
|
141
|
+
"""Quick check if general internet is available (tries DNS and active cloud endpoint)."""
|
|
142
|
+
for host, port in [("8.8.8.8", 53), ("1.1.1.1", 53), ("18.222.121.38", 8000)]:
|
|
127
143
|
try:
|
|
128
144
|
with socket.create_connection((host, port), timeout=timeout):
|
|
129
145
|
return True
|