perf(doctor): cut Git Bash process starts in doctor, hook-check and launch probe (GSTA-138)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
garrytanandcapy-ai[bot] committed 2026-10-28 11:03:05 +00:00
1 parent 9e3308f65a
commit 115355a38b
4 files changed
+44 -21

No files matched your search

+12 -5
View File
@@ -93,7 +93,14 @@ row() {
sq() { printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")"; }
# clamp CHARSET MAX — stdin's first line reduced to CHARSET, at most MAX chars.
clamp() { head -1 | tr -cd "$1" | cut -c1-"$2"; }
# Builtins only, bytewise like tr and cut: every caller pipes into it, and on
# Windows a head | tr | cut chain costs three process starts (~60 ms).
clamp() { local LC_ALL=C line pat="[^$1]"; IFS= read -r line; line=${line//$pat/}; printf '%s' "${line:0:$2}"; }
# cfg KEY DEFAULT — sets _cfg to KEY as `gstack-config get` reads it, or DEFAULT
# (gstack-config's own default) when unset. In-process through
# gstack-state-root.sh, sourced below: a gstack-config start costs ~200 ms on Windows.
cfg() { gstack_config_select "$1" 2>/dev/null; _cfg="${_gstack_cfg_value:-$2}"; }
# epoch_of VALUE — epoch seconds for an epoch or an ISO-8601 UTC time; "" otherwise.
epoch_of() {
@@ -202,7 +209,7 @@ check_hooks() {
check_codex() {
local reviews probe="$BIN/gstack-codex-probe" sel rc model src
CODEX_READY=0
reviews=$("$BIN/gstack-config" get codex_reviews 2>/dev/null || echo enabled)
cfg codex_reviews enabled; reviews=$_cfg
if [ "$reviews" = disabled ]; then
row "not configured" codex "codex_reviews disabled; $CODEX_FEATURES skip Codex" "$BIN/gstack-config set codex_reviews enabled"
return
@@ -269,7 +276,7 @@ check_codex_probe() {
check_sync() {
local mode file json status held drainable drain push queue=0 now f detail case_names fix="$BIN/gstack-brain-sync --status"
mode=$("$BIN/gstack-config" get artifacts_sync_mode 2>/dev/null || echo off)
cfg artifacts_sync_mode off; mode=$_cfg
if [ ! -d "$STATE_ROOT/.git" ]; then
row "not configured" "artifacts sync" "off; cross-machine artifacts sync is unavailable" "$BIN/gstack-artifacts-init"
return
@@ -373,7 +380,7 @@ check_binaries() {
check_cso() {
local file="$SRC/bin/.gstack-cso-build-result" result stage reason installed diag usable=0
[ -x "$SRC/bin/gstack-cso-launcher$EXE" ] && [ -x "$SRC/bin/gstack-cso-core$EXE" ] && usable=1
cso_field() { sed -n "s/^$1=//p" "$file" 2>/dev/null | head -1 | clamp ' -~' 200; }
cso_field() { sed -n "s/^$1=//p" "$file" 2>/dev/null | clamp ' -~' 200; }
result=$(cso_field result) stage=$(cso_field stage) reason=$(cso_field reason) installed=$(cso_field installed) diag=$(cso_field diagnostic)
case "$result" in
ok) if [ "$usable" -eq 1 ]; then row ok cso "native helper $installed"
@@ -603,7 +610,7 @@ if [ "$CHECK" -eq 1 ]; then
exit $?
fi
echo "gstack doctor $(head -1 "$ROOT/VERSION" 2>/dev/null | clamp '0-9A-Za-z.+-' 40)"
echo "gstack doctor $(clamp '0-9A-Za-z.+-' 40 2>/dev/null <"$ROOT/VERSION")"
check_install
check_rescue_refs
check_state_root
+11 -11
View File
@@ -2,7 +2,7 @@
# gstack-doctor-check.sh — `gstack-doctor --check`: the one-line install verdict.
#
# Sourced by bin/gstack-doctor after its prelude (ROOT, ROOT_REAL, BIN, SRC,
# DOCS, STATE_ROOT, EXE, clamp, the launch probe, the codex status helpers)
# DOCS, STATE_ROOT, EXE, clamp, cfg, the launch probe, the codex status helpers)
# and never executed on its own. Prints `required: <ids>`, one
# `PASS | FAIL | SKIP <id>` row per component in bin/gstack-doctor-components.sh
# (generated from lib/doctor-components.ts; the same ids feed --for, --require
@@ -142,7 +142,7 @@ _dc_check_patch() {
fi
# A tier 2+ render keeps the patch in the shared sections/preamble.md its SKILL.md points to.
for f in "$file" "${file%/SKILL.md}/sections/preamble.md"; do
model=$(grep -F 'Model-Specific Behavioral Patch (' "$f" 2>/dev/null | head -1 | sed 's/.*Model-Specific Behavioral Patch (\([^)]*\)).*/\1/' | clamp 'A-Za-z0-9._:/-' 60)
model=$(grep -F 'Model-Specific Behavioral Patch (' "$f" 2>/dev/null | sed 's/.*Model-Specific Behavioral Patch (\([^)]*\)).*/\1/' | clamp 'A-Za-z0-9._:/-' 60)
[ -n "$model" ] && { file="$f"; break; }
done
if [ -n "$model" ]; then
@@ -154,7 +154,7 @@ _dc_check_patch() {
_dc_check_codex_cli() {
local probe="$BIN/gstack-codex-probe" reviews sel rc model out state optional_note="optional; a Claude subagent serves as the outside voice"
reviews=$("$BIN/gstack-config" get codex_reviews 2>/dev/null || echo enabled)
cfg codex_reviews enabled; reviews=$_cfg
if ! command -v codex >/dev/null 2>&1; then
_dc_fail_or_skip codex-cli "Codex CLI not installed" "npm install -g @openai/codex, then codex login" COMPONENT_MISSING "$optional_note; Codex CLI not installed"
return
@@ -228,7 +228,7 @@ _dc_check_browser() {
if [ "$rc" -eq 0 ] && printf '%s\n' "$out" | grep -q '^RENDER_OK'; then
_dc_row PASS browser "Chromium $(printf '%s\n' "$out" | sed -n 's/^RENDER_OK //p' | clamp '0-9.' 20) launched and rendered ($engine)"
else
_dc_row FAIL browser "Chromium did not launch and render via $engine (exit $rc: $(printf '%s\n' "$out" | grep -v '^[[:space:]]*$' | head -1 | clamp ' -~' 160))" "$fix" BROWSER_UNAVAILABLE
_dc_row FAIL browser "Chromium did not launch and render via $engine (exit $rc: $(printf '%s\n' "$out" | grep -v '^[[:space:]]*$' | clamp ' -~' 160))" "$fix" BROWSER_UNAVAILABLE
fi
}
@@ -238,7 +238,7 @@ _dc_check_cso() {
_dc_row PASS cso "native helper built"
return
fi
[ -f "$file" ] && reason=$(sed -n 's/^reason=//p' "$file" 2>/dev/null | head -1 | clamp ' -~' 100)
[ -f "$file" ] && reason=$(sed -n 's/^reason=//p' "$file" 2>/dev/null | clamp ' -~' 100)
_dc_fail_or_skip cso "native helper not built${reason:+ ($reason)}" "cd $SRC && ./setup (it names any missing build prerequisite)" COMPONENT_MISSING "optional; toolchain absent or helper not built${reason:+: $reason}"
}
@@ -376,7 +376,7 @@ _dc_check_pins() {
return
fi
_dc_row FAIL pins "$failline$note" "$fix" PROJECT_PIN_MISMATCH ;;
*) _dc_row SKIP pins "gstack-runtime-pins could not evaluate $project (exit $rc: $(printf '%s\n' "$out" | grep -v '^[[:space:]]*$' | head -1 | clamp ' -~' 120))" ;;
*) _dc_row SKIP pins "gstack-runtime-pins could not evaluate $project (exit $rc: $(printf '%s\n' "$out" | grep -v '^[[:space:]]*$' | clamp ' -~' 120))" ;;
esac
}
@@ -394,7 +394,7 @@ _dc_check_state_root() {
}
# _dc_cfg KEY DEFAULT — a clamped config value, never the file or a message.
_dc_cfg() { local v; v=$("$BIN/gstack-config" get "$1" 2>/dev/null </dev/null | clamp 'a-z0-9_-' 24); printf '%s' "${v:-$2}"; }
_dc_cfg() { local v; cfg "$1" "$2"; v=$(printf '%s' "$_cfg" | clamp 'a-z0-9_-' 24); printf '%s' "${v:-$2}"; }
_dc_check_privacy() {
_dc_row PASS privacy "telemetry=$(_dc_cfg telemetry off) artifacts_sync=$(_dc_cfg artifacts_sync_mode off) codex_reviews=$(_dc_cfg codex_reviews enabled) update_check=$(_dc_cfg update_check true)"
@@ -408,7 +408,7 @@ _dc_check_cores() {
local n backend
n=$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 0)
n=$(printf '%s' "$n" | clamp '0-9' 6)
backend=$("$BIN/gstack-config" get test_backend 2>/dev/null </dev/null | clamp 'a-z' 8); backend=${backend:-local}
cfg test_backend local; backend=$(printf '%s' "$_cfg" | clamp 'a-z' 8); backend=${backend:-local}
case "$n" in ''|0) _dc_row PASS cores "unknown CPU count test_backend=$backend"; return ;; esac
if [ "$n" -lt 8 ] && [ "$backend" = local ]; then
_dc_row PASS cores "$n test_backend=local (under 8: run full unit and E2E tiers on a remote gate; set gstack-config set test_backend ubicloud, scripts/ubicloud/ubi-runner.sh)"
@@ -454,7 +454,7 @@ _dc_check_min_revision() {
_dc_check_revision() {
local installed head="" want="$CHECK_REVISION" target=""
installed=$(head -1 "$ROOT/VERSION" 2>/dev/null | clamp '0-9A-Za-z.+-' 40)
installed=$(clamp '0-9A-Za-z.+-' 40 2>/dev/null <"$ROOT/VERSION")
head=$(git -C "$ROOT_REAL" rev-parse --short HEAD 2>/dev/null | clamp '0-9a-f' 12)
_dc_revision="${installed:-unknown}"
_dc_check_min_revision "${installed:-0}" "$head" || return
@@ -500,7 +500,7 @@ _dc_check_floor() {
# first occurrence wins (the top-level field in a policy file), and only the
# first 64 KiB are read: a real policy is a few KB.
flat=$(head -c 65536 "$file" 2>/dev/null | tr '\n\r\t' ' ')
floor=$(printf '%s' "$flat" | grep -o '"'"$GSTACK_PROJECT_FLOOR_FIELD"'" *: *"[0-9][0-9.]*"' | head -1 | sed 's/.*"\([0-9][0-9.]*\)"$/\1/' | clamp '0-9.' 32)
floor=$(printf '%s' "$flat" | grep -o '"'"$GSTACK_PROJECT_FLOOR_FIELD"'" *: *"[0-9][0-9.]*"' | sed 's/.*"\([0-9][0-9.]*\)"$/\1/' | clamp '0-9.' 32)
if [ -z "$floor" ]; then
if printf '%s' "$flat" | grep -q '"'"$GSTACK_PROJECT_FLOOR_FIELD"'" *: *"'; then
_dc_row SKIP floor "$file sets $GSTACK_PROJECT_FLOOR_FIELD to something other than a plain dotted version"
@@ -509,7 +509,7 @@ _dc_check_floor() {
fi
return
fi
installed=$(head -1 "$ROOT/VERSION" 2>/dev/null | clamp '0-9A-Za-z.+-' 40)
installed=$(clamp '0-9A-Za-z.+-' 40 2>/dev/null <"$ROOT/VERSION")
if _dc_version_below "${installed:-0}" "$floor"; then
if [ -n "${GSTACK_CAPY_WRAPPER_PATH:-}" ]; then
fix="bash $GSTACK_CAPY_WRAPPER_PATH${CHECK_FOR:+ --for $CHECK_FOR} (fast-forwards a clean checkout to origin and reinstalls), or $SRC/bin/gstack-upgrade"
+17 -4
View File
@@ -155,11 +155,17 @@ ts_entries() {
# One bun process bundles every hook's TypeScript entries (a bun start costs
# seconds on Windows). Each line is "<entry>\tok\t<input>" per bundled input,
# or "<entry>\tfail\t<file:line>\t<message>".
# TS_OF[i] keeps hook i's entries for the check loop below, so each shim is
# scanned once (four process starts, ~80 ms on Windows).
ENTRIES=""
i=0
for hook in $HOOKS; do
shim="$ROOT/$hook"
TS_OF[i]=""
[ -f "$shim" ] && TS_OF[i]=$(ts_entries "$shim")
i=$((i + 1))
[ -f "$shim" ] || continue
for entry in $(ts_entries "$shim"); do
for entry in ${TS_OF[i - 1]}; do
[ -f "${shim%/*}/$entry" ] && ENTRIES="$ENTRIES${shim%/*}/$entry$NL"
done
done
@@ -190,11 +196,14 @@ if [ -n "$ENTRIES" ]; then
}' $ENTRIES) > "$BUILT" 2>/dev/null || true
fi
i=0
for hook in $HOOKS; do
shim="$ROOT/$hook"
i=$((i + 1))
if [ ! -f "$shim" ]; then echo "missing $hook"; continue; fi
hook_ok=1
shebang=$(head -1 "$shim")
shebang=""
IFS= read -r shebang < "$shim"
case "$shebang" in
'#!'*bash*) interp=bash ;;
'#!'*/sh|'#!'*/sh' '*|'#!'*' sh'|'#!'*' sh '*) interp=sh ;;
@@ -217,7 +226,7 @@ for hook in $HOOKS; do
scan="$scan$NL$helper"
done
dir=${shim%/*}
for entry in $(ts_entries "$shim"); do
for entry in ${TS_OF[i - 1]}; do
if [ ! -f "$dir/$entry" ]; then
fail "$hook" "$dir/$entry:1" "missing TypeScript entry (the hook runs it)"
hook_ok=0
@@ -244,7 +253,11 @@ for hook in $HOOKS; do
# and -H prefixes "<file>:<line>:" (the line is the last colon field before
# the marker text, so paths containing colons still split right).
# shellcheck disable=SC2046 # newline-split list (IFS is a newline)
for found in $(grep -HnE -m1 '^(<<<<<<<|=======|>>>>>>>)( |$)' $(printf '%s\n' "$scan" | awk '!seen[$0]++') 2>/dev/null); do
files=""
for f in $scan; do
case "$NL$files" in *"$NL$f$NL"*) ;; *) files="$files$f$NL" ;; esac
done
for found in $(grep -HnE -m1 '^(<<<<<<<|=======|>>>>>>>)( |$)' $files 2>/dev/null); do
marker_file=${found%%:[0-9]*:[<=>]*}
marker_line=${found#"$marker_file":}
marker_line=${marker_line%%:*}
+4 -1
View File
@@ -30,7 +30,10 @@ gstack_launch_probe() {
out=$("$1" --version </dev/null 2>&1)
fi
rc=$?
_glp_detail=$(printf '%s\n' "$out" | tr -d '\r' | grep -v '^[[:space:]]*$' | head -1 | cut -c1-200)
# The first non-blank line, CRs dropped, at most 200 bytes: one subshell, not
# a five-process pipeline (each process start is ~20 ms on Windows).
_glp_detail=$(set -f; IFS='
'; LC_ALL=C; for line in $out; do line=${line//$'\r'/}; case "$line" in *[![:space:]]*) printf '%s' "${line:0:200}"; break ;; esac; done)
case "$out" in
*[Aa]pplication\ [Cc]ontrol*|*"Smart App Control"*|*"blocked by group policy"*|*"has blocked this file"*)
_glp_state=blocked; return 0 ;;