From d6598d0b31e394ad828c412d9cfd87f4d8632393 Mon Sep 17 00:00:00 2001 From: Dasemu Date: Sun, 18 Oct 2026 15:02:43 +0200 Subject: [PATCH] chore: bootstrap Claude setup Add root CLAUDE.md, docs/architecture.md, LESSONS.md, .env.example, .claude/settings.json hooks (PostToolUse JS syntax check, Stop hook validating manifest.json + node --check on all JS), and GitHub Actions workflows (ci.yml, version.yml) for this plain-JS Chrome extension with no existing build/lint/test tooling. Co-Authored-By: Claude Sonnet 5 --- .claude/bootstrap-version | 1 + .claude/hooks/stop-check.sh | 17 +++++++++ .claude/settings.json | 25 ++++++++++++ .env.example | 2 + .github/workflows/ci.yml | 24 ++++++++++++ .github/workflows/version.yml | 72 +++++++++++++++++++++++++++++++++++ CLAUDE.md | 41 ++++++++++++++++++++ LESSONS.md | 6 +++ docs/architecture.md | 29 ++++++++++++++ 9 files changed, 217 insertions(+) create mode 100644 .claude/bootstrap-version create mode 100755 .claude/hooks/stop-check.sh create mode 100644 .claude/settings.json create mode 100644 .env.example create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/version.yml create mode 100644 CLAUDE.md create mode 100644 LESSONS.md create mode 100644 docs/architecture.md diff --git a/.claude/bootstrap-version b/.claude/bootstrap-version new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/.claude/bootstrap-version @@ -0,0 +1 @@ +2 diff --git a/.claude/hooks/stop-check.sh b/.claude/hooks/stop-check.sh new file mode 100755 index 0000000..069b97b --- /dev/null +++ b/.claude/hooks/stop-check.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Stop hook: quickest meaningful check available in this project. +# No test runner or linter is configured yet, so this validates: +# 1. manifest.json is valid JSON. +# 2. every tracked .js file passes `node --check` (syntax only). +set -euo pipefail + +cd "$(git rev-parse --show-toplevel)" + +node -e "JSON.parse(require('fs').readFileSync('manifest.json', 'utf8'))" + +status=0 +while IFS= read -r -d '' file; do + node --check "$file" || status=1 +done < <(git ls-files -z '*.js') + +exit "$status" diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..5cd9909 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,25 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "file=$(cat | python3 -c 'import json,sys; print(json.load(sys.stdin).get(\"tool_input\",{}).get(\"file_path\",\"\"))'); case \"$file\" in *.js) node --check \"$file\" ;; esac" + } + ] + } + ], + "Stop": [ + { + "hooks": [ + { + "type": "command", + "command": "bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/stop-check.sh\"" + } + ] + } + ] + } +} diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e324381 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +# No environment variables are read by this project today. +# This file is kept as a placeholder, in sync with the code, for when one is added. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..dfbb83a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI + +on: + pull_request: + branches: [development] + push: + branches: [development, main] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "20" + # No linter or test suite is configured for this plain-JS browser extension + # (no package.json/bundler). This validates manifest.json and runs a syntax + # check on every JS file, matching the local Stop hook. + - name: Validate manifest.json + run: node -e "JSON.parse(require('fs').readFileSync('manifest.json', 'utf8'))" + - name: Syntax check (node --check) + run: | + find . -name "*.js" -not -path "./.git/*" -print0 | xargs -0 -n1 node --check diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..636eece --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,72 @@ +name: Version bump + +on: + push: + branches: [development, main] + +permissions: + contents: write + +jobs: + bump: + if: github.actor != 'github-actions[bot]' && !contains(github.event.head_commit.message, '[skip ci]') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Configure git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Bump version in manifest.json + id: bump + run: | + set -euo pipefail + current=$(node -p "require('./manifest.json').version") + IFS='.' read -r major minor patch <<< "$current" + + if [ "${{ github.ref_name }}" = "development" ]; then + patch=$((patch + 1)) + else + # push to main: MINOR bump only when this commit is already part of + # development's history (i.e. an approved development -> main merge + # PR); otherwise treat it as a direct hotfix push (PATCH bump). + if git fetch origin development >/dev/null 2>&1 && \ + git merge-base --is-ancestor "$(git rev-parse HEAD)" origin/development; then + minor=$((minor + 1)) + patch=0 + else + patch=$((patch + 1)) + fi + fi + + new_version="$major.$minor.$patch" + node -e " + const fs = require('fs'); + const m = JSON.parse(fs.readFileSync('manifest.json', 'utf8')); + m.version = '$new_version'; + fs.writeFileSync('manifest.json', JSON.stringify(m, null, 2) + '\n'); + " + echo "new_version=$new_version" >> "$GITHUB_OUTPUT" + + - name: Commit version bump + run: | + git add manifest.json + git commit -m "chore(release): v${{ steps.bump.outputs.new_version }} [skip ci]" + git push origin HEAD:${{ github.ref_name }} + + - name: Merge main back into development + if: github.ref_name == 'main' + run: | + if git ls-remote --exit-code --heads origin development >/dev/null 2>&1; then + git fetch origin development + git checkout -B development origin/development + git merge --no-edit origin/main + git push origin development + else + echo "No development branch yet; skipping merge-back." + fi diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..74f37bb --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,41 @@ +# CLAUDE.md + +## Overview +Phenocheck is a Manifest V3 Chrome extension that shows estimated human phenotypes +for X.com (Twitter) users based on their declared location. No build step: plain +JS/CSS loaded directly by the browser. + +## Commands +- No package manager, build, lint, or test tooling exists yet (no `package.json`). +- Load locally: open `chrome://extensions`, enable Developer mode, "Load unpacked", + select the repo root. +- Quick syntax check: `node --check .js` (used by the Claude hooks below). +- Validate the manifest: `node -e "JSON.parse(require('fs').readFileSync('manifest.json'))"`. + +## Architecture +- `manifest.json` — MV3 manifest: permissions, content scripts, icons. +- `background.js` — service worker. +- `content.js` / `content.css` — injected into x.com / twitter.com pages. +- `data/data.js` — phenotype/location dataset loaded before `content.js`. +- `images/` — icons and phenotype images (including `images/phenotypes/custom/`). +- See `docs/` for anything deeper than this overview. + +## Conventions +- Plain ES JS (no bundler, no transpiler, no framework). Keep it that way unless asked. +- Keep `manifest.json` the source of truth for the extension version + (`MAJOR.MINOR.PATCH`), bumped only by `.github/workflows/version.yml`. + +## Workflow quirks +- Host is Gitea (`git.zenvairo.es`), not GitHub — use `tea`, not `gh`. +- No `development` branch exists yet; work directly against `main` via task branches + until one is created. + +## Deployment +- Not applicable: this is a browser extension loaded unpacked / published to a + web store, not a deployed web service. + +## Gotchas +- There is no linter, formatter, or test runner configured yet. The Stop hook only + runs `node --check` on the extension's JS files and validates `manifest.json`. +- No environment variables are read by the code today; `.env.example` is a + placeholder for when that changes. diff --git a/LESSONS.md b/LESSONS.md new file mode 100644 index 0000000..97aac46 --- /dev/null +++ b/LESSONS.md @@ -0,0 +1,6 @@ +# LESSONS.md + +Recurring mistakes and how to avoid them. Read before starting work; add an entry +whenever the same mistake happens twice. + +(No recurring mistakes recorded yet.) diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..48440f3 --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,29 @@ +# Architecture + +Phenocheck is a Manifest V3 Chrome extension with no build step. + +## Components +- `manifest.json` — declares permissions (`storage`, `cookies`), host permissions + for `x.com` / `twitter.com`, the background service worker, content scripts, and + web-accessible resources (phenotype images). +- `background.js` — the extension's service worker. +- `content.js` + `content.css` — injected into matched pages at `document_idle`; + reads the page DOM and renders phenotype estimates. +- `data/data.js` — static dataset (location → phenotype mapping or similar), loaded + before `content.js` so its globals are available to it. +- `images/icons/` — toolbar/extension icons. +- `images/phenotypes/` (incl. `images/phenotypes/custom/`) — images shown in the + injected UI, exposed via `web_accessible_resources`. + +## Data flow +1. `background.js` fetches the profile's declared "Account based in" country via + X's internal `AboutAccountQuery` API (using the `cookies` permission for auth). +2. `content.js` requests that country for the profile being viewed, with an + in-memory cache keyed by handle. +3. It maps the country to an estimate using `data/data.js` (plus hardcoded + per-handle overrides in `content.js`). +4. It renders the result into the page using `content.css` for styling and images + from `images/phenotypes/` (or `images/phenotypes/custom/` for overrides). + +No external backend of our own is involved; the only network calls are to X's own +internal API, made from the background service worker.