From f30706aeea15c5d8b9607087d8b8f7169483995c Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 5 Jun 2026 05:53:35 +0900 Subject: [PATCH] fix(DRIVE): portable package-dir resolution for the standalone release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit drive.hexa resolves the KB + retriever via DRIVE_PKG_DIR (exported by the released bin/drive launcher), falling back to ~/.hx/packages/DRIVE; rag_retrieve.py resolves its KB/cache relative to __file__. This makes RAG grounding work regardless of install name (~/.hx/packages/drive vs DRIVE) — needed by the standalone dancinlab/drive package. Co-Authored-By: Claude Opus 4.8 (1M context) --- DRIVE/drive.hexa | 10 ++++++++-- DRIVE/rag_retrieve.py | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/DRIVE/drive.hexa b/DRIVE/drive.hexa index 5afdd4a..550d025 100755 --- a/DRIVE/drive.hexa +++ b/DRIVE/drive.hexa @@ -203,12 +203,18 @@ fn apply_file_write(path: str, content: str) { // unavailable, so grounding never hard-depends on the embedding stack. // Missing KB / no backend -> "" (graceful: edit still works, just unguided). fn retrieve_recipes(instr: str) -> str { - let path = env("HOME") + "/.hx/packages/DRIVE/fix_recipes.txt" + // Resolve the package dir portably: DRIVE_PKG_DIR (exported by the bin/drive + // launcher of the released package) wins, else the in-repo/legacy install + // path. This keeps the KB + retriever findable regardless of install name + // (e.g. ~/.hx/packages/drive vs .../DRIVE). + let mut pkgdir = env("DRIVE_PKG_DIR") + if pkgdir.len() == 0 { pkgdir = env("HOME") + "/.hx/packages/DRIVE" } + let path = pkgdir + "/fix_recipes.txt" let present = exec("test -f " + shq(path) + " && echo Y || echo N").trim() if present != "Y" { return "" } // STAGE 1+2 — proper hybrid retriever (graceful: empty/err -> inline scan) let vpy = env("HOME") + "/.drive-rag-venv/bin/python" - let rag = env("HOME") + "/.hx/packages/DRIVE/rag_retrieve.py" + let rag = pkgdir + "/rag_retrieve.py" let has_rag = exec("test -x " + shq(vpy) + " && test -f " + shq(rag) + " && echo Y || echo N").trim() if has_rag == "Y" { diff --git a/DRIVE/rag_retrieve.py b/DRIVE/rag_retrieve.py index 3c005c2..07cf5a7 100644 --- a/DRIVE/rag_retrieve.py +++ b/DRIVE/rag_retrieve.py @@ -25,8 +25,9 @@ """ import sys, os, json, hashlib -KB = os.path.expanduser("~/.hx/packages/DRIVE/fix_recipes.txt") -CACHE = os.path.expanduser("~/.hx/packages/DRIVE/fix_recipes.emb.json") +_HERE = os.path.dirname(os.path.abspath(__file__)) # this script's dir = pkg root +KB = os.path.join(_HERE, "fix_recipes.txt") # KB ships beside this script +CACHE = os.path.join(_HERE, "fix_recipes.emb.json") # embedding cache (regenerable) MODEL = os.environ.get("DRIVE_EMBED_MODEL", "intfloat/multilingual-e5-large") EMBURL = os.environ.get("DRIVE_EMBED_URL", "").strip() # optional HTTP fallback TOPK = int(os.environ.get("DRIVE_RAG_TOPK", "3"))