Spaces:
Paused
Paused
Reset OpenCode user config to defaults
Browse files
app.py
CHANGED
|
@@ -383,6 +383,27 @@ async def install_opencode():
|
|
| 383 |
log.warning("⚠️ opencode 安裝失敗或已存在: %s", err[-500:])
|
| 384 |
|
| 385 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
async def install_editors():
|
| 387 |
"""安裝 vim / neovim(選用)。"""
|
| 388 |
log.info("正在安裝 vim / neovim ...")
|
|
@@ -438,8 +459,9 @@ def dummy_gpu():
|
|
| 438 |
@app.on_event("startup")
|
| 439 |
async def startup_event():
|
| 440 |
dummy_gpu()
|
| 441 |
-
#
|
| 442 |
await install_opencode()
|
|
|
|
| 443 |
#await run_installpi_script()
|
| 444 |
# 安裝編輯器不影響主要流程,放背景執行
|
| 445 |
asyncio.create_task(install_editors())
|
|
|
|
| 383 |
log.warning("⚠️ opencode 安裝失敗或已存在: %s", err[-500:])
|
| 384 |
|
| 385 |
|
| 386 |
+
def reset_opencode_config():
|
| 387 |
+
"""移除 OpenCode 使用者設定,令安裝使用內建預設值。"""
|
| 388 |
+
xdg_config = os.environ.get("XDG_CONFIG_HOME", os.path.join(HOME, ".config"))
|
| 389 |
+
config_files = [
|
| 390 |
+
os.path.join(xdg_config, "opencode", "opencode.json"),
|
| 391 |
+
os.path.join(xdg_config, "opencode", "opencode.jsonc"),
|
| 392 |
+
os.path.join(xdg_config, "opencode", "opencode.json5"),
|
| 393 |
+
os.path.join(HOME, ".opencode", "opencode.json"),
|
| 394 |
+
os.path.join(HOME, ".opencode", "opencode.jsonc"),
|
| 395 |
+
os.path.join(HOME, ".opencode", "opencode.json5"),
|
| 396 |
+
]
|
| 397 |
+
for path in config_files:
|
| 398 |
+
try:
|
| 399 |
+
os.remove(path)
|
| 400 |
+
log.info("Removed OpenCode config to restore defaults: %s", path)
|
| 401 |
+
except FileNotFoundError:
|
| 402 |
+
pass
|
| 403 |
+
except OSError as exc:
|
| 404 |
+
log.warning("Could not remove OpenCode config %s: %s", path, exc)
|
| 405 |
+
|
| 406 |
+
|
| 407 |
async def install_editors():
|
| 408 |
"""安裝 vim / neovim(選用)。"""
|
| 409 |
log.info("正在安裝 vim / neovim ...")
|
|
|
|
| 459 |
@app.on_event("startup")
|
| 460 |
async def startup_event():
|
| 461 |
dummy_gpu()
|
| 462 |
+
# 安裝 OpenCode 後清除使用者層級設定,使用 OpenCode 預設值。
|
| 463 |
await install_opencode()
|
| 464 |
+
reset_opencode_config()
|
| 465 |
#await run_installpi_script()
|
| 466 |
# 安裝編輯器不影響主要流程,放背景執行
|
| 467 |
asyncio.create_task(install_editors())
|