diff --git a/.env.example b/.env.example
index e99e05d..494b19a 100644
--- a/.env.example
+++ b/.env.example
@@ -1,22 +1,11 @@
-# Copy to .env. Add real values only to the ignored .env file.
+# Optional: local mode works without an env file or service accounts.
+COMIC_CODE_MODE=local
+NEXT_PUBLIC_APP_URL=http://127.0.0.1:3000
+WXT_PUBLIC_API_BASE_URL=http://127.0.0.1:3000
-NEXT_PUBLIC_APP_URL=http://localhost:3000
-WXT_PUBLIC_API_BASE_URL=http://localhost:3000
+# Optional server-side GitHub token for a higher public API request limit.
+# Never use a NEXT_PUBLIC_ or WXT_PUBLIC_ prefix for this token.
+GITHUB_TOKEN=
-TRIGGER_SECRET_KEY=
-TRIGGER_PROJECT_REF=
-
-GITHUB_APP_ID=
-GITHUB_CLIENT_ID=
-GITHUB_CLIENT_SECRET=
-GITHUB_PRIVATE_KEY_BASE64=
-GITHUB_WEBHOOK_SECRET=
-GITHUB_APP_SLUG=
-
-NEXT_PUBLIC_SUPABASE_URL=
-SUPABASE_SECRET_KEY=
-
-SHARE_TOKEN_PEPPER=
-SAFETY_IDENTIFIER_SECRET=
-SESSION_ENCRYPTION_SECRET=
-CRON_SECRET=
+# Optional absolute directory on a persistent local disk.
+# COMIC_CODE_DATA_DIR=/absolute/path/to/comic-data
diff --git a/.env.hosted.example b/.env.hosted.example
new file mode 100644
index 0000000..6626d40
--- /dev/null
+++ b/.env.hosted.example
@@ -0,0 +1,27 @@
+COMIC_CODE_MODE=hosted
+
+# Copy to .env. Add real values only to the ignored .env file.
+
+NEXT_PUBLIC_APP_URL=http://localhost:3000
+WXT_PUBLIC_API_BASE_URL=http://localhost:3000
+
+TRIGGER_SECRET_KEY=
+TRIGGER_PROJECT_REF=
+
+GITHUB_APP_ID=
+GITHUB_CLIENT_ID=
+GITHUB_CLIENT_SECRET=
+GITHUB_PRIVATE_KEY_BASE64=
+GITHUB_WEBHOOK_SECRET=
+# Hosted extension OAuth recipients. Comma-separated IDs from chrome://extensions.
+# Empty permits web login only. Local mode never needs OAuth or this setting.
+ALLOWED_EXTENSION_IDS=
+GITHUB_APP_SLUG=
+
+NEXT_PUBLIC_SUPABASE_URL=
+SUPABASE_SECRET_KEY=
+
+SHARE_TOKEN_PEPPER=
+SAFETY_IDENTIFIER_SECRET=
+SESSION_ENCRYPTION_SECRET=
+CRON_SECRET=
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
new file mode 100644
index 0000000..39e7833
--- /dev/null
+++ b/.github/workflows/ci.yaml
@@ -0,0 +1,42 @@
+name: CI
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened, ready_for_review]
+ push:
+ branches: [main]
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: ci-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ verify:
+ name: Tests, builds, and dependency audit
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+ env:
+ WXT_PUBLIC_API_BASE_URL: https://comic-code-ci.example
+ steps:
+ - name: Check out source
+ uses: actions/checkout@v4
+ - name: Set up Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: 24
+ - name: Set up pnpm
+ uses: pnpm/action-setup@v4
+ with:
+ version: 11.11.0
+ - name: Install locked dependencies
+ run: pnpm install --frozen-lockfile
+ - name: Run tests, lint, formatting, production builds and typechecks
+ run: pnpm check
+ - name: Package Chrome extension
+ run: pnpm extension:zip
+ - name: Audit runtime and development dependencies
+ run: pnpm audit
diff --git a/.gitignore b/.gitignore
index 58d1cd2..bcc67fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
# Local secrets
.env
.env.local
+.env.production
.env.*.local
*.pem
@@ -24,3 +25,9 @@ test-results/
.DS_Store
coverage/
.vercel
+
+# Single-user local comics (never commit generated content)
+.comic-code/
+# Built browser preview mirrors the extension output; regenerated by the build.
+apps/web/public/extension-preview/
+.impeccable/review/
diff --git a/.node-version b/.node-version
new file mode 100644
index 0000000..a45fd52
--- /dev/null
+++ b/.node-version
@@ -0,0 +1 @@
+24
diff --git a/.prettierignore b/.prettierignore
index 29dae7e..e52fe45 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -9,3 +9,5 @@ pnpm-lock.yaml
apps/web/next-env.d.ts
.env.example
supabase/migrations/*.sql
+
+apps/web/public/extension-preview
diff --git a/README.md b/README.md
index 4af484d..1d7f94c 100644
--- a/README.md
+++ b/README.md
@@ -1,207 +1,173 @@
# Comic Code
-Comic Code reads selected source files from a GitHub pull request and turns how the code works into a grounded four-panel comic. It includes a Chrome side-panel extension, a hosted Next.js demo, private Supabase storage, durable Trigger.dev jobs, and optional user-funded Cloudflare AI generation.
+Turn a public GitHub repository into a four- or twelve-panel comic with evidence links.
+The default local mode runs on your computer: no login, database account,
+background-worker account, AI key, or hosting subscription is required.
-Built for the OpenAI Build Week hackathon in the **Work & Productivity** category.
+## Start
-## What works
-
-- Public and private GitHub pull requests.
-- Native Chrome 114+ side panel with an injected **Explain PR** button.
-- GitHub App OAuth with state + PKCE and encrypted seven-hour sessions.
-- Read-only repository access; private repositories require a GitHub App installation.
-- Safe public-repository fallback without requiring an installation.
-- File selection with a maximum of 20 files and 3,000 changed lines.
-- Sensitive-file exclusion, secret masking, and high-entropy token detection.
-- Full selected-file reading at the PR head, with diff locations used only to prioritize bounded source sampling.
-- API-free structural scan that detects languages, control flow, validation, async work, data access, UI state, security checks, and tests.
-- Optional Cloudflare BYOK pipeline: Llama analyzes and verifies transient code context, then FLUX creates four distinct panels using the user's own Workers AI allocation; creator credits are never used as a hidden fallback.
-- Bundled visual-template fallback when artwork credentials or quota are unavailable.
-- Private PNG storage, short-lived downloads, seven-day revocable share links, and deletion.
-- Daily retention cleanup and a 25-generation-per-user safety limit.
-- Desktop, mobile, and narrow side-panel layouts using the supplied indigo visual direction.
-
-## Repository layout
-
-```text
-apps/web Next.js App Router site, API, OAuth, Trigger.dev task
-apps/extension WXT Manifest V3 Chrome extension
-packages/comic Analysis prompts, validation, artwork, PNG composition
-packages/contracts Shared Zod contracts
-packages/database Supabase repository and private storage operations
-packages/github GitHub App client, source filtering, masking, evidence mapping
-supabase CLI config and timestamped database migration
-```
-
-## Security model
-
-Raw source, reconstructed patches, and prompts containing source exist only in authenticated function or worker memory. They are never written to PostgreSQL, Storage, Trigger.dev payloads or outputs, audit metadata, analytics, or application logs.
-
-Cloudflare BYOK Account IDs and API tokens are accepted only by the authenticated code-analysis/artwork route over HTTPS. They remain in webpage tab memory or Chrome extension local storage, are never placed in Trigger.dev payloads, and are never persisted by Comic Code servers, databases, logs, or audit records. Masked selected code context is sent transiently to Cloudflare for Llama analysis and claim verification; FLUX then generates four images. The user's Cloudflare account pays for both text and image inference.
-
-The worker receives only an explanation UUID. It fetches selected files at the PR head, masks secrets, creates an API-free preview, and persists only sanitized claims, captions, evidence locators/hashes, and generated artwork. If a user supplies Cloudflare credentials, the authenticated web route refetches the same bounded source and sends it transiently to that user's Workers AI account.
-
-See [SECURITY.md](./SECURITY.md) and [PR_EXPLAINER_IMPLEMENTATION_PLAN.md](./PR_EXPLAINER_IMPLEMENTATION_PLAN.md) for the threat model and acceptance criteria.
-
-## Prerequisites
-
-- Node.js 20.12+
-- pnpm 11.11.0
-- Chrome 114+
-- Optional Cloudflare account for user-funded semantic analysis and FLUX artwork
-- GitHub App
-- Supabase project
-- Trigger.dev project
-- Vercel project for the hosted demo
-
-## Environment setup
-
-The repository-level `.env` is ignored by Git. Copy the example and add real values locally:
+Install Node.js 24+ and pnpm 11.11.0, then run from this repository:
```bash
-cp .env.example .env
+pnpm install --frozen-lockfile
+pnpm dev
```
-| Variable | Used by | Notes |
-| --------------------------- | --------------- | ------------------------------------------------------------------ |
-| `NEXT_PUBLIC_APP_URL` | Web | `http://localhost:3000` locally; production HTTPS origin on Vercel |
-| `WXT_PUBLIC_API_BASE_URL` | Extension build | Same origin as the hosted web app |
-| `TRIGGER_SECRET_KEY` | Web | Trigger.dev DEV key locally, production key on Vercel |
-| `TRIGGER_PROJECT_REF` | Trigger config | `proj_...` from the Trigger.dev dashboard |
-| `GITHUB_APP_ID` | Web + worker | Numeric GitHub App ID |
-| `GITHUB_CLIENT_ID` | Web | GitHub App OAuth client ID |
-| `GITHUB_CLIENT_SECRET` | Web | GitHub App OAuth client secret |
-| `GITHUB_PRIVATE_KEY_BASE64` | Web + worker | Entire GitHub App PEM encoded as one base64 line |
-| `GITHUB_WEBHOOK_SECRET` | Web | At least 32 random characters |
-| `GITHUB_APP_SLUG` | Web | Slug used by the install URL |
-| `NEXT_PUBLIC_SUPABASE_URL` | Web + worker | Project URL; no browser database access is used |
-| `SUPABASE_SECRET_KEY` | Web + worker | Server-side secret/service key only |
-| `SHARE_TOKEN_PEPPER` | Web | 32+ random bytes; changing it invalidates shares |
-| `SAFETY_IDENTIFIER_SECRET` | Web + worker | 32+ random bytes |
-| `SESSION_ENCRYPTION_SECRET` | Web | 32+ random bytes; changing it signs everyone out |
-| `CRON_SECRET` | Web | 32+ random bytes; Vercel sends it to cron routes |
-
-Generate independent local secrets with `openssl rand -hex 32`. Do not reuse one value for multiple variables. Encode the GitHub PEM without line breaks, for example:
+Open **http://127.0.0.1:3000**, paste a GitHub repository URL, inspect it, and
+choose **Generate fixed comic**. Download the PNG or reopen it from **Saved
+comics** after a restart. Leave the API key empty for the free flow.
+
+## Preview without using API quota
+
+Choose **Explore a sample** or **Try the sample** to inspect the bundled example
+story and evidence without contacting GitHub or image providers. The sample is labeled
+illustrative; it does not pretend to be a fresh scan. You can download its PNG. Twelve panels are selected by default; choose four
+for a quick overview. Existing saved comics keep their original length.
+
+To test image composition without an API key, open **Use your own images · no
+API key**, choose **Load sample artwork**, then **Compose 12-panel PNG**. You
+can also copy each panel prompt into an image tool manually and choose the
+resulting PNG/JPEG/WebP files. Files stay in browser memory; download the result
+before closing or changing the story. See [the manual artwork guide](docs/MANUAL_ARTWORK.md).
+
+Open **http://127.0.0.1:3000/extension** for the actual built side-panel interface
+in a browser. Explain, Story, Evidence and compact-layout controls work with sample
+data. Its browser-served preview blocks all `connect-src` requests with CSP. The
+installed Chrome extension also has an **Explore sample** control. Live OAuth,
+private repository access and provider quota behavior still need separate tests.
+`pnpm dev` and `pnpm build` generate the extension preview automatically.
+With the server running, `pnpm smoke:preview` checks preview assets, fonts,
+framing policy and the sample PNG without consuming provider quota.
+
+The free result uses bounded structural analysis and bundled artwork. It
+identifies patterns in sampled files; it does not provide AI semantic analysis
+or prove that the repository is correct. A scan selects up to 40 files and
+150,000 characters at the inspected commit. Branches containing slashes work.
+
+## What “free” means
+
+- Local generation, storage and PNG export make no paid API calls.
+- GitHub access still needs internet. Anonymous REST access has a limit of
+ [60 requests per hour per IP](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api).
+ A large scan can use most of that allowance. An optional server-side
+ `GITHUB_TOKEN` raises the limit; no token is needed to start.
+- Optional OpenAI or Google Gemini image generation uses **your own API key**.
+ Four or twelve panel images use your selected provider's quota and billing. Free API
+ access is not guaranteed. Captions and evidence come from the saved storyboard
+ and are not rewritten by the image provider. A failed request preserves the
+ existing comic. See [image BYOK setup](docs/IMAGE_BYOK.md).
+- Public hosting, private repository login and online share links need the
+ separate [hosted setup](docs/HOSTED_SETUP.md). Their free tiers are limited;
+ unlimited hosted AI generation is not promised.
+
+## Local data and limits
+
+Local mode accepts public repositories only, even if the optional token can read
+private code. It is a single-user desktop server bound to loopback by `pnpm dev`.
+Requests using public hostnames and cross-site mutations are rejected. Installed
+Chrome extensions may access it through their declared localhost host permission.
+Do not tunnel or reverse-proxy local mode to the internet or run several server
+processes against the same data directory.
+
+Completed analysis, evidence locators and PNG bytes are saved atomically under
+`apps/web/.comic-code/` when launched with the commands above. Raw source and
+Image API keys are not persisted. The directory is ignored by Git;
+new directories/files use owner-only permissions where the OS supports them.
+Records expire after 30 days and are removed on the next read/list. There is a
+100-record storage cap and a 25-generation daily safety limit over retained
+records. Download comics you want to keep. Delete removes the local record and
+its PNG; it cannot revoke a previously downloaded copy.
+
+To adjust local configuration, copy `.env.example` to `.env`. Set
+`COMIC_CODE_DATA_DIR` to an absolute directory for a persistent disk location.
+Keep secrets in the ignored `.env`; never put tokens in public-prefixed variables.
+Use `COMIC_CODE_MODE=hosted` for the authenticated service-backed runtime.
+
+## Chrome extension
+
+Keep the local server running, then build:
```bash
-base64 < path/to/github-app.private-key.pem | tr -d '\n'
+pnpm extension:build
+# Or create a distributable ZIP:
+pnpm extension:zip
```
-Only these variables belong in Trigger.dev: `GITHUB_APP_ID`, `GITHUB_PRIVATE_KEY_BASE64`, `NEXT_PUBLIC_SUPABASE_URL`, `SUPABASE_SECRET_KEY`, and `SAFETY_IDENTIFIER_SECRET`.
-
-## GitHub App configuration
-
-Create a GitHub App with:
-
-- Homepage URL: `NEXT_PUBLIC_APP_URL`
-- Callback URL: `NEXT_PUBLIC_APP_URL/api/v1/auth/github/callback`
-- Webhook URL: `NEXT_PUBLIC_APP_URL/api/v1/github/webhooks`
-- Webhook secret: `GITHUB_WEBHOOK_SECRET`
-- Repository permissions: **Contents: Read-only**, **Pull requests: Read-only**, **Metadata: Read-only**
-- No write permissions
-- User authorization enabled
-- Expiring user access tokens enabled
-
-Public PRs work without installing the app on that repository. Private PRs require the user to install the app on the selected repository and still revalidate the signed-in user’s access.
-
-## Supabase setup
-
-The migration was created with Supabase CLI 2.109.1 and enables RLS/forced RLS, explicit service-role grants, constraints, indexes, retention fields, and a private 10 MB PNG bucket.
-
-```bash
-pnpm dlx supabase@2.109.1 login
-pnpm dlx supabase@2.109.1 link --project-ref YOUR_PROJECT_REF
-pnpm dlx supabase@2.109.1 db push
-```
-
-Do not paste the migration into the SQL editor manually. The application intentionally exposes no anon/authenticated table policies; all database access goes through authenticated server routes.
-
-## Trigger.dev setup
-
-From `apps/web`:
+Load `apps/extension/.output/chrome-mv3` at `chrome://extensions` using
+**Developer mode → Load unpacked**. Open a GitHub repository and select its
+**Explain repository** button. The side panel detects the local server and
+needs no OAuth login. Local mode supports generation and PNG download; online
+sharing requires hosted mode. Image API keys stay in side-panel memory and are cleared when the panel
+closes or you select **Clear API key**. Old saved Cloudflare credentials are
+removed automatically when the updated extension initializes.
+
+For a hosted extension, set `WXT_PUBLIC_API_BASE_URL` to the final HTTPS origin
+before building. The manifest grants access to that exact API origin. For hosted OAuth, also add
+the extension ID from `chrome://extensions` to the server’s comma-separated
+`ALLOWED_EXTENSION_IDS`. An empty list allows web login only.
+
+## Where to enter your API key (BYOK)
+
+- **Web:** select **API key / BYOK** in the top navigation.
+- **Extension:** expand **API key / BYOK** below the header, from any tab.
+- Choose **OpenAI** or **Google Gemini**, choose an image model available to your
+ account, and enter that provider's API key. Keys from other providers are not
+ interchangeable. Switching providers clears the entered key.
+- Generate a comic or select **Generate 4 AI panels** or **Generate 12 AI panels** on a saved comic. One
+ provider request per panel creates an illustration; captions and evidence stay intact.
+- Keys remain in current tab/panel memory. **Clear API key** removes the value.
+ There is no API call just for entering a key or changing a provider.
+- Sample mode lets you inspect providers/models with key entry disabled. No
+ provider calls or credential storage occur in samples.
+
+Free bundled artwork works without a key. Image-provider keys do not raise
+GitHub's independent request limit; configure an optional server-side
+`GITHUB_TOKEN` separately in `.env`. Read the [setup and privacy details](docs/IMAGE_BYOK.md).
+
+## Project structure
-```bash
-pnpm exec trigger.dev login
-pnpm exec trigger.dev dev
+```text
+apps/web/ Next.js UI, APIs, local runtime, optional hosted worker
+apps/extension/ Chrome Manifest V3 side panel and GitHub page integration
+packages/comic/ Grounded analysis, optional providers and PNG composition
+packages/contracts/ Shared request and response validation
+packages/ui/ Browser-only manual artwork studio and PNG export
+packages/github/ GitHub access, file selection, source masking and evidence
+packages/database/ Optional Supabase repository and private artifact storage
+supabase/ Hosted database migrations
+scripts/ Repeatable local extension packaging
+docs/ Setup, deployment and debugging evidence
+docs/archive/ Historical implementation and hackathon documents
```
-After the task appears in the dashboard, sync only the worker variables listed above. Deploy the task with:
+## Check and build
```bash
-pnpm exec trigger.dev deploy
+pnpm check
+pnpm audit
+# With the local server running, check the real public GitHub flow:
+pnpm smoke:local
```
-The task payload is `{ explanationId }`; it never includes source, patches, prompts, GitHub tokens, or captions.
-
-## Local development
-
-Install dependencies and run the web app:
+`pnpm check` runs tests, lint, formatting, web/extension production builds and
+TypeScript checks. The web production build uses webpack for compatibility with
+restricted build environments. To run the built web app locally:
```bash
-pnpm install
-pnpm --filter @comic-code/web dev
+pnpm --filter @comic-code/web start --hostname 127.0.0.1
```
-In another terminal, run Trigger.dev as described above. For extension hot reload:
-
-```bash
-pnpm --filter @comic-code/extension dev
-```
-
-Load the generated extension directory from `chrome://extensions` → **Developer mode** → **Load unpacked**.
-
-Chrome controls whether side panels appear on the left or right. Comic Code reads the selected side and adapts its border treatment; users move it under Chrome **Settings → Appearance → Side panel**.
-
-### User-funded artwork
-
-Before generating, choose the image mode. Leave both fields empty for the fixed API-free comic, or provide:
-
-- Cloudflare Account ID.
-- API token with Workers AI Read and Workers AI Edit permissions.
-
-Web credentials live only in current tab memory. Extension credentials use `chrome.storage.local` until the user selects **Remove saved credentials** or uninstalls the extension. With a valid key, generation automatically creates the fixed preview first, then refetches and masks bounded source from the selected files, asks Cloudflare Llama for a grounded story plus independent claim verification, generates four distinct FLUX panels with separate prompts and seeds, composes a new PNG, then atomically replaces the preview. Failures leave the fixed comic unchanged.
-
-## Verification
-
-```bash
-pnpm typecheck
-pnpm lint
-pnpm test
-pnpm audit --prod
-pnpm --filter @comic-code/web build
-pnpm --filter @comic-code/extension build
-pnpm --filter @comic-code/extension zip
-```
-
-Current local verification:
-
-- Production dependency audit: no known vulnerabilities.
-- 23 unit/security/composition tests passing.
-- TypeScript passing across all workspaces.
-- ESLint passing with zero warnings.
-- Next.js production build passing for every page and API route.
-- WXT Chrome MV3 build and ZIP passing.
-- Browser checks passing at 1280 px and 390 px with no runtime errors or horizontal overflow.
-
-Live integration tests require real service credentials and a test PR; they cannot be meaningfully mocked as proof of deployment readiness.
-
-## Deployment
-
-See [docs/DEPLOYMENT_CHECKLIST.md](./docs/DEPLOYMENT_CHECKLIST.md) for the exact order. In short:
-
-1. Push the Supabase migration.
-2. Deploy the Trigger.dev task and worker environment.
-3. Deploy `apps/web` on Vercel with the server environment.
-4. Update the GitHub App URLs to the production origin.
-5. Set `WXT_PUBLIC_API_BASE_URL` to the production origin and rebuild the extension.
-6. If using a custom domain instead of `*.vercel.app`, add its exact origin to `host_permissions` before the final extension build.
-
-Release artifacts are generated at:
-
-- Unpacked extension: `apps/extension/.output/chrome-mv3`
-- Chrome ZIP: `apps/extension/.output/comic-codeextension-0.1.0-chrome.zip`
+GitHub Actions uses [`.github/workflows/ci.yaml`](.github/workflows/ci.yaml).
+It checks PRs when opened, updated, reopened or marked ready for review, as well
+as pushes to `main`. A manual trigger is available once the workflow is on the
+default branch. Draft PRs run checks too. The job runs `pnpm check`, extension
+packaging and the dependency audit for runtime and development tools; it needs no AI keys or hosted
+service credentials. CI reports results on the PR and does not merge it.
+See [the current functional audit](docs/FUNCTIONAL_AUDIT.md) for reproduced
+failures, fixes, cleanup decisions and current verification.
-## License
+See [the debugging report](docs/DEBUGGING_REPORT.md) for reproduced defects,
+fixes, test results and the limits of hosted verification.
-[MIT](./LICENSE)
+[Security model](SECURITY.md) · [Hosted deployment](docs/DEPLOYMENT_CHECKLIST.md) · [MIT license](LICENSE)
diff --git a/SECURITY.md b/SECURITY.md
index 4d37975..0adfb2f 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -1,8 +1,30 @@
-# Security policy
+# Security
+
+## Local runtime
+
+The default runtime is a single-user desktop service. It accepts public GitHub
+repositories only, with no OAuth session or remote database. Its proxy and API
+handler reject non-loopback hosts and origins. Mutations require a same-port
+loopback origin or a Chrome extension origin; bearer strings do not bypass this
+check. This trusts locally installed browser extensions and local processes.
+It is not an authentication boundary against another user on the same computer.
+Use `pnpm dev` or `next start --hostname 127.0.0.1`; do not expose it through a
+tunnel or reverse proxy. Vercel defaults to hosted mode and requires the hosted
+credentials. The `/api/local` handler returns 404 in hosted mode.
+
+Local persistence contains sanitized analysis, evidence locators and PNG bytes,
+never source or provider credentials. Writes replace complete records atomically
+using owner-only file permissions. One server process per data directory is
+supported, with one mutation at a time. Expired records are removed lazily on
+read/list, including their PNG bytes. Local deletion removes the complete file.
+Downloaded copies cannot be revoked. Online capability sharing is unavailable
+in local mode. See the README for storage and generation limits.
+
+## Hosted runtime
## Scope
-Comic Code handles private source code and treats pull-request titles, descriptions, paths, patches, and generated model output as untrusted.
+Comic Code handles private source code and treats repository names, descriptions, README content, manifests, paths, source, and generated model output as untrusted.
## Implemented controls
@@ -10,7 +32,7 @@ Comic Code handles private source code and treats pull-request titles, descripti
- Authenticated/encrypted seven-hour session JWE; browser cookies are HttpOnly, SameSite Lax, and Secure in production.
- Bearer sessions returned to the extension only in the `chromiumapp.org` URL fragment.
- Read-only GitHub permissions and separate user-access plus installation-access checks for private repositories.
-- Server verification of repository, PR number, selected paths, and captured head SHA.
+- Server verification of repository access, requested ref, and captured immutable commit SHA.
- Exclusion of `.env`, credentials, lockfiles, binary, generated, vendored, minified, and oversized reconstructed files.
- Secret/token/email/connection-string masking plus high-entropy masking.
- Prompt-injection boundaries, strict Zod structured output, no model tools, and opaque safety identifiers.
@@ -20,27 +42,32 @@ Comic Code handles private source code and treats pull-request titles, descripti
- Forced RLS and no anon/authenticated table grants.
- Tombstone-first deletion, worker tombstone checks, artifact cleanup, Trigger.dev cancellation, and daily retention.
- CSP, frame denial, HSTS, no-sniff, restrictive permissions policy, CSRF origin checks, webhook HMAC verification, quotas, and bounded request bodies.
-- Cloudflare BYOK credentials accepted only on authenticated, same-origin analysis/artwork requests; strict Account ID/token bounds; provider errors reduced to safe codes; credentials excluded from persistence, Trigger.dev, analytics, and audit metadata.
-- BYOK source context is secret-masked, bounded, and sent to Cloudflare only after an explicit user action; model output passes strict schema, grounding, leak, and safety validation.
+- Image BYOK requests require the existing local-origin or hosted authentication/ownership/repository-access checks. Provider/model/key combinations are validated strictly; only fixed official OpenAI and Gemini endpoints are used, with redirects disabled. Keys are excluded from persistence, Trigger.dev, analytics and audit metadata.
+- Image BYOK sends only sanitized illustration prompts from the saved storyboard, after an explicit generation action. No raw source or evidence bodies are sent. JSON responses, base64 data, raster signatures and decoded pixels are bounded; remote image URLs are never followed. Provider response/error bodies are never logged or returned to clients.
- BYOK artwork uploaded under a new random object path and swapped only after successful composition; failed regeneration preserves prior comic.
## Data that is persisted
-Repository/PR coordinates, captured SHAs, selected/excluded file paths, evidence line locators and hashes, sanitized claims/storyboard text, generated PNG paths, usage counts, progress, and low-cardinality audit metadata.
+Repository coordinates, captured ref and commit SHA, scan summary, selected/excluded file paths, evidence line locators and hashes, sanitized claims/storyboard text, generated PNG paths, usage counts, progress, and low-cardinality audit metadata.
Raw patches, source blobs, prompt bodies containing source, GitHub access tokens, OAuth codes, share tokens, and provider request bodies are not persisted.
-Cloudflare Account IDs and API tokens are not persisted by Comic Code. Web values remain in tab memory. Extension values remain in `chrome.storage.local` on the user's device until removed. API tokens and masked selected code context cross the Comic Code server transiently over HTTPS for Cloudflare Llama and FLUX calls. Tokens must be dedicated and scoped only to Workers AI.
+OpenAI and Gemini image keys remain in webpage tab or extension panel memory;
+they are not saved in Chrome storage. They cross the Comic Code server
+transiently and authenticate only with the selected provider. Hosted traffic
+uses HTTPS; local traffic stays on loopback. The extension removes obsolete
+saved Cloudflare credentials during initialization. Gemini Interactions calls
+set `store: false`; provider-specific data policies still apply.
## Residual considerations
-- Cloudflare receives the masked source context in BYOK mode under the user's Cloudflare account and applicable Cloudflare data-usage terms; Comic Code does not present that path as Zero Data Retention.
+- The selected image provider receives illustration prompts under the user's account and applicable provider data policies. Image generation does not verify the storyboard's claims or guarantee text-free artwork.
- A revoked share may retain an already minted signed asset URL for at most five minutes.
- The encrypted extension session is still a bearer capability and expires after seven hours. Chrome extension storage must be treated as sensitive.
- Public-repository fallback uses unauthenticated GitHub API capacity and may be rate limited.
- Chrome, not the extension, controls left/right side-panel placement.
-- A local extension credential can be read by Comic Code extension code and anyone controlling that Chrome profile. Users should create a dedicated least-privilege Workers AI token and revoke it if the device or extension becomes untrusted.
-- A complete live review must test the deployed GitHub, Supabase, Trigger.dev, Cloudflare BYOK, and Vercel configuration with real credentials.
+- Keys in tab/panel memory can be read by someone controlling that page or device. Use a dedicated provider key with suitable account limits and revoke it if compromised.
+- A complete live review must test the deployed GitHub, Supabase, Trigger.dev, OpenAI/Gemini BYOK, and Vercel configuration with real credentials.
## Dependency status
@@ -49,3 +76,12 @@ On 2026-07-20, `pnpm audit --prod` reported no known vulnerabilities after scope
## Reporting
Do not include private source, secrets, tokens, or full request logs in a report. Revoke affected credentials first, then provide a minimal reproduction through the repository’s private security-reporting channel.
+
+## Manual artwork
+
+The shared browser artwork studio accepts PNG/JPEG/WebP files up to 8 MB each,
+checks decoded images against a 40-megapixel limit, and composes four or twelve
+panels on a local Canvas. It makes no upload or AI-provider requests. Object URLs
+are revoked when artwork changes or the component closes. Manual artwork is not
+added to persisted comics or shared artifacts. The extension browser preview
+permits blob images while keeping API connections blocked.
diff --git a/apps/extension/entrypoints/background.ts b/apps/extension/entrypoints/background.ts
index 6b1667d..5c3c0b9 100644
--- a/apps/extension/entrypoints/background.ts
+++ b/apps/extension/entrypoints/background.ts
@@ -8,11 +8,6 @@ export default defineBackground(() => {
comicCodeCoordinate: message.coordinate,
})
- void chrome.sidePanel.setOptions({
- tabId: sender.tab.id,
- path: 'sidepanel.html',
- enabled: true,
- })
void chrome.sidePanel.open({ tabId: sender.tab.id })
})
diff --git a/apps/extension/entrypoints/github.content.ts b/apps/extension/entrypoints/github.content.ts
index f53aa5c..fcbf7c2 100644
--- a/apps/extension/entrypoints/github.content.ts
+++ b/apps/extension/entrypoints/github.content.ts
@@ -1,19 +1,7 @@
-const pullRequestPath = /^\/([^/]+)\/([^/]+)\/pull\/(\d+)(?:\/|$)/
+import { parseGitHubRepositoryUrl } from '@comic-code/contracts/repository-url'
function readCoordinate() {
- const match = window.location.pathname.match(pullRequestPath)
- if (!match) return null
-
- const pullRequestNumber = Number(match[3])
- if (!Number.isSafeInteger(pullRequestNumber) || pullRequestNumber < 1) {
- return null
- }
-
- return {
- owner: match[1]!,
- repository: match[2]!,
- pullRequestNumber,
- }
+ return parseGitHubRepositoryUrl(window.location.href)
}
function mountExplainButton() {
@@ -26,14 +14,13 @@ function mountExplainButton() {
existing?.remove()
return
}
-
if (existing) return
const button = document.createElement('button')
button.type = 'button'
button.dataset.comicCodeTrigger = 'true'
button.className = 'Button--primary Button--medium Button'
- button.textContent = 'Explain PR'
+ button.textContent = 'Explain Repository'
button.addEventListener('click', () => {
void chrome.runtime.sendMessage({
type: 'comic-code:open-sidepanel',
@@ -42,10 +29,9 @@ function mountExplainButton() {
})
const target =
- document.querySelector('.gh-header-actions') ??
- document.querySelector('[data-testid="pull-request-header"]') ??
+ document.querySelector('[data-testid="repository-overview"]') ??
+ document.querySelector('.file-navigation') ??
document.querySelector('main')
-
target?.prepend(button)
}
@@ -54,15 +40,22 @@ export default defineContentScript({
runAt: 'document_idle',
main() {
let currentHref = window.location.href
- mountExplainButton()
-
- const observer = new MutationObserver(() => {
+ let scheduled = false
+ const refresh = () => {
+ scheduled = false
if (window.location.href !== currentHref) {
currentHref = window.location.href
+ document.querySelector('[data-comic-code-trigger]')?.remove()
}
mountExplainButton()
+ }
+ const observer = new MutationObserver(() => {
+ if (scheduled) return
+ scheduled = true
+ window.requestAnimationFrame(refresh)
})
+ refresh()
observer.observe(document.documentElement, {
childList: true,
subtree: true,
diff --git a/apps/extension/entrypoints/sidepanel/bootstrap.tsx b/apps/extension/entrypoints/sidepanel/bootstrap.tsx
new file mode 100644
index 0000000..99d44c6
--- /dev/null
+++ b/apps/extension/entrypoints/sidepanel/bootstrap.tsx
@@ -0,0 +1,15 @@
+import React from 'react'
+import { createRoot } from 'react-dom/client'
+import { SidePanelShell } from './main'
+
+const root = document.getElementById('root')
+
+if (!root) {
+ throw new Error('Missing Comic Code side-panel root')
+}
+
+createRoot(root).render(
+