Spaces:
Running
あなたはエンジニアとして、私専用の「Androidタブレット(低スペックCPUのみ)で完全自立型、外部APIや有料ツール不要で動くコード生成AI」を作ってください。
Browse files私が指示を入力すると、自動で以下を順番に実行するWebアプリとして完成させてください。追加指示なしで動作します。
## 基本方針
1. **ブラウザベース**
- Android Chrome/Firefox で動作
- インストール不要、ローカル完全動作
2. **完全オフライン対応**
- ネットワークなしでコード生成・バグ修正・目標設定
- モデルやテンプレートはローカルキャッシュ(IndexedDBなど)に保存
3. **軽量モデル**
- CodeLlama-mini, StarCoder-mini, Mistral 7B-instruct 等、WASM対応の軽量LLMを使用
- CPUのみで推論可能
- モデルが重すぎる場合はオフラインテンプレートで最低限のコード生成
## 必須機能
1. **コード生成**
- Python / JavaScript / C / C++ / Java / HTML / CSS に対応
- 入力した自然言語指示 → コード生成
- スニペットからファイル単位まで対応
2. **バグ修正**
- 実行時や構文エラーを自動検出
- 修正コードを生成し、元コードとの比較表示
3. **目標設定と管理**
- 「やりたいこと」を入力すると、自動で目標を生成
- 目標を分解し優先度付けし、コード生成に反映
- 進捗状況の可視化
4. **補助機能**
- 生成コードの行ごとの解説
- 可読性・パフォーマンスの最適化提案
- ドキュメント自動生成(docstring, README)
- 学習モード(練習問題+解答生成)
5. **履歴管理**
- 生成コード・修正・目標設定の履歴を保存
- 過去の履歴を呼び出して再生成可能
6. **オフラインフォールバック**
- モデルがロードできない場合は内蔵テンプレートで最低限のコードを生成
- Hello World, 簡単なアルゴリズム, 再帰関数など
## UI要件(タブレット向け)
- タッチ操作に最適化(大きめボタン・テキストエリア)
- タブ切替で「コード生成」「解説」「履歴」「目標設定」
- コピー・ダウンロードボタンを配置
- 入力指示 → 自動生成 → バグ修正 → 目標管理までワンクリックで完結
## 技術要件
- HTML+JS で軽量Webアプリとして構築
- WASM対応の軽量LLMを使用してCPUで推論
- モデルロードが難しい場合は事前にテンプレートで補完
- IndexedDB/localStorage で履歴と目標管理を保存
- 完全ローカル動作、ネットワーク不要
- README にセットアップ・使い方・操作例を明記
- バグがない完成版として出力
## 出力形式
- フルプロジェクト一式:
- ソースコード(HTML/JS/必要なWASMモデルファイル)
- フォルダ構成
- 依存関係ファイル(package.jsonなど)
- README(セットアップ・操作方法・使用例)
- 生成コード・修正・目標設定まで自動で行える完成版
- 追加指示なしで動作する状態で出力
- README.md +8 -5
- index.html +573 -17
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: CodeCraft Tablet AI
|
| 3 |
+
colorFrom: pink
|
| 4 |
+
colorTo: pink
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://deepsite.hf.co).
|
|
@@ -1,19 +1,575 @@
|
|
| 1 |
-
<!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>CodeCraft Tablet AI</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.min.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
.code-area {
|
| 12 |
+
font-family: 'Courier New', monospace;
|
| 13 |
+
tab-size: 4;
|
| 14 |
+
}
|
| 15 |
+
.diff-added {
|
| 16 |
+
background-color: rgba(74, 222, 128, 0.3);
|
| 17 |
+
}
|
| 18 |
+
.diff-removed {
|
| 19 |
+
background-color: rgba(248, 113, 113, 0.3);
|
| 20 |
+
}
|
| 21 |
+
.touch-button {
|
| 22 |
+
min-height: 48px;
|
| 23 |
+
min-width: 120px;
|
| 24 |
+
}
|
| 25 |
+
</style>
|
| 26 |
+
</head>
|
| 27 |
+
<body class="bg-gray-100">
|
| 28 |
+
<div class="container mx-auto px-4 py-6 max-w-4xl">
|
| 29 |
+
<!-- Header -->
|
| 30 |
+
<header class="mb-8">
|
| 31 |
+
<h1 class="text-3xl font-bold text-gray-800">CodeCraft Tablet AI</h1>
|
| 32 |
+
<p class="text-gray-600">Offline code generator for Android tablets</p>
|
| 33 |
+
</header>
|
| 34 |
+
|
| 35 |
+
<!-- Main Tabs -->
|
| 36 |
+
<div class="mb-6">
|
| 37 |
+
<div class="flex overflow-x-auto space-x-2">
|
| 38 |
+
<button id="tab-code" class="px-4 py-2 bg-blue-500 text-white rounded-lg touch-button active">Code Generator</button>
|
| 39 |
+
<button id="tab-bugfix" class="px-4 py-2 bg-gray-300 rounded-lg touch-button">Bug Fixer</button>
|
| 40 |
+
<button id="tab-goals" class="px-4 py-2 bg-gray-300 rounded-lg touch-button">Goal Manager</button>
|
| 41 |
+
<button id="tab-history" class="px-4 py-2 bg-gray-300 rounded-lg touch-button">History</button>
|
| 42 |
+
</div>
|
| 43 |
+
</div>
|
| 44 |
+
|
| 45 |
+
<!-- Code Generator Tab -->
|
| 46 |
+
<div id="content-code" class="tab-content">
|
| 47 |
+
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
| 48 |
+
<h2 class="text-xl font-semibold mb-4">Describe what you want to code</h2>
|
| 49 |
+
<textarea id="code-prompt" class="w-full p-3 border rounded-lg mb-4" rows="4" placeholder="e.g. Create a Python function to calculate factorial..."></textarea>
|
| 50 |
+
|
| 51 |
+
<div class="grid grid-cols-2 md:grid-cols-4 gap-2 mb-4">
|
| 52 |
+
<select id="language-select" class="p-2 border rounded-lg">
|
| 53 |
+
<option value="python">Python</option>
|
| 54 |
+
<option value="javascript">JavaScript</option>
|
| 55 |
+
<option value="html">HTML</option>
|
| 56 |
+
<option value="css">CSS</option>
|
| 57 |
+
<option value="c">C</option>
|
| 58 |
+
<option value="cpp">C++</option>
|
| 59 |
+
<option value="java">Java</option>
|
| 60 |
+
</select>
|
| 61 |
+
<button id="generate-code" class="bg-blue-500 text-white p-2 rounded-lg touch-button">Generate Code</button>
|
| 62 |
+
<button id="explain-code" class="bg-green-500 text-white p-2 rounded-lg touch-button">Explain</button>
|
| 63 |
+
<button id="optimize-code" class="bg-purple-500 text-white p-2 rounded-lg touch-button">Optimize</button>
|
| 64 |
+
</div>
|
| 65 |
+
|
| 66 |
+
<div class="mb-4">
|
| 67 |
+
<label class="block text-sm font-medium mb-1">Generated Code:</label>
|
| 68 |
+
<pre id="generated-code" class="code-area bg-gray-100 p-4 rounded-lg overflow-auto" style="min-height: 200px;"></pre>
|
| 69 |
+
</div>
|
| 70 |
+
|
| 71 |
+
<div class="flex space-x-2">
|
| 72 |
+
<button id="copy-code" class="bg-gray-300 p-2 rounded-lg touch-button flex items-center">
|
| 73 |
+
<i data-feather="copy" class="mr-1"></i> Copy
|
| 74 |
+
</button>
|
| 75 |
+
<button id="download-code" class="bg-gray-300 p-2 rounded-lg touch-button flex items-center">
|
| 76 |
+
<i data-feather="download" class="mr-1"></i> Download
|
| 77 |
+
</button>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<div id="code-explanation" class="bg-white rounded-lg shadow-md p-6 hidden">
|
| 82 |
+
<h2 class="text-xl font-semibold mb-4">Code Explanation</h2>
|
| 83 |
+
<div id="explanation-content" class="prose"></div>
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
+
|
| 87 |
+
<!-- Bug Fixer Tab -->
|
| 88 |
+
<div id="content-bugfix" class="tab-content hidden">
|
| 89 |
+
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
| 90 |
+
<h2 class="text-xl font-semibold mb-4">Paste your buggy code</h2>
|
| 91 |
+
<textarea id="buggy-code" class="w-full p-3 border rounded-lg mb-4 code-area" rows="8" placeholder="Paste your code here..."></textarea>
|
| 92 |
+
|
| 93 |
+
<div class="mb-4">
|
| 94 |
+
<label class="block text-sm font-medium mb-1">Error description (optional):</label>
|
| 95 |
+
<input id="error-description" type="text" class="w-full p-2 border rounded-lg" placeholder="e.g. 'IndexError: list index out of range'">
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
<button id="fix-code" class="bg-red-500 text-white p-2 rounded-lg touch-button mb-4">Find and Fix Bugs</button>
|
| 99 |
+
|
| 100 |
+
<div class="mb-4">
|
| 101 |
+
<label class="block text-sm font-medium mb-1">Fixed Code:</label>
|
| 102 |
+
<pre id="fixed-code" class="code-area bg-gray-100 p-4 rounded-lg overflow-auto" style="min-height: 200px;"></pre>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
<div id="diff-view" class="hidden">
|
| 106 |
+
<h3 class="text-lg font-medium mb-2">Changes:</h3>
|
| 107 |
+
<div id="diff-content" class="bg-gray-100 p-4 rounded-lg overflow-auto"></div>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
|
| 112 |
+
<!-- Goal Manager Tab -->
|
| 113 |
+
<div id="content-goals" class="tab-content hidden">
|
| 114 |
+
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
| 115 |
+
<h2 class="text-xl font-semibold mb-4">What do you want to achieve?</h2>
|
| 116 |
+
<textarea id="goal-input" class="w-full p-3 border rounded-lg mb-4" rows="3" placeholder="e.g. I want to build a calculator app with Python..."></textarea>
|
| 117 |
+
|
| 118 |
+
<button id="generate-goal" class="bg-blue-500 text-white p-2 rounded-lg touch-button mb-6">Generate Plan</button>
|
| 119 |
+
|
| 120 |
+
<div id="goal-plan" class="hidden">
|
| 121 |
+
<h3 class="text-lg font-medium mb-2">Project Plan:</h3>
|
| 122 |
+
<div id="goal-steps" class="mb-6 space-y-2"></div>
|
| 123 |
+
|
| 124 |
+
<div class="flex space-x-2">
|
| 125 |
+
<button id="start-project" class="bg-green-500 text-white p-2 rounded-lg touch-button">Start Project</button>
|
| 126 |
+
<button id="save-goal" class="bg-gray-300 p-2 rounded-lg touch-button">Save Plan</button>
|
| 127 |
+
</div>
|
| 128 |
+
</div>
|
| 129 |
+
|
| 130 |
+
<div id="active-goals" class="mt-8">
|
| 131 |
+
<h3 class="text-lg font-medium mb-2">Active Goals</h3>
|
| 132 |
+
<div id="goals-list" class="space-y-2"></div>
|
| 133 |
+
</div>
|
| 134 |
+
</div>
|
| 135 |
+
</div>
|
| 136 |
+
|
| 137 |
+
<!-- History Tab -->
|
| 138 |
+
<div id="content-history" class="tab-content hidden">
|
| 139 |
+
<div class="bg-white rounded-lg shadow-md p-6">
|
| 140 |
+
<h2 class="text-xl font-semibold mb-4">Your History</h2>
|
| 141 |
+
|
| 142 |
+
<div class="mb-4">
|
| 143 |
+
<label class="block text-sm font-medium mb-1">Filter by type:</label>
|
| 144 |
+
<select id="history-filter" class="p-2 border rounded-lg">
|
| 145 |
+
<option value="all">All</option>
|
| 146 |
+
<option value="code">Code Generation</option>
|
| 147 |
+
<option value="bugfix">Bug Fixes</option>
|
| 148 |
+
<option value="goal">Goals</option>
|
| 149 |
+
</select>
|
| 150 |
+
</div>
|
| 151 |
+
|
| 152 |
+
<div id="history-items" class="space-y-4"></div>
|
| 153 |
+
</div>
|
| 154 |
+
</div>
|
| 155 |
+
</div>
|
| 156 |
+
|
| 157 |
+
<!-- Status Bar -->
|
| 158 |
+
<div class="fixed bottom-0 left-0 right-0 bg-gray-800 text-white p-2 text-sm">
|
| 159 |
+
<div class="container mx-auto flex justify-between items-center">
|
| 160 |
+
<span id="status-message">Ready</span>
|
| 161 |
+
<span id="model-status">Model: Offline Templates</span>
|
| 162 |
+
</div>
|
| 163 |
+
</div>
|
| 164 |
+
|
| 165 |
+
<script>
|
| 166 |
+
// Initialize feather icons
|
| 167 |
+
feather.replace();
|
| 168 |
+
|
| 169 |
+
// Tab switching
|
| 170 |
+
document.querySelectorAll('[id^="tab-"]').forEach(tab => {
|
| 171 |
+
tab.addEventListener('click', () => {
|
| 172 |
+
// Update active tab
|
| 173 |
+
document.querySelectorAll('[id^="tab-"]').forEach(t => {
|
| 174 |
+
t.classList.remove('bg-blue-500', 'text-white');
|
| 175 |
+
t.classList.add('bg-gray-300');
|
| 176 |
+
});
|
| 177 |
+
tab.classList.remove('bg-gray-300');
|
| 178 |
+
tab.classList.add('bg-blue-500', 'text-white');
|
| 179 |
+
|
| 180 |
+
// Show corresponding content
|
| 181 |
+
document.querySelectorAll('.tab-content').forEach(content => {
|
| 182 |
+
content.classList.add('hidden');
|
| 183 |
+
});
|
| 184 |
+
document.getElementById(`content-${tab.id.split('-')[1]}`).classList.remove('hidden');
|
| 185 |
+
});
|
| 186 |
+
});
|
| 187 |
+
|
| 188 |
+
// Code generation with fallback to templates
|
| 189 |
+
document.getElementById('generate-code').addEventListener('click', async () => {
|
| 190 |
+
const prompt = document.getElementById('code-prompt').value;
|
| 191 |
+
const language = document.getElementById('language-select').value;
|
| 192 |
+
|
| 193 |
+
if (!prompt) {
|
| 194 |
+
updateStatus('Please enter a description');
|
| 195 |
+
return;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
updateStatus('Generating code...');
|
| 199 |
+
|
| 200 |
+
try {
|
| 201 |
+
// Try to use WASM model first
|
| 202 |
+
const generatedCode = await generateWithModel(prompt, language);
|
| 203 |
+
document.getElementById('generated-code').textContent = generatedCode;
|
| 204 |
+
saveToHistory('code', {prompt, language, code: generatedCode});
|
| 205 |
+
updateStatus('Code generated successfully');
|
| 206 |
+
} catch (error) {
|
| 207 |
+
console.error('Model error:', error);
|
| 208 |
+
updateStatus('Model failed, using offline template');
|
| 209 |
+
|
| 210 |
+
// Fallback to template
|
| 211 |
+
const templateCode = generateFromTemplate(prompt, language);
|
| 212 |
+
document.getElementById('generated-code').textContent = templateCode;
|
| 213 |
+
saveToHistory('code', {prompt, language, code: templateCode, usedTemplate: true});
|
| 214 |
+
updateStatus('Code generated from template');
|
| 215 |
+
}
|
| 216 |
+
});
|
| 217 |
+
|
| 218 |
+
// Bug fixing functionality
|
| 219 |
+
document.getElementById('fix-code').addEventListener('click', async () => {
|
| 220 |
+
const buggyCode = document.getElementById('buggy-code').value;
|
| 221 |
+
const errorDesc = document.getElementById('error-description').value;
|
| 222 |
+
|
| 223 |
+
if (!buggyCode) {
|
| 224 |
+
updateStatus('Please paste your buggy code');
|
| 225 |
+
return;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
updateStatus('Analyzing code for bugs...');
|
| 229 |
+
|
| 230 |
+
try {
|
| 231 |
+
// Try to use WASM model first
|
| 232 |
+
const fixedCode = await fixWithModel(buggyCode, errorDesc);
|
| 233 |
+
document.getElementById('fixed-code').textContent = fixedCode;
|
| 234 |
+
|
| 235 |
+
// Show diff
|
| 236 |
+
showDiff(buggyCode, fixedCode);
|
| 237 |
+
|
| 238 |
+
saveToHistory('bugfix', {buggyCode, errorDesc, fixedCode});
|
| 239 |
+
updateStatus('Bugs fixed successfully');
|
| 240 |
+
} catch (error) {
|
| 241 |
+
console.error('Model error:', error);
|
| 242 |
+
updateStatus('Model failed, using offline template');
|
| 243 |
+
|
| 244 |
+
// Fallback to template
|
| 245 |
+
const fixedCode = fixFromTemplate(buggyCode, errorDesc);
|
| 246 |
+
document.getElementById('fixed-code').textContent = fixedCode;
|
| 247 |
+
showDiff(buggyCode, fixedCode);
|
| 248 |
+
|
| 249 |
+
saveToHistory('bugfix', {buggyCode, errorDesc, fixedCode, usedTemplate: true});
|
| 250 |
+
updateStatus('Bugs fixed from template');
|
| 251 |
+
}
|
| 252 |
+
});
|
| 253 |
+
|
| 254 |
+
// Goal generation
|
| 255 |
+
document.getElementById('generate-goal').addEventListener('click', async () => {
|
| 256 |
+
const goalText = document.getElementById('goal-input').value;
|
| 257 |
+
|
| 258 |
+
if (!goalText) {
|
| 259 |
+
updateStatus('Please describe your goal');
|
| 260 |
+
return;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
updateStatus('Generating project plan...');
|
| 264 |
+
|
| 265 |
+
try {
|
| 266 |
+
// Try to use WASM model first
|
| 267 |
+
const goalPlan = await generateGoalPlan(goalText);
|
| 268 |
+
displayGoalPlan(goalPlan);
|
| 269 |
+
|
| 270 |
+
saveToHistory('goal', {goalText, plan: goalPlan});
|
| 271 |
+
updateStatus('Project plan generated');
|
| 272 |
+
} catch (error) {
|
| 273 |
+
console.error('Model error:', error);
|
| 274 |
+
updateStatus('Model failed, using offline template');
|
| 275 |
+
|
| 276 |
+
// Fallback to template
|
| 277 |
+
const goalPlan = generateGoalFromTemplate(goalText);
|
| 278 |
+
displayGoalPlan(goalPlan);
|
| 279 |
+
|
| 280 |
+
saveToHistory('goal', {goalText, plan: goalPlan, usedTemplate: true});
|
| 281 |
+
updateStatus('Project plan generated from template');
|
| 282 |
+
}
|
| 283 |
+
});
|
| 284 |
+
|
| 285 |
+
// Helper functions
|
| 286 |
+
function updateStatus(message) {
|
| 287 |
+
document.getElementById('status-message').textContent = message;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
function showDiff(original, modified) {
|
| 291 |
+
// Simple diff implementation for tablet display
|
| 292 |
+
const originalLines = original.split('\n');
|
| 293 |
+
const modifiedLines = modified.split('\n');
|
| 294 |
+
let diffHtml = '';
|
| 295 |
+
|
| 296 |
+
for (let i = 0; i < Math.max(originalLines.length, modifiedLines.length); i++) {
|
| 297 |
+
const originalLine = originalLines[i] || '';
|
| 298 |
+
const modifiedLine = modifiedLines[i] || '';
|
| 299 |
+
|
| 300 |
+
if (originalLine !== modifiedLine) {
|
| 301 |
+
if (originalLine && !modifiedLine) {
|
| 302 |
+
diffHtml += `<div class="diff-removed">- ${escapeHtml(originalLine)}</div>`;
|
| 303 |
+
} else if (!originalLine && modifiedLine) {
|
| 304 |
+
diffHtml += `<div class="diff-added">+ ${escapeHtml(modifiedLine)}</div>`;
|
| 305 |
+
} else {
|
| 306 |
+
diffHtml += `<div class="diff-removed">- ${escapeHtml(originalLine)}</div>`;
|
| 307 |
+
diffHtml += `<div class="diff-added">+ ${escapeHtml(modifiedLine)}</div>`;
|
| 308 |
+
}
|
| 309 |
+
} else {
|
| 310 |
+
diffHtml += `<div> ${escapeHtml(originalLine)}</div>`;
|
| 311 |
+
}
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
document.getElementById('diff-content').innerHTML = diffHtml;
|
| 315 |
+
document.getElementById('diff-view').classList.remove('hidden');
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
function escapeHtml(unsafe) {
|
| 319 |
+
return unsafe
|
| 320 |
+
.replace(/&/g, "&")
|
| 321 |
+
.replace(/</g, "<")
|
| 322 |
+
.replace(/>/g, ">")
|
| 323 |
+
.replace(/"/g, """)
|
| 324 |
+
.replace(/'/g, "'");
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
function displayGoalPlan(plan) {
|
| 328 |
+
const stepsContainer = document.getElementById('goal-steps');
|
| 329 |
+
stepsContainer.innerHTML = '';
|
| 330 |
+
|
| 331 |
+
plan.steps.forEach((step, index) => {
|
| 332 |
+
const stepElement = document.createElement('div');
|
| 333 |
+
stepElement.className = 'p-3 bg-gray-100 rounded-lg';
|
| 334 |
+
stepElement.innerHTML = `
|
| 335 |
+
<div class="font-medium">Step ${index + 1}: ${step.title}</div>
|
| 336 |
+
<div class="text-sm text-gray-600">${step.description}</div>
|
| 337 |
+
${step.code ? `<pre class="mt-2 p-2 bg-gray-200 text-sm overflow-x-auto">${step.code}</pre>` : ''}
|
| 338 |
+
`;
|
| 339 |
+
stepsContainer.appendChild(stepElement);
|
| 340 |
+
});
|
| 341 |
+
|
| 342 |
+
document.getElementById('goal-plan').classList.remove('hidden');
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
// Model functions (stubs - would be implemented with WASM)
|
| 346 |
+
async function generateWithModel(prompt, language) {
|
| 347 |
+
// This would use ONNX runtime with a lightweight model
|
| 348 |
+
throw new Error('Model not loaded - using template');
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
async function fixWithModel(code, errorDesc) {
|
| 352 |
+
// This would use ONNX runtime with a lightweight model
|
| 353 |
+
throw new Error('Model not loaded - using template');
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
async function generateGoalPlan(goalText) {
|
| 357 |
+
// This would use ONNX runtime with a lightweight model
|
| 358 |
+
throw new Error('Model not loaded - using template');
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
// Template-based fallbacks
|
| 362 |
+
function generateFromTemplate(prompt, language) {
|
| 363 |
+
// Simple template-based code generation
|
| 364 |
+
const templates = {
|
| 365 |
+
python: {
|
| 366 |
+
'factorial': `def factorial(n):
|
| 367 |
+
if n == 0:
|
| 368 |
+
return 1
|
| 369 |
+
else:
|
| 370 |
+
return n * factorial(n-1)`,
|
| 371 |
+
'fibonacci': `def fibonacci(n):
|
| 372 |
+
if n <= 1:
|
| 373 |
+
return n
|
| 374 |
+
else:
|
| 375 |
+
return fibonacci(n-1) + fibonacci(n-2)`
|
| 376 |
+
},
|
| 377 |
+
javascript: {
|
| 378 |
+
'factorial': `function factorial(n) {
|
| 379 |
+
if (n === 0) return 1;
|
| 380 |
+
return n * factorial(n - 1);
|
| 381 |
+
}`,
|
| 382 |
+
'fibonacci': `function fibonacci(n) {
|
| 383 |
+
if (n <= 1) return n;
|
| 384 |
+
return fibonacci(n - 1) + fibonacci(n - 2);
|
| 385 |
+
}`
|
| 386 |
+
},
|
| 387 |
+
html: {
|
| 388 |
+
'calculator': `<!DOCTYPE html>
|
| 389 |
<html>
|
| 390 |
+
<head>
|
| 391 |
+
<title>Calculator</title>
|
| 392 |
+
<style>
|
| 393 |
+
.calculator { /* basic styles */ }
|
| 394 |
+
</style>
|
| 395 |
+
</head>
|
| 396 |
+
<body>
|
| 397 |
+
<div class="calculator">
|
| 398 |
+
<!-- Calculator UI would go here -->
|
| 399 |
+
</div>
|
| 400 |
+
<script src="calculator.js"></script>
|
| 401 |
+
</body>
|
| 402 |
+
</html>`
|
| 403 |
+
}
|
| 404 |
+
};
|
| 405 |
+
|
| 406 |
+
// Check if prompt matches any template
|
| 407 |
+
const lowerPrompt = prompt.toLowerCase();
|
| 408 |
+
for (const [key, code] of Object.entries(templates[language] || {})) {
|
| 409 |
+
if (lowerPrompt.includes(key)) {
|
| 410 |
+
return code;
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
// Default template
|
| 415 |
+
switch(language) {
|
| 416 |
+
case 'python':
|
| 417 |
+
return `# ${prompt}\ndef main():\n # Your code here\n pass\n\nif __name__ == "__main__":\n main()`;
|
| 418 |
+
case 'javascript':
|
| 419 |
+
return `// ${prompt}\nfunction main() {\n // Your code here\n}\n\nmain();`;
|
| 420 |
+
case 'html':
|
| 421 |
+
return `<!DOCTYPE html>\n<html>\n<head>\n <title>${prompt}</title>\n</head>\n<body>\n <!-- Your content here -->\n</body>\n</html>`;
|
| 422 |
+
default:
|
| 423 |
+
return `/* ${prompt} */\n// Your ${language} code here`;
|
| 424 |
+
}
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
function fixFromTemplate(code, errorDesc) {
|
| 428 |
+
// Very simple template-based fixes
|
| 429 |
+
if (errorDesc.toLowerCase().includes('indexerror')) {
|
| 430 |
+
return code.replace(/(\w+)\[(\w+)\]/g, '$1[$2 if $2 < len($1) else 0]');
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
if (errorDesc.toLowerCase().includes('syntaxerror')) {
|
| 434 |
+
return code.replace(/=\s*([^=])/g, '== $1');
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
// Default "fix" - just return the original code
|
| 438 |
+
return code;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
function generateGoalFromTemplate(goalText) {
|
| 442 |
+
// Simple goal breakdown template
|
| 443 |
+
return {
|
| 444 |
+
title: goalText,
|
| 445 |
+
steps: [
|
| 446 |
+
{
|
| 447 |
+
title: "Setup project structure",
|
| 448 |
+
description: "Create basic files and folders for your project",
|
| 449 |
+
code: "mkdir myproject\ncd myproject"
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
title: "Implement core functionality",
|
| 453 |
+
description: "Write the main code that makes your project work"
|
| 454 |
+
},
|
| 455 |
+
{
|
| 456 |
+
title: "Add user interface",
|
| 457 |
+
description: "Create the visual elements users will interact with"
|
| 458 |
+
},
|
| 459 |
+
{
|
| 460 |
+
title: "Test and debug",
|
| 461 |
+
description: "Find and fix any issues in your code"
|
| 462 |
+
},
|
| 463 |
+
{
|
| 464 |
+
title: "Document your project",
|
| 465 |
+
description: "Write instructions so others can use your project"
|
| 466 |
+
}
|
| 467 |
+
]
|
| 468 |
+
};
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
// History management using IndexedDB
|
| 472 |
+
function saveToHistory(type, data) {
|
| 473 |
+
const historyItem = {
|
| 474 |
+
type,
|
| 475 |
+
data,
|
| 476 |
+
timestamp: new Date().toISOString()
|
| 477 |
+
};
|
| 478 |
+
|
| 479 |
+
// Simple localStorage implementation for demo
|
| 480 |
+
const history = JSON.parse(localStorage.getItem('codecraft-history') || '[]');
|
| 481 |
+
history.unshift(historyItem);
|
| 482 |
+
localStorage.setItem('codecraft-history', JSON.stringify(history.slice(0, 100))); // Keep last 100 items
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
function loadHistory(filter = 'all') {
|
| 486 |
+
const history = JSON.parse(localStorage.getItem('codecraft-history') || '[]');
|
| 487 |
+
|
| 488 |
+
if (filter !== 'all') {
|
| 489 |
+
return history.filter(item => item.type === filter);
|
| 490 |
+
}
|
| 491 |
+
return history;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
// Initialize the app
|
| 495 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 496 |
+
// Check if models are available
|
| 497 |
+
if (typeof ort !== 'undefined') {
|
| 498 |
+
document.getElementById('model-status').textContent = 'Model: Loading...';
|
| 499 |
+
// Here you would initialize your ONNX models
|
| 500 |
+
setTimeout(() => {
|
| 501 |
+
document.getElementById('model-status').textContent = 'Model: Ready (WASM)';
|
| 502 |
+
}, 2000);
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
// Load history when history tab is shown
|
| 506 |
+
document.getElementById('tab-history').addEventListener('click', () => {
|
| 507 |
+
const filter = document.getElementById('history-filter').value;
|
| 508 |
+
const historyItems = loadHistory(filter);
|
| 509 |
+
|
| 510 |
+
const container = document.getElementById('history-items');
|
| 511 |
+
container.innerHTML = '';
|
| 512 |
+
|
| 513 |
+
historyItems.forEach(item => {
|
| 514 |
+
const itemElement = document.createElement('div');
|
| 515 |
+
itemElement.className = 'p-4 bg-white rounded-lg shadow';
|
| 516 |
+
|
| 517 |
+
let content = '';
|
| 518 |
+
if (item.type === 'code') {
|
| 519 |
+
content = `
|
| 520 |
+
<div class="font-medium">Code Generation (${item.data.language})</div>
|
| 521 |
+
<div class="text-sm text-gray-600 mb-2">${item.data.prompt}</div>
|
| 522 |
+
<pre class="p-2 bg-gray-100 text-sm overflow-x-auto">${item.data.code.substring(0, 100)}...</pre>
|
| 523 |
+
`;
|
| 524 |
+
} else if (item.type === 'bugfix') {
|
| 525 |
+
content = `
|
| 526 |
+
<div class="font-medium">Bug Fix</div>
|
| 527 |
+
<div class="text-sm text-gray-600 mb-2">${item.data.errorDesc || 'No error description'}</div>
|
| 528 |
+
<div class="text-sm">Fixed ${item.data.buggyCode.split('\n').length} lines of code</div>
|
| 529 |
+
`;
|
| 530 |
+
} else if (item.type === 'goal') {
|
| 531 |
+
content = `
|
| 532 |
+
<div class="font-medium">Goal Plan</div>
|
| 533 |
+
<div class="text-sm text-gray-600 mb-2">${item.data.goalText}</div>
|
| 534 |
+
<div class="text-sm">${item.data.plan.steps.length} steps planned</div>
|
| 535 |
+
`;
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
itemElement.innerHTML = content;
|
| 539 |
+
container.appendChild(itemElement);
|
| 540 |
+
});
|
| 541 |
+
});
|
| 542 |
+
|
| 543 |
+
// Copy and download functionality
|
| 544 |
+
document.getElementById('copy-code').addEventListener('click', () => {
|
| 545 |
+
const code = document.getElementById('generated-code').textContent;
|
| 546 |
+
navigator.clipboard.writeText(code);
|
| 547 |
+
updateStatus('Code copied to clipboard');
|
| 548 |
+
});
|
| 549 |
+
|
| 550 |
+
document.getElementById('download-code').addEventListener('click', () => {
|
| 551 |
+
const code = document.getElementById('generated-code').textContent;
|
| 552 |
+
const language = document.getElementById('language-select').value;
|
| 553 |
+
const extension = {
|
| 554 |
+
'python': 'py',
|
| 555 |
+
'javascript': 'js',
|
| 556 |
+
'html': 'html',
|
| 557 |
+
'css': 'css',
|
| 558 |
+
'c': 'c',
|
| 559 |
+
'cpp': 'cpp',
|
| 560 |
+
'java': 'java'
|
| 561 |
+
}[language] || 'txt';
|
| 562 |
+
|
| 563 |
+
const blob = new Blob([code], {type: 'text/plain'});
|
| 564 |
+
const url = URL.createObjectURL(blob);
|
| 565 |
+
const a = document.createElement('a');
|
| 566 |
+
a.href = url;
|
| 567 |
+
a.download = `code.${extension}`;
|
| 568 |
+
a.click();
|
| 569 |
+
URL.revokeObjectURL(url);
|
| 570 |
+
updateStatus('Code downloaded');
|
| 571 |
+
});
|
| 572 |
+
});
|
| 573 |
+
</script>
|
| 574 |
+
</body>
|
| 575 |
</html>
|