From bba3fee23a9fa29b184226cab0d4201d729bf3e5 Mon Sep 17 00:00:00 2001 From: Dasemu Date: Sun, 18 Oct 2026 15:05:18 +0200 Subject: [PATCH] chore: bootstrap Claude setup Add .claude/settings.json hooks (typecheck on edited .ts files, guard on package-lock.json edits, Stop runs typecheck + test), CI workflow (typecheck + test on PRs/pushes to development/main), and a version bump workflow keyed off package.json. Restructure CLAUDE.md to match the standard section order (Overview, Commands, Architecture, Conventions, Workflow quirks, Deployment, Gotchas); docs/, LESSONS.md and .env.example were already present and in sync. Co-Authored-By: Claude Sonnet 5 --- .claude/bootstrap-version | 1 + .claude/settings.json | 36 ++++++++++++++++++++++ .github/workflows/ci.yml | 27 +++++++++++++++++ .github/workflows/version.yml | 56 +++++++++++++++++++++++++++++++++++ CLAUDE.md | 20 ++++++++++++- 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 .claude/bootstrap-version create mode 100644 .claude/settings.json create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/version.yml 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/settings.json b/.claude/settings.json new file mode 100644 index 0000000..2063737 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,36 @@ +{ + "hooks": { + "PreToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "f=$(jq -r '.tool_input.file_path // empty'); case \"$f\" in *package-lock.json) echo 'package-lock.json is managed by npm; run npm install instead of editing it directly' >&2; exit 2 ;; esac" + } + ] + } + ], + "PostToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "f=$(jq -r '.tool_input.file_path // empty'); case \"$f\" in *.ts) cd \"$CLAUDE_PROJECT_DIR\" && npm run typecheck --silent >&2 || exit 2 ;; esac" + } + ] + } + ], + "Stop": [ + { + "hooks": [ + { + "type": "command", + "command": "cd \"$CLAUDE_PROJECT_DIR\" && { npm run typecheck --silent && npm test; } >&2 || exit 2" + } + ] + } + ] + } +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0a71088 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: CI + +on: + pull_request: + branches: [development] + push: + branches: [development, main] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: "20" + cache: npm + + - run: npm ci + + # No linter/formatter is configured: typecheck is the only static check. + - name: Typecheck + run: npm run typecheck + + - name: Test + run: npm test diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..61a9188 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,56 @@ +name: Version bump + +# MAJOR.MINOR.PATCH lives in package.json. +# push to development -> PATCH + 1 +# push to main merging development (PR) -> MINOR + 1, PATCH = 0 +# any other push to main (hotfix) -> PATCH + 1, then main is merged back into development + +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 + + - name: Bump version + id: bump + run: | + set -euo pipefail + branch="${GITHUB_REF_NAME}" + cur=$(node -p "require('./package.json').version") + IFS=. read -r major minor patch <<< "$cur" + kind=patch + if [ "$branch" = main ]; then + parents=$(git rev-list --parents -n1 HEAD | wc -w) + if [ "$parents" -eq 3 ] && git merge-base --is-ancestor HEAD^2 origin/development 2>/dev/null; then + kind=minor + fi + fi + if [ "$kind" = minor ]; then minor=$((minor + 1)); patch=0; else patch=$((patch + 1)); fi + new="$major.$minor.$patch" + npm pkg set version="$new" + echo "new=$new" >> "$GITHUB_OUTPUT" + + - name: Commit and push + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git commit -am "chore(release): v${{ steps.bump.outputs.new }} [skip ci]" + git push origin "HEAD:${GITHUB_REF_NAME}" + + - name: Merge main back into development + if: github.ref_name == 'main' + run: | + git fetch origin development + git checkout development + git merge --no-ff origin/main -m "chore: merge main into development [skip ci]" + git push origin development diff --git a/CLAUDE.md b/CLAUDE.md index 2170d00..5ca9e23 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,5 +1,7 @@ # CLAUDE.md +## Overview + MCP server (TypeScript, ESM, Express 5, `@modelcontextprotocol/sdk`) that generates images by driving chatgpt.com with Playwright. Mirrors the MCP contract of ZenvairoMediaGenerator-MCP (submit + poll, signed public URLs). ## Commands @@ -12,7 +14,9 @@ MCP server (TypeScript, ESM, Express 5, `@modelcontextprotocol/sdk`) that genera - `npm run selfheal` (`SELFHEAL_DRY_RUN=true`): codex repair of the scraper in a throwaway clone; live smoke test, auto-merge and deploy (docs/selfheal.md) - `npm run smoke`: generate one real image on chatgpt.com with the current code (uses quota; service stopped) -## Layout +## Architecture + +See [docs/architecture.md](docs/architecture.md) for the generation flow and lineage. Layout: - `src/index.ts`: HTTP app, auth, media routes, update routes - `src/tools.ts`: MCP tools @@ -29,3 +33,17 @@ MCP server (TypeScript, ESM, Express 5, `@modelcontextprotocol/sdk`) that genera - Never log prompts, reference images, tokens or profile contents. - Never commit `profiles/`, `diagnostics/`, `media/` or `.env`. - Read `LESSONS.md` before changing the browser automation. + +## Workflow quirks + +- No linter or formatter is configured; `npm run typecheck` is the only static check. The `.claude/settings.json` hooks run it on edited `.ts` files and, together with `npm test`, on Stop. +- Edit `.env.example` whenever the code gains or loses an environment variable. + +## Deployment + +Standalone on Debian/Ubuntu under systemd (no Docker), with an authenticated self-update endpoint. See [docs/deployment.md](docs/deployment.md) and [docs/update.md](docs/update.md). Unit and nginx files live in `deploy/`. + +## Gotchas + +- `scripts/update.sh` restarts the service via `sudo -n systemctl restart`; the systemd unit deliberately omits `NoNewPrivileges=true` to keep that working (see `deploy/sudoers.chatgpt-imagegen-mcp`). +- `npm run selfheal` needs a `codex` binary and pushes/merges/deploys on success when `SELFHEAL_AUTO_MERGE`/`SELFHEAL_AUTO_UPDATE` are enabled — never run it casually against `main`.