Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 15 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,29 @@ jobs:
name: Test and validate Workers
runs-on: ubuntu-latest
timeout-minutes: 10
services:
postgres:
image: postgres:17
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s
--health-timeout 5s
--health-retries 10
env:
AUTH_TEST_DATABASE_URL: postgresql://postgres@localhost:5432/postgres
AUTH_TEST_DATABASE_URL: postgresql://postgres:local-ci-only@localhost:5432/postgres
steps:
# ubuntu-latest includes PostgreSQL; no rate-limited container pull is needed.
- name: Start disposable runner PostgreSQL
run: |
sudo systemctl start postgresql
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'local-ci-only'"
pg_isready -h localhost -p 5432
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: actions/setup-node@v5
with:
node-version: 24
cache: npm
- run: npm ci
- name: Verify generated API contract
run: |
npm run generate:openapi
git diff --exit-code -- packages/docs/openapi.yaml
- run: npm run build:css
npm run generate
git diff --exit-code -- packages/docs/openapi.yaml packages/api-client/src/schema.d.ts
- name: Install browser for static application checks
run: npx playwright install --with-deps chromium
- run: npm run check
- name: Exercise compiled jobs/invocation/run slice against PostgreSQL
run: npm run test:static-slice --workspace=factorize
49 changes: 43 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

permissions:
contents: read
actions: read

concurrency:
group: production
Expand All @@ -21,31 +22,67 @@ jobs:
environment: production
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: actions/setup-node@v5
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run build:css
- name: Require the additive API stage before static cutover
run: node scripts/verify-public-routing.mjs https://app.factorize.sh --api-ready
- run: npm run build:app
- name: Retain legacy open-tab stylesheet during migration
run: git show 2d63d6480c398d29513329d7a604a4585d21de24:packages/api/public/styles.css > packages/app/dist/styles.css
- name: Snapshot this release before restoring older chunks
run: cp -R packages/app/dist "$RUNNER_TEMP/factorize-app-release"
- name: Restore assets from trusted production deployments in the last 30 days
uses: actions/github-script@v8
with:
script: |
const fs = require('node:fs');
const { execFileSync } = require('node:child_process');
const { isTrustedAppRelease } = await import(`${process.env.GITHUB_WORKSPACE}/scripts/trusted-app-release.mjs`);
const artifacts = await github.paginate(github.rest.actions.listArtifactsForRepo, { ...context.repo, per_page: 100 });
for (const artifact of artifacts) {
if (artifact.name !== 'factorize-app-assets' || artifact.expired || !artifact.workflow_run) continue;
const { data: run } = await github.rest.actions.getWorkflowRun({ ...context.repo, run_id: artifact.workflow_run.id });
const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, { ...context.repo, run_id: run.id, per_page: 100 });
if (!isTrustedAppRelease(artifact, run, jobs, `${context.repo.owner}/${context.repo.repo}`)) continue;
const { data } = await github.rest.actions.downloadArtifact({ ...context.repo, artifact_id: artifact.id, archive_format: 'zip' });
const archive = `${process.env.RUNNER_TEMP}/factorize-assets-${artifact.id}.zip`;
fs.writeFileSync(archive, Buffer.from(data));
execFileSync('python3', ['scripts/retain-app-assets.py', archive, 'packages/app/dist'], { stdio: 'inherit' });
fs.unlinkSync(archive);
}
- name: Apply database migrations
run: npm run db:migrate --workspace=factorize
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: Configure authentication email Worker secret
working-directory: packages/app
working-directory: packages/api
run: |
node -e 'process.stdout.write(JSON.stringify({ POSTMARK_SERVER_TOKEN: process.env.POSTMARK_SERVER_TOKEN }))' | npx wrangler secret bulk
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
POSTMARK_SERVER_TOKEN: ${{ secrets.POSTMARK_SERVER_TOKEN }}
- name: Deploy app Worker
run: npm run deploy:app
- name: Deploy marketing site
run: npm run deploy:marketing
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Deploy marketing site
run: npm run deploy:marketing
- name: Deploy app Worker
run: npm run deploy:prepared --workspace=factorize
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Retain deployed assets for subsequent releases and rollback
uses: actions/upload-artifact@v4
with:
name: factorize-app-assets
path: ${{ runner.temp }}/factorize-app-release
retention-days: 35
if-no-files-found: error
- name: Verify public production routing after deployment
run: node scripts/verify-public-routing.mjs https://app.factorize.sh --wait
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ coverage/
.idea/
.vscode/
*.swp

# Local TLS and Python test caches
.dev-certs/
__pycache__/
12 changes: 11 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ This project in Linear is "Factorize"

- Every JSON application endpoint must live under `/api/v1` and be documented in `packages/docs/openapi.yaml`.
- Frontend code must call the same `/api/v1` endpoints as external clients. Never add a frontend-only `/api/*` route.
- Register API operations only in `packages/app/src/protected-api.ts`; page, auth callback, webhook, health, and internal routes belong in their existing non-API namespaces.
- Register API operations only in `packages/api/src/protected-api.ts`; page, auth callback, webhook, health, and internal routes belong in their existing non-API namespaces.
- A new API operation must include authorization, validation, OpenAPI documentation, and contract or boundary tests in the same change.
- `/auth`, `/oauth`, `/webhooks`, `/internal`, `/mcp`, and `/healthz` are explicit non-API namespaces and must not be used to hide frontend application endpoints.

## Package boundaries

- `packages/api` owns the Worker. Its npm name remains `factorize` during the staged migration; this does not change production infrastructure identity.
- `packages/app` is the static frontend (`factorize-app`). It may only import the generated public contract through `factorize-api-client`; never import backend implementations.
- `packages/api-client` is generated from the published OpenAPI document. It must have no backend or frontend implementation dependencies. Run `npm run generate` after contract changes.
- Run `npm run check:boundaries` to validate imports, including dynamic imports and type imports. Do not add aliases or build configuration that bypasses these boundaries.
- Application HTML belongs to the static frontend. Backend protocol/form compatibility handlers may redirect or return JSON/text but must not generate UI HTML.
- Keep full-list/detail/trace and conditional-write omission compatibility for external REST/MCP clients.
- Deploy the documented additive API anchor before static cutover; preserve Worker identity/bindings/migrations and retain old hashed assets. Follow the release and rollback gates in `docs/package-migration.md`.
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Factorize

[![CI](https://github.com/GenerationSoftware/factorize/actions/workflows/ci.yml/badge.svg)](https://github.com/GenerationSoftware/factorize/actions/workflows/ci.yml)
[![Deploy to Cloudflare](https://img.shields.io/badge/Deploy_to-Cloudflare-F38020?style=flat&logo=cloudflare&logoColor=white)](https://deploy.workers.cloudflare.com/?url=https://github.com/GenerationSoftware/factorize&path=packages/app)
[![Deploy to Cloudflare](https://img.shields.io/badge/Deploy_to-Cloudflare-F38020?style=flat&logo=cloudflare&logoColor=white)](https://deploy.workers.cloudflare.com/?url=https://github.com/GenerationSoftware/factorize&path=packages/api)

**A no-code software factory for Linear teams.** Factorize turns selected Linear issue changes into coding-agent jobs on isolated, ephemeral exe.dev VMs.

Expand All @@ -21,21 +21,21 @@ Linear webhook → Cloudflare Worker → Durable Object → exe.dev /exec → is

## Deploy to Cloudflare

Click the **Deploy to Cloudflare** button above to create a copy of the app Worker in your own Cloudflare account. The button selects `packages/app` as the Worker root; Cloudflare provisions the Durable Object binding and configures Workers Builds for the copied repository.
Click the **Deploy to Cloudflare** button above to create a copy of the app Worker in your own Cloudflare account. The button selects `packages/api` as the Worker root; Cloudflare provisions the bindings for the copied repository. Configure Workers Builds to run `npm run build --workspace=factorize-app` before deploying; static output lives beside the backend package. Follow the API-first bootstrap in the rollout guide.

> The Deploy to Cloudflare button works for public GitHub or GitLab repositories. If you are using a private fork, deploy with Wrangler instead.

### Deploy with Wrangler

1. Clone the repository and install dependencies.
2. Set `APP_ORIGIN` in `packages/app/wrangler.jsonc` to your final HTTPS Worker URL or custom domain.
3. Create a dedicated OAuth KV namespace with `npm exec --workspace=factorize -- wrangler kv namespace create OAUTH_KV`, then set its ID in `packages/app/wrangler.jsonc`.
2. Set `APP_ORIGIN` in `packages/api/wrangler.jsonc` to your final HTTPS Worker URL or custom domain.
3. Create a dedicated OAuth KV namespace with `npm exec --workspace=factorize -- wrangler kv namespace create OAUTH_KV`, then set its ID in `packages/api/wrangler.jsonc`.
4. Configure the Linear OAuth callback as `https://your-domain.example/auth/linear/callback`.
5. Build assets, add secrets, and deploy:
5. Bootstrap the additive API stage and verify its marker as described in [the rollout guide](docs/package-migration.md), then build assets, add secrets, and deploy:

```bash
npm ci
npm run build:css
npm run build:app

npm exec --workspace=factorize -- wrangler secret put LINEAR_CLIENT_ID
npm exec --workspace=factorize -- wrangler secret put LINEAR_CLIENT_SECRET
Expand All @@ -62,7 +62,7 @@ For a headless machine, authenticate first with `npx wrangler login --device --b

```bash
npm install
cp packages/app/.dev.vars.example packages/app/.dev.vars
cp packages/api/.dev.vars.example packages/api/.dev.vars
npm run dev
```

Expand All @@ -84,7 +84,7 @@ Factorize owns authentication in PostgreSQL. Create a native account at `/auth/s

Postmark sends one-hour, single-use verification and password-reset links. `/auth/verify/request` resends verification; `/auth/password-reset` handles recovery. Links never appear in application responses or logs. Passwords use salted PBKDF2-SHA-256. **Change password** in the account menu requires the current password. Password reset, password change and sign-out invalidate existing sessions via membership session versions, including delegated API credentials.

Before deploying, configure `POSTMARK_SERVER_TOKEN` as a **production GitHub environment secret**. The deployment copies it to a Worker secret; the verified sender and transactional message stream are non-secret Worker vars in `packages/app/wrangler.jsonc`. For a manual Postmark preflight, set the following environment variables along with `APP_ORIGIN`:
Before deploying, configure `POSTMARK_SERVER_TOKEN` as a **production GitHub environment secret**. The deployment copies it to a Worker secret; the verified sender and transactional message stream are non-secret Worker vars in `packages/api/wrangler.jsonc`. For a manual Postmark preflight, set the following environment variables along with `APP_ORIGIN`:

| Setting | Required value |
| --- | --- |
Expand Down Expand Up @@ -142,7 +142,7 @@ Cloudflare Worker failures can also start Jobs through the separately deployable
| `CLICKUP_CLIENT_SECRET` | ClickUp OAuth client secret; ClickUp also uses a per-installation webhook secret stored encrypted by Factorize |
| `CREDENTIAL_ENCRYPTION_KEY` | Base64-encoded 32-byte key for encrypted credentials |
| `SESSION_SIGNING_SECRET` | Independent secret for signed browser sessions |
| `APP_ORIGIN` | Public Worker origin, configured in `packages/app/wrangler.jsonc` |
| `APP_ORIGIN` | Public Worker origin, configured in `packages/api/wrangler.jsonc` |
| `OAUTH_KV` | KV binding containing OAuth clients, grants, refresh tokens, and revocation state |

Never commit `.dev.vars` or production secret values. The included `.dev.vars.example` is a safe template.
Expand All @@ -151,11 +151,11 @@ Never commit `.dev.vars` or production secret values. The included `.dev.vars.ex

| Command | What it does |
| --- | --- |
| `npm run dev` | Build CSS and start local Wrangler development |
| `npm run build:css` | Compile Tailwind into `packages/app/public/styles.css` |
| `npm run dev` | Build the static frontend and start HTTPS Vite + local API development |
| `npm run build:app` | Build static React/Tailwind assets in `packages/app/dist` |
| `npm test` | Run the unit test suite |
| `npm run check` | Type-check/test the app and dry-run both Worker deployments |
| `npm run deploy:app` | Deploy only the `factorize` app Worker |
| `npm run check` | Check package boundaries/contracts, React/API tests, local routing and Worker dry runs |
| `npm run deploy:app` | Verify the API stage, build static assets and deploy the existing `factorize` Worker |
| `npm run deploy:tail-relay` | Deploy only the `factorize-tail-relay` Worker |
| `npm run deploy` | Deploy the app, then the Tail relay; stop on the first failure |

Expand Down Expand Up @@ -224,3 +224,20 @@ Factorize also supports the OAuth 2.0 Device Authorization Grant (RFC 8628) for

[Apache License 2.0](LICENSE)
Test line for the Factorize PR-check and merge-queue flow.

### Static application migration

The Worker lives in `packages/api`, the static React frontend in `packages/app`, and the OpenAPI-generated public client in `packages/api-client`. The frontend consumes only documented `/api/v1` operations. Same-origin routing preserves the existing Worker and state identities. See [the required API-first rollout and rollback procedure](docs/package-migration.md).

| Command | Purpose |
| --- | --- |
| `npm run dev:api` | Run the local HTTPS API Worker |
| `npm run dev:app` | Run the static frontend development server |
| `npm run generate` | Generate OpenAPI and browser client types |
| `npm run build:app` | Build static frontend assets |
| `npm run check:boundaries` | Reject frontend/backend implementation imports |
| `npm run check` | Validate packages, generated client, tests and builds |

Use Node 24. Keep local secrets in `packages/api/.dev.vars`; the static frontend does not expose environment variables.

The static app includes native auth, consent/device, jobs/editor/provider, run/history/trace, integration and credential-management screens. Install Chromium with `npx playwright install --with-deps chromium` before checking. Local development uses HTTPS at `https://localhost:5173`; `npm run dev` creates an ignored local Vite certificate. See [the migration guide](docs/package-migration.md) for local database setup, production gates, asset retention and rollback. No production deployment is implied by this source migration.
4 changes: 2 additions & 2 deletions docs/execution-trace-stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Normalized execution streams contain UTF-8, newline-terminated JSON objects in a

Required fields: `version` (1), `id`, `type`, `title`, `preview`. Optional fields:
`parentId`, `role`, `occurredAt` (ISO timestamp), `display` (object). Event types
match `TraceEventType` in `packages/app/src/trace.ts`. Sequence is assigned by the
match `TraceEventType` in `packages/api/src/trace.ts`. Sequence is assigned by the
projection, never trusted from the producer. Producers must append whole records
and finish each with LF. They must write human stdout/stderr to their separate
supervisor logs, never to the stream. The supervisor creates the stream directory
Expand Down Expand Up @@ -96,7 +96,7 @@ persisted source declaration continue to use native discovery. Native fallback
parsing retains tool IDs, result names and error flags, including across artifact
read chunks.

`packages/app/test/fixtures/claude-2.1.293/` contains synthetic, version-pinned
`packages/api/test/fixtures/claude-2.1.293/` contains synthetic, version-pinned
schema fixtures for Claude Code 2.1.293 (the installed CLI version used during
implementation). They model default root/subagent-tool behavior, not forwarded
child text. Boundary tests execute the exact guest supervisor with a fake CLI,
Expand Down
2 changes: 1 addition & 1 deletion docs/marketing-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Factorize is deployed as a Cloudflare Pages site and an app Worker:

- `packages/marketing` owns the public landing page at `https://factorize.sh`. It is a static Cloudflare Pages project named `factorize-marketing`; its production branch is `main` and its output directory is `packages/marketing/public`. It contains no authenticated APIs or tenant data. Login and Create a Job links cross to `https://app.factorize.sh`.
- `packages/app` owns the authenticated dashboard, OAuth callbacks, API/MCP endpoints, provider webhooks, and job deep links at `https://app.factorize.sh`. Its `/` route is the signed-out login entry point and redirects signed-in users to `/jobs`.
- `packages/api` owns the authenticated dashboard, OAuth callbacks, API/MCP endpoints, provider webhooks, and job deep links at `https://app.factorize.sh`. Its `/` route is the signed-out login entry point and redirects signed-in users to `/jobs`.

The Pages project is connected to `GenerationSoftware/factorize` for pull request previews, but Cloudflare's automatic production deployments are disabled. Production deploys from `main` run through `.github/workflows/deploy.yml`, where failures are visible in GitHub Actions. For a manual deployment, authenticate Wrangler and run `npm run deploy:marketing`; this uploads `packages/marketing/public` to the `factorize-marketing` project.

Expand Down
Loading
Loading