opencode-agent-harness 0.2.0 → 0.3.14

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.
@@ -26,7 +26,7 @@
26
26
  # No-op outside WSL (override with AGENT_WSL_TUNE_FORCE=1). Env overrides:
27
27
  # AGENT_WSL_TUNE_SYSCTL, AGENT_WSL_TUNE_SLICE_DIR, AGENT_WSL_CONFIG,
28
28
  # AGENT_WSL_TUNE_DRY_RUN, AGENT_WSL_TUNE_PROCESSORS, AGENT_WSL_TUNE_SWAP,
29
- # AGENT_WSL_TUNE_IDLE_MS
29
+ # AGENT_WSL_TUNE_IDLE_MS, AGENT_WSL_TUNE_NODE (node binary for the merge)
30
30
  set -euo pipefail
31
31
 
32
32
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -120,8 +120,50 @@ WantedBy=multi-user.target
120
120
  EOF
121
121
  }
122
122
 
123
+ # `sudo` resets PATH to the secure_path, so a user-local node (nvm, volta,
124
+ # fnm, ~/.local/bin) is invisible to `sudo bash scripts/wsl-tune.sh apply`.
125
+ # Resolve it from the invoking user's installs instead of assuming PATH.
126
+ node_bin() {
127
+ if [ -n "${AGENT_WSL_TUNE_NODE:-}" ]; then
128
+ if [ -x "$AGENT_WSL_TUNE_NODE" ]; then printf '%s' "$AGENT_WSL_TUNE_NODE"; return 0; fi
129
+ warn "wsl-tune: AGENT_WSL_TUNE_NODE=$AGENT_WSL_TUNE_NODE is not executable"
130
+ return 1
131
+ fi
132
+ if command -v node >/dev/null 2>&1; then command -v node; return 0; fi
133
+ local home="" cand
134
+ if [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != "root" ]; then
135
+ home="$(getent passwd "$SUDO_USER" 2>/dev/null | cut -d: -f6 || true)"
136
+ fi
137
+ [ -n "$home" ] || home="${HOME:-}"
138
+ for cand in \
139
+ "$home/.local/bin/node" \
140
+ "$home/.volta/bin/node" \
141
+ "$home/.asdf/shims/node" \
142
+ /usr/local/bin/node /usr/bin/node /snap/bin/node; do
143
+ [ -x "$cand" ] && { printf '%s' "$cand"; return 0; }
144
+ done
145
+ # nvm/fnm keep versioned installs; take the newest.
146
+ cand="$(ls -1d "$home"/.nvm/versions/node/*/bin/node \
147
+ "$home"/.fnm/node-versions/*/installation/bin/node 2>/dev/null | sort -V | tail -n1 || true)"
148
+ [ -n "$cand" ] && [ -x "$cand" ] && { printf '%s' "$cand"; return 0; }
149
+ return 1
150
+ }
151
+
152
+ # The merge only touches the Windows-side .wslconfig, so under sudo run it as
153
+ # the invoking user: that is whose node we resolved, and the backup keeps the
154
+ # user's ownership on the drvfs mount.
155
+ run_merger() {
156
+ local nb="$1"; shift
157
+ if [ "$(id -u)" -eq 0 ] && [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != "root" ] \
158
+ && command -v sudo >/dev/null 2>&1; then
159
+ sudo -u "$SUDO_USER" -H "$nb" "$MERGERS" "$@"
160
+ else
161
+ "$nb" "$MERGERS" "$@"
162
+ fi
163
+ }
164
+
123
165
  apply_wslconfig() {
124
- local cfg sets=()
166
+ local cfg sets=() nb
125
167
  cfg="$(find_config)"
126
168
  if [ -z "$cfg" ]; then
127
169
  warn "wsl-tune: no .wslconfig found (set AGENT_WSL_CONFIG to target one) — skipping host tuning"
@@ -137,12 +179,19 @@ apply_wslconfig() {
137
179
  sets+=("--set" "experimental.autoMemoryReclaim=gradual")
138
180
  sets+=("--set" "experimental.sparseVhd=true")
139
181
 
182
+ if ! nb="$(node_bin)"; then
183
+ warn "wsl-tune: node not found (sudo resets PATH, so a user-local node is invisible)."
184
+ warn " merge .wslconfig as your user: npm run wsl-tune -- wslconfig"
185
+ warn " (or pass AGENT_WSL_TUNE_NODE=/path/to/node)"
186
+ return 1
187
+ fi
188
+
140
189
  if [ "$DRY_RUN" = "1" ]; then
141
190
  log "wsl-tune: would merge into $cfg:"
142
- node "$MERGERS" --file "$cfg" "${sets[@]}" | sed 's/^/ /'
191
+ run_merger "$nb" --file "$cfg" "${sets[@]}" | sed 's/^/ /'
143
192
  return 0
144
193
  fi
145
- node "$MERGERS" --file "$cfg" --write --backup "${sets[@]}"
194
+ run_merger "$nb" --file "$cfg" --write --backup "${sets[@]}"
146
195
  }
147
196
 
148
197
  do_status() {
@@ -191,8 +240,9 @@ do_apply() {
191
240
  exec sudo -E bash "$0" apply "$@"
192
241
  fi
193
242
  warn "wsl-tune: in-WSL tunables need root — re-run: sudo bash scripts/wsl-tune.sh apply"
194
- apply_wslconfig
195
- return 0
243
+ local rc=0
244
+ apply_wslconfig || rc=$?
245
+ return "$rc"
196
246
  fi
197
247
  printf '%s\n' "$SYSCTL_BODY" > "$SYSCTL_FILE"
198
248
  log "wsl-tune: wrote $SYSCTL_FILE"
@@ -217,10 +267,18 @@ do_apply() {
217
267
  warn " systemctl set-property init.scope MemoryHigh=$BACKSTOP"
218
268
  fi
219
269
  fi
220
- apply_wslconfig
270
+ local merge_rc=0
271
+ apply_wslconfig || merge_rc=$?
221
272
  log ""
222
- log "wsl-tune: done. MANUAL STEP — from Windows PowerShell run: wsl --shutdown"
223
- log " (only needed for the .wslconfig changes: processors/swap/vmIdleTimeout.)"
273
+ if [ "$merge_rc" -eq 0 ]; then
274
+ log "wsl-tune: in-WSL tunables applied; .wslconfig merged."
275
+ log "wsl-tune: done. MANUAL STEP — from Windows PowerShell run: wsl --shutdown"
276
+ log " (only needed for the .wslconfig changes: processors/swap/vmIdleTimeout.)"
277
+ else
278
+ warn "wsl-tune: in-WSL tunables applied, but the .wslconfig merge did not complete (see above)."
279
+ warn " Finish it as your user: npm run wsl-tune -- wslconfig"
280
+ fi
281
+ return "$merge_rc"
224
282
  }
225
283
 
226
284
  do_down() {