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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
run: |
npm run generate
git diff --exit-code -- packages/docs/openapi.yaml packages/api-client/src/schema.d.ts
- name: Validate hosted docs, MCP inventory and generated exports
run: npm run validate --workspace=factorize-docs
- name: Install browser for static application checks
run: npx playwright install --with-deps chromium
- run: npm run check
Expand Down
236 changes: 14 additions & 222 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/job-trigger-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ The available value beneath a slug is:
| Trigger | Fields |
| --- | --- |
| Manual | `prompt`, `data` |
| Schedule | `scheduled_at`, `cron`, `timezone` |
| Schedule | `occurredAt`, `externalId`, `metadata.timezone` |
| Linear webhook | Complete Linear delivery, plus `provider`, `event`, `delivery_id` |
| GitHub webhook | Complete GitHub delivery, plus `provider`, `event`, `delivery_id` |
| Cloudflare Tail | Complete sanitized Tail delivery, plus `provider`, `event`, `delivery_id` |
| Job lifecycle | `source_job_id`, `source_run_id`, `final_state`, `transitioned_at`, `observation_destination` |
| Job lifecycle | Terminal: `sourceJobId`, `sourceRunId`, `state`, `completedAt`; edited: `source_job_id`, `event`, `edited_at` |

Every trigger returned by `GET /api/v1/jobs` and `GET /api/v1/jobs/:id` (and the corresponding MCP `list_jobs` and `get_job` tools) includes a `reflection` object. It contains the stable `slug`, trigger kind/provider, whether the result is dynamic, and a flat `paths` list with nested path, basic value type, description, and occasional example. The Job editor consumes this same canonical contract for Mustache autocomplete. Webhook conditions preserve normal provider context reflection.
Every trigger returned by `GET /api/v1/jobs` and `GET /api/v1/jobs/:id` (and the corresponding MCP `list_jobs` and `get_job` tools) includes a `reflection` object. It contains the stable `slug`, trigger kind/provider, whether the result is dynamic, and a flat `paths` list with nested path, basic value type, description, and occasional example. The Job editor consumes this contract for Mustache autocomplete. Current terminal lifecycle reflection still advertises older snake_case fields; the scheduler emits the camelCase fields above, so inspect persisted context when verifying templates. Webhook conditions preserve normal provider context reflection.

Manual invocation accepts an optional display `name`, `prompt`, JSON object `data`, and `idempotencyKey`. The display name is used as the run name, while prompt and data are exposed beneath the manual trigger slug. `idempotencyKey` is the client-facing value and must not include the reserved internal `manual:` prefix. Reusing the same value returns the original invocation. Run inspection exposes that reusable value as `invocation.idempotency_key`, while `invocation.claim_key` is the internal prefixed claim and must not be passed back to the invocation API. Parameter defaults and invocation, schedule, or webhook parameter overrides are not accepted.
Manual invocation accepts an optional display `name`, `prompt`, JSON object `data`, and `idempotencyKey`. The display name is used as the run name, while prompt and data are exposed beneath the manual trigger slug. `idempotencyKey` is the client-facing value and must not include the reserved internal `manual:` prefix. Reusing the same value returns the original invocation. Retain the submitted key. Current run inspection does not expose `invocation.idempotency_key`; `invocation.claim_key` is the internal prefixed claim and must not be passed back to the invocation API. Parameter defaults and invocation, schedule, or webhook parameter overrides are not accepted.

Run inspection returns `context` as the complete persisted object and `invocation.trigger_id` as the trigger that fired. Parameter-era stored Jobs are migrated: old context and parameters are retained beneath `legacy_context` and `legacy_parameters` in the corresponding trigger context. They are not used as global template variables.

Expand Down
11 changes: 6 additions & 5 deletions packages/api/test/api-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ describe("versioned API contract", () => {
}
});

it("configures Mintlify to render the exact committed artifact", () => {
it("keeps the exact committed REST artifact available in the Reference group", () => {
const docs = JSON.parse(
readFileSync(new URL("../../docs/docs.json", import.meta.url), "utf8"),
);
expect(
docs.navigation.tabs.find((tab: any) => tab.tab === "API Reference")
.openapi,
).toBe("/openapi.yaml");
const pages = docs.navigation.groups.find((group: any) => group.group === "Reference").pages;
expect(pages).toContain("api/reference");
expect(pages.find((page: any) => page.openapi)?.openapi).toBe("/openapi.yaml");
expect(readFileSync(new URL("../../docs/api/reference.mdx", import.meta.url), "utf8")).toContain("](/openapi.yaml)");

const reference = readFileSync(
new URL("../../docs/api/reference.mdx", import.meta.url),
"utf8",
Expand Down
79 changes: 79 additions & 0 deletions packages/api/test/docs-workflows.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { jobInputSchema, manualInvocationSchema, triggerSchema } from "../src/flow-schemas";
import { jobUpdateInput } from "../src/job-contracts";
import { executionTargetResponse } from "../src/editor-contracts";
import { ApiService } from "../src/flow-service";
import { InvocationService, type Invocation, type Job, type JobRun } from "../src/job-domain";
import { validateScheduleConfig, nextOccurrence } from "../src/schedule";
import { evaluateWebhookConditions } from "../src/webhook-conditions";

const guide = (path: string) => readFileSync(new URL(`../../docs/${path}.mdx`, import.meta.url), "utf8");
const examples = (path: string) => [...guide(path).matchAll(/```json\n([\s\S]*?)\n```/g)].map(match => JSON.parse(match[1]!));

describe("maintained hosted documentation examples", () => {
it("first-job discovery/create/invoke renders the actual prompt and deduplicates a lost response", async () => {
const [create, invocation] = examples("quickstart");
const target = executionTargetResponse.parse({ id: "TARGET_ID", kind: "exe-vm", name: "Ephemeral exe.dev VMs", workspace: "ephemeral", cwd: "/home/exedev/workspace", agentKind: "codex", capabilities: ["stop"] });
const input = jobInputSchema.parse(create);
expect(input.executionTargetId).toBe(target.id);
const service = new ApiService({} as any, {} as any);
const triggers = (service as any).normalizedTriggers(input.triggers);
expect(triggers[0].slug).toBe("trigger-1");
const job: Job = { ...input, id: "JOB_ID", model: "", enabled: true, triggers, executionTarget: { connectionId: target.id, agentKind: target.agentKind, workspace: target.workspace, cwd: target.cwd }, createdAt: "now", updatedAt: "now" };
const stored = new Map<string, { invocation: Invocation; run: JobRun }>();
const repository = {
getJob: async () => job,
findInvocation: async (_jobId: string, key: string) => stored.get(key) ?? null,
insertInvocationAndRun: async (value: Invocation, run: JobRun) => { stored.set(value.claimKey, { invocation: value, run }); return true; },
countActiveRuns: async () => 0,
markRunRunning: async () => { throw new Error("not used"); },
};
const { jobId, ...request } = invocation;
const parsed = manualInvocationSchema.parse(request);
const invoker = new InvocationService(repository, async text => text);
const call = { source: "manual" as const, triggerId: triggers[0].id, claimKey: `manual:${parsed.idempotencyKey}`, context: { [triggers[0].slug]: { prompt: parsed.prompt, data: parsed.data ?? {} } } };
const first = await invoker.invoke(jobId, call);
const retry = await invoker.invoke(jobId, call);
expect(first.run.encryptedPrompt).toContain("https://github.com/YOUR_ORG/YOUR_REPO.git");
expect(first.run.encryptedPrompt).toContain("Review now");
expect(retry.duplicate).toBe(true);
expect(retry.run.id).toBe(first.run.id);
expect(stored.size).toBe(1);
});

it("scheduled, Linear, GitHub, ClickUp and lifecycle recipe configurations satisfy current schemas", () => {
for (const path of ["recipes/scheduled-review", "recipes/linear-job", "recipes/chaining", "integrations/github", "integrations/clickup"]) {
for (const example of examples(path)) triggerSchema.parse(example);
}
const schedule = examples("recipes/scheduled-review")[0].config;
validateScheduleConfig(schedule);
expect(nextOccurrence(schedule, new Date("2026-10-09T09:01:00Z")).toISOString()).toBe("2026-10-12T09:00:00.000Z");
});

it("reference create/replacement/invocation and conditions examples are actionable", async () => {
const blocks = examples("mcp/tools");
const create = blocks.find(value => value.promptTemplate && !value.jobId && !value.id);
jobInputSchema.parse(create);
jobUpdateInput.extend({ jobId: jobInputSchema.shape.executionTargetId }).parse(blocks.find(value => value.expectedUpdatedAt));
const invoke = blocks.find(value => value.idempotencyKey);
const { jobId, ...request } = invoke;
expect(jobId).toBe("JOB_ID");
manualInvocationSchema.parse(request);
expect(manualInvocationSchema.safeParse({ idempotencyKey: "manual:internal" }).success).toBe(false);
const condition = blocks.find(value => value.conditions);
expect((await evaluateWebhookConditions(condition.conditions, condition.webhook)).decision).toBe("match");
});

it("documented current limitations match implementation rather than stale tool descriptions", () => {
const service = readFileSync(new URL("../src/flow-service.ts", import.meta.url), "utf8");
const scheduler = readFileSync(new URL("../src/postgres/automation-scheduler.ts", import.meta.url), "utf8");
expect(service).toContain("killRun(runId: string) { return this.stopRun(runId); }");
for (const key of ["sourceRunId", "sourceJobId", "completedAt", "occurredAt"]) {
expect(scheduler).toContain(key);
expect(guide("work/prompts")).toContain(key);
}
expect(guide("mcp/tools")).toContain("does not include `output`");
expect(guide("work/stop-retry")).toContain("does not return `invocation.idempotency_key`");
});
});
4 changes: 2 additions & 2 deletions packages/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

This is an independently previewable and publishable [Mintlify](https://mintlify.com) package. Install the Mintlify CLI, run `npm run dev --workspace=factorize-docs`, and open the local URL. Publish with `npm run deploy --workspace=factorize-docs` from a configured Mintlify project. See [the publishing runbook](../../docs/mintlify.md) for repository, custom-domain, DNS, and verification configuration.

The API Reference tab renders `openapi.yaml` directly. This is the generated API artifact consumed by the docs, clients, and CI. Update the executable catalog in `packages/api/src/api-contract.ts`, run `npm run generate:openapi` from the repository root, and commit the resulting YAML. Shared schemas and general metadata live beside the catalog.
The REST reference links to `openapi.yaml` directly. This is the generated API artifact consumed by the docs, clients, and CI. Update the executable catalog in `packages/api/src/api-contract.ts`, run `npm run generate:openapi` from the repository root, and commit the resulting YAML. Shared schemas and general metadata live beside the catalog.

Run `npm run validate --workspace=factorize-docs` to check artifact freshness, parsed method/path equality, Mintlify configuration, and LLM exports. CI also regenerates the artifact and rejects any diff. `llms.txt` and `llms-full.txt` provide documentation summaries and point to the generated contract for operation details.
Run `npm run validate --workspace=factorize-docs` to check artifact freshness, parsed method/path equality, Mintlify configuration, and LLM exports. CI also regenerates the artifact and rejects any diff. Run `npm run generate --workspace=factorize-docs` after editing guides/navigation. Both LLM exports are generated from every maintained navigation guide; validation rejects stale exports, missing/invented MCP tools, broken local links and onboarding drift. JSON examples in the first-job and recipes are parsed against implementation schemas by the API docs-workflows tests.
2 changes: 1 addition & 1 deletion packages/docs/api/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Protected API and MCP requests use `Authorization: Bearer <token>`. Browser user

## Browser accounts

Create a username/password account at `/auth/signup` and verify the email delivered by Postmark before signing in at `/auth/login`. Recovery is at `/auth/password-reset`; legacy Linear-only users use that flow to choose a username/password while retaining their workspace. Change your password from the account menu. Resetting/changing passwords or signing out invalidates existing sessions and delegated credentials.
Create an email/password account at `/auth/signup` and verify the email delivered by Postmark before signing in at `/auth/login`. Recovery is at `/auth/password-reset`; legacy Linear-only users use that flow to choose a password while retaining their workspace. Change your password from the account menu. Resetting/changing passwords or signing out invalidates existing sessions and delegated credentials.

Linear OAuth is an integration connection available only after native sign-in. Workspace membership, not the connected Linear identity, controls authorization.

Expand Down
6 changes: 3 additions & 3 deletions packages/docs/api/discovery.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ title: OAuth discovery
description: Endpoints and metadata for OAuth-aware clients.
---

At the deployment origin, clients can retrieve:
At `https://app.factorize.sh`, clients can retrieve:

* `/.well-known/oauth-authorization-server` — issuer, authorization, token, registration, revocation, and device endpoints plus supported grants/scopes.
* `/.well-known/oauth-protected-resource` — resource `APP_ORIGIN/mcp`, authorization server, header bearer authentication, and supported scopes.
* `/.well-known/oauth-protected-resource` — resource `https://app.factorize.sh/mcp`, authorization server, header bearer authentication, and supported scopes.

The authorization endpoint is `/authorize`, token endpoint `/oauth/token`, dynamic registration endpoint `/oauth/register`, and device endpoint `/oauth/device_authorization`. Client ID Metadata Documents are enabled. MCP clients should use `APP_ORIGIN/mcp`; they can discover OAuth automatically and complete browser PKCE consent.
The authorization endpoint is `/authorize`, token endpoint `/oauth/token`, dynamic registration endpoint `/oauth/register`, and device endpoint `/oauth/device_authorization`. Client ID Metadata Documents are enabled. MCP clients should use `https://app.factorize.sh/mcp`; they can discover OAuth automatically and complete browser PKCE consent.
2 changes: 1 addition & 1 deletion packages/docs/api/openapi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: OpenAPI definition
description: Download the verified Factorize REST contract.
---

[Download openapi.yaml](/openapi.yaml). The API Reference tab renders this exact file, and clients can use it to generate SDKs or inspect request and response schemas.
[Download openapi.yaml](/openapi.yaml). Clients can use this exact file to generate SDKs or inspect request and response schemas.

The definition is generated from the executable route catalog in `packages/api/src/api-contract.ts`, which the Worker dispatches in `protected-api.ts`. To change an API operation, update its catalog entry (method, path, scope, validation, handler, and documentation), then run:

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/api/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: REST API reference
description: How to use the generated API reference.
---

The **API Reference** tab renders every application operation directly from [openapi.yaml](/openapi.yaml), including request validation, required scopes, owner-session restrictions, and JSON response schemas. This is the same generated artifact verified by CI and available to API clients.
The **REST operations** group under Reference renders every application operation directly from [openapi.yaml](/openapi.yaml), including request validation, required scopes, owner-session restrictions, and JSON response schemas. This is the same generated artifact verified by CI and available to API clients.

All application endpoints use `/api/v1`. Authenticate with a scoped bearer token or an interactive owner session; credential management and trace replay require an interactive owner session. Errors use `{ "error": { "code": "...", "message": "..." } }`.

Expand Down
Loading
Loading