Skip to content

klack: rebuild with stats and standalone support - #28135

Merged
raycastbot merged 3 commits into
raycast:mainfrom
henrikruscon:klack/rebuild
May 20, 2026
Merged

raycastbot merged 3 commits into
raycast:mainfrom
henrikruscon:klack/rebuild

Conversation

@JaceThings

Copy link
Copy Markdown
Contributor

Summary

Klack 2.1.x added a new current stats AppleScript command. This PR rebuilds the extension on top of the modern Klack scripting dictionary, expands its surface, and ships a live stats view. Done with Henrik's blessing — he invited me as a collaborator on his fork to land this update.

The store identity (name: klack, author: henrikruscon) is preserved so stars, install count, and the existing listing URL carry over.

What's new

  • Klack Stats view — live keystroke / ding / click counts and favourite-switch breakdown, refreshing while open. Per-switch tinted tag chips that adapt to light vs. dark Raycast themes. "Copy Stats as Markdown" action and a "Tracking since" line that surfaces Klack's firstTrackedAt.
  • Set Volume view — 0–100 scrubber with a custom-input form.
  • Turn Klack on / Turn Klack off / Wake Klack — explicit state commands using the v2 sdef.
  • AI extension tools — toggle, turn-on, turn-off, wake-up, set-switch, set-volume, get-status. All include runtime guards against unknown inputs.
  • Super Red switch (Keychron).
  • Per-switch icons in the picker.
  • Redundancy-aware feedback — every command reports when Klack is already in the requested state instead of silently no-op'ing.
  • Standalone Klack support — the tryklack.com build shares the bundle ID and sdef, so this extension drives both.

What's fixed

  • Switch search is case-insensitive.
  • "Current" badge correctly identifies multi-word switch names (e.g. "Crystal Purple", "Japanese Black").
  • Select action no longer requires the initial current switch fetch to have resolved.
  • Set Volume to Soft / Balanced / Loud work under Klack v2 (the old volume preset enum no longer exists in the sdef — these now call the integer volume command directly).
  • Error toasts distinguish "Klack is not installed" vs. "Klack needs an update" vs. "Permission required" instead of one generic message.
  • Install check no longer leaks a rejected promise after a transient getApplications() failure.

Performance

  • Multi-field state reads collapsed into one AppleScript spawn.
  • Per-process install-check memoization (and a TTL'd cache key for cross-process cold starts).
  • Optimistic mutations with shouldRevalidateAfter: false — no post-action refetch.
  • useCachedPromise seeded from a persistent Cache for instant cold-start paint across all commands.
  • closeMainWindow() no longer blocked-on for no-view commands.
  • CustomVolumeForm lazy-loaded.

Tooling

  • @raycast/api → ^1.104.17
  • React → 19
  • TypeScript → 5.9
  • Dropped run-applescript dependency in favour of @raycast/utils runAppleScript.

Test plan

  • npx ray build -e dist
  • npx ray lint
  • Manual verification of all 10 commands and 7 AI tools against Klack 2.1.3.
  • Verified empty states: stats off (statsEnabled: false) and permission required (hasStatsPermission: false).

@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: klack Issues related to the klack extension AI Extension platform: macOS labels May 19, 2026
@raycastbot

raycastbot commented May 19, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! 🎉

🔔 @henrikruscon you might want to have a look.

You can use this guide to learn how to check out the Pull Request locally in order to test it.

📋 Quick checkout commands
BRANCH="klack/rebuild"
FORK_URL="https://github.com/henrikruscon/raycast-extensions.git"
EXTENSION_NAME="klack"
REPO_NAME="raycast-extensions"

git clone -n --depth=1 --filter=tree:0 -b $BRANCH $FORK_URL
cd $REPO_NAME
git sparse-checkout set --no-cone "extensions/$EXTENSION_NAME"
git checkout
cd "extensions/$EXTENSION_NAME"
npm install && npm run dev

We're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 10-15 business days.

@henrikruscon

Copy link
Copy Markdown
Contributor

Looks good!

@greptile-apps

greptile-apps Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR substantially rebuilds the Klack Raycast extension on top of the Klack 2.1.x scripting dictionary, adding a live stats view, a volume scrubber, explicit on/off/wake commands, AI tools, per-switch icons, redundancy-aware feedback, and standalone build support.

  • New features: Klack Stats view (1 s polling with inflight guard, Markdown export, tracking-since timestamp), Set Volume scrubber, Turn on/off/Wake Klack commands, seven AI tools with runtime input guards, Super Red switch, and case-insensitive switch search.
  • Performance & correctness fixes: Multi-field state collapsed into one AppleScript spawn, per-process install-check memoization, optimistic mutations with shouldRevalidateAfter: false, persistent Cache seeding for cold-start paint, closeMainWindow() fire-and-forget, lazy CustomVolumeForm, and fixed install-check promise leak.
  • Tooling: Upgraded to @raycast/api ^1.104.17, React 19, TypeScript 5.9; dropped run-applescript in favour of @raycast/utils runAppleScript; migrated to ESLint v9 flat config.

Confidence Score: 4/5

Safe to merge after swapping the hardcoded date in CHANGELOG.md for the {PR_MERGE_DATE} placeholder.

The only actionable finding is the CHANGELOG entry using the literal date 2026-05-20 rather than the required template placeholder. All new logic — install-check memoization, optimistic mutations, inflight polling guard, AppleScript batching, and AI tool input validation — is well-structured and tested against Klack 2.1.3.

extensions/klack/CHANGELOG.md — date placeholder needs to be updated before merging.

Important Files Changed

Filename Overview
extensions/klack/CHANGELOG.md New entry present with correct ordering, but uses a hardcoded date instead of the required {PR_MERGE_DATE} placeholder.
extensions/klack/src/lib/klack.ts Core AppleScript wrapper with per-process install-check memoization, TTL'd cache key, and optimistic state writes. Logic looks correct.
extensions/klack/src/lib/stats.ts getStats batches AppleScript + defaults read in parallel; parseStats is defensive with proper fallbacks; readFirstTrackedAt fails silently when key is absent.
extensions/klack/src/stats.tsx Live-polling stats view with an inflight guard preventing concurrent revalidations; empty states for disabled/no-permission scenarios handled correctly.
extensions/klack/src/lib/errors.ts Classifies AppleScript errors into four distinct KlackError kinds using regex patterns; toast titles are clear and actionable.
extensions/klack/src/lib/cache.ts TTL-based install-check cache and persistent state patch helper; straightforward and correct.
extensions/klack/src/components/switch-list.tsx Case-insensitive current-switch detection, optimistic mutation with shouldRevalidateAfter:false, and redundancy-aware HUD messages. Logic is sound.
extensions/klack/package.json Schema reference present, dependencies are correct and lean (dropped run-applescript), platforms restricted to macOS, categories appropriate.
extensions/klack/src/tools/set-switch.ts Runtime guard validates switch name against ALL_SWITCH_NAMES before applying; redundancy feedback present.
extensions/klack/src/tools/set-volume.ts Clamps and rounds input before the current-volume comparison and passes the clamped target to setVolume; logic is correct.
extensions/klack/eslint.config.js Upgraded from legacy .eslintrc.json to ESLint v9 flat config using defineConfig from eslint/config subpath; pattern is correct.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
extensions/klack/CHANGELOG.md:3
The new entry uses a hardcoded date instead of the required `{PR_MERGE_DATE}` placeholder. The placeholder is automatically replaced with the actual merge date when the PR is merged; hardcoding a date bypasses that mechanism and will appear incorrect in the store changelog if the merge happens on a different day.

```suggestion
## [Stats and Standalone Support] - {PR_MERGE_DATE}
```

Reviews (3): Last reviewed commit: "Update CHANGELOG.md and optimise images" | Re-trigger Greptile

Comment thread extensions/klack/src/stats.tsx Resolved
- tools/set-volume: pass clamped target to klack.setVolume for explicit intent
- stats: coalesce polling so a slow current-stats call doesn't queue concurrent spawns
@0xdhrv 0xdhrv self-assigned this May 19, 2026

@0xdhrv 0xdhrv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, approved ✅

@raycastbot
raycastbot merged commit 54ef688 into raycast:main May 20, 2026
3 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@raycastbot

Copy link
Copy Markdown
Collaborator

🎉 🎉 🎉

We've rewarded your Raycast account with some credits. You will soon be able to exchange them for some swag.

@@ -1,5 +1,24 @@
# Klack Changelog

## [Stats and Standalone Support] - 2026-05-20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The new entry uses a hardcoded date instead of the required {PR_MERGE_DATE} placeholder. The placeholder is automatically replaced with the actual merge date when the PR is merged; hardcoding a date bypasses that mechanism and will appear incorrect in the store changelog if the merge happens on a different day.

Suggested change
## [Stats and Standalone Support] - 2026-05-20
## [Stats and Standalone Support] - {PR_MERGE_DATE}

Rule Used: What: Changelog entries must use {PR_MERGE_DATE}... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/klack/CHANGELOG.md
Line: 3

Comment:
The new entry uses a hardcoded date instead of the required `{PR_MERGE_DATE}` placeholder. The placeholder is automatically replaced with the actual merge date when the PR is merged; hardcoding a date bypasses that mechanism and will appear incorrect in the store changelog if the merge happens on a different day.

```suggestion
## [Stats and Standalone Support] - {PR_MERGE_DATE}
```

**Rule Used:** What: Changelog entries must use `{PR_MERGE_DATE}`... ([source](https://app.greptile.com/review/custom-context?memory=c2214c11-df56-490a-b1c0-09a385df481a))

How can I resolve this? If you propose a fix, please make it concise.

almatkai pushed a commit to almatkai/raymes-extensions that referenced this pull request Jul 13, 2026
* klack: rebuild with stats and standalone support

* klack: address greptile review feedback

- tools/set-volume: pass clamped target to klack.setVolume for explicit intent
- stats: coalesce polling so a slow current-stats call doesn't queue concurrent spawns

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: raycastbot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Extension extension fix / improvement Label for PRs with extension's fix improvements extension: klack Issues related to the klack extension platform: macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants