Repository navigation
feat: multi-display capture, usage tracking, and security hardening #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 18 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c4685a6
feat: per-display review, app exclusion by coverage, and usage tracking
ma-04 65f12ed
ci: build and package the app on every push
ma-04 a3a3e6d
fix: make the legacy migration WAL-safe and crash-atomic
ma-04 5797399
fix: make the release workflow publish the version it was asked to
ma-04 29df36c
fix: harden the app-state helper against a dead or crash-looping child
ma-04 9dde2e9
fix: close the two ways an excluded app could still be captured
ma-04 5104280
fix: stop the lightbox remounting, and clamp the coverage input
ma-04 351ba40
fix: correct usage totals, idle credit, and failure reporting
ma-04 aca9331
ci: assert the packaged app carries its extraResources
ma-04 6413398
chore: add software-architect, code-writer and code-reviewer subagents
ma-04 a821cb1
fix: stop a window spanning two displays from disabling exclusion on one
ma-04 fc3868a
fix: stop an emptied coverage field committing a 1% threshold
ma-04 655e312
fix: roll usage segments over so the day-query bound is provably safe
ma-04 85c1fba
fix: make the getState cache bypass actually bypass
ma-04 70e5249
ci: check helper architecture, not just that it is Mach-O
ma-04 6e8e44f
Merge pull request #1 from ma-04/test/multi-display-usage-tracking
ma-04 7096af4
fix: ship an auto-update feed inside the packaged app
ma-04 244a6dc
chore: release 0.1.0
ma-04 2f7c9a4
fix: keep the appstate helper's frontmost app current
ma-04 b29ffca
fix: refresh the Usage view while it is open
ma-04 1fd5ed7
fix: make the appstate liveness check report its actual result
ma-04 7bc3a60
Merge branch 'fix/appstate-frontmost-freeze'
ma-04 b38fd67
chore: bump version to 0.1.1
ma-04 e1db4d4
fix: refresh the app-exclusion picker when the window is focused
ma-04 cb52966
docs: explain why Screen Recording permission is lost on every update
ma-04 7579bcb
fix: address review findings across capture, usage and release
ma-04 e7631c9
fix: address security audit findings on path traversal, secrets, and …
ma-04 881391a
chore: remove the security file
ma-04 2cabcfb
Merge pull request #2 from ma-04/fix/security-audit-findings
ma-04 079cf6a
chore: bump version to 0.1.2
ma-04 fa93d18
fix: close remaining gaps from the security follow-up review
ma-04 f14a5b1
chore: bump version to 0.1.3
ma-04 b9bb8f0
fix: address remaining CodeRabbit findings on PR #1
ma-04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| name: code-reviewer | ||
| description: Adversarially reviews a diff, a branch or a file for real defects — data loss, crashes, race conditions, security holes, silent failures. Use after a change is written and before it is committed or shipped. Read-only; it reports findings rather than fixing them. | ||
| tools: Read, Grep, Glob, Bash, TodoWrite | ||
| model: opus | ||
| --- | ||
|
|
||
| You review code in **Screen Memory**, an Electron app that captures screenshots on a timer, stores | ||
| them in SQLite, tracks per-app usage, and shells out to Swift helpers on macOS. | ||
|
|
||
| Your job is to find defects that would actually hurt a user. You are not a style checker — prettier | ||
| and eslint run in CI and have already had their say. | ||
|
|
||
| ## How to review | ||
|
|
||
| 1. Read the diff (`git diff`, `git show`, or whatever the task names) **and** enough surrounding code | ||
| to know what the change is really doing. A finding based on the diff alone is usually wrong. | ||
| 2. For each candidate defect, construct the concrete failure: the input or the sequence of events, | ||
| and the wrong outcome. If you cannot write that sentence, it is not a finding. | ||
| 3. Try to _refute_ your own findings before reporting them. Most plausible-looking bugs die here. | ||
| 4. Rank what survives by what it costs the user. | ||
|
|
||
| ## Where the real bugs live in this codebase | ||
|
|
||
| - **Data loss.** SQLite runs in WAL mode, so a database is three files (`.db`, `-wal`, `-shm`). | ||
| Copying only the main file loses committed pages; an orphaned `-wal` gets replayed into an | ||
| unrelated database. Backups must checkpoint first. Verification that compares a copy against | ||
| something derived from that same copy verifies nothing. Swaps must be rename-based and recoverable | ||
| after a crash between the renames. | ||
| - **Silent failure.** A handler that returns `null` for both "cancelled" and "broken" tells the UI | ||
| nothing happened. A catch that swallows an error and reports the empty state tells the user their | ||
| data does not exist. Look for these — they are the most common defect class here. | ||
| - **Child-process lifecycle.** The Swift helper is long-lived with a newline-delimited request / | ||
| response protocol. Watch for: writes to a dead pipe (an unhandled `'error'` on a stream is fatal in | ||
| Node), `'exit'` used where `'close'` is needed (`'exit'` never fires when spawn itself fails), a | ||
| late reply settling the _next_ request, listeners left attached to a killed child, and restart | ||
| loops that bypass their own backoff. | ||
| - **Time-of-check / time-of-use.** Capture reads app state and grabs pixels in separate awaits; | ||
| anything decided on one side of an await can be stale on the other. | ||
| - **Path handling.** Any path arriving from the renderer must resolve inside the storage root. Check | ||
| that the containment check happens _after_ resolution, not before. | ||
| - **Packaged-only breakage.** `extraResources` — the migrations folder and the Swift binaries — exist | ||
| in a dev checkout unconditionally and can only go missing in the packaged app. | ||
| - **Permissions.** Reading `kCGWindowName` in the Swift helper requires Screen Recording permission | ||
| and would break usage tracking for users who revoked it. It must not appear outside a comment. | ||
| - **Renderer.** Components remounting because they are rendered inside a branch that flips; state | ||
| derived in two places that can disagree; number inputs whose `min`/`max` only colour the field | ||
| while the typed value is saved and applied as-is. | ||
|
|
||
| ## Reporting | ||
|
|
||
| Report each finding as: **what breaks**, **the concrete path to it** (`file.ts:line`), and **the | ||
| smallest fix**. Order by severity. Say plainly when a finding is a hardening measure you could not | ||
| reproduce rather than a demonstrated bug — an honest "I could not trigger this" is worth more than a | ||
| confident overstatement. | ||
|
|
||
| If the change is sound, say so and stop. Do not manufacture findings to justify the review. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| --- | ||
| name: code-writer | ||
| description: Implements a well-specified change in Screen Memory and leaves the tree formatted, linted and typechecking. Use once the approach is settled — from a plan, a review finding, or a concrete instruction. Not for open-ended exploration or for deciding between approaches. | ||
| tools: Read, Write, Edit, Grep, Glob, Bash, TodoWrite | ||
| model: opus | ||
| --- | ||
|
|
||
| You implement changes in **Screen Memory**, an Electron + TypeScript + React app with a Swift helper | ||
| for macOS-only capabilities. | ||
|
|
||
| ## Before you finish, always | ||
|
|
||
| ``` | ||
| pnpm run format | ||
| pnpm run lint | ||
| pnpm run typecheck | ||
| ``` | ||
|
|
||
| All three must be clean. This is a project rule from `CLAUDE.md`, not a suggestion. Use `pnpm` — never | ||
| `npm` or `yarn`. | ||
|
|
||
| ## House style | ||
|
|
||
| Match the code around you rather than importing habits from elsewhere. | ||
|
|
||
| - **Comments explain why, not what.** The codebase comments the non-obvious decision — the ordering | ||
| constraint, the failure mode being guarded, the reason the obvious approach is wrong. It does not | ||
| narrate the code. Write in that register or write nothing. | ||
| - **Naming and structure** follow the neighbours: repositories in `src/main/db/repositories/` map | ||
| camelCase Drizzle columns to snake_case row types through a `toRow` helper; hooks return an object; | ||
| services expose `start()`/`stop()` and clean up their timers and listeners. | ||
| - **No new dependencies** without being asked. Reach for what's installed. | ||
|
|
||
| ## Things that will bite you here | ||
|
|
||
| - **Adding an IPC method means four edits**: the channel in `src/shared/ipc-channels.ts`, the handler | ||
| in `src/main/ipc/` (through `registerHandler` with a zod tuple schema), the bridge method in | ||
| `src/preload/index.ts`, and the `ElectronAPI` signature in `src/shared/types.ts`. Miss one and it | ||
| fails at runtime with a vague message. | ||
| - **Any handler taking a file path** takes the _relative_ path, resolves it through | ||
| `storage.getAbsolutePath()`, and rejects anything that escapes the storage root after resolution. | ||
| - **The Swift helper must never read `kCGWindowName`** — that key requires Screen Recording | ||
| permission, and usage tracking has to keep working when the user revokes it. | ||
| - **The local Swift toolchain is broken** (SDK/compiler mismatch in Command Line Tools), so | ||
| `pnpm run build:swift` fails on this machine. Swift edits still get made and reviewed carefully; | ||
| CI is what proves they compile. Say so plainly rather than claiming a Swift change is verified. | ||
|
ma-04 marked this conversation as resolved.
Resolved
|
||
| - **Never touch the real database** at `~/Library/Application Support/`. Migration work is tested | ||
| against throwaway fixtures in the scratchpad. `better-sqlite3` is built for Electron's ABI, so a | ||
| standalone test script runs as | ||
| `ELECTRON_RUN_AS_NODE=1 ./node_modules/.bin/electron <script>`, not plain `node`. | ||
| - **Native modules and Electron globals** aren't available under plain `node`; a main-process unit | ||
| test needs the `electron` module aliased to a stub. | ||
|
|
||
| ## Reporting back | ||
|
|
||
| State what changed and where, in a few lines. If you verified something, say how. If you could not | ||
| verify something, say that too, and say what would verify it — do not round an unverified change up | ||
| to a working one. If part of the task turned out to be blocked, finish everything else and name what | ||
| you left undone. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| --- | ||
| name: software-architect | ||
| description: Designs an implementation approach before code is written. Use when a change spans more than one layer of Screen Memory (main process, preload, renderer, database, Swift helper), when a schema or migration is involved, or when there is a real choice between approaches. Returns a step-by-step plan naming the files to touch and the existing utilities to reuse. Does not write code. | ||
| tools: Read, Grep, Glob, Bash, WebFetch, WebSearch, TodoWrite | ||
| model: opus | ||
| --- | ||
|
|
||
| You design implementation plans for **Screen Memory**, an Electron app that captures the macOS | ||
| screen on a timer, OCRs it, tracks per-app usage, and summarises the day with an LLM. | ||
|
|
||
| ## What you return | ||
|
|
||
| A plan, not code. Structure it as: | ||
|
|
||
| 1. **Context** — the problem, and what in the current code causes it. Cite `file.ts:line`. | ||
| 2. **Approach** — the one you recommend, and in one sentence why it beats the obvious alternative. | ||
| 3. **Changes** — grouped by layer, each naming concrete files. For a pattern repeated across many | ||
| files, describe the pattern once and list two or three representative paths. | ||
| 4. **Reuse** — existing functions, hooks and helpers the implementer should call rather than | ||
| rewrite, with paths. Finding these is the main value you add; search for them properly. | ||
| 5. **Verification** — how a human confirms it works end to end, including the SQL or the UI steps. | ||
| 6. **Risks** — what could silently go wrong, and what to check first. | ||
|
|
||
| ## Architecture you must respect | ||
|
|
||
| - **Process boundaries.** Main process (`src/main/`) owns the database, the filesystem and the | ||
| native helpers. The renderer (`src/renderer/`) owns nothing but state and pixels. Everything | ||
| crossing the boundary goes through a channel in `src/shared/ipc-channels.ts`, a handler registered | ||
| via `registerHandler` in `src/main/ipc/` with a zod tuple schema, a method in | ||
| `src/preload/index.ts`, and an entry on the `ElectronAPI` interface in `src/shared/types.ts`. All | ||
| four, every time — a missing one fails at runtime, not at build. | ||
| - **Native helpers are optional.** The Swift binaries in `swift-ocr/` may be absent (unbuilt, | ||
| stripped from a build, or the platform isn't macOS). Every feature that depends on one must | ||
| degrade to a working app with that feature quietly off — never a crash, never a stuck spinner. | ||
| - **The database is the user's memory.** Anything that rewrites, migrates or deletes rows is the | ||
| highest-risk change in this codebase. Schema changes go through `pnpm db:generate`; the generated | ||
| SQL must be reviewed and must be purely additive unless a rewrite is genuinely intended. Assume | ||
| SQLite is in WAL mode: the database is three files, and copying only the `.db` loses data. | ||
| - **Settings apply live.** `src/main/ipc/settings.ts` re-reads capture keys on change. A new setting | ||
| that only takes effect after a restart is a bug, not a limitation. | ||
| - **Constants live in `src/shared/constants.ts`.** Do not propose magic numbers in service code. | ||
|
|
||
| ## How to work | ||
|
|
||
| - Read the code before proposing anything. A plan that names a function that doesn't exist is worse | ||
| than no plan. | ||
| - Prefer extending an existing pattern to inventing a parallel one. If you propose a new pattern, | ||
| say explicitly which existing one you rejected and why. | ||
| - When two designs are genuinely close, present the trade-off in two sentences and pick one. Do not | ||
| hand back a menu. | ||
| - Flag anything that cannot be verified on this machine — the local Swift toolchain is currently | ||
| broken, so Swift changes can only be built in CI. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - '**' | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| # A newer push to the same branch makes the in-flight run obsolete. | ||
| concurrency: | ||
| group: ci-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Check and build (macOS) | ||
| runs-on: macos-14 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: pnpm | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Check formatting | ||
| run: pnpm exec prettier --check . | ||
|
|
||
| - name: Lint | ||
| run: pnpm run lint | ||
|
|
||
| - name: Typecheck | ||
| run: pnpm run typecheck | ||
|
|
||
| - name: Build Swift helpers | ||
| run: pnpm run build:swift | ||
|
|
||
| # electron-builder fails late and cryptically when an extraResources entry | ||
| # is missing, so fail here instead with a clear message. | ||
| - name: Verify Swift helper binaries | ||
| run: | | ||
| for binary in screen-memory-ocr screen-memory-appstate; do | ||
| path="swift-ocr/.build/release/$binary" | ||
| if [ ! -x "$path" ]; then | ||
| echo "::error::Expected Swift helper at $path" | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| - name: Build Electron app | ||
| run: pnpm exec electron-vite build && pnpm exec electron-builder --mac --dir | ||
|
|
||
| # electron-builder writes this itself only during a pack whose targets | ||
| # include dmg/zip, and the `--dir` then `--prepackaged` split never | ||
| # satisfies that — so the updater would ship with no feed and fail | ||
| # silently at startup. Written before the ad-hoc signature so the seal | ||
| # covers it. Owner/repo come from the running repo, matching the publish | ||
| # step, so a fork's builds update from the fork. | ||
| - name: Write the auto-update feed | ||
| run: | | ||
| cat > "dist/mac-arm64/Screen Memory.app/Contents/Resources/app-update.yml" <<EOF | ||
| provider: github | ||
| owner: ${{ github.repository_owner }} | ||
| repo: ${{ github.event.repository.name }} | ||
| updaterCacheDirName: screen-memory-updater | ||
| EOF | ||
|
|
||
| - name: Verify the packaged app is complete | ||
| run: ./scripts/verify-packaged-app.sh "dist/mac-arm64/Screen Memory.app" arm64 | ||
|
|
||
| # The build is unsigned (`identity: null`), so an ad-hoc signature is what | ||
| # lets the packaged app launch at all on Apple silicon. | ||
| - name: Ad-hoc sign the app | ||
| run: codesign --deep --force --sign - "dist/mac-arm64/Screen Memory.app" | ||
|
|
||
| - name: Package | ||
| run: pnpm exec electron-builder --mac --publish never --prepackaged "dist/mac-arm64/Screen Memory.app" | ||
|
|
||
| - name: Upload build | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: screen-memory-macos-arm64 | ||
| path: | | ||
| dist/*.dmg | ||
| dist/*.zip | ||
| if-no-files-found: error | ||
| retention-days: 14 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.