alpiecode 6.2.0__tar.gz → 7.0.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-6.2.0 → alpiecode-7.0.0}/PKG-INFO +1 -1
- {alpiecode-6.2.0 → alpiecode-7.0.0}/pyproject.toml +1 -1
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/alpiecode.egg-info/PKG-INFO +1 -1
- alpiecode-7.0.0/src/codeagent/extension/alpiecode.vsix +0 -0
- alpiecode-7.0.0/src/codeagent/ipython_ext.py +325 -0
- alpiecode-6.2.0/src/codeagent/extension/alpiecode.vsix +0 -0
- alpiecode-6.2.0/src/codeagent/ipython_ext.py +0 -156
- {alpiecode-6.2.0 → alpiecode-7.0.0}/README.md +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/setup.cfg +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/alpiecode/__init__.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/alpiecode.egg-info/SOURCES.txt +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/alpiecode.egg-info/dependency_links.txt +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/alpiecode.egg-info/entry_points.txt +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/alpiecode.egg-info/requires.txt +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/alpiecode.egg-info/top_level.txt +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/__init__.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/agent.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/backends/__init__.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/backends/base.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/backends/local_backend.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/backends/openai_backend.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/cache.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/cli.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/client.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/compaction.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/config.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/context.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/discovery.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/doctor.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/executor.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/github.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/guardian.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/local_model.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/media.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/memory.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/orchestrator.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/progress.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/prompt.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/server.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/session.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/tools.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/updater.py +0 -0
- {alpiecode-6.2.0 → alpiecode-7.0.0}/src/codeagent/vscode_installer.py +0 -0
|
Binary file
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"""
|
|
2
|
+
IPython & Jupyter / Google Colab extension for AlpieCode.
|
|
3
|
+
|
|
4
|
+
Enables seamless usage of AlpieCode inside Jupyter Notebooks, JupyterLab,
|
|
5
|
+
and Google Colab via cell/line magic commands and rich interactive displays:
|
|
6
|
+
|
|
7
|
+
%load_ext alpiecode
|
|
8
|
+
%alpie write a quick pandas script to inspect data.csv
|
|
9
|
+
%%alpie
|
|
10
|
+
Create a complete PyTorch model training pipeline.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import html
|
|
14
|
+
import re
|
|
15
|
+
import sys
|
|
16
|
+
import warnings
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Optional, List, Dict, Any
|
|
19
|
+
|
|
20
|
+
# Suppress noisy Jupyter / Python 3.12+ deprecation warnings
|
|
21
|
+
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
22
|
+
warnings.filterwarnings("ignore", category=FutureWarning)
|
|
23
|
+
warnings.filterwarnings("ignore", module="jupyter_client.*")
|
|
24
|
+
warnings.filterwarnings("ignore", module="ipykernel.*")
|
|
25
|
+
|
|
26
|
+
from .config import load_config
|
|
27
|
+
from .orchestrator import AgentOrchestrator, AgentEvent, resolve_backend
|
|
28
|
+
from .session import SessionManager
|
|
29
|
+
from .agent import run_agent
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _is_notebook() -> bool:
|
|
33
|
+
"""Check if code is running inside a Jupyter notebook or Google Colab."""
|
|
34
|
+
try:
|
|
35
|
+
from IPython import get_ipython
|
|
36
|
+
shell = get_ipython()
|
|
37
|
+
if shell is None:
|
|
38
|
+
return False
|
|
39
|
+
shell_name = shell.__class__.__name__
|
|
40
|
+
if "ZMQInteractiveShell" in shell_name or "Shell" in shell_name:
|
|
41
|
+
return True
|
|
42
|
+
return False
|
|
43
|
+
except Exception:
|
|
44
|
+
return False
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _display_html(html_str: str):
|
|
48
|
+
"""Render rich HTML in Jupyter or Google Colab."""
|
|
49
|
+
try:
|
|
50
|
+
from IPython.display import HTML, display
|
|
51
|
+
display(HTML(html_str))
|
|
52
|
+
except Exception:
|
|
53
|
+
print(html_str)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _display_markdown(md_str: str):
|
|
57
|
+
"""Render rich Markdown in Jupyter or Google Colab."""
|
|
58
|
+
try:
|
|
59
|
+
from IPython.display import Markdown, display
|
|
60
|
+
display(Markdown(md_str))
|
|
61
|
+
except Exception:
|
|
62
|
+
print(md_str)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _get_notebook_context() -> str:
|
|
66
|
+
"""Inspect active user variables in the notebook session (DataFrames, tensors, etc.)."""
|
|
67
|
+
try:
|
|
68
|
+
from IPython import get_ipython
|
|
69
|
+
ip = get_ipython()
|
|
70
|
+
if not ip or not hasattr(ip, "user_ns"):
|
|
71
|
+
return ""
|
|
72
|
+
|
|
73
|
+
var_summaries = []
|
|
74
|
+
for name, val in list(ip.user_ns.items()):
|
|
75
|
+
if name.startswith("_"):
|
|
76
|
+
continue
|
|
77
|
+
type_name = type(val).__name__
|
|
78
|
+
module_name = getattr(type(val), "__module__", "")
|
|
79
|
+
|
|
80
|
+
# Pandas DataFrame
|
|
81
|
+
if "pandas" in module_name and type_name == "DataFrame":
|
|
82
|
+
cols = list(val.columns)[:15]
|
|
83
|
+
var_summaries.append(f"- DataFrame `{name}`: shape={val.shape}, columns={cols}")
|
|
84
|
+
# Pandas Series
|
|
85
|
+
elif "pandas" in module_name and type_name == "Series":
|
|
86
|
+
var_summaries.append(f"- Series `{name}`: shape={val.shape}, dtype={val.dtype}")
|
|
87
|
+
# Numpy ndarray
|
|
88
|
+
elif "numpy" in module_name and type_name == "ndarray":
|
|
89
|
+
var_summaries.append(f"- NumPy Array `{name}`: shape={val.shape}, dtype={val.dtype}")
|
|
90
|
+
# PyTorch Tensor
|
|
91
|
+
elif "torch" in module_name and "Tensor" in type_name:
|
|
92
|
+
shape = list(val.shape) if hasattr(val, "shape") else []
|
|
93
|
+
var_summaries.append(f"- PyTorch Tensor `{name}`: shape={shape}, dtype={getattr(val, 'dtype', 'unknown')}")
|
|
94
|
+
|
|
95
|
+
if not var_summaries:
|
|
96
|
+
return ""
|
|
97
|
+
return "\n[Active In-Memory Notebook Variables]\n" + "\n".join(var_summaries[:8]) + "\n"
|
|
98
|
+
except Exception:
|
|
99
|
+
return ""
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _extract_primary_code_block(text: str) -> Optional[str]:
|
|
103
|
+
"""Extract Python code block from assistant text to insert into cell."""
|
|
104
|
+
# Match ```python ... ``` or ```py ... ```
|
|
105
|
+
match = re.search(r"```(?:python|py)\n(.*?)```", text, flags=re.DOTALL)
|
|
106
|
+
if match:
|
|
107
|
+
return match.group(1).strip()
|
|
108
|
+
# Match generic ``` ... ```
|
|
109
|
+
match = re.search(r"```\n(.*?)```", text, flags=re.DOTALL)
|
|
110
|
+
if match:
|
|
111
|
+
return match.group(1).strip()
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _render_colab_card(task: str, tool_actions: List[Dict[str, str]], content: str) -> str:
|
|
116
|
+
"""Render a modern, sleek Colab/Jupyter responsive card."""
|
|
117
|
+
task_escaped = html.escape(task[:140])
|
|
118
|
+
|
|
119
|
+
actions_html = ""
|
|
120
|
+
if tool_actions:
|
|
121
|
+
actions_html = '<div style="margin-top: 8px; margin-bottom: 8px; font-family: ui-monospace, monospace; font-size: 12px;">'
|
|
122
|
+
for act in tool_actions:
|
|
123
|
+
name = html.escape(act.get("name", ""))
|
|
124
|
+
summary = html.escape(act.get("summary", ""))
|
|
125
|
+
status = act.get("status", "✓")
|
|
126
|
+
actions_html += (
|
|
127
|
+
f'<div style="display: flex; align-items: center; gap: 6px; padding: 3px 0; color: #94a3b8;">'
|
|
128
|
+
f'<span style="color: #38bdf8;">⏺</span> '
|
|
129
|
+
f'<strong style="color: #f1f5f9;">{name}</strong> '
|
|
130
|
+
f'<span style="color: #64748b;">{summary}</span>'
|
|
131
|
+
f'</div>'
|
|
132
|
+
)
|
|
133
|
+
actions_html += '</div>'
|
|
134
|
+
|
|
135
|
+
card = (
|
|
136
|
+
f'<div style="'
|
|
137
|
+
f'background: #0f172a; border: 1px solid #1e293b; border-left: 4px solid #38bdf8; '
|
|
138
|
+
f'border-radius: 8px; padding: 12px 16px; margin: 8px 0; font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif;'
|
|
139
|
+
f'box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);">'
|
|
140
|
+
f'<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #1e293b; padding-bottom: 8px;">'
|
|
141
|
+
f'<span style="font-weight: 600; font-size: 13px; color: #38bdf8; display: flex; align-items: center; gap: 6px;">'
|
|
142
|
+
f'⚡ AlpieCode Agent'
|
|
143
|
+
f'</span>'
|
|
144
|
+
f'<span style="font-size: 11px; color: #64748b; background: #1e293b; padding: 2px 8px; border-radius: 9999px;">'
|
|
145
|
+
f'Goal-Driven'
|
|
146
|
+
f'</span>'
|
|
147
|
+
f'</div>'
|
|
148
|
+
f'<div style="font-size: 13px; color: #cbd5e1; margin-top: 8px; font-weight: 500;">{task_escaped}</div>'
|
|
149
|
+
f'{actions_html}'
|
|
150
|
+
f'</div>'
|
|
151
|
+
)
|
|
152
|
+
return card
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def alpie_magic(line: str, cell: Optional[str] = None):
|
|
156
|
+
"""
|
|
157
|
+
%alpie <task> (line magic)
|
|
158
|
+
%%alpie (cell magic)
|
|
159
|
+
<multiline task>
|
|
160
|
+
|
|
161
|
+
Flags:
|
|
162
|
+
--insert, -i: Automatically insert generated code into the next cell
|
|
163
|
+
"""
|
|
164
|
+
raw_task = (cell if cell is not None and cell.strip() else line).strip()
|
|
165
|
+
if not raw_task:
|
|
166
|
+
print("Usage: %alpie <task> OR %%alpie\n<multiline task>")
|
|
167
|
+
return
|
|
168
|
+
|
|
169
|
+
# Check for --insert flag
|
|
170
|
+
auto_insert = False
|
|
171
|
+
if raw_task.startswith("--insert ") or raw_task.startswith("-i "):
|
|
172
|
+
auto_insert = True
|
|
173
|
+
raw_task = re.sub(r"^(--insert|-i)\s+", "", raw_task).strip()
|
|
174
|
+
|
|
175
|
+
# Append in-memory notebook context (DataFrames, tensors)
|
|
176
|
+
nb_context = _get_notebook_context()
|
|
177
|
+
full_task = f"{raw_task}\n{nb_context}" if nb_context else raw_task
|
|
178
|
+
|
|
179
|
+
cfg = load_config()
|
|
180
|
+
workdir = Path(".").resolve()
|
|
181
|
+
|
|
182
|
+
if not _is_notebook():
|
|
183
|
+
# Running in standard terminal / ipython shell
|
|
184
|
+
run_agent(full_task, workdir, cfg, verbose=True)
|
|
185
|
+
return
|
|
186
|
+
|
|
187
|
+
# In Jupyter or Google Colab: run with rich streaming & UI
|
|
188
|
+
from IPython import get_ipython
|
|
189
|
+
ip = get_ipython()
|
|
190
|
+
|
|
191
|
+
backend = resolve_backend(cfg)
|
|
192
|
+
orchestrator = AgentOrchestrator(backend)
|
|
193
|
+
session_mgr = SessionManager()
|
|
194
|
+
session = session_mgr.create_session(workdir, max_tokens=cfg.n_ctx if not backend.is_available else 262_144)
|
|
195
|
+
|
|
196
|
+
tool_actions: List[Dict[str, str]] = []
|
|
197
|
+
final_content = ""
|
|
198
|
+
|
|
199
|
+
for event in orchestrator.run_task(session=session, task=full_task, cfg=cfg):
|
|
200
|
+
if event.type == "tool_call":
|
|
201
|
+
t_name = event.data.get("name", "")
|
|
202
|
+
t_args = event.data.get("arguments", {})
|
|
203
|
+
if isinstance(t_args, str):
|
|
204
|
+
try:
|
|
205
|
+
import json
|
|
206
|
+
t_args = json.loads(t_args)
|
|
207
|
+
except Exception:
|
|
208
|
+
t_args = {}
|
|
209
|
+
|
|
210
|
+
summary = ""
|
|
211
|
+
if t_name == "bash":
|
|
212
|
+
cmd = t_args.get("command", "")
|
|
213
|
+
summary = f"$ {cmd[:60]}..." if len(cmd) > 60 else f"$ {cmd}"
|
|
214
|
+
elif t_name in ("write_file", "edit_file", "read_file"):
|
|
215
|
+
summary = str(t_args.get("path", ""))
|
|
216
|
+
tool_actions.append({"name": t_name, "summary": summary})
|
|
217
|
+
|
|
218
|
+
elif event.type == "message":
|
|
219
|
+
final_content = event.data.get("content", "")
|
|
220
|
+
|
|
221
|
+
elif event.type == "done":
|
|
222
|
+
if not final_content:
|
|
223
|
+
final_content = event.data.get("summary", "")
|
|
224
|
+
|
|
225
|
+
# Clean up DONE: prefix
|
|
226
|
+
cleaned_content = final_content.strip()
|
|
227
|
+
if cleaned_content.upper().startswith("DONE:"):
|
|
228
|
+
cleaned_content = cleaned_content[5:].strip()
|
|
229
|
+
|
|
230
|
+
# Render modern card & markdown
|
|
231
|
+
_display_html(_render_colab_card(raw_task, tool_actions, cleaned_content))
|
|
232
|
+
if cleaned_content:
|
|
233
|
+
_display_markdown(cleaned_content)
|
|
234
|
+
|
|
235
|
+
# If code block is present, insert into next cell if requested or suggested
|
|
236
|
+
code_block = _extract_primary_code_block(cleaned_content)
|
|
237
|
+
if code_block and (auto_insert or (cell is not None and "code" in raw_task.lower())):
|
|
238
|
+
try:
|
|
239
|
+
ip.set_next_input(code_block, replace=False)
|
|
240
|
+
_display_html(
|
|
241
|
+
'<div style="font-size: 11px; color: #10b981; margin-top: 4px; font-family: sans-serif;">'
|
|
242
|
+
'✨ Code block automatically populated in next cell. Hit <b>Shift+Enter</b> to run.'
|
|
243
|
+
'</div>'
|
|
244
|
+
)
|
|
245
|
+
except Exception:
|
|
246
|
+
pass
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def alpie_plan_magic(line: str, cell: Optional[str] = None):
|
|
250
|
+
"""%alpie_plan <task> — Generate a structured implementation plan without making edits."""
|
|
251
|
+
task = (cell if cell is not None and cell.strip() else line).strip()
|
|
252
|
+
if not task:
|
|
253
|
+
print("Usage: %alpie_plan <task>")
|
|
254
|
+
return
|
|
255
|
+
|
|
256
|
+
plan_task = (
|
|
257
|
+
f"PLANNING ONLY — Do NOT make any file edits. "
|
|
258
|
+
f"Analyze the codebase and create a detailed implementation plan for the following task. "
|
|
259
|
+
f"Use list_files, read_file, and file_search to understand the project. "
|
|
260
|
+
f"Then use update_plan to write a structured plan with deliverables and checks. "
|
|
261
|
+
f"Finish with DONE: when the plan is complete.\n\n"
|
|
262
|
+
f"Task: {task}"
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
alpie_magic(plan_task)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def alpie_explain_magic(line: str):
|
|
269
|
+
"""%alpie_explain <file_path_or_concept> — Explain code or architecture."""
|
|
270
|
+
target = line.strip()
|
|
271
|
+
if not target:
|
|
272
|
+
print("Usage: %alpie_explain <file_path_or_concept>")
|
|
273
|
+
return
|
|
274
|
+
|
|
275
|
+
workdir = Path(".").resolve()
|
|
276
|
+
target_path = workdir / target if not Path(target).is_absolute() else Path(target)
|
|
277
|
+
|
|
278
|
+
if target_path.exists() and target_path.is_file():
|
|
279
|
+
content = target_path.read_text(encoding="utf-8", errors="replace")
|
|
280
|
+
explain_task = (
|
|
281
|
+
f"EXPLANATION ONLY — Do NOT make any file edits.\n\n"
|
|
282
|
+
f"Please explain the file `{target}` in detail:\n"
|
|
283
|
+
f"1. Overview of its purpose and role\n"
|
|
284
|
+
f"2. Key functions, classes, and internal logic\n"
|
|
285
|
+
f"3. Dependencies and how it connects to the project\n"
|
|
286
|
+
f"4. Step-by-step walkthrough of how it executes\n\n"
|
|
287
|
+
f"File content ({target}):\n```\n{content[:16000]}\n```"
|
|
288
|
+
)
|
|
289
|
+
else:
|
|
290
|
+
explain_task = (
|
|
291
|
+
f"EXPLANATION ONLY — Do NOT make any file edits.\n\n"
|
|
292
|
+
f"Explain the following codebase concept or architecture in detail:\n"
|
|
293
|
+
f"Topic: {target}\n\n"
|
|
294
|
+
f"Use read_file or file_search if needed to understand codebase context."
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
alpie_magic(explain_task)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def alpie_doctor_magic(line: str = ""):
|
|
301
|
+
"""%alpie_doctor — Run system health diagnostic checks."""
|
|
302
|
+
from .doctor import run_doctor
|
|
303
|
+
run_doctor()
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def load_ipython_extension(ipython):
|
|
307
|
+
"""Called by IPython when user runs `%load_ext alpiecode`."""
|
|
308
|
+
ipython.register_magic_function(alpie_magic, magic_kind="line_cell", magic_name="alpie")
|
|
309
|
+
ipython.register_magic_function(alpie_plan_magic, magic_kind="line_cell", magic_name="alpie_plan")
|
|
310
|
+
ipython.register_magic_function(alpie_explain_magic, magic_kind="line", magic_name="alpie_explain")
|
|
311
|
+
ipython.register_magic_function(alpie_doctor_magic, magic_kind="line", magic_name="alpie_doctor")
|
|
312
|
+
if _is_notebook():
|
|
313
|
+
_display_html(
|
|
314
|
+
'<div style="background: #0f172a; border-left: 4px solid #38bdf8; border-radius: 6px; padding: 8px 12px; margin: 4px 0; font-family: sans-serif; font-size: 13px; color: #e2e8f0;">'
|
|
315
|
+
'<strong style="color: #38bdf8;">✨ AlpieCode IPython & Colab Extension Loaded!</strong> '
|
|
316
|
+
'<span style="color: #94a3b8; font-size: 12px;">Try: <code>%alpie <task></code> or <code>%%alpie</code> (supports <code>--insert</code> to populate code cells)</span>'
|
|
317
|
+
'</div>'
|
|
318
|
+
)
|
|
319
|
+
else:
|
|
320
|
+
print("✨ AlpieCode IPython/Jupyter Extension Loaded! Try: %alpie <task> or %%alpie")
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def unload_ipython_extension(ipython):
|
|
324
|
+
"""Called when user runs `%unload_ext alpiecode`."""
|
|
325
|
+
pass
|
|
Binary file
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
IPython & Jupyter / Google Colab extension for AlpieCode.
|
|
3
|
-
|
|
4
|
-
Enables seamless usage of AlpieCode inside Jupyter Notebooks, JupyterLab,
|
|
5
|
-
and Google Colab via cell/line magic commands and rich interactive displays:
|
|
6
|
-
|
|
7
|
-
%load_ext alpiecode
|
|
8
|
-
%alpie write a quick pandas script to inspect data.csv
|
|
9
|
-
%%alpie
|
|
10
|
-
Create a complete PyTorch model training pipeline.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
import sys
|
|
14
|
-
import warnings
|
|
15
|
-
from pathlib import Path
|
|
16
|
-
from typing import Optional
|
|
17
|
-
|
|
18
|
-
# Suppress noisy Jupyter / Python 3.12+ deprecation warnings (e.g. datetime.utcnow in jupyter_client)
|
|
19
|
-
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
20
|
-
warnings.filterwarnings("ignore", category=FutureWarning)
|
|
21
|
-
warnings.filterwarnings("ignore", module="jupyter_client.*")
|
|
22
|
-
warnings.filterwarnings("ignore", module="ipykernel.*")
|
|
23
|
-
|
|
24
|
-
from .config import load_config
|
|
25
|
-
from .agent import run_agent
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def _is_notebook() -> bool:
|
|
29
|
-
"""Check if code is running inside a Jupyter notebook or Google Colab."""
|
|
30
|
-
try:
|
|
31
|
-
from IPython import get_ipython
|
|
32
|
-
shell = get_ipython()
|
|
33
|
-
if shell is None:
|
|
34
|
-
return False
|
|
35
|
-
shell_name = shell.__class__.__name__
|
|
36
|
-
if "ZMQInteractiveShell" in shell_name or "Shell" in shell_name:
|
|
37
|
-
return True
|
|
38
|
-
return False
|
|
39
|
-
except Exception:
|
|
40
|
-
return False
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def _display_html(html_str: str):
|
|
44
|
-
"""Render rich HTML in Jupyter or Google Colab."""
|
|
45
|
-
try:
|
|
46
|
-
from IPython.display import HTML, display
|
|
47
|
-
display(HTML(html_str))
|
|
48
|
-
except Exception:
|
|
49
|
-
print(html_str)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def _display_markdown(md_str: str):
|
|
53
|
-
"""Render rich Markdown in Jupyter or Google Colab."""
|
|
54
|
-
try:
|
|
55
|
-
from IPython.display import Markdown, display
|
|
56
|
-
display(Markdown(md_str))
|
|
57
|
-
except Exception:
|
|
58
|
-
print(md_str)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def alpie_magic(line: str, cell: Optional[str] = None):
|
|
62
|
-
"""
|
|
63
|
-
%alpie <task> (line magic)
|
|
64
|
-
%%alpie (cell magic)
|
|
65
|
-
<multiline task>
|
|
66
|
-
"""
|
|
67
|
-
task = (cell if cell is not None and cell.strip() else line).strip()
|
|
68
|
-
if not task:
|
|
69
|
-
print("Usage: %alpie <task> OR %%alpie\\n<multiline task>")
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
cfg = load_config()
|
|
73
|
-
workdir = Path(".").resolve()
|
|
74
|
-
|
|
75
|
-
if _is_notebook():
|
|
76
|
-
_display_html(
|
|
77
|
-
f'<div style="border-left: 3px solid #60a5fa; padding: 6px 12px; background: rgba(96,165,250,0.08); border-radius: 4px; font-family: sans-serif; margin-bottom: 8px;">'
|
|
78
|
-
f'<strong style="color: #60a5fa;">⚡ AlpieCode Agent:</strong> {task[:120]}'
|
|
79
|
-
f'</div>'
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
run_agent(task, workdir, cfg, verbose=True)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def alpie_plan_magic(line: str, cell: Optional[str] = None):
|
|
86
|
-
"""%alpie_plan <task> — Generate a structured implementation plan without making edits."""
|
|
87
|
-
task = (cell if cell is not None and cell.strip() else line).strip()
|
|
88
|
-
if not task:
|
|
89
|
-
print("Usage: %alpie_plan <task>")
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
plan_task = (
|
|
93
|
-
f"PLANNING ONLY — Do NOT make any file edits. "
|
|
94
|
-
f"Analyze the codebase and create a detailed implementation plan for the following task. "
|
|
95
|
-
f"Use list_files, read_file, and file_search to understand the project. "
|
|
96
|
-
f"Then use update_plan to write a structured plan with deliverables and checks. "
|
|
97
|
-
f"Finish with DONE: when the plan is complete.\n\n"
|
|
98
|
-
f"Task: {task}"
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
cfg = load_config()
|
|
102
|
-
workdir = Path(".").resolve()
|
|
103
|
-
run_agent(plan_task, workdir, cfg, verbose=True)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def alpie_explain_magic(line: str):
|
|
107
|
-
"""%alpie_explain <file_path_or_concept> — Explain code or architecture."""
|
|
108
|
-
target = line.strip()
|
|
109
|
-
if not target:
|
|
110
|
-
print("Usage: %alpie_explain <file_path_or_concept>")
|
|
111
|
-
return
|
|
112
|
-
|
|
113
|
-
cfg = load_config()
|
|
114
|
-
workdir = Path(".").resolve()
|
|
115
|
-
target_path = workdir / target if not Path(target).is_absolute() else Path(target)
|
|
116
|
-
|
|
117
|
-
if target_path.exists() and target_path.is_file():
|
|
118
|
-
content = target_path.read_text(encoding="utf-8", errors="replace")
|
|
119
|
-
explain_task = (
|
|
120
|
-
f"EXPLANATION ONLY — Do NOT make any file edits.\n\n"
|
|
121
|
-
f"Please explain the file `{target}` in detail:\n"
|
|
122
|
-
f"1. Overview of its purpose and role\n"
|
|
123
|
-
f"2. Key functions, classes, and internal logic\n"
|
|
124
|
-
f"3. Dependencies and how it connects to the project\n"
|
|
125
|
-
f"4. Step-by-step walkthrough of how it executes\n\n"
|
|
126
|
-
f"File content ({target}):\n```\n{content[:16000]}\n```"
|
|
127
|
-
)
|
|
128
|
-
else:
|
|
129
|
-
explain_task = (
|
|
130
|
-
f"EXPLANATION ONLY — Do NOT make any file edits.\n\n"
|
|
131
|
-
f"Explain the following codebase concept or architecture in detail:\n"
|
|
132
|
-
f"Topic: {target}\n\n"
|
|
133
|
-
f"Use read_file or file_search if needed to understand codebase context."
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
run_agent(explain_task, workdir, cfg, verbose=True)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def alpie_doctor_magic(line: str = ""):
|
|
140
|
-
"""%alpie_doctor — Run system health diagnostic checks."""
|
|
141
|
-
from .doctor import run_doctor
|
|
142
|
-
run_doctor()
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def load_ipython_extension(ipython):
|
|
146
|
-
"""Called by IPython when user runs `%load_ext alpiecode`."""
|
|
147
|
-
ipython.register_magic_function(alpie_magic, magic_kind="line_cell", magic_name="alpie")
|
|
148
|
-
ipython.register_magic_function(alpie_plan_magic, magic_kind="line_cell", magic_name="alpie_plan")
|
|
149
|
-
ipython.register_magic_function(alpie_explain_magic, magic_kind="line", magic_name="alpie_explain")
|
|
150
|
-
ipython.register_magic_function(alpie_doctor_magic, magic_kind="line", magic_name="alpie_doctor")
|
|
151
|
-
print("✨ AlpieCode IPython/Jupyter Extension Loaded! Try: %alpie <task> or %%alpie")
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def unload_ipython_extension(ipython):
|
|
155
|
-
"""Called when user runs `%unload_ext alpiecode`."""
|
|
156
|
-
pass
|
|
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
|