{"repo": "blackeagle686/giyu-agent", "files": {"giyu.context.json": {"d33e86253d58e98045be06d06c8f339f846febbb": {"t": 1785599328.010131, "n": 3459, "h": "105d12aa50bbb697", "c": "{\n \"context_id\": \"79b03dea-a7be-40c1-a301-369a6c022350\",\n \"metadata\": {\n \"created_at\": \"2026-05-12T04:37:01.664344\",\n \"updated_at\": \"2026-05-12T04:41:16.332643\",\n \"original_prompt\": \"what is the ram stauts\"\n },\n \"tasks\": [\n {\n \"id\": 1,\n \"priority\": 1,\n \"title\": \"Retrieve Current RAM Usage\",\n \"description\": \"Execute system command to obtain real-time memory utilization data for stability assessment.\",\n \"status\": \"failed\",\n \"type\": \"command\"\n }\n ],\n \"plans\": [\n {\n \"plan_step_id\": 1,\n \"task_id\": 1,\n \"step_index\": 1,\n \"type\": \"analysis\",\n \"solution\": {\n \"approach\": \"Analyze the task to understand the requirement: retrieve real-time RAM usage for system stability assessment. Identify that this is a monitoring/diagnostic task and should leverage existing CLI tools rather than writing new Python code.\",\n \"algorithm\": null,\n \"complexity\": \"O(1)\"\n },\n \"dependencies\": [],\n \"status\": \"failed\"\n },\n {\n \"plan_step_id\": 2,\n \"task_id\": 1,\n \"step_index\": 2,\n \"type\": \"design\",\n \"solution\": {\n \"approach\": \"Design the solution using standard Unix/Linux system commands. Use `free -h` command which provides human-readable memory information including total, used, free, shared, buff/cache, and available RAM. This command gives immediate real-time data suitable for stability assessment.\",\n \"algorithm\": null,\n \"complexity\": \"O(1)\"\n },\n \"dependencies\": [\n 1\n ],\n \"status\": \"pending\"\n },\n {\n \"plan_step_id\": 3,\n \"task_id\": 1,\n \"step_index\": 3,\n \"type\": \"implementation\",\n \"solution\": {\n \"approach\": \"Execute the `free -h` command via run_shell_command to capture current RAM usage statistics. The output will be displayed directly without redirection to files, showing memory utilization in human-readable format.\",\n \"algorithm\": null,\n \"complexity\": \"O(1)\"\n },\n \"dependencies\": [\n 2\n ],\n \"status\": \"pending\"\n },\n {\n \"plan_step_id\": 4,\n \"task_id\": 1,\n \"step_index\": 4,\n \"type\": \"validation\",\n \"solution\": {\n \"approach\": \"Validate the output by checking that the command executed successfully (exit code 0) and that the response contains expected memory metrics (total, used, free, available). Ensure no errors are present in stderr.\",\n \"algorithm\": null,\n \"complexity\": \"O(1)\"\n },\n \"dependencies\": [\n 3\n ],\n \"status\": \"pending\"\n }\n ],\n \"generations\": [],\n \"execution_state\": {\n \"completed_steps\": [],\n \"pending_steps\": [],\n \"failed_steps\": [\n {\n \"id\": 1,\n \"title\": \"Retrieve Current RAM Usage\"\n }\n ]\n },\n \"memory\": {},\n \"stability_reports\": [\n {\n \"score\": 100.0,\n \"state\": \"stable\",\n \"timestamp\": 1778549821.6643445,\n \"metrics_evaluated\": [\n \"cpu\",\n \"ram\",\n \"disk\"\n ],\n \"escalation_level\": \"ignore\",\n \"necessity\": \"low\",\n \"decision_reason\": \"Stability score is 100.0\",\n \"metrics\": {\n \"cpu_usage\": 50,\n \"ram_usage\": 50,\n \"disk_usage\": 50,\n \"net_latency\": 0,\n \"process_count\": 0\n }\n }\n ],\n \"anomalies\": [],\n \"escalation_state\": {\n \"current_level\": \"ignore\",\n \"reason\": \"Stability score is 100.0\",\n \"timestamp\": \"2026-05-12T04:37:23.152846\"\n }\n}"}}, "giyu/backend/routes_chat.py": {"e02c8eada04b5d1cdef4f4fb9fd520b10987c4b6": {"t": 1785599328.0137963, "n": 3114, "h": "adb2f2051468f3da", "c": "\"\"\"\nGiyu Backend β Chat & Agent streaming endpoints.\n\"\"\"\nimport asyncio\nimport json\nimport uuid\nfrom fastapi import APIRouter\nfrom fastapi.responses import StreamingResponse\n\nfrom .state import (\n log, vscode_ipc_context, _pending_file_opens,\n get_agent, _ipc_responses,\n)\nfrom .schemas import ChatRequest, ToolResult\n\nrouter = APIRouter()\n\n\n@router.post(\"/chat/stream\")\nasync def chat_stream(req: ChatRequest):\n \"\"\"Stream agent response as Server-Sent Events.\"\"\"\n agent = get_agent()\n if agent is None:\n async def _error():\n yield f\"data: {json.dumps({'type':'error','content':'Agent not ready.'})}\\n\\n\"\n return StreamingResponse(_error(), media_type=\"text/event-stream\")\n\n session_id = req.session_id or str(uuid.uuid4())\n queue: asyncio.Queue = asyncio.Queue()\n\n async def _emit_event(event: dict):\n await queue.put(event)\n\n async def _vscode_call(tool_name: str, arguments: dict) -> str:\n call_id = str(uuid.uuid4())\n future = asyncio.get_event_loop().create_future()\n _ipc_responses[call_id] = future\n\n await _emit_event({\n \"type\": \"vscode_tool\",\n \"call_id\": call_id,\n \"tool\": tool_name,\n \"arguments\": arguments,\n })\n\n try:\n return await asyncio.wait_for(future, timeout=60.0)\n except asyncio.TimeoutError:\n return \"ERROR: VS Code tool call timed out.\"\n finally:\n _ipc_responses.pop(call_id, None)\n\n async def _run_agent():\n token = vscode_ipc_context.set(_vscode_call)\n try:\n async for event in agent.run_stream(\n req.task, session_id=session_id, mode=req.mode\n ):\n await queue.put(event)\n except Exception as exc:\n log.exception(\"Stream error\")\n await queue.put({\"type\": \"error\", \"content\": str(exc)})\n finally:\n vscode_ipc_context.reset(token)\n await queue.put({\"type\": \"done\"})\n\n async def _generate():\n agent_task = asyncio.create_task(_run_agent())\n yield f\"data: {json.dumps({'type':'session','session_id':session_id})}\\n\\n\"\n\n while True:\n while _pending_file_opens:\n file_path = _pending_file_opens.popleft()\n yield f\"data: {json.dumps({'type':'vscode_tool','call_id':'noop','tool':'open_file','arguments':{'path': file_path}})}\\n\\n\"\n\n event = await queue.get()\n yield f\"data: {json.dumps(event)}\\n\\n\"\n if event.get(\"type\") == \"done\":\n break\n\n await agent_task\n\n return StreamingResponse(_generate(), media_type=\"text/event-stream\")\n\n\n@router.post(\"/tool/result\")\nasync def tool_result(res: ToolResult):\n \"\"\"Receive results for pending VS Code tool calls.\"\"\"\n if res.call_id in _ipc_responses:\n _ipc_responses[res.call_id].set_result(res.result)\n return {\"status\": \"ok\"}\n return {\"status\": \"error\", \"message\": \"Call ID not found or already timed out.\"}\n\n\n@router.post(\"/reset\")\nasync def reset_session():\n return {\"status\": \"reset\"}\n"}}, "dashboard/main.js": {"27f1c83b0564ebd9362192c007405b3c177e79e5": {"t": 1785599328.1776156, "n": 21748, "h": "0843a4681898c1c2", "c": "const API_BASE = 'http://127.0.0.1:8765';\nlet cpuChart, ramChart, diskChart, netChart, scoreChart;\nconst historySize = 20;\n\nconst charts = {\n cpu: { instance: null, data: Array(historySize).fill(0) },\n ram: { instance: null, data: Array(historySize).fill(0) },\n disk: { instance: null, data: Array(historySize).fill(0) },\n net: { instance: null, data: Array(historySize).fill(0) }\n};\n\nlet isStreaming = false;\n\n// Colors from style.css\nconst COLORS = {\n primary: '#00f2ff',\n secondary: '#7000ff',\n success: '#10b981',\n warning: '#f59e0b',\n danger: '#ef4444',\n ghost: '#475569'\n};\n\nfunction initCharts() {\n const commonOptions = {\n responsive: true,\n maintainAspectRatio: false,\n plugins: { legend: { display: false }, tooltip: { enabled: false } },\n scales: {\n x: { display: false },\n y: { display: false, min: 0, max: 100 }\n },\n elements: {\n line: { \n tension: 0.4, \n borderWidth: 2, \n borderColor: COLORS.primary, \n fill: true, \n backgroundColor: 'rgba(0, 242, 255, 0.05)' \n },\n point: { radius: 0 }\n },\n animation: { duration: 1000 }\n };\n\n charts.cpu.instance = new Chart(document.getElementById('cpuChart'), {\n type: 'line',\n data: { labels: Array(historySize).fill(''), datasets: [{ data: charts.cpu.data }] },\n options: commonOptions\n });\n\n charts.ram.instance = new Chart(document.getElementById('ramChart'), {\n type: 'line',\n data: { labels: Array(historySize).fill(''), datasets: [{ data: charts.ram.data }] },\n options: commonOptions\n });\n\n charts.disk.instance = new Chart(document.getElementById('diskChart'), {\n type: 'line',\n data: { labels: Array(historySize).fill(''), datasets: [{ data: charts.disk.data }] },\n options: commonOptions\n });\n\n charts.net.instance = new Chart(document.getElementById('netChart'), {\n type: 'line',\n data: { labels: Array(historySize).fill(''), datasets: [{ data: charts.net.data }] },\n options: commonOptions\n });\n\n // Score Doughnut Chart\n scoreChart = new Chart(document.getElementById('scoreChart'), {\n type: 'doughnut',\n data: {\n datasets: [{\n data: [0, 100],\n backgroundColor: [COLORS.primary, 'rgba(255, 255, 255, 0.03)'],\n borderWidth: 0,\n circumference: 270,\n rotation: 225,\n cutout: '85%'\n }]\n },\n options: {\n responsive: true,\n maintainAspectRatio: false,\n plugins: { tooltip: { enabled: false } },\n animation: { animateRotate: true, duration: 2000 }\n }\n });\n}\n\nfunction updateClock() {\n const now = new Date();\n document.getElementById('clock').textContent = now.toLocaleTimeString([], { hour12: false });\n}\n\nlet lastDataHash = '';\nlet localReports = [];\n\nasync function updateData() {\n if (isStreaming) return; // Prevent background sync from wiping active chat\n try {\n const healthRes = await fetch(`${API_BASE}/health`);\n const health = await healthRes.json();\n \n const overlay = document.getElementById('loading-overlay');\n if (health.agent_ready) {\n overlay.classList.add('hidden');\n } else {\n overlay.classList.remove('hidden');\n return;\n }\n\n const statusRes = await fetch(`${API_BASE}/stability/status`);\n const status = await statusRes.json();\n const backboneRes = await fetch(`${API_BASE}/stability/backbone`);\n const backbone = await backboneRes.json();\n\n const currentHash = JSON.stringify({status, backbone});\n if (currentHash === lastDataHash) return;\n lastDataHash = currentHash;\n\n updateStabilityUI(status.current_report);\n updateMetrics(status.current_report);\n updateHeartbeat(status.agent_heartbeats);\n updateTasks(backbone.tasks, backbone.plans);\n updateLogs(backbone.stability_reports);\n updateReports(backbone.generations);\n\n } catch (error) {\n console.warn('Sync failed:', error);\n }\n}\n\nfunction updateStabilityUI(report) {\n const score = Math.round(report.score);\n const scoreEl = document.getElementById('stability-score');\n const stateEl = document.getElementById('stability-state');\n \n scoreEl.textContent = score;\n stateEl.textContent = report.state.toUpperCase();\n document.getElementById('anomaly-count').textContent = report.anomalies?.length || 0;\n\n scoreChart.data.datasets[0].data = [score, 100 - score];\n let color = COLORS.primary;\n if (score < 50) color = COLORS.danger;\n else if (score < 80) color = COLORS.warning;\n \n scoreChart.data.datasets[0].backgroundColor[0] = color;\n scoreChart.update('none');\n\n stateEl.style.color = color;\n scoreEl.style.color = color;\n}\n\nfunction updateMetrics(report) {\n const metrics = report.metrics || {};\n const values = {\n cpu: metrics.cpu_usage || 0,\n ram: metrics.ram_usage || 0,\n disk: metrics.disk_usage || 0,\n net: metrics.net_latency || 0\n };\n\n document.getElementById('cpu-value').textContent = Math.round(values.cpu);\n document.getElementById('ram-value').textContent = Math.round(values.ram);\n document.getElementById('disk-value').textContent = Math.round(values.disk);\n document.getElementById('net-value').textContent = Math.round(values.net);\n\n updateChart(charts.cpu, values.cpu);\n updateChart(charts.ram, values.ram);\n updateChart(charts.disk, values.disk);\n updateChart(charts.net, values.net);\n}\n\nfunction updateChart(chartObj, newValue) {\n chartObj.data.push(newValue);\n chartObj.data.shift();\n chartObj.instance.update('none');\n}\n\nfunction updateHeartbeat(heartbeats) {\n if (!heartbeats) return;\n const grid = document.getElementById('heartbeat-grid');\n const fragment = document.createDocumentFragment();\n \n Object.entries(heartbeats).forEach(([name, status]) => {\n const node = document.createElement('div');\n node.className = `agent-dot ${status === 'active' ? '' : 'missing'}`;\n node.innerHTML = `\n
\n ${name}\n `;\n fragment.appendChild(node);\n });\n grid.innerHTML = '';\n grid.appendChild(fragment);\n}\n\nfunction updateTasks(tasks, plans) {\n const list = document.getElementById('task-list');\n if (!tasks || tasks.length === 0) return;\n\n const fragment = document.createDocumentFragment();\n tasks.forEach(task => {\n const taskEl = document.createElement('div');\n taskEl.className = `step ${task.status === 'in_progress' ? 'active' : (task.status === 'done' ? 'done' : '')}`;\n \n let planHtml = '';\n const taskPlans = (plans || []).filter(p => p.task_id === task.id);\n if (taskPlans.length > 0) {\n planHtml = `${task.description || ''}
\n ${planHtml}\n