Merge origin/main into the Oct 8 triage wave

# Conflicts:
#	extension/sidepanel-terminal.js
#	test/gstack-doctor.test.ts
This commit is contained in:
garrytan committed 2026-10-08 15:57:20 +00:00
commit f10032f174
40 files changed
+1511 -80

No files matched your search

+17 -6
View File
@@ -367,17 +367,28 @@ export function amendImplementation(phase: string, activePlan: string, snapshotP
return checkPhaseImplementation(phase, source, snapshotPath, extractImplementationPlan(next) === prior ? 'unchanged' : 'changed');
}
/**
* The canonical spelling of an init destination: the deepest existing ancestor is
* realpathed (so /tmp -> /private/tmp on macOS) and any missing segments plus the
* basename are re-joined. Pure path computation; the regular-file check stays in
* initializePlan. Init reports this spelling, so callers comparing against the
* argv they passed must canonicalize the argv the same way.
*/
export function canonicalDestination(file: string): string {
let parent = dirname(file);
const missing: string[] = [];
while (!lstatSync(parent, { throwIfNoEntry: false })) {
missing.unshift(basename(parent)); parent = dirname(parent);
}
return join(realpathSync(parent), ...missing, basename(file));
}
/** Initialize the existing strict section contract before any scope or review call. */
export function initializePlan(sourcePlan: string, activePlan: string, restorePath: string) {
if (![sourcePlan, activePlan, restorePath].every(isAbsolute)) throw new Error('Initialization requires three absolute paths');
const source = realpathSync(sourcePlan);
const destination = (file: string) => {
let parent = dirname(file);
const missing: string[] = [];
while (!lstatSync(parent, { throwIfNoEntry: false })) {
missing.unshift(basename(parent)); parent = dirname(parent);
}
const canonical = join(realpathSync(parent), ...missing, basename(file));
const canonical = canonicalDestination(file);
const state = lstatSync(canonical, { throwIfNoEntry: false, bigint: true });
if (state && !state.isFile()) throw new Error('Initialization destinations must be regular files, not links or directories');
return { file: canonical, state, bytes: state ? readFileSync(canonical) : undefined };
+70 -6
View File
@@ -6,7 +6,7 @@
# gstack-doctor --live also run the paid Codex model probe (one short call)
#
# Rows: install root, state root, bun, hooks, codex, codex probe, artifacts
# sync, browse bundle, claude code, session journal, guard log. Each row is
# sync, browse bundle, binaries, cso, claude code, session journal, guard log. Each row is
# `ok`, `warn`, `not configured` or `fail`; a row that is not ok carries a fix
# line, and every gstack helper in a fix line is an absolute path under this
# install root. Exit 1 when any row is `fail`, 2 on a usage error, else 0.
@@ -15,8 +15,9 @@
# install registry rows behind `./setup --status`, bin/gstack-bun-version.sh,
# bin/gstack-hook-check, bin/gstack-codex-probe's subcommands (the paid
# `probe-model` only with --live; otherwise the cached result and its age),
# the status file bin/gstack-brain-sync writes, and setup's browse build
# outputs. The sync row prints only a clamped status code and counts, never
# the status file bin/gstack-brain-sync writes, setup's browse build
# outputs, setup's launch probe (bin/gstack-launch-probe.sh, which runs each
# compiled binary's side-effect-free --version) and the CSO build-result record. The sync row prints only a clamped status code and counts, never
# the status message or file paths: the message can quote a matched secret.
# Bash 3.2 plus POSIX tools; it still reports when bun or python3 is missing.
@@ -272,13 +273,26 @@ check_sync() {
fi
}
# launch_fix — the fix line for a binary the OS refuses to start.
launch_fix() {
if [ -n "$EXE" ]; then
echo "Windows Smart App Control (or another application-control policy) blocks unsigned local builds (#2595): run gstack inside WSL or turn Smart App Control off, then cd $SRC && ./setup ($DOCS#windows-smart-app-control)"
else
echo "the OS refused to execute it (permissions or a noexec mount under $ROOT); fix that, then cd $SRC && ./setup"
fi
}
check_browse() {
local exe="" missing="" f
case "${OSTYPE:-}" in msys*|cygwin*|win32*) exe=".exe" ;; esac
if [ ! -x "$ROOT/browse/dist/browse$exe" ]; then
local missing="" f
if [ ! -x "$ROOT/browse/dist/browse$EXE" ]; then
row warn "browse bundle" "not built; the gstack browser fallback for /browse, /qa, /qa-only, /design-review, /make-pdf, /pair-agent is unavailable (the Aside browser is unaffected)" "cd $SRC && ./setup"
return
fi
gstack_launch_probe "$ROOT/browse/dist/browse$EXE"
case "$_glp_state" in
blocked) row warn "browse bundle" "built, but blocked at launch (${_glp_detail:-no output}); the gstack browser fallback is unavailable (the Aside browser is unaffected)" "$(launch_fix)"; return ;;
broken) row warn "browse bundle" "built, but browse --version failed (${_glp_detail})" "cd $SRC && bun run build"; return ;;
esac
for f in server-node.mjs .build-complete; do [ -e "$ROOT/browse/dist/$f" ] || missing="${missing:+$missing, }$f"; done
if [ -n "$missing" ]; then
row warn "browse bundle" "incomplete build (missing browse/dist: $missing)" "cd $SRC && ./setup"
@@ -287,6 +301,50 @@ check_browse() {
fi
}
# check_binaries — the other compiled binaries, by launch state (browse has its own row).
check_binaries() {
local rel detail blocked="" broken="" missing="" skills="" n=0
for rel in browse/dist/find-browse design/dist/design make-pdf/dist/pdf bin/gstack-global-discover; do
gstack_launch_probe "$ROOT/$rel$EXE"
detail="${rel##*/}"
case "$_glp_state" in
native) n=$((n + 1)) ;;
blocked) blocked="${blocked:+$blocked, }$detail (${_glp_detail:-no output})"; skills="${skills:+$skills, }$(gstack_launch_probe_skills "$rel")" ;;
broken) broken="${broken:+$broken, }$detail (${_glp_detail})" ;;
missing) missing="${missing:+$missing, }$detail" ;;
esac
done
if [ -n "$blocked" ]; then
row warn binaries "blocked at launch: $blocked; unavailable: $skills" "$(launch_fix)"
elif [ -n "$broken" ]; then
row warn binaries "launched but failed: $broken" "cd $SRC && bun run build"
elif [ -n "$missing" ]; then
row warn binaries "not built: $missing" "cd $SRC && ./setup"
else
row ok binaries "find-browse, design, pdf, gstack-global-discover launch ($n of 4)"
fi
}
# check_cso — from the build-result record setup and scripts/build-cso.sh write.
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; }
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"
else row warn cso "the last build succeeded but the native helper is missing; /cso reports not assessed" "cd $SRC && ./setup"; fi ;;
failed)
if [ "$usable" -eq 1 ] && [ -n "$installed" ]; then
row warn cso "$stage step failed ($reason) for $(cso_field revision); previous CSO kept: $installed" "cd $SRC && bun run build:cso && ./setup (log: ${diag:-none}; $DOCS#cso-build-or-publish-failed)"
else
row warn cso "unavailable: the $stage step failed ($reason); /cso reports not assessed" "cd $SRC && bun run build:cso && ./setup (log: ${diag:-none}; $DOCS#cso-build-or-publish-failed)"
fi ;;
*) if [ "$usable" -eq 1 ]; then row ok cso "native helper built (no build record yet)"
else row "not configured" cso "native helper not built; /cso reports not assessed" "cd $SRC && ./setup (it names any missing build prerequisite)"; fi ;;
esac
}
check_claude() {
local override cmd raw ver rc a
local args=()
@@ -376,6 +434,10 @@ STATE_ROOT="$_gstack_sr_root"
GSTACK_STATE_ROOT="$STATE_ROOT"
. "$BIN/gstack-codex-status.sh" 2>/dev/null || { echo "gstack-doctor: $BIN/gstack-codex-status.sh is missing; reinstall with cd $SRC && ./setup" >&2; exit 1; }
. "$BIN/gstack-launch-probe.sh" 2>/dev/null || { echo "gstack-doctor: $BIN/gstack-launch-probe.sh is missing; reinstall with cd $SRC && ./setup" >&2; exit 1; }
EXE=""
case "${OSTYPE:-}" in msys*|cygwin*|win32*) EXE=".exe" ;; esac
echo "gstack doctor $(head -1 "$ROOT/VERSION" 2>/dev/null | clamp '0-9A-Za-z.+-' 40)"
check_install
check_state_root
@@ -385,6 +447,8 @@ check_codex
[ "$CODEX_READY" -eq 1 ] && check_codex_probe
check_sync
check_browse
check_binaries
check_cso
check_claude
check_journal
check_guard_log
+17 -1
View File
@@ -10,7 +10,7 @@
*/
import { existsSync, readdirSync, statSync, readFileSync, openSync, readSync, closeSync } from "fs";
import { join, basename } from "path";
import { join, basename, dirname } from "path";
import { execSync } from "child_process";
import { homedir } from "os";
import { canonicalRemote } from "../lib/remote-identity";
@@ -55,12 +55,24 @@ function printUsage(): void {
--since <window> Time window: e.g. 7d, 14d, 30d, 24h
--format <fmt> Output format: json (default) or summary
--help Show this help
--version Print the gstack version and exit (no scan)
Examples:
gstack-global-discover --since 7d
gstack-global-discover --since 14d --format summary`);
}
function readGstackVersion(): string {
// The compiled binary and this source file both live in bin/, one level below VERSION.
for (const dir of [dirname(process.execPath), import.meta.dir]) {
try {
const version = readFileSync(join(dir, "..", "VERSION"), "utf8").trim();
if (version) return version;
} catch {}
}
return "unknown";
}
function parseArgs(): { since: string; format: "json" | "summary" } {
const args = process.argv.slice(2);
let since = "";
@@ -70,6 +82,10 @@ function parseArgs(): { since: string; format: "json" | "summary" } {
if (args[i] === "--help" || args[i] === "-h") {
printUsage();
process.exit(0);
} else if (args[i] === "--version") {
// setup's and gstack-doctor's launch probe (#2595): exits before any scan.
console.log(readGstackVersion());
process.exit(0);
} else if (args[i] === "--since" && args[i + 1]) {
since = args[++i];
} else if (args[i] === "--format" && args[i + 1]) {
+72
View File
@@ -0,0 +1,72 @@
# shellcheck shell=bash
# gstack-launch-probe.sh — sourced by setup and bin/gstack-doctor.
#
# Windows Smart App Control (and other application-control policies) blocks
# unsigned executables at launch, and Git Bash reports that as a plain
# "Permission denied" (#2595, #2124). `[ -x ]` cannot see it, so this runs
# each compiled binary's side-effect-free `--version` and classifies it:
#
# native launched and exited 0
# blocked could not launch: spawn error, permission denied (exit 126/127),
# or an application-control message in its output
# broken launched but exited non-zero or timed out: a build problem
# missing not built
#
# The exact Windows error text is unverified on a real SAC machine, so callers
# show the raw first output line ($_glp_detail) beside the classification.
# Bash 3.2 plus POSIX tools.
GSTACK_COMPILED_BINARIES="browse/dist/browse browse/dist/find-browse design/dist/design make-pdf/dist/pdf bin/gstack-global-discover"
# gstack_launch_probe PATH — sets _glp_state and _glp_detail.
gstack_launch_probe() {
local out rc
_glp_state=missing
_glp_detail=""
[ -e "$1" ] || return 0
if command -v timeout >/dev/null 2>&1; then
out=$(timeout 20 "$1" --version </dev/null 2>&1)
else
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)
case "$out" in
*[Aa]pplication\ [Cc]ontrol*|*"Smart App Control"*|*"blocked by group policy"*|*"has blocked this file"*)
_glp_state=blocked; return 0 ;;
esac
case "$rc" in
0) _glp_state=native ;;
126|127) _glp_state=blocked ;;
124) _glp_state=broken; _glp_detail="timed out after 20s${_glp_detail:+: $_glp_detail}" ;;
*) _glp_state=broken; _glp_detail="exit $rc${_glp_detail:+: $_glp_detail}" ;;
esac
}
# gstack_launch_probe_skills REL — the skills that stop working without it.
gstack_launch_probe_skills() {
case "$1" in
browse/dist/browse|browse/dist/find-browse) printf '%s' "/browse, /qa, /qa-only, /design-review, /canary, /benchmark, /pair-agent, /scrape, /make-pdf" ;;
design/dist/design) printf '%s' "/design-consultation, /design-shotgun, /design-html, /plan-design-review" ;;
make-pdf/dist/pdf) printf '%s' "/make-pdf" ;;
bin/gstack-global-discover) printf '%s' "/retro global" ;;
esac
}
# gstack_launch_probe_all ROOT EXE — probes every compiled binary under ROOT
# (EXE is ".exe" on Windows). Sets _glp_blocked and _glp_broken to
# newline-separated "rel<TAB>detail" rows, and _glp_missing to a list.
gstack_launch_probe_all() {
local rel
_glp_blocked="" _glp_broken="" _glp_missing=""
for rel in $GSTACK_COMPILED_BINARIES; do
gstack_launch_probe "$1/$rel$2"
case "$_glp_state" in
blocked) _glp_blocked="$_glp_blocked$rel $_glp_detail
" ;;
broken) _glp_broken="$_glp_broken$rel $_glp_detail
" ;;
missing) _glp_missing="${_glp_missing:+$_glp_missing, }$rel" ;;
esac
done
}