Skip to content

feat: v1.2.2.0 — Windows cookie import, hardening wave, caveman lock - #2

Merged
JerkyJesse merged 19 commits into
mainfrom
feat/gstack-wave-v0.18.1
Apr 18, 2026
Merged

JerkyJesse merged 19 commits into
mainfrom
feat/gstack-wave-v0.18.1

Conversation

@JerkyJesse

Copy link
Copy Markdown
Owner

Summary

Ports 5 upstream PRs from garrytan/gstack's community wave v0.18.1 plus
applies 7 hardening fixes surfaced by adversarial review and 3
maintainability fixes from the specialist pass. 18 commits, one v1.2.2.0
release.

Windows cookie import + CDP v20 fallback (PRs garrytan#892, garrytan#996, garrytan#993, garrytan#994, garrytan#1020)

OpenClaw native skill frontmatter normalization (PR garrytan#864)

  • Normalized YAML frontmatter on 4 hand-authored OpenClaw skills so
    Codex CLI can parse them. Dropped non-standard version +
    metadata fields; rewrote descriptions into "Use when..." form
    without inline colons.

Caveman voice locked to full (local)

  • /caveman lite and /caveman ultra removed. caveman-lite.json and
    caveman-ultra.json voice profiles deleted. Wenyan variants still
    available.

Hardening (adversarial review response)

  • Windows tree-kill. Every kill site now uses taskkill /F /T /PID
    on Windows so Chrome renderer/GPU/utility children don't orphan.
  • DevToolsActivePort port discovery. Random port 9222-9321 replaced
    with --remote-debugging-port=0 + file-polling the chosen port.
  • Parent-PID reuse guard. Watchdog captures parent's start time
    (WMIC / PowerShell / ps -o lstart=) and rejects recycled PIDs.
  • Temp DB crash sweep. Exit + uncaughtException + unhandledRejection
    handlers unlink temp cookie DB copies.
  • powershell.exe / pwsh.exe fallback for hardened Windows systems.
  • AES key zeroing — Windows now caches the DPAPI-encrypted blob
    and zeros decrypted plaintext after each import.
  • Preflight UI warning before v20 CDP launch (profile-corruption
    risk disclosure; user confirms before Chrome opens).

Maintainability

  • Async watchdog — parent-PID start-time probes run via Bun.spawn
    • await proc.exited so the 15s tick doesn't block the event loop
      50-200ms on Windows.
  • Fresh CDP target-discovery deadline — two sequential poll loops
    no longer share one 15s budget.
  • importCookiesWithV20Fallback() helper consolidates the v10→CDP
    heuristic duplicated between the picker route and CLI import.
  • Exit sweep handlers stop re-throwing — uncaughtException /
    unhandledRejection sweep-only, let Node's default diagnostic fire.

Test Coverage

  • 54 targeted tests pass (cookie-import-browser + cookie-picker-routes +
    openclaw frontmatter).
  • New direct tests: hasActivePicker() lifecycle, /cookie-picker/preflight
    endpoint shape + auth, hasV20Cookies cross-platform safety, session
    key reuse through the SessionKeys refactor.
  • Full suite: 161 pre-existing fails (Windows path-with-spaces in
    working directory — identical count on main; documented in
    CLAUDE.md). Zero in-branch regressions.

Pre-Landing Review

  • Initial adversarial pass found 7 real issues in the ported code
    (orphan Chrome processes, port collisions, PID reuse, temp file leak
    on crash, hardened-Windows missing powershell.exe, AES key memory
    lifetime, profile corruption risk). All 7 fixed with follow-on commits.
  • Specialist pass (testing + maintainability) found 4 + 8 findings.
    Testing: 1 MEDIUM auto-fixed (hasActivePicker tests); 3 informational
    on harder-to-reach internal paths noted but not addressed.
    Maintainability: 3 auto-fixed (cdp timeout, watchdog sync, v20
    fallback DRY), 1 false positive (hasActivePicker race — Node is
    single-threaded), rest skip.

Eval Results

Skipped. Diff touched voice profile infra and SKILL regens; user opted
to skip the paid eval suite since the changes are deletions +
OS-specific + frontmatter normalization rather than new prompt
semantics. Blast radius on prompt quality is low.

Scope Drift

CLEAN. Intent: port gstack v0.18.1 + caveman lock + harden surfaced
adversarial findings. Delivered: exactly that.

TODOS

None completed. No scope additions.

Test plan

  • bun test passes on touched files (54/54 targeted)
  • Bundle builds clean (cookie-import-browser, server, write-commands, cookie-picker-routes)
  • CHANGELOG sequence contiguous (1.2.2.0 → 1.2.1.0 → 1.2.0.0 → …)
  • VERSION matches CHANGELOG header
  • Manual Windows cookie import smoke test (requires Windows + Chrome
    install; deferred to post-merge — cannot reliably test on current
    path-with-spaces working dir).

🤖 Generated with Claude Code

JerkyJesse and others added 19 commits April 17, 2026 22:32
…n, CDP fallback

Ports gstack garrytan#892 + garrytan#1021 hardening. Windows-first CaveStack users can now
import cookies from Chrome/Edge/Brave without falling back to mac/linux paths.

- BrowserPlatform extended to win32; windowsDataDir for Chrome/Edge/Brave/Chromium
- getBaseDir('win32') -> ~/AppData/Local
- findBrowserMatch checks Network/Cookies first on Windows (Chrome 80+)
- getWindowsAesKey() reads os_crypt.encrypted_key from Local State JSON
- dpapiDecrypt() via PowerShell ProtectedData.Unprotect (stdin/stdout)
- decryptCookieValue branches: AES-256-GCM (Windows) vs AES-128-CBC (mac/linux)
- v20 App-Bound Encryption detected with specific error code
- CDP-based extraction fallback (importCookiesViaCdp) for v20 cookies
  - launches Chrome headless with --remote-debugging-port on real profile
  - extracts via Network.getAllCookies over CDP WebSocket
  - requires Chrome closed (v20 keys path-bound to user-data-dir)
- Inline security comment on CDP debug port (127.0.0.1 only, collision-avoid port)
- One-time Chrome version log on CDP entry via /json/version
- openDb() uses copy-then-read on Windows (exclusive locks)
- Hardcoded /tmp -> TEMP_DIR from platform.ts in openDbFromCopy
- cookie-import-browser.ts:494 error rethrow preserves underlying message

Upstream: garrytan/gstack@1211b6b (community wave v0.18.1.0)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Ports gstack garrytan#996 (msr-hickory) + the v20 CDP fallback wiring from garrytan#892.

- Add hasActivePicker() export — returns true while any picker code or
  session is still live. Used by server watchdog to avoid tearing down
  the server mid-import and stranding the picker UI with "Failed to fetch".
- Picker import path now auto-falls back to importCookiesViaCdp() when
  standard decrypt returns zero cookies AND hasV20Cookies() signals v20
  App-Bound Encryption. Surface actionable error with close-chrome hint
  when CDP fallback itself fails.

Rename kept: cavestack_picker cookie name (vs gstack's gstack_picker).

Upstream: garrytan/gstack@1211b6b

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Ports gstack garrytan#994 (joelgreen) + garrytan#1020 gating + SIGINT wrapper fix (garrytan#1025).

The browse server was dying between Claude Code Bash tool invocations because:
1. SIGTERM: Claude Code sandbox sends SIGTERM to child processes when a Bash
   command completes. Server called shutdown() and deleted state file.
2. Parent watchdog: 15s BROWSE_PARENT_PID poll shut down on parent death.

Both made every new $B call start a fresh server with no cookies or state.

Fix (scoped to normal headless mode):
- SIGTERM handler: in headless mode, log and ignore. Idle timeout (30min)
  handles eventual cleanup. Headed/tunnel modes respect SIGTERM and shutdown
  cleanly (idle timeout early-returns in those modes, so ignoring would leak).
- Parent watchdog: same three-way resolution. Active cookie picker always
  stays alive to avoid stranding picker UI with "Failed to fetch".
- SIGINT (Ctrl+C) always shuts down — intentional stop.
- Outer IS_HEADED_WATCHDOG gate skips watchdog entirely in headed mode.
- shutdown() called via arrow wrapper so signal name arg doesn't become
  NaN exitCode (fixes legacy exit-code-1 bug).

Imports hasActivePicker() from cookie-picker-routes (added in prior commit).

/open-cavestack-browser path used in place of /open-gstack-browser in inline docs.

Upstream: garrytan/gstack@1211b6b

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Ports gstack garrytan#993 (byliu-labs) + its follow-up extending coverage to design
resolver + 5 more skill templates.

Shell variable assignments that use a bare \`~/\` (rather than a quoted
"\$HOME/...") trigger Claude Code's sandbox permission prompt on every run.
Replace with explicit \$HOME expansion.

Source-of-truth fixes:
- scripts/resolvers/design.ts — 3 spots (D=, B=, _DESIGN_DIR=)
- cavestack-upgrade/SKILL.md.tmpl — _SNOOZE_FILE=
- design-consultation/SKILL.md.tmpl — _DESIGN_DIR=
- design-review/SKILL.md.tmpl — REPORT_DIR=
- design-shotgun/SKILL.md.tmpl — _DESIGN_DIR=
- plan-design-review/SKILL.md.tmpl — _DESIGN_DIR=

Uses the same .replace(/^~/, '') pattern from upstream for ctx.paths.*
substitutions so rendered output becomes "\$HOME/..." across all hosts.

Upstream: garrytan/gstack@1211b6b

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Regenerate claude-host SKILL.md files to absorb the tilde fix from
scripts/resolvers/design.ts and the 5 edited .tmpl files.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Normalizes YAML frontmatter on the 4 hand-authored OpenClaw skills so stricter
parsers like Codex can load them.

- Drops non-standard version + metadata fields
- Rewrites descriptions into simple "Use when..." form (no inline colons)
- Adds regression test enforcing strict frontmatter (name + description only)

Ported from garrytan#864 (cathrynlavery); adjusted for cavestack- prefix.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Cavestack divergence from upstream caveman. Users get a single compression
level — classic caveman "full" — with no intensity toggle. Removes:

- /caveman lite and /caveman ultra commands (mode tracker)
- lite/ultra entries from VALID_MODES (config validator)
- caveman-lite.json and caveman-ultra.json voice profiles
- lite/ultra rows, examples, intensity tables in SKILL docs
- lite/ultra mentions in README, web docs, setup hint, voices/README
- lite/ultra tests in voice-density, caveman-voice-verify, skill-validation

Wenyan variants (wenyan-lite, wenyan-full, wenyan-ultra) and sibling
skills (caveman-commit/review/compress) stay untouched.

"stop caveman" / "normal mode" continues to disable per session;
"/caveman" re-enables to full.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Follow-up to 06e5f97. CLAUDE.md section described the tracker as
handling "/caveman lite|full|ultra" toggles, which is no longer true
after the lock. Updated to describe the locked-full behavior and the
surviving wenyan + stop paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Test was checking for LF-only sentinels in file content, but Windows git
checkouts produce CRLF line endings for tracked .md files. Normalize to
LF before checking boundaries so the test works across platforms.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Ports 5 upstream PRs from garrytan#1028 (community wave v0.18.1.0):

- garrytan#892 Windows cookie import (DPAPI + v20 CDP fallback)
- garrytan#996 Cookie picker survives CLI exit
- garrytan#994 + garrytan#1020 SIGTERM persistence + headless-mode gating
- garrytan#993 Tilde-in-assignment fix (design resolver + 5 templates)
- garrytan#864 OpenClaw native skill frontmatter normalization (codex-friendly)

Plus local change: caveman mode locked to full (lite/ultra removed).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… pwsh fallback, key zeroing, temp cleanup)

Adversarial review turned up 5 weaknesses in the ported Windows cookie
import code. All fail visibly (no silent corruption) but every one is
addressable.

Tree-kill on Windows (killProcessTree helper)
  Bun.spawn.kill() uses TerminateProcess and does not reap child
  processes. Chrome spawns renderer/GPU/utility procs that survive as
  orphans and keep the profile locked. We now route every kill path
  (DPAPI PowerShell, macOS Keychain, secret-tool, Chrome headless)
  through taskkill /F /T /PID on Windows with a fallback to proc.kill
  elsewhere.

Chrome debug port discovery via DevToolsActivePort
  Replaced the random [9222,9321] port picker with --remote-debugging-port=0.
  Chrome writes the chosen port to DevToolsActivePort in user-data-dir;
  we poll the file until it appears. Avoids the silent-timeout failure
  mode where two Chrome-based tools collide on the same random port.

powershell.exe / pwsh.exe resolution
  Hardened Windows installs may ship without powershell.exe (deprecated
  on Win11) or without pwsh.exe (no PowerShell 7). Added findPowerShellExe()
  which probes PATH + canonical install locations for both, and raises
  a clear keychain_error if neither is found.

AES key zeroing + encrypted-blob cache
  Refactored the key cache so Windows caches the DPAPI-encrypted blob
  (safe at rest — DPAPI binds to the current user) instead of the
  decrypted AES-256 key. getDerivedKeys now returns a SessionKeys
  wrapper with ephemeral buffers that zeroSessionKeys() scrubs in the
  finally block of importCookies. macOS / Linux still cache the derived
  key (Keychain prompt makes re-derivation expensive, and the threat
  model there is the same as the source DB).

Temp DB sweep on crash
  Cookie DB copies land in os.tmpdir() and are normally unlinked when
  Database.close() runs. A process crash (SIGKILL, uncaught exception)
  bypassed cleanup and left .db / .db-wal / .db-shm behind. Added an
  exit + uncaughtException + unhandledRejection sweep driven by a
  tempDbPaths Set so crashes no longer leak temp files.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
On Windows, PIDs recycle aggressively. The parent-process watchdog
was polling `process.kill(BROWSE_PARENT_PID, 0)` every 15s; if the OS
reassigned the parent's PID to an unrelated new process within that
window, the existence check kept succeeding and the server stayed
alive forever thinking its parent was still around.

Now capture the parent's creation time at server launch (WMIC on
Windows, `ps -o lstart=` on mac/linux) and compare it on every poll.
Mismatch means PID reuse, so we treat the parent as exited even though
the PID still resolves. Logged with a "(PID reused)" note so the
shutdown reason is explicit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The v20 CDP fallback must launch Chrome headless against the user's
real profile directory because v20 App-Bound Encryption keys are
path-bound to user-data-dir. If Chrome is force-killed mid-launch
(SIGKILL, machine sleep, /ship interrupt) the profile's Preferences
or Local State can be corrupted. Risk is low but non-zero.

Added a GET /cookie-picker/preflight endpoint that runs hasV20Cookies
and returns { v20Detected, warning }. The picker UI calls it after
loadDomains(). When v20 is detected, the banner is upgraded to a
warning style and import actions are gated behind a confirm dialog
(ensureV20Confirmed) so the user explicitly acknowledges the risk
before Chrome is launched against their real profile. Ack persists
per browser+profile; switching either resets it.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Covers the new behavior introduced by the Windows hardening pass:
- /cookie-picker/preflight requires browser param, returns the
  {v20Detected, warning} shape, and gates on auth
- hasV20Cookies returns false on non-Windows and unknown browsers
  without throwing
- importCookies key reuse survives the SessionKeys wrapper (second
  sequential import on the same profile decrypts to the same value)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…throwing

Maintainability pass after adversarial review:

- extractCookiesViaCdp shared a 15s deadline across two sequential poll
  loops. If the first (DevToolsActivePort write) took 8s, the second
  (page target discovery) silently shrank to 7s and could time out
  unrelated to actual Chrome state. Give target-discovery its own
  fresh 15s budget.

- ensureTempDbExitHandler re-threw from uncaughtException and
  unhandledRejection after sweeping, which masked any other listener's
  behavior and could double-report the error. Attach sweep-only
  listeners; let Node's default handler produce the diagnostic and
  terminate.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Watchdog ticks every 15s and spawned wmic / PowerShell / ps
synchronously on each tick to read the parent's start time. On
Windows this blocked the event loop ~50-200ms per tick, starving
inbound HTTP requests and delaying the Playwright driver's own I/O.

Switch getProcessStartTime to Bun.spawn + await proc.exited so the
probes run concurrently with everything else the server is doing.
Cache the launch-time start-time in a Promise so every tick resolves
the same value without re-spawning a probe at startup. Guard against
overlapping ticks with a watchdogBusy flag (belt-and-suspenders if a
single probe ever exceeds 15s).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The heuristic "if every v10 decrypt failed AND the DB contains v20
bytes, try CDP" was duplicated between the picker route and the
write-commands direct-import path. Drift risk — one site could change
the trigger condition while the other kept the old behavior.

Extract importCookiesWithV20Fallback in cookie-import-browser.ts
as a single exported entry point. Picker route keeps its custom
"v20_encryption" JSON error response by catching the CDP exception;
write-commands loses a few lines and is easier to read.

No behavior change on the happy path.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
hasActivePicker gates the SIGTERM handler and the parent-PID watchdog
shutdown path. A regression that made it always return false would
silently tear down the server mid-import (stranding the picker UI).
A regression that made it always return true would keep the server
alive forever.

Add three direct tests: baseline boolean, TTL-live code, and session
established via a route exchange. Previously this behavior was only
tested indirectly through higher-level route + signal tests.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The initial v1.2.2.0 entry covered the 5-PR upstream port wave. This
branch also applied 7 adversarial-review hardening fixes (tree-kill,
port discovery, PID reuse guard, temp sweep, pwsh fallback, key
zeroing, preflight UI warning) plus 3 maintainability fixes (async
watchdog, CDP poll deadline, v20 fallback DRY). Regenerate the entry
to cover all 18 commits on the branch.

No version bump — same branch, same shipping artifact. Date moved to
2026-04-18 since the hardening + regeneration landed today.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@JerkyJesse
JerkyJesse merged commit 6e44347 into main Apr 18, 2026
@JerkyJesse
JerkyJesse deleted the feat/gstack-wave-v0.18.1 branch April 18, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant