diff --git a/lib/container.sh b/lib/container.sh index a952dad..1fe3f40 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -123,5 +123,84 @@ echo "→ Stopping \$CONTAINER_NAME..." STOP chmod +x "$project_dir/stop.sh" - success "Generated: start.sh stop.sh bin/claude" + # ── update.sh — update core, claude-code, and optionally OS packages ── + cat > "$project_dir/update.sh" </dev/null | grep -q true; then + CONTAINER_RUNNING=true +fi + +# ── 1. Update Context Studio Core ─────────────────────────────────────── +info "Updating Context Studio Core..." +if [[ -d "\$CS_CORE/.git" ]]; then + git -C "\$CS_CORE" pull --ff-only && success "Core updated." || warn "Core pull failed — continuing with current version." +else + warn "Core not found at \$CS_CORE — skipping." +fi + +# ── 2. Update Claude Code in container ────────────────────────────────── +info "Updating Claude Code (claude-code)..." +if \$CONTAINER_RUNNING; then + "\$RUNTIME" exec "\$CONTAINER_NAME" npm install -g @anthropic-ai/claude-code \ + && success "Claude Code updated in running container." \ + || warn "Claude Code update failed." +else + warn "Container not running — Claude Code will be updated on next image build." +fi + +# ── 3. Update OS packages in container ────────────────────────────────── +info "Updating OS packages in container..." +if \$CONTAINER_RUNNING; then + "\$RUNTIME" exec "\$CONTAINER_NAME" bash -c "apt-get update -qq && apt-get upgrade -y" \ + && success "OS packages updated in running container." \ + || warn "OS package update failed." +else + warn "Container not running — OS packages will be updated on next image build." +fi + +# ── 4. Rebuild image to persist updates ───────────────────────────────── +echo "" +echo -e "\${BOLD}Rebuild container image?\${RESET}" +echo -e " Rebuilds from scratch with latest base image + all packages." +echo -e " ${YELLOW}⚠ Takes 5–15 minutes. Stops the running container.\${RESET}" +echo -ne "Rebuild now? \${CYAN}[y/N]\${RESET}: " +read -r _rebuild || true +_rebuild="\${_rebuild:-n}" + +if [[ "\$_rebuild" =~ ^[Yy]\$ ]]; then + info "Stopping container..." + "\$RUNTIME" rm -f "\$CONTAINER_NAME" 2>/dev/null || true + + info "Rebuilding image '\$IMAGE_NAME' (--pull --no-cache)..." + "\$RUNTIME" build --pull --no-cache -t "\$IMAGE_NAME" "\$PROJECT_DIR/.devcontainer/" \ + && success "Image rebuilt. Run ./start.sh to start with the fresh image." \ + || { echo "Image build failed." >&2; exit 1; } +else + info "Skipped image rebuild." + if \$CONTAINER_RUNNING; then + warn "In-container updates are temporary — they will be lost when the container is recreated." + warn "Run ./update.sh again and choose 'y' to rebuild, or run ./start.sh (which recreates the container from the old image)." + fi +fi + +echo "" +success "Update complete." +UPDATE + chmod +x "$project_dir/update.sh" + + success "Generated: start.sh stop.sh update.sh bin/claude" } diff --git a/wizard.sh b/wizard.sh index 6ec131d..48574fb 100755 --- a/wizard.sh +++ b/wizard.sh @@ -137,6 +137,11 @@ print_next_steps() { echo -e "${BOLD}Stop the container:${RESET}" echo -e " ${CYAN}./stop.sh${RESET}" echo "" + echo -e "${BOLD}Update everything:${RESET}" + echo -e " ${CYAN}./update.sh${RESET}" + echo -e " Updates Context Studio Core, Claude Code, and OS packages." + echo -e " Optionally rebuilds the image from scratch." + echo "" echo -e "${BOLD}How it works:${RESET}" echo -e " • Context Studio Core runs on your host (Electron UI, no display issues)" echo -e " • Claude Code agents run inside container ${CYAN}cs-${slug}${RESET}"