@@ -222,11 +222,31 @@ CONFIG_REF="${LPB_CONFIG_REF:-main}"
222222export PI_CODING_AGENT_DIR= " ${AGENT_DIR} "
223223
224224if [[ ! -d " ${AGENT_DIR} /.git" ]]; then
225- info " Cloning config repo from ${CONFIG_REMOTE} ..."
226- if git clone --depth=1 --branch " ${CONFIG_REF} " " ${CONFIG_REMOTE} " " ${AGENT_DIR} " ; then
227- info " Config repo cloned."
225+ if [[ -d " ${AGENT_DIR} " && -n " $( ls -A " ${AGENT_DIR} " 2> /dev/null) " ]]; then
226+ # ~/.pi already exists and is non-empty but not a git repo — e.g. stale
227+ # pre-refactor state, or a fresh container booting over a persisted
228+ # ~/.pi volume. `git clone` refuses a non-empty target, so initialize
229+ # the repo in place instead. Existing files are left untouched
230+ # (gitignored by the config repo) so nothing is lost.
231+ info " Config area not empty — initializing config repo in place..."
232+ if git -C " ${AGENT_DIR} " init -q \
233+ && git -C " ${AGENT_DIR} " remote add origin " ${CONFIG_REMOTE} " 2> /dev/null \
234+ && git -C " ${AGENT_DIR} " fetch --depth=1 origin " ${CONFIG_REF} " ; then
235+ # Reset to the fetched ref: tracked files land at the repo root,
236+ # untracked runtime state stays as-is. No force (won't clobber a
237+ # conflicting local i.e. settings file).
238+ git -C " ${AGENT_DIR} " reset -q --hard " origin/${CONFIG_REF} " 2> /dev/null || true
239+ info " Config repo initialized."
240+ else
241+ warn " Config repo initialization failed — Pi will use defaults."
242+ fi
228243 else
229- warn " Config clone failed — Pi will use defaults."
244+ info " Cloning config repo from ${CONFIG_REMOTE} ..."
245+ if git clone --depth=1 --branch " ${CONFIG_REF} " " ${CONFIG_REMOTE} " " ${AGENT_DIR} " ; then
246+ info " Config repo cloned."
247+ else
248+ warn " Config clone failed — Pi will use defaults."
249+ fi
230250 fi
231251else
232252 # Non-destructive fetch only — local customizations are never wiped.
@@ -248,7 +268,8 @@ if [[ "$FIRST_RUN" = "true" ]]; then
248268 chown -R " $( id -u) :$( id -g) " " ${HOME_DIR} /.pi" " ${HOME_DIR} /.npm" " ${HOME_DIR} /.config" 2> /dev/null || true
249269 chmod -R u+rwX " ${HOME_DIR} /.pi" " ${HOME_DIR} /.npm" 2> /dev/null || true
250270
251- mkdir -p " ${HOME_DIR} /.pi/agent/git" \
271+ mkdir -p " ${HOME_DIR} /.pi/git" \
272+ " ${HOME_DIR} /.pi/npm" \
252273 " ${HOME_DIR} /.venvs"
253274
254275 npm config set prefix ' /home/lpb/.npm-global' 2> /dev/null || true
@@ -262,7 +283,7 @@ if [[ "$FIRST_RUN" = "true" ]]; then
262283 npm config set allow-scripts ' better-sqlite3 agent-browser esbuild protobufjs @google/genai' 2> /dev/null || true
263284
264285 # Pre-create .npmrc so npm reads allow-scripts from parent dir
265- printf ' allow-scripts=better-sqlite3\nallow-scripts=agent-browser\nallow-scripts=esbuild\nallow-scripts=protobufjs\nallow-scripts=@google/genai\n' > " ${HOME_DIR} /.pi/agent/ git/.npmrc" 2> /dev/null || true
286+ printf ' allow-scripts=better-sqlite3\nallow-scripts=agent-browser\nallow-scripts=esbuild\nallow-scripts=protobufjs\nallow-scripts=@google/genai\n' > " ${HOME_DIR} /.pi/git/.npmrc" 2> /dev/null || true
266287 printf ' allow-scripts=better-sqlite3\nallow-scripts=agent-browser\nallow-scripts=esbuild\nallow-scripts=protobufjs\nallow-scripts=@google/genai\n' > " ${HOME_DIR} /.npmrc" 2> /dev/null || true
267288
268289 # Fix pi-coding-agent package.json to include allowScripts
@@ -373,7 +394,7 @@ persist_devstack_env
373394
374395debug " Checking native modules..."
375396NEED_REBUILD=false
376- EXT_BASE=" ${HOME_DIR} /.pi/agent/ git"
397+ EXT_BASE=" ${HOME_DIR} /.pi/git"
377398
378399# Look for any better-sqlite3 that's missing its bindings
379400while IFS= read -r pkg_json; do
@@ -421,7 +442,7 @@ if [[ "$NEED_REBUILD" = "true" ]]; then
421442 [[ -f " $path " ]] && binding_found=true && break
422443 done
423444 if [[ " $binding_found " = " false" ]]; then
424- local_name=$( echo " $ext_dir " | sed " s|.*/agent /git/||" )
445+ local_name=$( echo " $ext_dir " | sed " s|.*/\.pi /git/||" )
425446 info " Rebuilding: ${local_name} ..."
426447 (cd " $ext_dir " && PATH=" /home/lpb/.npm-global/bin:${PATH} " npm rebuild better-sqlite3 --loglevel=error 2>&1 | tail -3) || \
427448 warn " npm rebuild failed for ${local_name} , trying node-gyp..."
0 commit comments