ltcai 9.0.0 → 9.1.0

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.
Files changed (187) hide show
  1. package/README.md +80 -46
  2. package/auto_setup.py +7 -853
  3. package/desktop/electron/README.md +9 -0
  4. package/desktop/electron/main.cjs +5 -3
  5. package/docs/CHANGELOG.md +146 -2
  6. package/docs/COMMUNITY_AND_PLUGINS.md +3 -2
  7. package/docs/DEVELOPMENT.md +53 -14
  8. package/docs/LEGACY_COMPATIBILITY.md +4 -4
  9. package/docs/ONBOARDING.md +10 -2
  10. package/docs/OPERATIONS.md +8 -4
  11. package/docs/PRODUCT_DIRECTION_REVIEW.md +4 -0
  12. package/docs/TRUST_MODEL.md +5 -2
  13. package/docs/WHY_LATTICE.md +15 -10
  14. package/docs/WORKFLOW_DESIGNER.md +22 -0
  15. package/docs/kg-schema.md +13 -2
  16. package/docs/mcp-tools.md +17 -6
  17. package/docs/privacy.md +19 -3
  18. package/docs/public-deploy.md +32 -3
  19. package/docs/security-model.md +46 -11
  20. package/lattice_brain/__init__.py +1 -1
  21. package/lattice_brain/archive.py +1 -6
  22. package/lattice_brain/context.py +66 -9
  23. package/lattice_brain/graph/_kg_fsutil.py +1 -5
  24. package/lattice_brain/graph/discovery_index.py +174 -20
  25. package/lattice_brain/graph/documents.py +44 -9
  26. package/lattice_brain/graph/ingest.py +47 -20
  27. package/lattice_brain/graph/provenance.py +13 -6
  28. package/lattice_brain/graph/retrieval.py +140 -39
  29. package/lattice_brain/graph/retrieval_docgen.py +37 -4
  30. package/lattice_brain/ingestion.py +4 -7
  31. package/lattice_brain/portability.py +28 -14
  32. package/lattice_brain/runtime/agent_runtime.py +5 -9
  33. package/lattice_brain/runtime/hooks.py +30 -13
  34. package/lattice_brain/runtime/multi_agent.py +27 -8
  35. package/lattice_brain/runtime/statuses.py +10 -0
  36. package/lattice_brain/utils.py +20 -2
  37. package/lattice_brain/workflow.py +1 -5
  38. package/latticeai/__init__.py +1 -1
  39. package/latticeai/api/admin.py +1 -1
  40. package/latticeai/api/agent_registry.py +10 -8
  41. package/latticeai/api/agents.py +22 -3
  42. package/latticeai/api/auth.py +78 -16
  43. package/latticeai/api/browser.py +303 -34
  44. package/latticeai/api/chat.py +320 -850
  45. package/latticeai/api/chat_agent_http.py +356 -0
  46. package/latticeai/api/chat_contracts.py +54 -0
  47. package/latticeai/api/chat_documents.py +256 -0
  48. package/latticeai/api/chat_helpers.py +24 -1
  49. package/latticeai/api/chat_history.py +99 -0
  50. package/latticeai/api/chat_intents.py +302 -0
  51. package/latticeai/api/chat_stream.py +115 -0
  52. package/latticeai/api/computer_use.py +62 -9
  53. package/latticeai/api/health.py +9 -3
  54. package/latticeai/api/hooks.py +17 -6
  55. package/latticeai/api/knowledge_graph.py +78 -14
  56. package/latticeai/api/local_files.py +7 -2
  57. package/latticeai/api/mcp.py +102 -23
  58. package/latticeai/api/models.py +72 -33
  59. package/latticeai/api/network.py +5 -5
  60. package/latticeai/api/permissions.py +67 -26
  61. package/latticeai/api/plugins.py +21 -7
  62. package/latticeai/api/portability.py +5 -5
  63. package/latticeai/api/realtime.py +33 -5
  64. package/latticeai/api/setup.py +2 -2
  65. package/latticeai/api/static_routes.py +123 -24
  66. package/latticeai/api/tools.py +96 -14
  67. package/latticeai/api/workflow_designer.py +37 -0
  68. package/latticeai/api/workspace.py +2 -1
  69. package/latticeai/app_factory.py +110 -52
  70. package/latticeai/core/agent.py +19 -9
  71. package/latticeai/core/agent_registry.py +1 -5
  72. package/latticeai/core/config.py +23 -3
  73. package/latticeai/core/context_builder.py +21 -3
  74. package/latticeai/core/invitations.py +1 -4
  75. package/latticeai/core/io_utils.py +9 -1
  76. package/latticeai/core/legacy_compatibility.py +24 -3
  77. package/latticeai/core/marketplace.py +1 -1
  78. package/latticeai/core/plugins.py +15 -0
  79. package/latticeai/core/policy.py +1 -1
  80. package/latticeai/core/realtime.py +38 -15
  81. package/latticeai/core/sessions.py +7 -2
  82. package/latticeai/core/timeutil.py +10 -0
  83. package/latticeai/core/tool_registry.py +90 -18
  84. package/latticeai/core/users.py +1 -5
  85. package/latticeai/core/workspace_graph_trace.py +31 -5
  86. package/latticeai/core/workspace_memory.py +3 -1
  87. package/latticeai/core/workspace_os.py +18 -7
  88. package/latticeai/core/workspace_os_utils.py +0 -5
  89. package/latticeai/core/workspace_permissions.py +2 -1
  90. package/latticeai/core/workspace_plugins.py +1 -1
  91. package/latticeai/core/workspace_runs.py +14 -5
  92. package/latticeai/core/workspace_skills.py +1 -1
  93. package/latticeai/core/workspace_snapshots.py +2 -1
  94. package/latticeai/core/workspace_timeline.py +2 -1
  95. package/latticeai/integrations/telegram_bot.py +94 -43
  96. package/latticeai/models/router.py +130 -36
  97. package/latticeai/runtime/access_runtime.py +62 -4
  98. package/latticeai/runtime/automation_runtime.py +13 -7
  99. package/latticeai/runtime/brain_runtime.py +19 -7
  100. package/latticeai/runtime/chat_wiring.py +2 -0
  101. package/latticeai/runtime/config_runtime.py +58 -26
  102. package/latticeai/runtime/context_runtime.py +16 -4
  103. package/latticeai/runtime/hooks_runtime.py +1 -1
  104. package/latticeai/runtime/model_wiring.py +33 -5
  105. package/latticeai/runtime/namespace_runtime.py +62 -72
  106. package/latticeai/runtime/platform_runtime_wiring.py +4 -3
  107. package/latticeai/runtime/review_wiring.py +1 -1
  108. package/latticeai/runtime/router_registration.py +34 -1
  109. package/latticeai/runtime/security_runtime.py +110 -13
  110. package/latticeai/runtime/stages.py +27 -0
  111. package/latticeai/server_app.py +5 -1
  112. package/latticeai/services/architecture_readiness.py +74 -5
  113. package/latticeai/services/brain_automation.py +3 -26
  114. package/latticeai/services/chat_service.py +205 -15
  115. package/latticeai/services/local_knowledge.py +423 -0
  116. package/latticeai/services/memory_service.py +55 -21
  117. package/latticeai/services/model_engines.py +48 -33
  118. package/latticeai/services/model_errors.py +17 -0
  119. package/latticeai/services/model_loading.py +28 -25
  120. package/latticeai/services/model_runtime.py +228 -162
  121. package/latticeai/services/p_reinforce.py +22 -3
  122. package/latticeai/services/platform_runtime.py +83 -23
  123. package/latticeai/services/product_readiness.py +19 -17
  124. package/latticeai/services/review_queue.py +12 -0
  125. package/latticeai/services/router_context.py +1 -0
  126. package/latticeai/services/run_executor.py +4 -9
  127. package/latticeai/services/search_service.py +203 -28
  128. package/latticeai/services/tool_dispatch.py +28 -5
  129. package/latticeai/services/triggers.py +53 -4
  130. package/latticeai/services/upload_service.py +13 -2
  131. package/latticeai/setup/__init__.py +25 -0
  132. package/latticeai/setup/auto_setup.py +857 -0
  133. package/latticeai/setup/wizard.py +1264 -0
  134. package/latticeai/tools/__init__.py +278 -0
  135. package/{tools → latticeai/tools}/commands.py +67 -7
  136. package/{tools → latticeai/tools}/computer.py +1 -1
  137. package/{tools → latticeai/tools}/documents.py +1 -1
  138. package/{tools → latticeai/tools}/filesystem.py +3 -3
  139. package/latticeai/tools/knowledge.py +178 -0
  140. package/{tools → latticeai/tools}/local_files.py +1 -1
  141. package/{tools → latticeai/tools}/network.py +0 -1
  142. package/local_knowledge_api.py +4 -342
  143. package/package.json +22 -2
  144. package/scripts/brain_quality_eval.py +3 -1
  145. package/scripts/bump_version.py +3 -0
  146. package/scripts/capture_release_evidence.mjs +180 -0
  147. package/scripts/check_current_release_docs.mjs +142 -0
  148. package/scripts/check_i18n_literals.mjs +107 -31
  149. package/scripts/check_openapi_drift.mjs +56 -0
  150. package/scripts/export_openapi.py +67 -7
  151. package/scripts/i18n_literal_allowlist.json +22 -24
  152. package/scripts/run_integration_tests.mjs +72 -10
  153. package/scripts/validate_release_artifacts.py +49 -7
  154. package/scripts/wheel_smoke.py +5 -0
  155. package/setup_wizard.py +3 -1260
  156. package/src-tauri/Cargo.lock +1 -1
  157. package/src-tauri/Cargo.toml +1 -1
  158. package/src-tauri/tauri.conf.json +1 -1
  159. package/static/app/asset-manifest.json +11 -11
  160. package/static/app/assets/Act-Bzz0bUyW.js +1 -0
  161. package/static/app/assets/Brain-Dj2J20YA.js +321 -0
  162. package/static/app/assets/Capture-CqlEl1Ga.js +1 -0
  163. package/static/app/assets/Library-B03FP1Yx.js +1 -0
  164. package/static/app/assets/System-80lHW0Ux.js +1 -0
  165. package/static/app/assets/index-BiMofBTM.js +17 -0
  166. package/static/app/assets/index-Bmx9rzTc.css +2 -0
  167. package/static/app/assets/primitives-Q1A96_7v.js +1 -0
  168. package/static/app/assets/textarea-D13RtnTo.js +1 -0
  169. package/static/app/index.html +2 -2
  170. package/static/sw.js +1 -1
  171. package/tools/__init__.py +21 -269
  172. package/docs/CODE_REVIEW_2026-07-06.md +0 -764
  173. package/latticeai/runtime/app_context_runtime.py +0 -13
  174. package/latticeai/runtime/tail_wiring.py +0 -21
  175. package/scripts/com.pts.claudecode.discord.plist +0 -31
  176. package/scripts/pts-claudecode-discord-bridge.mjs +0 -207
  177. package/scripts/start-pts-claudecode-discord.sh +0 -51
  178. package/static/app/assets/Act-21lIXx2E.js +0 -1
  179. package/static/app/assets/Brain-BqUd5UJJ.js +0 -321
  180. package/static/app/assets/Capture-BA7Z2Q1u.js +0 -1
  181. package/static/app/assets/Library-bFMtyni3.js +0 -1
  182. package/static/app/assets/System-K6krGCqn.js +0 -1
  183. package/static/app/assets/index-C4R3ws30.js +0 -17
  184. package/static/app/assets/index-ChSeOB02.css +0 -2
  185. package/static/app/assets/primitives-sQU3it5I.js +0 -1
  186. package/static/app/assets/textarea-DK3Fd_lR.js +0 -1
  187. package/tools/knowledge.py +0 -95
package/auto_setup.py CHANGED
@@ -1,857 +1,11 @@
1
- """
2
- Lattice AI — Zero-Config Auto Setup
3
- ===================================
1
+ """Compatibility shim for :mod:`latticeai.setup.auto_setup`."""
4
2
 
5
- 명세: ``lattice_ai_full_spec.pptx`` 슬라이드 16·17 (자동 환경 매트릭스 + 5단계 흐름)
6
-
7
- 5단계
8
- -----
9
- ① PROBE OS · CPU · GPU · RAM · 디스크 · 가속 SDK 감지
10
- ② RECOMMEND 사양 점수 → 최적 모델 / 런타임 / 양자화 자동 선택
11
- ③ INSTALL OS별 패키지 매니저 어댑터 호출 (winget · brew · apt · 스토어)
12
- ④ VERIFY 추론 토큰/초 측정, 첫 응답 지연, 메모리 누수 점검
13
- ⑤ PRESET 기본/고급 모드 분기 + 단축키·MCP·테마 적용
14
-
15
- 원칙
16
- ----
17
- - **표준 라이브러리 only.** 외부 패키지 import 는 모두 try/except 로 감싼다.
18
- - **변경하지 않는다, 추천만 한다.** INSTALL 단계는 *실행 명령어* 를 생성하고
19
- 돌려보낼 뿐, ``--apply`` 플래그 없이는 시스템을 건드리지 않는다.
20
- - **모든 출력은 JSON-직렬화 가능**해야 UI(설치 마법사 화면) 에서 그대로 표시 가능.
21
-
22
- 사용
23
- ----
24
- ```bash
25
- python3 auto_setup.py probe # 1단계만
26
- python3 auto_setup.py recommend # 1+2단계
27
- python3 auto_setup.py plan # 1+2+3 (설치 계획 출력)
28
- python3 auto_setup.py plan --apply --confirm-token <token>
29
- python3 auto_setup.py verify # 4단계 단독
30
- python3 auto_setup.py preset # 5단계
31
- python3 auto_setup.py all # 전체 흐름
32
- ```
33
- """
34
-
35
- from __future__ import annotations
36
-
37
- import argparse
38
- import json
39
- import os
40
- import platform
41
- import re
42
- import shutil
43
- import subprocess
44
- import sys
45
- import time
46
- from dataclasses import asdict, dataclass, field
47
- from pathlib import Path
48
- from typing import Any, Dict, List, Optional, Tuple
49
-
50
- from latticeai.services.process_audit import (
51
- CommandConfirmationError,
52
- append_process_audit_event,
53
- command_plan,
54
- command_plan_for_commands,
55
- require_command_confirmation,
56
- )
57
- from latticeai.services.setup_detection import (
58
- detect_cuda,
59
- detect_tools,
60
- detect_wsl_from_text,
61
- parse_windows_video_controllers as _parse_windows_video_controllers,
62
- )
63
-
64
- __all__ = [
65
- "SystemProfile", "Recommendation", "InstallPlan",
66
- "probe", "recommend", "plan", "verify", "preset", "run_all",
67
- ]
68
-
69
-
70
- # ── 1. PROBE ────────────────────────────────────────────────────────────────
71
- @dataclass
72
- class GPUInfo:
73
- vendor: str = "unknown" # nvidia | amd | intel | apple | none
74
- model: str = ""
75
- vram_mb: int = 0
76
- sdk: List[str] = field(default_factory=list) # ['cuda', 'metal', 'mlx', ...]
77
-
78
-
79
- @dataclass
80
- class SystemProfile:
81
- os: str = "" # windows | darwin | linux | ios | android
82
- os_version: str = ""
83
- arch: str = "" # x86_64 | arm64 | …
84
- cpu_model: str = ""
85
- cpu_cores: int = 0
86
- cpu_logical_cores: int = 0
87
- cpu_instructions: List[str] = field(default_factory=list)
88
- ram_mb: int = 0
89
- disk_free_mb: int = 0
90
- gpu: GPUInfo = field(default_factory=GPUInfo)
91
- package_manager: Optional[str] = None # winget | brew | apt | dnf | pacman
92
- has_internet: bool = True
93
- python_version: str = ""
94
- is_wsl: bool = False
95
- wsl_version: str = ""
96
- cuda_available: bool = False
97
- cuda_version: str = ""
98
- tools: Dict[str, str] = field(default_factory=dict)
99
-
100
- def score(self) -> int:
101
- """LLM 적합도 점수 (0..100). RECOMMEND 의 입력."""
102
- s = 0
103
- s += min(self.cpu_cores * 2, 24)
104
- s += min(self.ram_mb // 1024 * 2, 40)
105
- s += min(self.gpu.vram_mb // 1024 * 4, 36)
106
- return min(s, 100)
107
-
108
- def to_json(self) -> Dict[str, Any]:
109
- d = asdict(self)
110
- d["score"] = self.score()
111
- return d
112
-
113
-
114
- def _read_text(path: str) -> str:
115
- try:
116
- return Path(path).read_text(encoding="utf-8", errors="replace")
117
- except Exception:
118
- return ""
119
-
120
-
121
- def _run(cmd: List[str], timeout: float = 4.0) -> str:
122
- try:
123
- out = subprocess.run(cmd, capture_output=True, text=True,
124
- timeout=timeout, check=False)
125
- return (out.stdout or "") + (out.stderr or "")
126
- except Exception:
127
- return ""
128
-
129
-
130
- def _windows_candidate_paths(binary: str) -> List[str]:
131
- local_appdata = os.environ.get("LOCALAPPDATA", "")
132
- program_files = os.environ.get("ProgramFiles", r"C:\Program Files")
133
- program_files_x86 = os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)")
134
- candidates = {
135
- "ollama": [
136
- str(Path(local_appdata) / "Programs" / "Ollama" / "ollama.exe") if local_appdata else "",
137
- str(Path(program_files) / "Ollama" / "ollama.exe"),
138
- ],
139
- "lms": [
140
- str(Path(local_appdata) / "Programs" / "LM Studio" / "resources" / "app" / ".webpack" / "lms.exe") if local_appdata else "",
141
- str(Path(program_files) / "LM Studio" / "resources" / "app" / ".webpack" / "lms.exe"),
142
- ],
143
- "nvidia-smi": [
144
- str(Path(program_files) / "NVIDIA Corporation" / "NVSMI" / "nvidia-smi.exe"),
145
- str(Path(program_files_x86) / "NVIDIA Corporation" / "NVSMI" / "nvidia-smi.exe"),
146
- ],
147
- }
148
- return [item for item in candidates.get(binary, []) if item]
149
-
150
-
151
- def _which(binary: str) -> Optional[str]:
152
- found = shutil.which(binary)
153
- if found:
154
- return found
155
- if platform.system() == "Windows":
156
- for candidate in _windows_candidate_paths(binary):
157
- if Path(candidate).exists():
158
- return candidate
159
- return None
160
-
161
-
162
- def _detect_gpu(prof_os: str, arch: str) -> GPUInfo:
163
- """OS별 휴리스틱으로 GPU 감지. 외부 라이브러리 없이 가능한 만큼만."""
164
- gpu = GPUInfo()
165
-
166
- # NVIDIA
167
- nvidia_smi = _which("nvidia-smi")
168
- if nvidia_smi:
169
- info = _run([nvidia_smi, "--query-gpu=name,memory.total",
170
- "--format=csv,noheader,nounits"])
171
- if info.strip():
172
- first = info.strip().splitlines()[0]
173
- try:
174
- name, mem = [x.strip() for x in first.split(",", 1)]
175
- gpu.vendor = "nvidia"
176
- gpu.model = name
177
- gpu.vram_mb = int(float(mem))
178
- gpu.sdk.append("cuda")
179
- except ValueError:
180
- pass
181
-
182
- # Apple Silicon / Metal
183
- if prof_os == "darwin":
184
- sp = _run(["system_profiler", "SPDisplaysDataType"], timeout=6.0)
185
- if "Apple" in sp and arch == "arm64":
186
- gpu.vendor = "apple"
187
- for line in sp.splitlines():
188
- if "Chipset Model" in line:
189
- gpu.model = line.split(":", 1)[-1].strip()
190
- break
191
- # Apple Silicon 의 GPU 메모리는 통합 메모리 = RAM. 별도 표기 안 함.
192
- gpu.sdk.extend(["metal", "mlx" if _has_module("mlx") else ""])
193
- gpu.sdk = [s for s in gpu.sdk if s]
194
-
195
- # Windows
196
- if prof_os == "windows" and gpu.vendor == "unknown":
197
- shell = _which("powershell") or _which("pwsh")
198
- info = ""
199
- if shell:
200
- info = _run([
201
- shell, "-NoProfile", "-Command",
202
- "Get-CimInstance Win32_VideoController | Select-Object Name,AdapterRAM | ConvertTo-Json -Compress",
203
- ], timeout=8.0)
204
- if not info:
205
- info = _run(["wmic", "path", "win32_VideoController", "get",
206
- "Name,AdapterRAM", "/format:list"])
207
- controllers = _parse_windows_video_controllers(info)
208
- if controllers:
209
- primary = max(controllers, key=lambda item: int(item.get("vram_mb") or 0))
210
- name = str(primary.get("name") or "")
211
- gpu.model = name
212
- gpu.vram_mb = int(primary.get("vram_mb") or 0)
213
- low = name.lower()
214
- if "nvidia" in low or "rtx" in low or "geforce" in low:
215
- gpu.vendor = "nvidia"; gpu.sdk.append("cuda")
216
- elif "amd" in low or "radeon" in low:
217
- gpu.vendor = "amd"; gpu.sdk.extend(["directml", "vulkan"])
218
- elif "intel" in low or "arc" in low or "iris" in low:
219
- gpu.vendor = "intel"; gpu.sdk.extend(["directml", "vulkan"])
220
-
221
- # Linux (lspci)
222
- if prof_os == "linux" and gpu.vendor == "unknown":
223
- info = _run(["lspci"], timeout=3.0).lower()
224
- if "nvidia" in info:
225
- gpu.vendor = "nvidia"; gpu.sdk.append("cuda")
226
- elif "amd/ati" in info or "advanced micro devices" in info:
227
- gpu.vendor = "amd"; gpu.sdk.extend(["rocm", "vulkan"])
228
- elif "intel corporation" in info and "vga" in info:
229
- gpu.vendor = "intel"; gpu.sdk.append("vulkan")
230
-
231
- return gpu
232
-
233
-
234
- def _detect_package_manager(prof_os: str) -> Optional[str]:
235
- if prof_os == "windows":
236
- return "winget" if _which("winget") else None
237
- if prof_os == "darwin":
238
- return "brew" if _which("brew") else None
239
- if prof_os == "linux":
240
- for pm in ("apt", "dnf", "pacman", "zypper", "apk"):
241
- if _which(pm):
242
- return pm
243
- return None
244
-
245
-
246
- def _detect_tools() -> Dict[str, str]:
247
- detected = detect_tools(_which, ("ollama", "lms", "nvidia-smi", "nvcc", "winget", "brew", "apt", "git", "node", "python", "python3"))
248
- return {binary: path for binary, path in detected.items() if path}
249
-
250
-
251
- def _detect_wsl(prof_os: str) -> Tuple[bool, str]:
252
- return detect_wsl_from_text(prof_os, _read_text("/proc/version"))
253
-
254
-
255
- def _detect_cuda() -> Tuple[bool, str]:
256
- available, version, _nvidia_smi, _nvcc = detect_cuda(_which, lambda args: _run(args, timeout=4.0))
257
- return available, version
258
-
259
-
260
- def _detect_cpu_details(prof_os: str) -> Tuple[str, int, int, List[str]]:
261
- model = platform.processor() or ""
262
- physical = os.cpu_count() or 0
263
- logical = os.cpu_count() or 0
264
- flags: List[str] = []
265
- if prof_os == "darwin":
266
- model = _run(["sysctl", "-n", "machdep.cpu.brand_string"]).strip() or model
267
- try:
268
- physical = int((_run(["sysctl", "-n", "hw.physicalcpu"]).strip() or physical))
269
- logical = int((_run(["sysctl", "-n", "hw.logicalcpu"]).strip() or logical))
270
- except ValueError:
271
- pass
272
- flags = [item.lower() for item in _run(["sysctl", "-n", "machdep.cpu.features"]).split()]
273
- elif prof_os == "linux":
274
- text = _read_text("/proc/cpuinfo")
275
- for line in text.splitlines():
276
- if line.lower().startswith("model name") and not model:
277
- model = line.split(":", 1)[-1].strip()
278
- if line.lower().startswith(("flags", "features")) and not flags:
279
- flags = line.split(":", 1)[-1].strip().lower().split()
280
- elif prof_os == "windows":
281
- raw = _run(["wmic", "cpu", "get", "Name,NumberOfCores,NumberOfLogicalProcessors", "/format:list"])
282
- for line in raw.splitlines():
283
- key, _, value = line.partition("=")
284
- if key == "Name" and value.strip():
285
- model = value.strip()
286
- elif key == "NumberOfCores" and value.strip():
287
- try:
288
- physical = int(value.strip())
289
- except ValueError:
290
- pass
291
- elif key == "NumberOfLogicalProcessors" and value.strip():
292
- try:
293
- logical = int(value.strip())
294
- except ValueError:
295
- pass
296
- try:
297
- import ctypes
298
- kernel32 = ctypes.windll.kernel32
299
- feature_map = {6: "sse", 10: "sse2", 13: "sse3", 19: "neon", 28: "rdrand"}
300
- flags.extend(name for code, name in feature_map.items() if kernel32.IsProcessorFeaturePresent(code))
301
- except Exception:
302
- pass
303
- interesting = {"avx", "avx2", "avx512f", "fma", "neon", "sse4_2", "sse", "sse2", "sse3", "rdrand"}
304
- return model, physical, logical, sorted({flag for flag in flags if flag in interesting})
305
-
306
-
307
- def _has_module(name: str) -> bool:
308
- try:
309
- __import__(name)
310
- return True
311
- except Exception:
312
- return False
313
-
314
-
315
- def probe() -> SystemProfile:
316
- """① PROBE — 외부 의존성 없이 가능한 만큼 환경을 감지한다."""
317
- prof = SystemProfile()
318
- prof.os = {"Darwin": "darwin", "Windows": "windows",
319
- "Linux": "linux"}.get(platform.system(), platform.system().lower())
320
- prof.os_version = platform.release()
321
- prof.arch = platform.machine().lower()
322
- cpu_model, cpu_cores, cpu_logical_cores, cpu_instructions = _detect_cpu_details(prof.os)
323
- prof.cpu_model = cpu_model
324
- prof.cpu_cores = cpu_cores
325
- prof.cpu_logical_cores = cpu_logical_cores
326
- prof.cpu_instructions = cpu_instructions
327
- prof.python_version = platform.python_version()
328
- prof.is_wsl, prof.wsl_version = _detect_wsl(prof.os)
329
- prof.cuda_available, prof.cuda_version = _detect_cuda()
330
- prof.tools = _detect_tools()
331
-
332
- # RAM
333
- try:
334
- if prof.os == "linux":
335
- for line in _read_text("/proc/meminfo").splitlines():
336
- if line.startswith("MemTotal:"):
337
- prof.ram_mb = int(line.split()[1]) // 1024
338
- break
339
- elif prof.os == "darwin":
340
- out = _run(["sysctl", "-n", "hw.memsize"])
341
- if out.strip():
342
- try:
343
- prof.ram_mb = int(out.strip()) // (1024 * 1024)
344
- except ValueError:
345
- prof.ram_mb = 0
346
- if not prof.ram_mb:
347
- profiler = _run(["system_profiler", "SPHardwareDataType"], timeout=8.0)
348
- m = re.search(r"Memory:\s+([\d.]+)\s*(TB|GB|MB)", profiler, re.IGNORECASE)
349
- if m:
350
- value = float(m.group(1))
351
- unit = m.group(2).lower()
352
- if unit == "tb":
353
- prof.ram_mb = int(value * 1024 * 1024)
354
- elif unit == "gb":
355
- prof.ram_mb = int(value * 1024)
356
- else:
357
- prof.ram_mb = int(value)
358
- if not prof.ram_mb:
359
- hostinfo = _run(["hostinfo"])
360
- m = re.search(r"Primary memory available:\s+([\d.]+)\s+gigabytes", hostinfo, re.IGNORECASE)
361
- if m:
362
- prof.ram_mb = int(float(m.group(1)) * 1024)
363
- elif prof.os == "windows":
364
- out = _run(["wmic", "ComputerSystem", "get", "TotalPhysicalMemory",
365
- "/format:list"])
366
- for line in out.splitlines():
367
- if line.startswith("TotalPhysicalMemory="):
368
- prof.ram_mb = int(line.split("=", 1)[-1].strip()) // (1024 * 1024)
369
- break
370
- except Exception:
371
- pass
372
-
373
- # Disk
374
- try:
375
- usage = shutil.disk_usage(Path.home())
376
- prof.disk_free_mb = usage.free // (1024 * 1024)
377
- except Exception:
378
- pass
379
-
380
- prof.gpu = _detect_gpu(prof.os, prof.arch)
381
- prof.package_manager = _detect_package_manager(prof.os)
382
- return prof
383
-
384
-
385
- # ── 2. RECOMMEND ────────────────────────────────────────────────────────────
386
- @dataclass
387
- class Recommendation:
388
- runtime: str # llama.cpp | mlx | vllm | mlc-llm | tflite
389
- backend: str # cuda | metal+mlx | directml | vulkan | rocm | cpu
390
- model_id: str # 추천 모델 (huggingface-like id)
391
- quantization: str # q4_K_M | q5_K_M | mxfp4 | f16
392
- rationale: List[str] # 왜 이걸 골랐는지 (UI에 표시)
393
- estimated_tokens_per_sec: Optional[float] = None
394
-
395
- def to_json(self) -> Dict[str, Any]:
396
- return asdict(self)
397
-
398
-
399
- # 모델 카탈로그. PPT 슬라이드 16 의 "추천 모델" 열과 동기화.
400
- _MODEL_CATALOG: List[Dict[str, Any]] = [
401
- # (min_ram_mb, min_vram_mb, model_id, quant, runtime_preference)
402
- # OS 오버헤드(~4-6 GB) + KV 캐시 여유를 감안한 보수적 RAM 임계값
403
- {"ram": 64 * 1024, "vram": 32 * 1024,
404
- "id": "mlx-community/gemma-4-31b-it-4bit", "q": "4bit", "multimodal": True},
405
- {"ram": 64 * 1024, "vram": 32 * 1024,
406
- "id": "Qwen/Qwen3-VL-30B-A3B-Instruct", "q": "q4_K_M", "multimodal": True},
407
- {"ram": 48 * 1024, "vram": 24 * 1024,
408
- "id": "mlx-community/gemma-4-31b-it-4bit", "q": "4bit", "multimodal": True},
409
- {"ram": 32 * 1024, "vram": 16 * 1024,
410
- "id": "mlx-community/gemma-4-26b-a4b-it-4bit", "q": "4bit", "multimodal": True},
411
- {"ram": 48 * 1024, "vram": 24 * 1024,
412
- "id": "Qwen/Qwen3-VL-30B-A3B-Instruct", "q": "q4_K_M", "multimodal": True},
413
- {"ram": 24 * 1024, "vram": 12 * 1024,
414
- "id": "mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit", "q": "4bit", "multimodal": True},
415
- {"ram": 16 * 1024, "vram": 8 * 1024,
416
- "id": "mlx-community/gemma-4-12b-it-4bit", "q": "4bit", "multimodal": True},
417
- {"ram": 32 * 1024, "vram": 16 * 1024,
418
- "id": "Qwen/Qwen3-VL-8B-Instruct", "q": "q5_K_M", "multimodal": True},
419
- {"ram": 24 * 1024, "vram": 12 * 1024,
420
- "id": "Qwen/Qwen3-VL-8B-Instruct", "q": "q4_K_M", "multimodal": True},
421
- {"ram": 16 * 1024, "vram": 8 * 1024,
422
- "id": "Qwen/Qwen3-VL-8B-Instruct", "q": "q4_K_M", "multimodal": True},
423
- {"ram": 12 * 1024, "vram": 6 * 1024,
424
- "id": "Qwen/Qwen3-VL-4B-Instruct", "q": "q4_K_M", "multimodal": True},
425
- {"ram": 8 * 1024, "vram": 4 * 1024,
426
- "id": "Qwen/Qwen3-VL-4B-Instruct", "q": "q4_K_M", "multimodal": True},
427
- {"ram": 4 * 1024, "vram": 0,
428
- "id": "Qwen/Qwen3-VL-4B-Instruct", "q": "q4_K_M", "multimodal": True},
429
- ]
430
-
431
-
432
- def recommend(profile: SystemProfile) -> Recommendation:
433
- """② RECOMMEND — 프로파일을 보고 런타임/모델/양자화를 결정한다."""
434
- rationale: List[str] = []
435
-
436
- # backend / runtime
437
- if profile.os == "darwin" and profile.gpu.vendor == "apple":
438
- backend = "metal+mlx"
439
- runtime = "mlx" if _has_module("mlx_vlm") else "llama.cpp"
440
- rationale.append("Apple Silicon → Metal + MLX-VLM")
441
- elif profile.gpu.vendor == "nvidia" and profile.cuda_available and (profile.os == "linux" or profile.is_wsl):
442
- backend = "cuda"
443
- runtime = "vllm" if profile.gpu.vram_mb >= 12 * 1024 else "llama.cpp"
444
- rationale.append(f"NVIDIA GPU {profile.gpu.vram_mb} MB VRAM + CUDA → {runtime}")
445
- elif profile.gpu.vendor == "nvidia":
446
- backend = "cuda" if profile.cuda_available else "vulkan"
447
- runtime = "lmstudio" if profile.tools.get("lms") else ("ollama" if profile.tools.get("ollama") else "llama.cpp")
448
- rationale.append("Windows NVIDIA는 LM Studio/Ollama 우선, vLLM은 WSL/Linux 권장")
449
- elif profile.os == "windows" and profile.gpu.vendor in ("amd", "intel"):
450
- backend = "directml/vulkan"
451
- runtime = "lmstudio" if profile.tools.get("lms") else ("ollama" if profile.tools.get("ollama") else "llama.cpp")
452
- rationale.append("Windows + AMD/Intel GPU → DirectML/Vulkan")
453
- elif profile.os == "linux" and profile.gpu.vendor == "amd":
454
- backend = "rocm" if "rocm" in profile.gpu.sdk else "vulkan"
455
- runtime = "ollama" if profile.tools.get("ollama") else "llama.cpp"
456
- rationale.append("Linux + AMD GPU → ROCm/Vulkan")
457
- else:
458
- backend = "cpu"
459
- runtime = "ollama" if profile.tools.get("ollama") else "llama.cpp"
460
- instruction_hint = ", ".join(profile.cpu_instructions) or "명령어 미감지"
461
- rationale.append(f"GPU 가속이 없거나 미감지 → CPU 추론 ({profile.cpu_logical_cores or profile.cpu_cores} threads, {instruction_hint})")
462
-
463
- # model size by RAM/VRAM
464
- pick = _MODEL_CATALOG[-1] # 가장 작은 모델 기본값
465
- for entry in _MODEL_CATALOG:
466
- if profile.ram_mb >= entry["ram"] and (
467
- backend in {"cpu", "metal+mlx"} or profile.gpu.vram_mb >= entry["vram"]
468
- ):
469
- pick = entry
470
- break
471
- rationale.append(
472
- f"RAM {profile.ram_mb} MB · VRAM {profile.gpu.vram_mb} MB → {pick['id']}"
473
- )
474
- if pick.get("multimodal"):
475
- rationale.append("최신 멀티모달 모델을 우선 선택")
476
-
477
- # 양자화: VRAM 충분 → 더 정밀한 양자화로 업그레이드
478
- quant = pick["q"]
479
- if profile.gpu.vram_mb >= 24 * 1024:
480
- quant = "f16"
481
- rationale.append("VRAM ≥ 24 GB → f16 풀 정밀도")
482
-
483
- # 거친 tokens/sec 예측 (very rough)
484
- est_tps = None
485
- if backend == "cuda":
486
- est_tps = max(8.0, profile.gpu.vram_mb / 800)
487
- elif backend == "metal+mlx":
488
- est_tps = max(6.0, (profile.ram_mb // 1024) * 0.7)
489
- elif backend == "cpu":
490
- est_tps = max(1.5, profile.cpu_cores * 0.6)
491
-
492
- return Recommendation(
493
- runtime=runtime, backend=backend,
494
- model_id=pick["id"], quantization=quant,
495
- rationale=rationale, estimated_tokens_per_sec=est_tps,
496
- )
497
-
498
-
499
- # ── 3. INSTALL plan ─────────────────────────────────────────────────────────
500
- @dataclass
501
- class InstallStep:
502
- name: str
503
- why: str
504
- command: List[str]
505
- requires_admin: bool = False
506
-
507
- def to_json(self) -> Dict[str, Any]:
508
- return {
509
- "name": self.name,
510
- "why": self.why,
511
- "command": self.command,
512
- "requires_admin": self.requires_admin,
513
- "command_plan": command_plan(
514
- self.command,
515
- name=self.name,
516
- purpose="auto_setup_install",
517
- requires_admin=self.requires_admin,
518
- metadata={"why": self.why},
519
- ),
520
- }
521
-
522
-
523
- @dataclass
524
- class InstallPlan:
525
- package_manager: Optional[str]
526
- steps: List[InstallStep]
527
- notes: List[str] = field(default_factory=list)
528
-
529
- def to_json(self) -> Dict[str, Any]:
530
- plan_summary = command_plan_for_commands(
531
- [step.command for step in self.steps],
532
- name="auto_setup_plan",
533
- purpose="auto_setup_install",
534
- metadata={"package_manager": self.package_manager},
535
- )
536
- return {
537
- "package_manager": self.package_manager,
538
- "steps": [s.to_json() for s in self.steps],
539
- "notes": self.notes,
540
- "command_plan": plan_summary,
541
- "confirmation_token": plan_summary["confirmation_token"],
542
- }
543
-
544
-
545
- # 패키지 카탈로그: 핵심 의존성을 OS별 명령으로 매핑
546
- _PKG_MAP: Dict[str, Dict[str, Tuple[str, ...]]] = {
547
- # name : { pm : (cmd parts) }
548
- "python3.11+": {
549
- "winget": ("winget", "install", "-e", "--id", "Python.Python.3.11"),
550
- "brew": ("brew", "install", "python@3.11"),
551
- "apt": ("apt-get", "install", "-y", "python3.11"),
552
- "dnf": ("dnf", "install", "-y", "python3.11"),
553
- },
554
- "node20": {
555
- "winget": ("winget", "install", "-e", "--id", "OpenJS.NodeJS.LTS"),
556
- "brew": ("brew", "install", "node@20"),
557
- "apt": ("apt-get", "install", "-y", "nodejs"),
558
- "dnf": ("dnf", "install", "-y", "nodejs"),
559
- },
560
- "ollama": {
561
- "brew": ("brew", "install", "ollama"),
562
- "winget": ("winget", "install", "-e", "--id", "Ollama.Ollama"),
563
- "apt": ("sh", "-c", "curl -fsSL https://ollama.com/install.sh | sh"),
564
- },
565
- "huggingface-cli": {
566
- "brew": ("pip3", "install", "--upgrade", "huggingface_hub"),
567
- "winget": ("pip", "install", "--upgrade", "huggingface_hub"),
568
- "apt": ("pip3", "install", "--upgrade", "huggingface_hub"),
569
- "dnf": ("pip3", "install", "--upgrade", "huggingface_hub"),
570
- },
571
- }
572
-
573
-
574
- def plan(profile: SystemProfile, rec: Recommendation) -> InstallPlan:
575
- """③ INSTALL — 추천을 만족시키는 *명령 계획* 을 만든다. 실행하지 않는다."""
576
- pm = profile.package_manager
577
- steps: List[InstallStep] = []
578
- notes: List[str] = []
579
-
580
- def need(name: str, why: str) -> None:
581
- cmd_tuple = _PKG_MAP.get(name, {}).get(pm or "")
582
- if cmd_tuple:
583
- steps.append(InstallStep(
584
- name=name, why=why,
585
- command=list(cmd_tuple),
586
- requires_admin=(cmd_tuple[0] in ("apt-get", "dnf", "pacman")),
587
- ))
588
- else:
589
- notes.append(f"패키지 매니저 어댑터 없음: {name} ({pm}) — 수동 설치 필요")
590
-
591
- if sys.version_info < (3, 11):
592
- need("python3.11+", "Lattice AI 서버는 Python 3.11 이상이 필요합니다.")
593
- if not _which("node"):
594
- need("node20", "VSCode 확장 / npm CLI 부트스트랩에 필요")
595
-
596
- # 런타임별 추가
597
- if rec.runtime == "mlx" and not _has_module("mlx_vlm"):
598
- steps.append(InstallStep(
599
- name="mlx-vlm", why="Apple Silicon 멀티모달 추론",
600
- command=["pip3", "install", "--upgrade", "mlx-vlm"],
601
- ))
602
- if rec.runtime in {"llama.cpp", "ollama"} and not _which("ollama"):
603
- need("ollama", "llama.cpp 가중치를 가장 쉽게 받는 경로")
604
- if rec.runtime == "lmstudio" and not _which("lms"):
605
- notes.append("LM Studio CLI(lms)를 찾지 못했습니다. https://lmstudio.ai/download 에서 설치하면 Windows/macOS/Linux 모델 다운로드와 GPU 백엔드를 자동 감지합니다.")
606
- if rec.runtime == "vllm" and not _has_module("vllm"):
607
- steps.append(InstallStep(
608
- name="vllm", why="NVIDIA CUDA/WSL/Linux 서버형 추론",
609
- command=["pip3", "install", "--upgrade", "vllm", "huggingface_hub"],
610
- ))
611
- if profile.gpu.vendor == "nvidia" and not profile.cuda_available:
612
- notes.append("NVIDIA GPU는 감지됐지만 CUDA/nvidia-smi를 찾지 못했습니다. Windows에서는 NVIDIA 드라이버와 CUDA Toolkit 설치 후 재검사를 권장합니다.")
613
- if profile.os == "windows" and profile.gpu.vendor == "nvidia" and not profile.is_wsl:
614
- notes.append("vLLM은 Windows native보다 WSL2/Linux에서 안정적입니다. Windows 데스크톱은 LM Studio 또는 Ollama GPU 경로를 먼저 권장합니다.")
615
-
616
- if not _which("huggingface-cli"):
617
- need("huggingface-cli", "추천 모델 가중치 다운로드용")
618
-
619
- # 모델 가중치 풀
620
- model_command = ["huggingface-cli", "download", rec.model_id, "--quiet"]
621
- if rec.runtime == "ollama":
622
- lower = rec.model_id.lower()
623
- if "gemma-4-31b" in lower:
624
- model_command = ["ollama", "pull", "hf.co/ggml-org/gemma-4-31B-it-GGUF:Q4_K_M"]
625
- elif "gemma-4-12b" in lower:
626
- model_command = ["ollama", "pull", "hf.co/ggml-org/gemma-4-12B-it-GGUF:Q4_K_M"]
627
- elif "llama-4-scout" in lower:
628
- model_command = ["ollama", "pull", "hf.co/ggml-org/Llama-4-Scout-17B-16E-Instruct-GGUF:Q4_K_M"]
629
- elif "qwen3-vl-8b" in lower:
630
- model_command = ["ollama", "pull", "qwen3-vl:8b"]
631
- elif "qwen3-vl-4b" in lower:
632
- model_command = ["ollama", "pull", "qwen3-vl:4b"]
633
- elif rec.runtime == "lmstudio":
634
- model_command = ["lms", "get", rec.model_id]
635
- steps.append(InstallStep(
636
- name=f"weights:{rec.model_id}",
637
- why="추론에 사용할 모델 가중치",
638
- command=model_command,
639
- ))
640
-
641
- return InstallPlan(package_manager=pm, steps=steps, notes=notes)
642
-
643
-
644
- def apply_plan(
645
- plan_obj: InstallPlan,
646
- *,
647
- confirm: bool = False,
648
- confirmation_token: Optional[str] = None,
649
- ) -> List[Dict[str, Any]]:
650
- """위험: 실제로 설치 명령을 실행한다. ``confirm`` and token are required."""
651
- if not confirm:
652
- raise RuntimeError("refuse to apply: pass confirm=True")
653
- expected = plan_obj.to_json().get("confirmation_token")
654
- if str(confirmation_token or "").strip() != expected:
655
- raise CommandConfirmationError("refuse to apply: confirmation token mismatch")
656
- results: List[Dict[str, Any]] = []
657
- for step in plan_obj.steps:
658
- step_plan = command_plan(
659
- step.command,
660
- name=step.name,
661
- purpose="auto_setup_install",
662
- requires_admin=step.requires_admin,
663
- metadata={"why": step.why},
664
- )
665
- try:
666
- require_command_confirmation(
667
- step.command,
668
- step_plan["confirmation_token"],
669
- purpose="auto_setup_install",
670
- )
671
- append_process_audit_event("installer_command", plan=step_plan, status="started")
672
- r = subprocess.run(step.command, capture_output=True, text=True,
673
- timeout=300, check=False)
674
- append_process_audit_event(
675
- "installer_command",
676
- plan=step_plan,
677
- status="finished",
678
- returncode=r.returncode,
679
- stdout=r.stdout,
680
- stderr=r.stderr,
681
- )
682
- results.append({
683
- "name": step.name,
684
- "command_hash": step_plan["command_hash"],
685
- "command_preview": step_plan["command_preview"],
686
- "returncode": r.returncode,
687
- "stdout_tail": (r.stdout or "")[-2000:],
688
- "stderr_tail": (r.stderr or "")[-2000:],
689
- })
690
- except Exception as exc:
691
- append_process_audit_event("installer_command", plan=step_plan, status="error", error=str(exc))
692
- results.append({"name": step.name, "command_hash": step_plan["command_hash"], "error": str(exc)})
693
- return results
694
-
695
-
696
- # ── 4. VERIFY ───────────────────────────────────────────────────────────────
697
- def verify(profile: SystemProfile, rec: Recommendation) -> Dict[str, Any]:
698
- """④ VERIFY — 가벼운 sanity check. 실제 LLM 추론 벤치는 별도 도구로.
699
- 여기서는 ‘설치된 것들이 import 되는가’ + ‘디스크/RAM 여유’ 정도만 본다."""
700
- checks: List[Dict[str, Any]] = []
701
-
702
- def add(label: str, ok: bool, detail: str = "") -> None:
703
- checks.append({"label": label, "ok": ok, "detail": detail})
704
-
705
- add("Python 3.11+", sys.version_info >= (3, 11), platform.python_version())
706
- add("RAM ≥ 4 GB", profile.ram_mb >= 4 * 1024, f"{profile.ram_mb} MB")
707
- add("디스크 여유 ≥ 8 GB", profile.disk_free_mb >= 8 * 1024,
708
- f"{profile.disk_free_mb} MB free")
709
-
710
- if rec.runtime == "mlx":
711
- add("mlx_vlm import", _has_module("mlx_vlm"), "Apple Silicon 멀티모달 런타임")
712
- if rec.runtime in {"llama.cpp", "ollama"}:
713
- add("ollama binary", _which("ollama") is not None,
714
- _which("ollama") or "not found")
715
- if rec.runtime == "lmstudio":
716
- add("LM Studio CLI", _which("lms") is not None, _which("lms") or "not found")
717
- if rec.backend == "cuda":
718
- add("CUDA/nvidia-smi", profile.cuda_available, profile.cuda_version or "not found")
719
-
720
- # CPU/메모리 잠깐 측정
721
- t0 = time.perf_counter()
722
- _ = sum(i * i for i in range(200_000))
723
- cpu_ms = (time.perf_counter() - t0) * 1000
724
- add("CPU latency sample", cpu_ms < 200, f"{cpu_ms:.1f} ms / 200k ops")
725
-
726
- return {
727
- "checks": checks,
728
- "all_pass": all(c["ok"] for c in checks),
729
- }
730
-
731
-
732
- # ── 5. PRESET ───────────────────────────────────────────────────────────────
733
- def preset(profile: SystemProfile, rec: Recommendation) -> Dict[str, Any]:
734
- """⑤ PRESET — UX 분기 + 단축키 + 테마 + MCP 도구 기본값.
735
-
736
- PPT 슬라이드 3 (모드 선택) · 17 (PRESET) 명세를 따른다.
737
- """
738
- # 기본 모드 vs 고급 모드 자동 선택 휴리스틱
739
- advanced = (
740
- profile.gpu.vendor in ("nvidia", "apple") or
741
- profile.ram_mb >= 24 * 1024 or
742
- "code" in (profile.cpu_model or "").lower() # 개발자 머신 추정
743
- )
744
- mode = "advanced" if advanced else "basic"
745
-
746
- # 단축키는 OS별 자연 컨벤션 따름
747
- mod = "Cmd" if profile.os == "darwin" else "Ctrl"
748
- shortcuts = {
749
- "newChat": f"{mod}+N",
750
- "toggleSidebar": f"{mod}+B",
751
- "openGraph": f"{mod}+G",
752
- "search": f"{mod}+K",
753
- "toggleMode": f"{mod}+Shift+M",
754
- "submit": "Enter",
755
- "newline": "Shift+Enter",
756
- }
757
-
758
- # 기본 MCP 도구 (PPT 슬라이드 11 의 기본 5종)
759
- mcp_defaults = [
760
- {"id": "filesystem", "scope": "local", "enabled": True},
761
- {"id": "web-search", "scope": "remote", "enabled": True},
762
- {"id": "code-execute", "scope": "local", "enabled": True},
763
- {"id": "browser-automation","scope": "remote","enabled": False},
764
- {"id": "database", "scope": "remote", "enabled": False},
765
- ]
766
-
767
- # 테마: OS 다크 모드 추종이 기본
768
- theme = {"mode": "auto", # auto | light | dark
769
- "accent": "#6E4AE6", # PPT 슬라이드 19 토큰
770
- "density": "comfortable" if mode == "basic" else "compact"}
771
-
772
- # 다국어: OS locale 기반 추정
773
- locale = os.environ.get("LANG", os.environ.get("LC_ALL", "ko_KR"))
774
- lang = "ko" if locale.lower().startswith("ko") else (
775
- "ja" if locale.lower().startswith("ja") else "en"
776
- )
777
-
778
- return {
779
- "mode": mode,
780
- "model": {"id": rec.model_id, "runtime": rec.runtime,
781
- "backend": rec.backend, "quantization": rec.quantization},
782
- "shortcuts": shortcuts,
783
- "mcp": mcp_defaults,
784
- "theme": theme,
785
- "language": lang,
786
- "tips": (
787
- ["기본 모드는 카드형 액션과 큰 입력창 위주. 언제든 '고급 모드' 로 전환할 수 있어요."]
788
- if mode == "basic"
789
- else ["고급 모드: 사이드바·디테일 패널·파이프라인 도구가 모두 활성화됩니다."]
790
- ),
791
- }
792
-
793
-
794
- # ── orchestrator ────────────────────────────────────────────────────────────
795
- def run_all(*, apply_install: bool = False, confirmation_token: Optional[str] = None) -> Dict[str, Any]:
796
- p = probe()
797
- r = recommend(p)
798
- pl = plan(p, r)
799
- install_results = None
800
- if apply_install:
801
- install_results = apply_plan(pl, confirm=True, confirmation_token=confirmation_token)
802
- v = verify(p, r)
803
- ps = preset(p, r)
804
- return {
805
- "probe": p.to_json(),
806
- "recommend": r.to_json(),
807
- "plan": pl.to_json(),
808
- "install": install_results,
809
- "verify": v,
810
- "preset": ps,
811
- }
812
-
813
-
814
- # ── CLI ────────────────────────────────────────────────────────────────────
815
- def _main() -> int:
816
- parser = argparse.ArgumentParser(prog="auto_setup",
817
- description="Lattice AI zero-config setup")
818
- sub = parser.add_subparsers(dest="cmd", required=True)
819
- sub.add_parser("probe")
820
- sub.add_parser("recommend")
821
- sp_plan = sub.add_parser("plan")
822
- sp_plan.add_argument("--apply", action="store_true",
823
- help="actually run the install commands (DANGER)")
824
- sp_plan.add_argument("--confirm-token", default=None,
825
- help="confirmation token from the dry-run plan output")
826
- sub.add_parser("verify")
827
- sub.add_parser("preset")
828
- sub.add_parser("all")
829
- args = parser.parse_args()
830
-
831
- if args.cmd == "probe":
832
- print(json.dumps(probe().to_json(), indent=2, ensure_ascii=False)); return 0
833
- if args.cmd == "recommend":
834
- p = probe(); r = recommend(p)
835
- print(json.dumps({"probe": p.to_json(), "recommend": r.to_json()},
836
- indent=2, ensure_ascii=False))
837
- return 0
838
- if args.cmd == "plan":
839
- p = probe(); r = recommend(p); pl = plan(p, r)
840
- out: Dict[str, Any] = {"plan": pl.to_json()}
841
- if args.apply:
842
- out["install"] = apply_plan(pl, confirm=True, confirmation_token=args.confirm_token)
843
- print(json.dumps(out, indent=2, ensure_ascii=False)); return 0
844
- if args.cmd == "verify":
845
- p = probe(); r = recommend(p)
846
- print(json.dumps(verify(p, r), indent=2, ensure_ascii=False)); return 0
847
- if args.cmd == "preset":
848
- p = probe(); r = recommend(p)
849
- print(json.dumps(preset(p, r), indent=2, ensure_ascii=False)); return 0
850
- if args.cmd == "all":
851
- print(json.dumps(run_all(apply_install=False), indent=2, ensure_ascii=False))
852
- return 0
853
- return 2
3
+ from latticeai.setup import auto_setup as _impl
854
4
 
855
5
 
856
6
  if __name__ == "__main__":
857
- raise SystemExit(_main())
7
+ raise SystemExit(_impl._main())
8
+ else:
9
+ import sys
10
+
11
+ sys.modules[__name__] = _impl