alpiecode 10.8.3__tar.gz → 10.8.5__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.8.3 → alpiecode-10.8.5}/PKG-INFO +1 -1
- {alpiecode-10.8.3 → alpiecode-10.8.5}/pyproject.toml +1 -1
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/alpiecode.egg-info/PKG-INFO +1 -1
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/__init__.py +1 -1
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/agent.py +33 -3
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/blueprints.py +5 -2
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/compaction.py +1 -1
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/discovery.py +7 -4
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/guardrails.py +15 -5
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/memory.py +5 -5
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/orchestrator.py +6 -6
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/prompt.py +12 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/tools.py +18 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_deloop_and_sessions.py +71 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/README.md +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/setup.cfg +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/alpiecode/__init__.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/alpiecode.egg-info/SOURCES.txt +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/alpiecode.egg-info/dependency_links.txt +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/alpiecode.egg-info/entry_points.txt +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/alpiecode.egg-info/requires.txt +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/alpiecode.egg-info/top_level.txt +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/assessment.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/backends/__init__.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/backends/base.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/backends/local_backend.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/backends/openai_backend.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/cache.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/cli.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/client.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/config.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/context.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/diff_preview.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/doctor.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/dream_rsi.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/executor.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/git_ops.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/github.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/guardian.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/ipython_ext.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/local_model.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/media.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/metrics.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/paths.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/progress.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/project_template.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/rephraser.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/server.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/session.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/slash.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/subagent.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/system1.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/updater.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/verifier.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/vscode_installer.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/src/codeagent/walkthrough.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_adaptive_resilience.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_cli_ui.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_context_and_trajectory.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_dream_rsi.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_local_model_download.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_non_thinking_and_local_stream.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_project_templates.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_slash_and_diff.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_subagents.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_task_assessment.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_verifier.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_walkthrough.py +0 -0
- {alpiecode-10.8.3 → alpiecode-10.8.5}/test/test_web_resilience_and_guardrails.py +0 -0
|
@@ -17,7 +17,7 @@ Supports:
|
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
from typing import Optional, Any, Dict
|
|
19
19
|
|
|
20
|
-
__version__ = "10.8.
|
|
20
|
+
__version__ = "10.8.5"
|
|
21
21
|
|
|
22
22
|
def run(task: str, workdir: str = ".", reasoning_level: str = "thinking", **kwargs):
|
|
23
23
|
"""Run an autonomous coding task programmatically."""
|
|
@@ -79,7 +79,11 @@ def _format_bash_summary(args: dict) -> str:
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
def _format_file_summary(args: dict, name: str) -> str:
|
|
82
|
-
path = args.get("path"
|
|
82
|
+
path = args.get("path") or args.get("file") or ""
|
|
83
|
+
if name == "edit_file":
|
|
84
|
+
old_lines = len(str(args.get("old_str", "")).splitlines())
|
|
85
|
+
new_lines = len(str(args.get("new_str", "")).splitlines())
|
|
86
|
+
return f"{path} (-{old_lines}/+{new_lines} lines)"
|
|
83
87
|
extra = f" ({len(str(args['content']).splitlines())} lines)" if name == "write_file" and "content" in args else ""
|
|
84
88
|
return f"{path}{extra}"
|
|
85
89
|
|
|
@@ -592,8 +596,34 @@ def run_agent(
|
|
|
592
596
|
|
|
593
597
|
elif event.type == "tool_result":
|
|
594
598
|
status_spinner.pause()
|
|
595
|
-
|
|
596
|
-
|
|
599
|
+
res_content = str(event.data.get("content", ""))
|
|
600
|
+
if "@@" in res_content and ("--- a/" in res_content or "+++ b/" in res_content):
|
|
601
|
+
from .diff_preview import format_colored_diff
|
|
602
|
+
diff_idx = res_content.find("--- a/")
|
|
603
|
+
if diff_idx != -1:
|
|
604
|
+
header_line = res_content[:diff_idx].strip()
|
|
605
|
+
if header_line and verbose:
|
|
606
|
+
if HAS_RICH:
|
|
607
|
+
console.print(Text(f" └ {header_line}", style="dim green"))
|
|
608
|
+
else:
|
|
609
|
+
print(f" └ {header_line}")
|
|
610
|
+
diff_text = res_content[diff_idx:]
|
|
611
|
+
else:
|
|
612
|
+
diff_text = res_content
|
|
613
|
+
d_lines = diff_text.splitlines()
|
|
614
|
+
if len(d_lines) > 25:
|
|
615
|
+
diff_snippet = "\n".join(d_lines[:22]) + f"\n ... ({len(d_lines)-22} diff lines omitted)"
|
|
616
|
+
else:
|
|
617
|
+
diff_snippet = diff_text
|
|
618
|
+
formatted = format_colored_diff(diff_snippet, has_rich=HAS_RICH)
|
|
619
|
+
if verbose:
|
|
620
|
+
if HAS_RICH:
|
|
621
|
+
console.print(formatted)
|
|
622
|
+
else:
|
|
623
|
+
print(formatted)
|
|
624
|
+
has_printed_anything = True
|
|
625
|
+
elif verbose and debug:
|
|
626
|
+
_print_tool_result(res_content)
|
|
597
627
|
_checkpoint(workdir, f"checkpoint: turn {event.data['turn']}")
|
|
598
628
|
status_spinner.resume("Evaluating result & planning next step...", style="bold cyan")
|
|
599
629
|
|
|
@@ -64,18 +64,21 @@ def get_web_app_blueprint(task: str) -> DomainBlueprint:
|
|
|
64
64
|
entry_point="index.html",
|
|
65
65
|
execution_runner="python3 -m http.server 8000 (view at http://localhost:8000)",
|
|
66
66
|
architecture_rules=[
|
|
67
|
+
"Architecture: 100% Pure Vanilla Web Stack (HTML5 + CSS3 + Vanilla JavaScript IIFE). Fast, zero dependencies, zero build step, instant load.",
|
|
67
68
|
"Write `index.html` FIRST with rich static-first markup: Pre-render headers, hero, navigation, card containers, and modal structure in HTML. NEVER leave an empty body or empty `<div id='app'>`.",
|
|
68
69
|
"Include an on-screen Error Boundary in `index.html` via `window.addEventListener('error', ...)` to display any JavaScript exceptions visually instead of a blank white screen.",
|
|
69
70
|
"Write `styles.css` SECOND: Modern responsive styling (CSS Grid/Flexbox, clean typography, badge counters, glassmorphism, card hover lift).",
|
|
70
|
-
"Write `app.js` THIRD: Universal vanilla JavaScript in an IIFE `(function() { 'use strict'; ... })();`.
|
|
71
|
+
"Write `app.js` THIRD: Universal vanilla JavaScript in an IIFE `(function() { 'use strict'; ... })();`. Keep `app.js` concise and modular (< 350 lines). Include 6 to 8 rich mock items, not dozens.",
|
|
71
72
|
"Use `download_asset` or curated Unsplash CDN URLs / inline SVGs for all imagery to ensure 100% working images without 404 broken icons.",
|
|
72
73
|
"Write EXACTLY ONE complete file per turn in order (Turn 1: index.html, Turn 2: styles.css, Turn 3: app.js).",
|
|
73
74
|
"Verify all files exist and validate JavaScript with `node --check app.js` before completing.",
|
|
74
75
|
],
|
|
75
76
|
prohibitions=[
|
|
77
|
+
"NEVER load React, ReactDOM, Babel Standalone (`@babel/standalone`), Vue, or Angular via `<script>` CDN in `index.html`. Browser web applications MUST run natively in standard browsers without in-browser compilation.",
|
|
78
|
+
"NEVER write React JSX syntax (`<Component />` or HTML tags inside JS) in `.js` or `.jsx` files. Node cannot run JSX, and browsers without build tools cannot parse JSX. Use `document.createElement`, template literals, or `innerHTML`.",
|
|
79
|
+
"NEVER write oversized JavaScript files (> 350 lines) with gigantic mock datasets. Keep mock data focused and clean (6-8 items).",
|
|
76
80
|
"NEVER generate an empty `<div id='app'></div>` without pre-rendered static HTML fallback markup (prevents blank white screens).",
|
|
77
81
|
"NEVER use ES module `import`/`export` in browser scripts without a bundler -- use self-executing functions so it works on both `file://` and `http://localhost`.",
|
|
78
|
-
"NEVER write standalone `.jsx` files without a build tool like Vite -- Node cannot execute raw JSX.",
|
|
79
82
|
"NEVER write utility files like `utils/formatPrice.js` before `index.html` exists.",
|
|
80
83
|
"NEVER start blocking daemon servers with `&` or real `sleep` in terminal commands.",
|
|
81
84
|
],
|
|
@@ -66,7 +66,7 @@ def _summarize_tool_result(tool_name: str, content: str) -> str:
|
|
|
66
66
|
first_line = content.strip().splitlines()[0][:90]
|
|
67
67
|
return f"[Historical tool result (addressed in subsequent turns): {first_line}]"
|
|
68
68
|
|
|
69
|
-
if tool_name
|
|
69
|
+
if tool_name in ("write_file", "edit_file") or "wrote " in c_lower or "successfully wrote" in c_lower or "edit applied" in c_lower:
|
|
70
70
|
first_line = content.strip().splitlines()[0][:90]
|
|
71
71
|
return f"[Completed: {first_line}]"
|
|
72
72
|
|
|
@@ -724,16 +724,19 @@ def build_task_context(task: str, workdir: Path) -> TaskContext:
|
|
|
724
724
|
session_data = read_project_session(workdir)
|
|
725
725
|
has_session = session_data is not None
|
|
726
726
|
|
|
727
|
-
|
|
727
|
+
from .blueprints import resolve_domain_blueprint, BlueprintType
|
|
728
|
+
blueprint = resolve_domain_blueprint(task, repo, intent)
|
|
729
|
+
|
|
730
|
+
if blueprint and blueprint.blueprint_type in (BlueprintType.WEB_APP, BlueprintType.GAME, BlueprintType.CLI_SCRIPT):
|
|
731
|
+
# Keep web applications, games, and CLI tools clean and focused (no 15-file markdown clutter)
|
|
732
|
+
project_profile = "basic"
|
|
733
|
+
elif complexity in ("high", "extreme") or len(repo.get("frameworks", [])) > 1:
|
|
728
734
|
project_profile = "advanced"
|
|
729
735
|
elif complexity == "low" and repo.get("file_count", 0) <= 2:
|
|
730
736
|
project_profile = "basic"
|
|
731
737
|
else:
|
|
732
738
|
project_profile = "standard"
|
|
733
739
|
|
|
734
|
-
from .blueprints import resolve_domain_blueprint
|
|
735
|
-
blueprint = resolve_domain_blueprint(task, repo, intent)
|
|
736
|
-
|
|
737
740
|
return TaskContext(
|
|
738
741
|
symbol_index=symbol_index,
|
|
739
742
|
# Assessment & Strategy
|
|
@@ -100,11 +100,13 @@ def validate_javascript_syntax(file_path: str, content: str) -> Tuple[bool, Opti
|
|
|
100
100
|
err = res_esm.stderr.strip() or "Syntax error in ES module"
|
|
101
101
|
return False, f"JavaScript SyntaxError in '{file_path}': {err}"
|
|
102
102
|
|
|
103
|
-
# 3. If file contains JSX syntax,
|
|
104
|
-
if "<" in
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
# 3. If file contains JSX syntax in a .js file, provide an actionable directive
|
|
104
|
+
if "Unexpected token '<'" in err_output or "Unexpected token <" in err_output:
|
|
105
|
+
return False, (
|
|
106
|
+
f"JavaScript SyntaxError in '{file_path}': Raw JSX/HTML syntax ('<tag>') detected. "
|
|
107
|
+
"Node.js and browsers cannot execute raw JSX in .js files without a build step. "
|
|
108
|
+
"Use standard JavaScript DOM APIs (document.createElement, innerHTML, or template literals) instead of JSX."
|
|
109
|
+
)
|
|
108
110
|
|
|
109
111
|
err = res.stderr.strip() or "Syntax error in JavaScript code"
|
|
110
112
|
return False, f"JavaScript SyntaxError in '{file_path}': {err}"
|
|
@@ -148,6 +150,14 @@ def validate_code_syntax(file_path: str, content: str) -> Tuple[bool, Optional[s
|
|
|
148
150
|
if not content or not content.strip():
|
|
149
151
|
return True, None
|
|
150
152
|
|
|
153
|
+
# Guard against accidental persistence of compaction summary markers
|
|
154
|
+
stripped = content.strip()
|
|
155
|
+
if stripped.startswith("[Content saved to ") or "[Content saved to " in stripped[:120]:
|
|
156
|
+
return False, (
|
|
157
|
+
f"Pre-commit error for '{file_path}': File content contains a compacted history placeholder marker ('{stripped[:60]}...'). "
|
|
158
|
+
"You must write the complete, actual code implementation, not the historical summary marker."
|
|
159
|
+
)
|
|
160
|
+
|
|
151
161
|
ext = Path(file_path).suffix.lower()
|
|
152
162
|
validator = SYNTAX_VALIDATORS.get(ext)
|
|
153
163
|
if validator:
|
|
@@ -15,7 +15,7 @@ import json
|
|
|
15
15
|
import hashlib
|
|
16
16
|
import time
|
|
17
17
|
from pathlib import Path
|
|
18
|
-
from typing import List, Optional
|
|
18
|
+
from typing import List, Optional, Union
|
|
19
19
|
|
|
20
20
|
from .paths import ensure_dir, get_alpiecode_dir
|
|
21
21
|
|
|
@@ -27,17 +27,17 @@ def get_memory_dir() -> Path:
|
|
|
27
27
|
MEMORY_DIR = get_alpiecode_dir() / "memories"
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
def _project_key(workdir: Path) -> str:
|
|
30
|
+
def _project_key(workdir: Union[Path, str]) -> str:
|
|
31
31
|
"""Generate a stable key for a project directory."""
|
|
32
|
-
return hashlib.md5(str(workdir.resolve()).encode()).hexdigest()[:12]
|
|
32
|
+
return hashlib.md5(str(Path(workdir).resolve()).encode()).hexdigest()[:12]
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def _memory_path(workdir: Path) -> Path:
|
|
35
|
+
def _memory_path(workdir: Union[Path, str]) -> Path:
|
|
36
36
|
"""Get the memory file path for a project."""
|
|
37
37
|
return get_memory_dir() / f"{_project_key(workdir)}.json"
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
def load_memories(workdir: Path) -> List[dict]:
|
|
40
|
+
def load_memories(workdir: Union[Path, str]) -> List[dict]:
|
|
41
41
|
"""
|
|
42
42
|
Load memories for a specific project directory.
|
|
43
43
|
|
|
@@ -284,10 +284,10 @@ class AgentOrchestrator:
|
|
|
284
284
|
if is_offline:
|
|
285
285
|
session.context.max_tokens = getattr(cfg, "n_ctx", 8192)
|
|
286
286
|
else:
|
|
287
|
-
b_window = getattr(task_backend, "context_window",
|
|
288
|
-
if not isinstance(b_window, int):
|
|
289
|
-
b_window =
|
|
290
|
-
session.context.max_tokens =
|
|
287
|
+
b_window = getattr(task_backend, "context_window", 262144)
|
|
288
|
+
if not isinstance(b_window, int) or b_window <= 0:
|
|
289
|
+
b_window = 262144
|
|
290
|
+
session.context.max_tokens = b_window
|
|
291
291
|
# ?? Dream-RSI Trajectory Recorder ??
|
|
292
292
|
trajectory_store = TrajectoryStore()
|
|
293
293
|
trajectory_record = TrajectoryRecord(
|
|
@@ -344,9 +344,9 @@ class AgentOrchestrator:
|
|
|
344
344
|
f"[ARCHITECTURE DIRECTIVE: {bp.name.upper()}]\n"
|
|
345
345
|
f"- Required Deliverables: {', '.join(bp.target_files)}\n"
|
|
346
346
|
f"- Primary Entry Point: {bp.entry_point}\n"
|
|
347
|
-
f"- Step 1 (Turn 1): Create '{bp.target_files[0]}' with complete static structure. NEVER
|
|
347
|
+
f"- Step 1 (Turn 1): Create '{bp.target_files[0]}' with complete static structure. Pure Vanilla HTML5/CSS3. NEVER load React, Babel Standalone, Vue, or JSX tooling.\n"
|
|
348
348
|
f"- Step 2: Implement styling and components sequentially.\n"
|
|
349
|
-
f"- Step 3: Implement client JavaScript (Universal IIFE,
|
|
349
|
+
f"- Step 3: Implement client JavaScript (Universal Vanilla JS IIFE, NO JSX, NO unbundled ES modules, keep under 300 lines).\n\n"
|
|
350
350
|
)
|
|
351
351
|
effective_task = bp_directive + effective_task
|
|
352
352
|
|
|
@@ -177,8 +177,14 @@ When creating or modifying multi-file projects (e.g. websites, full-stack apps,
|
|
|
177
177
|
- Turn 3: Write the logic or component (e.g. `app.js`).
|
|
178
178
|
- Focus on ONE complete file per turn: this prevents output truncation, guarantees 100% valid syntax, and ensures production-ready code.
|
|
179
179
|
|
|
180
|
+
## Language Selection Policy — CRITICAL
|
|
181
|
+
- Web Development (websites, web applications, stores, dashboards, UI): ALWAYS use standard HTML5, modern CSS3, and Vanilla JavaScript (`index.html`, `styles.css`, `app.js`).
|
|
182
|
+
- All Other Tasks (scripts, CLI tools, APIs, backends, AI/ML, data processing, algorithms, autonomous agents): Default to **Python** (clean, modern Python 3.10+).
|
|
183
|
+
- Use other languages (Rust, Go, C, C++, Java, etc.) ONLY if the user explicitly mentioned that specific language in their prompt (e.g. "in rust", "using golang", "in c++").
|
|
184
|
+
|
|
180
185
|
## Tool Rules
|
|
181
186
|
- Use write_file for NEW files, edit_file for EXISTING files
|
|
187
|
+
- NEVER use write_file to overwrite an existing file from line 0 — use edit_file to modify targeted lines!
|
|
182
188
|
- Always read_file before edit_file — never edit blind
|
|
183
189
|
- bash for running code, compiling, testing
|
|
184
190
|
- Do NOT use bash just to list files or explore — start coding instead
|
|
@@ -269,8 +275,14 @@ For multi-file projects, build in dependency order, emitting ONE complete file p
|
|
|
269
275
|
- For all projects: Build/compile or verify syntax after each file to catch errors early
|
|
270
276
|
- Integration build + test after all files written
|
|
271
277
|
|
|
278
|
+
## Language Selection Policy — CRITICAL
|
|
279
|
+
- Web Development (websites, web applications, stores, dashboards, UI): ALWAYS use standard HTML5, modern CSS3, and Vanilla JavaScript (`index.html`, `styles.css`, `app.js`).
|
|
280
|
+
- All Other Tasks (scripts, CLI tools, APIs, backends, AI/ML, data processing, algorithms, autonomous agents): Default to **Python** (clean, modern Python 3.10+).
|
|
281
|
+
- Use other languages (Rust, Go, C, C++, Java, etc.) ONLY if the user explicitly mentioned that specific language in their prompt (e.g. "in rust", "using golang", "in c++").
|
|
282
|
+
|
|
272
283
|
## Tool Rules
|
|
273
284
|
- Use write_file for NEW files, edit_file for EXISTING files
|
|
285
|
+
- NEVER use write_file to overwrite an existing file from line 0 — use edit_file to modify targeted lines!
|
|
274
286
|
- Always read_file before edit_file
|
|
275
287
|
- Use list_files to understand project structure when modifying existing code
|
|
276
288
|
- Use file_search to find specific code patterns
|
|
@@ -640,10 +640,20 @@ def _write_file(workdir: Path, path: str, content: str) -> str:
|
|
|
640
640
|
|
|
641
641
|
p = _resolve_safe_path(workdir, path)
|
|
642
642
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
643
|
+
file_existed = p.exists() and p.is_file()
|
|
644
|
+
old_content = p.read_text(encoding="utf-8", errors="replace") if file_existed else ""
|
|
645
|
+
|
|
643
646
|
p.write_text(content, encoding="utf-8")
|
|
644
647
|
_RECENTLY_WRITTEN_FILES.add(Path(path).name.lower())
|
|
645
648
|
get_file_cache().invalidate(p)
|
|
646
649
|
get_test_cache().invalidate(workdir)
|
|
650
|
+
|
|
651
|
+
if file_existed and old_content and old_content != content:
|
|
652
|
+
from .diff_preview import generate_unified_diff
|
|
653
|
+
diff_text = generate_unified_diff(old_content, content, filepath=path, context_lines=2)
|
|
654
|
+
if diff_text.strip():
|
|
655
|
+
return f"wrote {len(content)} bytes to {path}\n{diff_text.strip()}"
|
|
656
|
+
|
|
647
657
|
return f"wrote {len(content)} bytes to {path}"
|
|
648
658
|
|
|
649
659
|
|
|
@@ -700,6 +710,14 @@ def _edit_file(workdir: Path, path: str, old_str: str, new_str: str) -> str:
|
|
|
700
710
|
return f"error: Edit would result in a syntax error in '{path}':\n{err}\nPlease revise the replacement."
|
|
701
711
|
|
|
702
712
|
p.write_text(new_text, encoding="utf-8")
|
|
713
|
+
_RECENTLY_WRITTEN_FILES.add(Path(path).name.lower())
|
|
714
|
+
get_file_cache().invalidate(p)
|
|
715
|
+
get_test_cache().invalidate(workdir)
|
|
716
|
+
|
|
717
|
+
from .diff_preview import generate_unified_diff
|
|
718
|
+
diff_text = generate_unified_diff(text, new_text, filepath=path, context_lines=2)
|
|
719
|
+
if diff_text.strip():
|
|
720
|
+
return f"edit applied to {path}\n{diff_text.strip()}"
|
|
703
721
|
return "edit applied"
|
|
704
722
|
|
|
705
723
|
|
|
@@ -148,3 +148,74 @@ def test_verifier_batch_missing_dom_ids(tmp_path):
|
|
|
148
148
|
assert res.error_type == "dom_id_mismatch"
|
|
149
149
|
assert "'#cart-container'" in res.message
|
|
150
150
|
assert "'#close-cart-btn'" in res.message
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_raw_jsx_in_js_file_rejected_with_directive():
|
|
154
|
+
"""Verify raw JSX in a .js file produces an actionable pre-commit directive."""
|
|
155
|
+
from codeagent.guardrails import validate_code_syntax
|
|
156
|
+
raw_jsx = """
|
|
157
|
+
function renderApp() {
|
|
158
|
+
return <ShopContext.Provider value={value}>{children}</ShopContext.Provider>;
|
|
159
|
+
}
|
|
160
|
+
"""
|
|
161
|
+
passed, err = validate_code_syntax("app.js", raw_jsx)
|
|
162
|
+
assert not passed
|
|
163
|
+
assert "Raw JSX/HTML syntax ('<tag>') detected" in err
|
|
164
|
+
assert "Use standard JavaScript DOM APIs" in err
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_compacted_placeholder_rejected_by_guardrail():
|
|
168
|
+
"""Verify that accidental writes of compaction placeholder markers are caught before hitting disk."""
|
|
169
|
+
from codeagent.guardrails import validate_code_syntax
|
|
170
|
+
compacted_stub = "[Content saved to app.js (487 lines, 15890 bytes)]"
|
|
171
|
+
passed, err = validate_code_syntax("app.js", compacted_stub)
|
|
172
|
+
assert not passed
|
|
173
|
+
assert "compacted history placeholder marker" in err
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def test_web_app_blueprint_rules_enforce_vanilla_stack():
|
|
177
|
+
"""Verify that get_web_app_blueprint explicitly forbids React/Babel CDN and raw JSX."""
|
|
178
|
+
from codeagent.blueprints import get_web_app_blueprint
|
|
179
|
+
bp = get_web_app_blueprint("create a grocery ecommerce website")
|
|
180
|
+
prohib_text = " ".join(bp.prohibitions)
|
|
181
|
+
assert "React" in prohib_text
|
|
182
|
+
assert "Babel Standalone" in prohib_text
|
|
183
|
+
assert "JSX" in prohib_text
|
|
184
|
+
assert bp.target_files == ["index.html", "styles.css", "app.js"]
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def test_edit_file_produces_git_diff(tmp_path):
|
|
188
|
+
"""Verify that edit_file returns a unified git-style diff."""
|
|
189
|
+
from codeagent.tools import _edit_file
|
|
190
|
+
target = tmp_path / "app.js"
|
|
191
|
+
target.write_text("const a = 1;\nconst b = 2;\nconsole.log(a + b);\n")
|
|
192
|
+
|
|
193
|
+
res = _edit_file(tmp_path, "app.js", "const b = 2;", "const b = 20;")
|
|
194
|
+
assert "edit applied to app.js" in res
|
|
195
|
+
assert "--- a/app.js" in res
|
|
196
|
+
assert "+++ b/app.js" in res
|
|
197
|
+
assert "-const b = 2;" in res
|
|
198
|
+
assert "+const b = 20;" in res
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def test_write_file_on_existing_file_produces_git_diff(tmp_path):
|
|
202
|
+
"""Verify that write_file modifying an existing file returns a unified git diff."""
|
|
203
|
+
from codeagent.tools import _write_file
|
|
204
|
+
target = tmp_path / "main.py"
|
|
205
|
+
target.write_text("def hello():\n return 'world'\n")
|
|
206
|
+
|
|
207
|
+
res = _write_file(tmp_path, "main.py", "def hello():\n return 'universe'\n")
|
|
208
|
+
assert "wrote" in res
|
|
209
|
+
assert "main.py" in res
|
|
210
|
+
assert "--- a/main.py" in res
|
|
211
|
+
assert "- return 'world'" in res
|
|
212
|
+
assert "+ return 'universe'" in res
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def test_clean_folder_structure_for_web_app_blueprint(tmp_path):
|
|
216
|
+
"""Verify that web app tasks resolve to clean basic scaffolding without 15-file clutter."""
|
|
217
|
+
from codeagent.discovery import build_task_context
|
|
218
|
+
ctx = build_task_context("create a fruit store website", tmp_path)
|
|
219
|
+
assert ctx.project_profile == "basic"
|
|
220
|
+
assert ctx.blueprint is not None
|
|
221
|
+
assert ctx.blueprint.name == "Browser-First Web Application"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|