* feat(#498): generated package-identity seam derived from package.json Introduce a single source for GSD's published-package coordinates: scripts/generate-package-identity.cjs (pure deriveIdentity + formatManualInstall + render) emits the generated get-shit-done/bin/lib/package-identity.cjs with values baked from package.json at build time. Baking is required because the installed tree carries only a synthetic {"type":"commonjs"} package.json, so a runtime require('package.json').name resolves to undefined (#378). Reconciles Wired into npm run build; a parity test fails CI if the committed file drifts from package.json. Refs #498 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#498): repoint update worker + check-latest-version at the seam - check-latest-version.cjs sources PACKAGE_NAME from the package-identity seam instead of a re-typed literal (single source; #2992's constant guarantee is preserved since the seam bakes from package.json). - gsd-check-update-worker.js no longer does require('../package.json').name (resolved to undefined in the installed tree → background update check silently broken, #378). It now delegates the latest-version lookup to checkLatestVersion(), collapsing the duplicated npm-view call onto the single deterministic adapter and inheriting its typed {ok,version,reason} surface. - Move the PR #3102 Windows shell-gate contract test onto execNpm (where the spawn now lives) and assert the worker no longer spawns npm directly. - Rewrite the #378 contract: worker must NOT use require(package.json).name and must delegate; check-latest-version PACKAGE_NAME is single-sourced from the seam. Fixes #378-class runtime breakage. Refs #498 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore(#498): changeset for package-identity seam + update-check fix Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * feat(#498): drift-guard lint — value-check GSD coordinate literals against the seam scripts/lint-package-identity-drift.cjs scans the runtime/code surface (bin/, hooks/, scripts/, get-shit-done/) and asserts every GSD package name and GitHub repo slug literal equals the Package Identity seam's current value. Passes today; fails the moment a repoint isn't propagated (rename package.json, regenerate the seam, and stale literals are reported until updated). This is the second adapter that makes the seam real and a repoint mechanically safe. Enforced via tests/issue-498-identity-drift-lint.test.cjs (scanRepo === []) under npm test; also exposed as `npm run check:identity-drift`. Refs #498 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * feat(#498): update-context projection — port update.md resolution to a tested seam Add get-shit-done/bin/lib/update-context.cjs: a pure, injected-fs port of update.md's ~280-line get_installed_version bash. resolveUpdateContext() reproduces the full precedence cascade (preferred fast-path -> local probe -> global probe via env overrides then $HOME -> LOCAL-if-distinct -> scope cascade -> UNKNOWN) and returns the 4-field contract { installedVersion, scope, runtime, gsdDir }. The fs is injected so every branch is finally testable without a live multi-runtime install. Expose it as `gsd-tools update-context [--config-dir <d>] [--runtime <r>] --json`. Purely additive — update.md is unchanged in this commit; the workflow swap follows separately. Refs #498 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * feat(#498): swap update.md resolution to the update-context projection Replace ~280 lines of inline runtime/scope/config-dir bash in update.md's get_installed_version step with a call to `gsd-tools update-context --json` (60 lines: derive PREFERRED_* from execution_context, resolve gsd-tools.cjs, parse the 4-field JSON). Behavior is unchanged — the projection reproduces the same cascade — but the logic is now tested in update-context.cjs instead of untestable bash-in-markdown. Relocate the #3608 antigravity-first-class contract onto the projection (RUNTIME_DIRS order, inferPreferredRuntime, envRuntimeDirs) plus a behavioral test; keep the execution_context path-classification assertion on update.md. Re-point install.test's custom-config-dir assertion (kilo.jsonc/KILO_CONFIG) to update-context.cjs where that detection now lives. Full root suite: 2022 pass / 0 fail. Refs #498 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * docs(#498): record Update Context Module in CONTEXT.md Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#498): CI — avoid bare gsd-tools in update.md; register new CLI modules - update.md update-context invocation: resolve the PATH gsd-tools shim into a variable and call "$GSD_TOOLS" (never a bare `gsd-tools` command) — satisfies the #2851 workflow-bare-gsd-tools guard. - Register package-identity.cjs and update-context.cjs in docs/INVENTORY.md (CLI Modules 76 -> 78 + rows) and regenerate docs/INVENTORY-MANIFEST.json, fixing inventory-counts and inventory-manifest-sync. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * test(#498): make update-context + parity tests OS-agnostic (Windows CI) Two Windows-only test failures, both test-portability (production code is fine — the real-fs CLI integration test passed on Windows): - update-context resolver tests + bug-3608 behavioral test used POSIX path-string keys in their fake fs, but the resolver builds lookups via path.join/resolve (backslash + drive letter on Windows) → keys never matched → everything resolved to UNKNOWN/claude. Normalize fake-fs keys and gsdDir comparisons through path.resolve so they match on both platforms. - package-identity parity test compared render() (LF) to the committed file, which Windows git checks out as CRLF (no .gitattributes eol rule). Normalize line endings before comparing, matching the repo convention (autonomous-decomposition, bug-3707). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#498): update.md backup must use GSD_DIR (adversarial-review finding) The get_installed_version rewrite emits GSD_DIR but dropped the probe-loop variables LOCAL_DIR/GLOBAL_DIR. The backup_custom_files step still read those, so RUNTIME_DIR went empty for every LOCAL/GLOBAL install and detect-custom-files was skipped — and since the update then runs a clean install that wipes managed dirs (commands/gsd, get-shit-done), user-added files could be deleted without the intended backup. Set RUNTIME_DIR="$GSD_DIR" directly (the resolved config dir; empty for UNKNOWN scope, which still skips the backup). Add a structural regression (tests/issue-498-update-backup-runtime-dir.test.cjs). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * test(#503): re-point Antigravity .agent detection at the #498 projection #499 moves the runtime/scope detection cascade out of update.md inline bash into get-shit-done/bin/lib/update-context.cjs. The #503 regression test asserted on the inline RUNTIME_DIRS array, which no longer exists, so it would fail against the projected update.md even though the .agent guarantee is preserved. Rewrite it to verify the surviving surfaces: - behavioral: resolveUpdateContext resolves a LOCAL ./.agent install to the antigravity runtime (the original root cause, now covered by adding ['antigravity', '.agent'] to the projection RUNTIME_DIRS table) - update.md prose classifier still maps /.agent/ -> antigravity - the post-update cache-clear for-dir loop still includes .agent Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#498): finish de-hardcoding consumers + close adversarial-review parity gaps Restore the consumer de-hardcoding that is the point of the seam, and close the parity gaps an adversarial review (codex) found in the update-context projection. De-hardcode the repo slug + install command in the changeset tooling — #516 only single-sourced the package NAME, leaving 'open-gsd/get-shit-done-redux' hardcoded in scripts/changeset/cli.cjs and github-release-notes.cjs. Route both through the seam's repoSlug/packageName so a rename is a regenerate, not a hand edit. The drift-lint real scan now reports zero divergent coordinate literals. Projection parity vs the old inline bash, as ONE consistent rule (trustedVersionAt) applied on every path: - expand a leading ~/ in preferredConfigDir before the fast path (the bash ran expand_home first; a custom --config-dir ~/foo otherwise fell to UNKNOWN) - trust a version only when BOTH VERSION and the update.md marker exist — fast path AND LOCAL/GLOBAL cascade; a partial dir falls to 0.0.0 keeping scope - apply the same same-path dedup to the 0.0.0 fallback so a partial install probed from cwd===home is not misdetected as LOCAL Adds regression tests for tilde expansion, VERSION-only (cascade + fast path), and the cwd===home partial-install dedup. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -9,285 +9,70 @@ Read all files referenced by the invoking prompt's execution_context before star
|
||||
<process>
|
||||
|
||||
<step name="get_installed_version">
|
||||
Detect whether GSD is installed locally or globally by checking both locations and validating install integrity.
|
||||
Detect the installed GSD version, scope, runtime, and config dir.
|
||||
|
||||
First, derive `PREFERRED_CONFIG_DIR` and `PREFERRED_RUNTIME` from the invoking prompt's `execution_context` path:
|
||||
- If the path contains `/get-shit-done/workflows/update.md`, strip that suffix and store the remainder as `PREFERRED_CONFIG_DIR`
|
||||
- Path contains `/.codex/` -> `codex`
|
||||
- Path contains `/.gemini/antigravity-ide/` -> `antigravity`
|
||||
- Path contains `/.gemini/antigravity-cli/` -> `antigravity`
|
||||
- Path contains `/.gemini/antigravity/` -> `antigravity`
|
||||
- Path contains `/.agent/` -> `antigravity` (local Antigravity install dir; see bin/install.js getDirName('antigravity'))
|
||||
- Path contains `/.gemini/` -> `gemini`
|
||||
- Path contains `/.config/kilo/` or `/.kilo/`, or `PREFERRED_CONFIG_DIR` contains `kilo.json` / `kilo.jsonc` -> `kilo`
|
||||
- Path contains `/.config/opencode/` or `/.opencode/`, or `PREFERRED_CONFIG_DIR` contains `opencode.json` / `opencode.jsonc` -> `opencode`
|
||||
- Otherwise -> `claude`
|
||||
First, derive `PREFERRED_CONFIG_DIR` and `PREFERRED_RUNTIME` from the invoking prompt's `execution_context` path — this is the one input only the workflow knows:
|
||||
- If the path contains `/get-shit-done/workflows/update.md`, strip that suffix and store the remainder as `PREFERRED_CONFIG_DIR`.
|
||||
- Infer `PREFERRED_RUNTIME` from the path: `/.codex/` -> `codex`; `/.gemini/antigravity-ide/`, `/.gemini/antigravity-cli/`, `/.gemini/antigravity/`, `/.agent/` -> `antigravity` (`.agent` is the local Antigravity install dir; see bin/install.js `getDirName('antigravity')`, #503); `/.gemini/` -> `gemini`; `/.config/kilo/` or `/.kilo/` -> `kilo`; `/.config/opencode/` or `/.opencode/` -> `opencode`; otherwise `claude`.
|
||||
|
||||
Use `PREFERRED_CONFIG_DIR` when available so custom `--config-dir` installs are checked before default locations.
|
||||
Use `PREFERRED_RUNTIME` as the first runtime checked so `/gsd:update` targets the runtime that invoked it.
|
||||
|
||||
Kilo config precedence must match the installer: `KILO_CONFIG_DIR` -> `dirname(KILO_CONFIG)` -> `XDG_CONFIG_HOME/kilo` -> `~/.config/kilo`.
|
||||
Then resolve the install context via the deterministic projection (#498). **Do NOT re-derive scope, runtime, or version by hand** — `update-context` owns that cascade in tested code (`get-shit-done/bin/lib/update-context.cjs`), the same way `check-latest-version` owns the package name (#2992):
|
||||
|
||||
```bash
|
||||
expand_home() {
|
||||
case "$1" in
|
||||
"~/"*) printf '%s/%s\n' "$HOME" "${1#~/}" ;;
|
||||
*) printf '%s\n' "$1" ;;
|
||||
# Resolve gsd-tools.cjs WITHOUT yet knowing GSD_DIR. The running workflow lives
|
||||
# at <PREFERRED_CONFIG_DIR>/get-shit-done/workflows/update.md, so its sibling
|
||||
# bin/gsd-tools.cjs is the authoritative tool for THIS install. Fall back to a
|
||||
# global copy, then to gsd-tools on PATH.
|
||||
GSD_TOOLS=""
|
||||
for cand in \
|
||||
"$PREFERRED_CONFIG_DIR/get-shit-done/bin/gsd-tools.cjs" \
|
||||
"$HOME/.claude/get-shit-done/bin/gsd-tools.cjs"; do
|
||||
if [ -n "$cand" ] && [ -f "$cand" ]; then GSD_TOOLS="$cand"; break; fi
|
||||
done
|
||||
# Last resort: the gsd-tools shim on PATH — resolved to its absolute path and
|
||||
# invoked via the variable (never a bare `gsd-tools` command; see #2851).
|
||||
if [ -z "$GSD_TOOLS" ] && command -v gsd-tools >/dev/null 2>&1; then
|
||||
GSD_TOOLS="$(command -v gsd-tools)"
|
||||
fi
|
||||
|
||||
UC=""
|
||||
if [ -n "$GSD_TOOLS" ]; then
|
||||
case "$GSD_TOOLS" in
|
||||
*.cjs) UC="$(node "$GSD_TOOLS" update-context --config-dir "$PREFERRED_CONFIG_DIR" --runtime "$PREFERRED_RUNTIME" --json 2>/dev/null)" ;;
|
||||
*) UC="$("$GSD_TOOLS" update-context --config-dir "$PREFERRED_CONFIG_DIR" --runtime "$PREFERRED_RUNTIME" --json 2>/dev/null)" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Runtime candidates: "<runtime>:<config-dir>" stored as an array.
|
||||
# Using an array instead of a space-separated string ensures correct
|
||||
# iteration in both bash and zsh (zsh does not word-split unquoted
|
||||
# variables by default). Fixes #1173.
|
||||
RUNTIME_DIRS=( "claude:.claude" "opencode:.config/opencode" "opencode:.opencode" "antigravity:.gemini/antigravity-ide" "antigravity:.gemini/antigravity-cli" "antigravity:.gemini/antigravity" "antigravity:.agent" "gemini:.gemini" "kilo:.config/kilo" "kilo:.kilo" "codex:.codex" )
|
||||
ENV_RUNTIME_DIRS=()
|
||||
|
||||
# PREFERRED_CONFIG_DIR / PREFERRED_RUNTIME should be set from execution_context
|
||||
# before running this block.
|
||||
if [ -n "$PREFERRED_CONFIG_DIR" ]; then
|
||||
PREFERRED_CONFIG_DIR="$(expand_home "$PREFERRED_CONFIG_DIR")"
|
||||
if [ -z "$PREFERRED_RUNTIME" ]; then
|
||||
if [ -f "$PREFERRED_CONFIG_DIR/kilo.json" ] || [ -f "$PREFERRED_CONFIG_DIR/kilo.jsonc" ]; then
|
||||
PREFERRED_RUNTIME="kilo"
|
||||
elif [ -f "$PREFERRED_CONFIG_DIR/opencode.json" ] || [ -f "$PREFERRED_CONFIG_DIR/opencode.jsonc" ]; then
|
||||
PREFERRED_RUNTIME="opencode"
|
||||
elif [ -f "$PREFERRED_CONFIG_DIR/config.toml" ]; then
|
||||
PREFERRED_RUNTIME="codex"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# If runtime is still unknown, infer from runtime env vars; fallback to claude.
|
||||
if [ -z "$PREFERRED_RUNTIME" ]; then
|
||||
if [ -n "$CODEX_HOME" ]; then
|
||||
PREFERRED_RUNTIME="codex"
|
||||
elif [ -n "$ANTIGRAVITY_CONFIG_DIR" ]; then
|
||||
PREFERRED_RUNTIME="antigravity"
|
||||
elif [ -n "$GEMINI_CONFIG_DIR" ]; then
|
||||
PREFERRED_RUNTIME="gemini"
|
||||
elif [ -n "$KILO_CONFIG_DIR" ]; then
|
||||
PREFERRED_RUNTIME="kilo"
|
||||
elif [ -n "$KILO_CONFIG" ]; then
|
||||
PREFERRED_RUNTIME="kilo"
|
||||
elif [ -n "$OPENCODE_CONFIG_DIR" ] || [ -n "$OPENCODE_CONFIG" ]; then
|
||||
PREFERRED_RUNTIME="opencode"
|
||||
elif [ -n "$CLAUDE_CONFIG_DIR" ]; then
|
||||
PREFERRED_RUNTIME="claude"
|
||||
else
|
||||
PREFERRED_RUNTIME="claude"
|
||||
fi
|
||||
fi
|
||||
|
||||
# If execution_context already points at an installed config dir, trust it first.
|
||||
# This covers custom --config-dir installs that do not live under the default
|
||||
# runtime directories.
|
||||
if [ -n "$PREFERRED_CONFIG_DIR" ] && { [ -f "$PREFERRED_CONFIG_DIR/get-shit-done/VERSION" ] || [ -f "$PREFERRED_CONFIG_DIR/get-shit-done/workflows/update.md" ]; }; then
|
||||
INSTALL_SCOPE="GLOBAL"
|
||||
# Normalize a path for comparison: on Windows with Git Bash, pwd returns
|
||||
# POSIX-style /c/Users/... but PREFERRED_CONFIG_DIR may carry C:/Users/...
|
||||
# Convert Windows drive-letter paths to POSIX form so the comparison works
|
||||
# on both Windows (Git Bash) and POSIX systems.
|
||||
normalize_path() {
|
||||
local p="$1"
|
||||
case "$p" in
|
||||
[A-Za-z]:/*)
|
||||
local drive rest
|
||||
drive="${p%%:*}"
|
||||
rest="${p#?:}"
|
||||
p="/$(printf '%s' "$drive" | tr '[:upper:]' '[:lower:]')$rest"
|
||||
;;
|
||||
esac
|
||||
printf '%s' "$p"
|
||||
}
|
||||
normalized_preferred="$(normalize_path "$PREFERRED_CONFIG_DIR")"
|
||||
for dir in .claude .config/opencode .opencode .gemini/antigravity-ide .gemini/antigravity-cli .gemini/antigravity .agent .gemini .config/kilo .kilo .codex; do
|
||||
resolved_local="$(cd "./$dir" 2>/dev/null && pwd)"
|
||||
normalized_local="$(normalize_path "$resolved_local")"
|
||||
if [ -n "$normalized_local" ] && [ "$normalized_local" = "$normalized_preferred" ]; then
|
||||
INSTALL_SCOPE="LOCAL"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -f "$PREFERRED_CONFIG_DIR/get-shit-done/VERSION" ] && grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+' "$PREFERRED_CONFIG_DIR/get-shit-done/VERSION"; then
|
||||
INSTALLED_VERSION="$(cat "$PREFERRED_CONFIG_DIR/get-shit-done/VERSION")"
|
||||
else
|
||||
INSTALLED_VERSION="0.0.0"
|
||||
fi
|
||||
|
||||
echo "$INSTALLED_VERSION"
|
||||
echo "$INSTALL_SCOPE"
|
||||
echo "${PREFERRED_RUNTIME:-claude}"
|
||||
# 4-line output contract (#2993 CR): early-return path must also emit
|
||||
# GSD_DIR or downstream check_latest_version misreads the install as
|
||||
# UNKNOWN. PREFERRED_CONFIG_DIR is the resolved config dir we just
|
||||
# validated above (line 95-96); it is the right GSD_DIR value for
|
||||
# this fast path.
|
||||
echo "$PREFERRED_CONFIG_DIR"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Absolute global candidates from env overrides (covers custom config dirs).
|
||||
if [ -n "$CLAUDE_CONFIG_DIR" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "claude:$(expand_home "$CLAUDE_CONFIG_DIR")" )
|
||||
fi
|
||||
if [ -n "$ANTIGRAVITY_CONFIG_DIR" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "antigravity:$(expand_home "$ANTIGRAVITY_CONFIG_DIR")" )
|
||||
fi
|
||||
if [ -n "$GEMINI_CONFIG_DIR" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "gemini:$(expand_home "$GEMINI_CONFIG_DIR")" )
|
||||
fi
|
||||
if [ -n "$KILO_CONFIG_DIR" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "kilo:$(expand_home "$KILO_CONFIG_DIR")" )
|
||||
elif [ -n "$KILO_CONFIG" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "kilo:$(dirname "$(expand_home "$KILO_CONFIG")")" )
|
||||
elif [ -n "$XDG_CONFIG_HOME" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "kilo:$(expand_home "$XDG_CONFIG_HOME")/kilo" )
|
||||
fi
|
||||
if [ -n "$OPENCODE_CONFIG_DIR" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "opencode:$(expand_home "$OPENCODE_CONFIG_DIR")" )
|
||||
elif [ -n "$OPENCODE_CONFIG" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "opencode:$(dirname "$(expand_home "$OPENCODE_CONFIG")")" )
|
||||
elif [ -n "$XDG_CONFIG_HOME" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "opencode:$(expand_home "$XDG_CONFIG_HOME")/opencode" )
|
||||
fi
|
||||
if [ -n "$CODEX_HOME" ]; then
|
||||
ENV_RUNTIME_DIRS+=( "codex:$(expand_home "$CODEX_HOME")" )
|
||||
fi
|
||||
|
||||
# Reorder entries so preferred runtime is checked first.
|
||||
ORDERED_RUNTIME_DIRS=()
|
||||
for entry in "${RUNTIME_DIRS[@]}"; do
|
||||
runtime="${entry%%:*}"
|
||||
if [ "$runtime" = "$PREFERRED_RUNTIME" ]; then
|
||||
ORDERED_RUNTIME_DIRS+=( "$entry" )
|
||||
fi
|
||||
done
|
||||
ORDERED_ENV_RUNTIME_DIRS=()
|
||||
for entry in "${ENV_RUNTIME_DIRS[@]}"; do
|
||||
runtime="${entry%%:*}"
|
||||
if [ "$runtime" = "$PREFERRED_RUNTIME" ]; then
|
||||
ORDERED_ENV_RUNTIME_DIRS+=( "$entry" )
|
||||
fi
|
||||
done
|
||||
for entry in "${ENV_RUNTIME_DIRS[@]}"; do
|
||||
runtime="${entry%%:*}"
|
||||
if [ "$runtime" != "$PREFERRED_RUNTIME" ]; then
|
||||
ORDERED_ENV_RUNTIME_DIRS+=( "$entry" )
|
||||
fi
|
||||
done
|
||||
for entry in "${RUNTIME_DIRS[@]}"; do
|
||||
runtime="${entry%%:*}"
|
||||
if [ "$runtime" != "$PREFERRED_RUNTIME" ]; then
|
||||
ORDERED_RUNTIME_DIRS+=( "$entry" )
|
||||
fi
|
||||
done
|
||||
|
||||
# Check local first (takes priority only if valid and distinct from global)
|
||||
LOCAL_VERSION_FILE="" LOCAL_MARKER_FILE="" LOCAL_DIR="" LOCAL_RUNTIME=""
|
||||
for entry in "${ORDERED_RUNTIME_DIRS[@]}"; do
|
||||
runtime="${entry%%:*}"
|
||||
dir="${entry#*:}"
|
||||
if [ -f "./$dir/get-shit-done/VERSION" ] || [ -f "./$dir/get-shit-done/workflows/update.md" ]; then
|
||||
LOCAL_RUNTIME="$runtime"
|
||||
LOCAL_VERSION_FILE="./$dir/get-shit-done/VERSION"
|
||||
LOCAL_MARKER_FILE="./$dir/get-shit-done/workflows/update.md"
|
||||
LOCAL_DIR="$(cd "./$dir" 2>/dev/null && pwd)"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
GLOBAL_VERSION_FILE="" GLOBAL_MARKER_FILE="" GLOBAL_DIR="" GLOBAL_RUNTIME=""
|
||||
for entry in "${ORDERED_ENV_RUNTIME_DIRS[@]}"; do
|
||||
runtime="${entry%%:*}"
|
||||
dir="${entry#*:}"
|
||||
if [ -f "$dir/get-shit-done/VERSION" ] || [ -f "$dir/get-shit-done/workflows/update.md" ]; then
|
||||
GLOBAL_RUNTIME="$runtime"
|
||||
GLOBAL_VERSION_FILE="$dir/get-shit-done/VERSION"
|
||||
GLOBAL_MARKER_FILE="$dir/get-shit-done/workflows/update.md"
|
||||
GLOBAL_DIR="$(cd "$dir" 2>/dev/null && pwd)"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$GLOBAL_RUNTIME" ]; then
|
||||
for entry in "${ORDERED_RUNTIME_DIRS[@]}"; do
|
||||
runtime="${entry%%:*}"
|
||||
dir="${entry#*:}"
|
||||
if [ -f "$HOME/$dir/get-shit-done/VERSION" ] || [ -f "$HOME/$dir/get-shit-done/workflows/update.md" ]; then
|
||||
GLOBAL_RUNTIME="$runtime"
|
||||
GLOBAL_VERSION_FILE="$HOME/$dir/get-shit-done/VERSION"
|
||||
GLOBAL_MARKER_FILE="$HOME/$dir/get-shit-done/workflows/update.md"
|
||||
GLOBAL_DIR="$(cd "$HOME/$dir" 2>/dev/null && pwd)"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Only treat as LOCAL if the resolved paths differ (prevents misdetection when CWD=$HOME)
|
||||
IS_LOCAL=false
|
||||
if [ -n "$LOCAL_VERSION_FILE" ] && [ -f "$LOCAL_VERSION_FILE" ] && [ -f "$LOCAL_MARKER_FILE" ] && grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+' "$LOCAL_VERSION_FILE"; then
|
||||
if [ -z "$GLOBAL_DIR" ] || [ "$LOCAL_DIR" != "$GLOBAL_DIR" ]; then
|
||||
IS_LOCAL=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$IS_LOCAL" = true ]; then
|
||||
INSTALLED_VERSION="$(cat "$LOCAL_VERSION_FILE")"
|
||||
INSTALL_SCOPE="LOCAL"
|
||||
TARGET_RUNTIME="$LOCAL_RUNTIME"
|
||||
RESOLVED_GSD_DIR="$LOCAL_DIR"
|
||||
elif [ -n "$GLOBAL_VERSION_FILE" ] && [ -f "$GLOBAL_VERSION_FILE" ] && [ -f "$GLOBAL_MARKER_FILE" ] && grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+' "$GLOBAL_VERSION_FILE"; then
|
||||
INSTALLED_VERSION="$(cat "$GLOBAL_VERSION_FILE")"
|
||||
INSTALL_SCOPE="GLOBAL"
|
||||
TARGET_RUNTIME="$GLOBAL_RUNTIME"
|
||||
RESOLVED_GSD_DIR="$GLOBAL_DIR"
|
||||
elif [ -n "$LOCAL_RUNTIME" ] && [ -f "$LOCAL_MARKER_FILE" ]; then
|
||||
# Runtime detected but VERSION missing/corrupt: treat as unknown version, keep runtime target
|
||||
INSTALLED_VERSION="0.0.0"
|
||||
INSTALL_SCOPE="LOCAL"
|
||||
TARGET_RUNTIME="$LOCAL_RUNTIME"
|
||||
RESOLVED_GSD_DIR="$LOCAL_DIR"
|
||||
elif [ -n "$GLOBAL_RUNTIME" ] && [ -f "$GLOBAL_MARKER_FILE" ]; then
|
||||
INSTALLED_VERSION="0.0.0"
|
||||
INSTALL_SCOPE="GLOBAL"
|
||||
TARGET_RUNTIME="$GLOBAL_RUNTIME"
|
||||
RESOLVED_GSD_DIR="$GLOBAL_DIR"
|
||||
if [ -n "$UC" ]; then
|
||||
INSTALLED_VERSION="$(printf '%s' "$UC" | jq -r '.installedVersion')"
|
||||
INSTALL_SCOPE="$(printf '%s' "$UC" | jq -r '.scope')"
|
||||
TARGET_RUNTIME="$(printf '%s' "$UC" | jq -r '.runtime')"
|
||||
GSD_DIR="$(printf '%s' "$UC" | jq -r '.gsdDir')"
|
||||
else
|
||||
# No tool resolvable / projection failed -> treat as a fresh install.
|
||||
INSTALLED_VERSION="0.0.0"
|
||||
INSTALL_SCOPE="UNKNOWN"
|
||||
TARGET_RUNTIME="claude"
|
||||
RESOLVED_GSD_DIR=""
|
||||
GSD_DIR=""
|
||||
fi
|
||||
|
||||
echo "$INSTALLED_VERSION"
|
||||
echo "$INSTALL_SCOPE"
|
||||
echo "$TARGET_RUNTIME"
|
||||
echo "$RESOLVED_GSD_DIR"
|
||||
echo "$GSD_DIR"
|
||||
```
|
||||
|
||||
Parse output:
|
||||
- Line 1 = installed version (`0.0.0` means unknown version)
|
||||
- Line 2 = install scope (`LOCAL`, `GLOBAL`, or `UNKNOWN`)
|
||||
- Line 3 = target runtime (`claude`, `opencode`, `gemini`, `kilo`, or `codex`)
|
||||
- Line 4 = resolved GSD config dir (e.g. `/Users/me/.claude`, `/Users/me/.gemini`); empty if scope is `UNKNOWN`. Capture this as `GSD_DIR` and pass it to subsequent steps so they don't have to re-derive the runtime path.
|
||||
- If scope is `UNKNOWN`, proceed to install step using `--claude --global` fallback.
|
||||
- Line 3 = target runtime (`claude`, `opencode`, `gemini`, `kilo`, `codex`, `antigravity`)
|
||||
- Line 4 = resolved GSD config dir (e.g. `/Users/me/.claude`, `/Users/me/.gemini`); empty if scope is `UNKNOWN`. Capture this as `GSD_DIR` and pass it to subsequent steps so they don't re-derive the runtime path.
|
||||
- If scope is `UNKNOWN`, proceed to install using the `--claude --global` fallback.
|
||||
|
||||
`update-context` reproduces the previous detection cascade — preferred-config-dir fast path, local-over-global with same-path dedup (so `CWD=$HOME` does not misdetect as LOCAL), env-var overrides (`CLAUDE_CONFIG_DIR`, `OPENCODE_CONFIG_DIR`, `KILO_CONFIG`, `XDG_CONFIG_HOME`, `CODEX_HOME`, …), and semver validation — but as a tested projection rather than ~280 lines of inline bash. Branch coverage lives in `tests/issue-498-update-context.test.cjs`.
|
||||
|
||||
If multiple runtime installs are detected and the invoking runtime cannot be determined from execution_context, ask the user which runtime to update before running install.
|
||||
|
||||
**If VERSION file missing:**
|
||||
```
|
||||
## GSD Update
|
||||
|
||||
**Installed version:** Unknown
|
||||
|
||||
Your installation doesn't include version tracking.
|
||||
|
||||
Running fresh install...
|
||||
```
|
||||
|
||||
Proceed to install step (treat as version 0.0.0 for comparison).
|
||||
**If VERSION file missing (version resolves to `0.0.0`):** report the installed version as Unknown and proceed to install (treated as `0.0.0` for comparison).
|
||||
</step>
|
||||
|
||||
<step name="check_latest_version">
|
||||
@@ -466,16 +251,10 @@ First, resolve the config directory (`RUNTIME_DIR`) from the install scope
|
||||
detected in `get_installed_version`:
|
||||
|
||||
```bash
|
||||
# RUNTIME_DIR is the resolved config directory (e.g. ~/.config/opencode, ~/.gemini)
|
||||
# It should already be set from get_installed_version as GLOBAL_DIR or LOCAL_DIR.
|
||||
# Use the appropriate variable based on INSTALL_SCOPE.
|
||||
if [ "$INSTALL_SCOPE" = "LOCAL" ]; then
|
||||
RUNTIME_DIR="$LOCAL_DIR"
|
||||
elif [ "$INSTALL_SCOPE" = "GLOBAL" ]; then
|
||||
RUNTIME_DIR="$GLOBAL_DIR"
|
||||
else
|
||||
RUNTIME_DIR=""
|
||||
fi
|
||||
# RUNTIME_DIR is the resolved config directory (e.g. ~/.config/opencode, ~/.gemini).
|
||||
# get_installed_version emits it as GSD_DIR (LOCAL or GLOBAL install dir, or empty
|
||||
# when scope is UNKNOWN). Empty RUNTIME_DIR skips the backup below.
|
||||
RUNTIME_DIR="$GSD_DIR"
|
||||
```
|
||||
|
||||
If `RUNTIME_DIR` is empty or does not exist, skip this step (no config dir to
|
||||
|
||||
Reference in New Issue
Block a user