@kokorolx/ai-sandbox-wrapper 3.0.1 → 3.0.3

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.
package/README.md CHANGED
@@ -198,6 +198,10 @@ When running nano-brain inside the sandbox, `ai-run` performs a targeted preflig
198
198
 
199
199
  It also suppresses known **non-fatal** tree-sitter symbol-graph warnings when the command succeeds, so normal query output stays clean. To see suppressed diagnostics, run with debug mode (`AI_RUN_DEBUG=1`).
200
200
 
201
+ This behavior applies to both:
202
+ - direct mode (`ai-run npx nano-brain ...`)
203
+ - interactive shell mode (`ai-run`, then run `npx nano-brain ...` inside the container shell)
204
+
201
205
  ```bash
202
206
  # Auto-repair enabled by default
203
207
  ai-run npx nano-brain status
package/bin/ai-run CHANGED
@@ -701,6 +701,7 @@ get_installed_tools() {
701
701
  # Tool config persistence via bind mounts
702
702
  # Bind-mount host paths directly to ensure changes persist to the host.
703
703
  TOOL_CONFIG_MOUNTS=""
704
+ RG_COMPAT_MOUNT=""
704
705
 
705
706
  mount_tool_config() {
706
707
  local host_path="$1"
@@ -724,6 +725,32 @@ for tool in $(get_installed_tools); do
724
725
  done
725
726
  done
726
727
 
728
+ setup_opencode_rg_compat() {
729
+ [[ "$TOOL" != "opencode" ]] && return 0
730
+
731
+ local bundled_rg="$HOME/.local/share/opencode/bin/rg"
732
+ local rg_shim_path="$SANDBOX_DIR/shared/rg-linux-shim"
733
+
734
+ [[ -f "$bundled_rg" ]] || return 0
735
+ command -v file &>/dev/null || return 0
736
+
737
+ local rg_file_info
738
+ rg_file_info=$(file -b "$bundled_rg" 2>/dev/null || true)
739
+
740
+ if echo "$rg_file_info" | grep -qi "Mach-O"; then
741
+ mkdir -p "$(dirname "$rg_shim_path")"
742
+ cat > "$rg_shim_path" << 'EOF'
743
+ #!/usr/bin/env bash
744
+ exec /usr/bin/rg "$@"
745
+ EOF
746
+ chmod +x "$rg_shim_path"
747
+ RG_COMPAT_MOUNT="-v $rg_shim_path:/home/agent/.local/share/opencode/bin/rg:ro"
748
+ echo "⚠️ Detected incompatible OpenCode bundled rg (Mach-O). Using /usr/bin/rg in container."
749
+ fi
750
+ }
751
+
752
+ setup_opencode_rg_compat
753
+
727
754
  # Bundle OpenCode default skills (if opencode is installed)
728
755
  if get_installed_tools | grep -qw "opencode"; then
729
756
  AIRUN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -756,11 +783,12 @@ if [[ -d "$HOST_SKILLS_DIR" ]]; then
756
783
  SHARED_CACHE_MOUNTS="$SHARED_CACHE_MOUNTS -v $HOST_SKILLS_DIR:/home/agent/.config/opencode/skills:ro"
757
784
  fi
758
785
 
759
- # Nano-brain mount disabled to prevent SQLite conflicts between host and container
760
- # All tools should use the MCP interface to interact with nano-brain on the host
786
+ # Nano-brain read-only mount
787
+ # Exposes logs/index/sqlite files to container while preventing writes
788
+ NANO_BRAIN_MOUNT=""
761
789
  if [[ -d "$HOME/.nano-brain" ]]; then
762
- echo "ℹ️ Skipping .nano-brain mount to prevent SQLite database corruption"
763
- echo " Use MCP interface for nano-brain access instead of direct CLI"
790
+ NANO_BRAIN_MOUNT="-v $HOME/.nano-brain:/home/agent/.nano-brain:ro"
791
+ echo "ℹ️ Mounted .nano-brain as read-only at /home/agent/.nano-brain"
764
792
  fi
765
793
 
766
794
 
@@ -2230,6 +2258,7 @@ if [[ "${AI_RUN_DEBUG:-}" == "1" ]]; then
2230
2258
  echo "🔧 Debug: PORT_MAPPINGS='$PORT_MAPPINGS'"
2231
2259
  echo "🔧 Debug: WEB_DETECTED='$WEB_DETECTED'"
2232
2260
  echo "🔧 Debug: EXPOSE_PORTS_LIST='$EXPOSE_PORTS_LIST'"
2261
+ echo "🔧 Debug: RG_COMPAT_MOUNT='$RG_COMPAT_MOUNT'"
2233
2262
  fi
2234
2263
 
2235
2264
  is_nano_brain_command() {
@@ -2299,6 +2328,61 @@ run_with_capture() {
2299
2328
  run_with_capture
2300
2329
  '
2301
2330
 
2331
+ NANO_BRAIN_SHELL_HOOK=$(cat <<'EOF'
2332
+ nano_brain_shell_wrapper() {
2333
+ local ORIG_CMD=("$@")
2334
+ local REPAIR_PATTERN="(tree-sitter|native binding|Cannot find module.*tree-sitter|compiled against a different Node.js version|Exec format error|invalid ELF header|Native bindings not available)"
2335
+ local WARN_PATTERN="(\\[treesitter\\] Native bindings not available|symbol graph disabled|tree-sitter-typescript\\.node|No such file or directory)"
2336
+
2337
+ local err_file
2338
+ err_file=$(mktemp)
2339
+
2340
+ set +e
2341
+ "${ORIG_CMD[@]}" 2>"$err_file"
2342
+ local exit_code=$?
2343
+ set -e
2344
+
2345
+ if [[ $exit_code -ne 0 ]] && grep -Eqi "$REPAIR_PATTERN" "$err_file"; then
2346
+ cat "$err_file" >&2
2347
+ echo "⚠️ Detected nano-brain native module issue."
2348
+ echo "🔧 Running automatic repair (clearing npx/node-gyp caches)..."
2349
+ rm -rf /home/agent/.npm/_npx /home/agent/.cache/node-gyp 2>/dev/null || true
2350
+ npm cache clean --force >/dev/null 2>&1 || true
2351
+ echo "🔁 Retrying nano-brain command once..."
2352
+ "${ORIG_CMD[@]}"
2353
+ local retry_code=$?
2354
+ rm -f "$err_file"
2355
+ return $retry_code
2356
+ fi
2357
+
2358
+ if [[ $exit_code -eq 0 ]] && grep -Eqi "$WARN_PATTERN" "$err_file"; then
2359
+ if [[ "${AI_RUN_DEBUG:-}" == "1" ]]; then
2360
+ echo "ℹ️ nano-brain: non-fatal tree-sitter warning captured." >&2
2361
+ cat "$err_file" >&2
2362
+ else
2363
+ grep -Eiv "$WARN_PATTERN" "$err_file" >&2 || true
2364
+ fi
2365
+ rm -f "$err_file"
2366
+ return 0
2367
+ fi
2368
+
2369
+ cat "$err_file" >&2
2370
+ rm -f "$err_file"
2371
+ return $exit_code
2372
+ }
2373
+
2374
+ npx() {
2375
+ if [[ "${1:-}" == "nano-brain" ]]; then
2376
+ nano_brain_shell_wrapper command npx "$@"
2377
+ return $?
2378
+ fi
2379
+ command npx "$@"
2380
+ }
2381
+
2382
+ export -f nano_brain_shell_wrapper npx
2383
+ EOF
2384
+ )
2385
+
2302
2386
  # Prepare command based on mode
2303
2387
  ENTRYPOINT_OVERRIDE=""
2304
2388
  if [[ -n "$TOOL" && "$SHELL_MODE" != "true" ]]; then
@@ -2332,6 +2416,10 @@ else
2332
2416
  fi
2333
2417
 
2334
2418
  # Nano-brain targeted preflight + auto-repair wrapper
2419
+ if [[ "$SHELL_MODE" == "true" ]] && [[ "$NANO_BRAIN_AUTO_REPAIR" == "true" ]] && [[ "${DOCKER_COMMAND[0]:-}" == "-c" ]]; then
2420
+ DOCKER_COMMAND[1]="$NANO_BRAIN_SHELL_HOOK ${DOCKER_COMMAND[1]}"
2421
+ fi
2422
+
2335
2423
  if [[ "$SHELL_MODE" != "true" ]] && is_nano_brain_command; then
2336
2424
  if [[ "$NANO_BRAIN_AUTO_REPAIR" == "true" ]]; then
2337
2425
  ENTRYPOINT_OVERRIDE="--entrypoint bash"
@@ -2457,6 +2545,7 @@ docker run $CONTAINER_NAME --rm $TTY_FLAGS \
2457
2545
  $VOLUME_MOUNTS \
2458
2546
  $CONFIG_MOUNT \
2459
2547
  $TOOL_CONFIG_MOUNTS \
2548
+ $RG_COMPAT_MOUNT \
2460
2549
  $GIT_MOUNTS \
2461
2550
  $SSH_AGENT_ENV \
2462
2551
  $NETWORK_OPTIONS \
@@ -2466,6 +2555,7 @@ docker run $CONTAINER_NAME --rm $TTY_FLAGS \
2466
2555
  $OPENCODE_PASSWORD_ENV \
2467
2556
  -v "$HOME_DIR":/home/agent \
2468
2557
  $SHARED_CACHE_MOUNTS \
2558
+ $NANO_BRAIN_MOUNT \
2469
2559
  -w "$CURRENT_DIR" \
2470
2560
  --env-file "$ENV_FILE" \
2471
2561
  -e TERM="$TERM" \
@@ -90,6 +90,7 @@ RUN mkdir -p /opt/playwright-browsers && \
90
90
  ENV CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS=1
91
91
  RUN npm install -g chrome-devtools-mcp@latest && \
92
92
  touch /opt/.mcp-chrome-devtools-installed
93
+ RUN touch /opt/.mcp-playwright-installed
93
94
 
94
95
  # Create workspace
95
96
  WORKDIR /workspace
@@ -90,6 +90,7 @@ RUN mkdir -p /opt/playwright-browsers && \
90
90
  ENV CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS=1
91
91
  RUN npm install -g chrome-devtools-mcp@latest && \
92
92
  touch /opt/.mcp-chrome-devtools-installed
93
+ RUN touch /opt/.mcp-playwright-installed
93
94
 
94
95
  # Create workspace
95
96
  WORKDIR /workspace
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokorolx/ai-sandbox-wrapper",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "Docker-based security sandbox for AI coding agents. Isolate Claude, Gemini, Aider, and other AI tools from your host system.",
5
5
  "keywords": [
6
6
  "ai",