120 120
121Choose a feature with a written contract and a clear stopping point: a new API endpoint, a validation rule, or a small addition to an existing service. The issue should fit in one pull request and have checks that can run without production access.121Choose a feature with a written contract and a clear stopping point: a new API endpoint, a validation rule, or a small addition to an existing service. The issue should fit in one pull request and have checks that can run without production access.
122 122
123The example adds pagination to a project's activity feed. The runnable Node.js sample includes authentication, project access, signed cursors, and an existing project-detail route. It uses fixed test records in memory, so you can check the pagination contract without a database or external service.123The example adds pagination to a project's activity feed. The runnable TypeScript sample includes authentication, project access, signed cursors, and an existing project-detail route. It uses fixed test records in memory, so you can check the pagination contract without a database or external service.
124 124
125## Try the runnable sample125## Try the runnable sample
126 126
128 128
129```bash129```bash
130node --version130node --version
131node api.mjs131node --experimental-strip-types api.ts
132node test.mjs --seeded132node --experimental-strip-types test.ts --seeded
133node test.mjs133node --experimental-strip-types test.ts
134node reproduce.mjs ./evidence134node --experimental-strip-types reproduce.ts ./evidence
135```135```
136 136
137`node api.mjs` starts a local HTTP server, requests the first page, prints its public IDs, and closes the server.137`node --experimental-strip-types api.ts` starts a local HTTP server, requests the first page, prints its public IDs, and closes the server.
138 138
139The `--seeded` test run deliberately exits nonzero: its timestamp-only continuation skips two events tied at the first page boundary. The same tests pass with the corrected timestamp-and-ID tuple continuation.139The `--seeded` test run deliberately exits nonzero: its timestamp-only continuation skips two events tied at the first page boundary. The same tests pass with the corrected timestamp-and-ID tuple continuation.
140 140
156 156
157To verify your environment, put the files in your selected repository, prepare and publish an environment with a supported Node runtime, then run the commands in a new Cloud task and record its results.157To verify your environment, put the files in your selected repository, prepare and publish an environment with a supported Node runtime, then run the commands in a new Cloud task and record its results.
158 158
159`reproduce.mjs` saves `red.log`, `green.log`, `observed-http.json`, and `run-manifest.json` in the requested evidence directory. The manifest identifies the runtime, commands, exit codes, seeded defect, correction, and SHA-256 source hashes.159`reproduce.ts` saves `red.log`, `green.log`, `observed-http.json`, and `run-manifest.json` in the requested evidence directory. The manifest identifies the runtime, commands, exit codes, seeded defect, correction, and SHA-256 source hashes.
160 160
161It does not record session tokens or the signing key. Read `README.md` and `openapi.json` for the sample's setup and public contract.161It does not record session tokens or the signing key. Read `README.md` and `openapi.json` for the sample's setup and public contract.
162 162
166 166
167<details>167<details>
168 <summary>Cursor and ordering implementation</summary>168 <summary>Cursor and ordering implementation</summary>
169```javascript169```typescript
170import { createFixtures } from "./fixtures.ts";
171type Fixtures = ReturnType<typeof createFixtures>;
172type EventKey = { created_at: string; id: string };
173
170export function createApi({174export function createApi({
171 sessions,175 sessions,
172 projects,176 projects,
173 events,177 events,
174 signingKey,178 signingKey,
175 seededBug = false,179 seededBug = false,
176}) {180}: Fixtures & { seededBug?: boolean }) {
177 return createServer((request, response) => {181 return createServer((request, response) => {
178 const send = (status, body) => {182 const send = (status: number, body: unknown) => {
179 response.writeHead(status, { "content-type": "application/json" });183 response.writeHead(status, { "content-type": "application/json" });
180 response.end(JSON.stringify(body));184 response.end(JSON.stringify(body));
181 };185 };
182 const fail = (code) => {186 const fail = (code: string) => {
183 const [status, message] = errors[code];187 const [status, message] = errors[code];
184 send(status, { error: { code, message } });188 send(status, { error: { code, message } });
185 };189 };
200 const project = projectId ? projects.get(projectId) : undefined;204 const project = projectId ? projects.get(projectId) : undefined;
201 if (205 if (
202 request.method !== "GET" ||206 request.method !== "GET" ||
207 !route ||
203 !project ||208 !project ||
204 project.tenant_id !== tenantId209 project.tenant_id !== tenantId
205 ) {210 ) {
219 ) {224 ) {
220 return fail("invalid_limit");225 return fail("invalid_limit");
221 }226 }
222 let cursor;227 let cursor: EventKey | undefined;
223 if (url.searchParams.has("cursor")) {228 if (url.searchParams.has("cursor")) {
224 try {229 try {
225 if (url.searchParams.getAll("cursor").length !== 1)230 if (url.searchParams.getAll("cursor").length !== 1)
259 }));264 }));
260 const nextCursor =265 const nextCursor =
261 matching.length > limit266 matching.length > limit
262 ? encodeCursor(selected.at(-1), tenantId, projectId, signingKey)267 ? encodeCursor(
268 selected[selected.length - 1],
269 tenantId,
270 projectId,
271 signingKey
272 )
263 : null;273 : null;
264 return send(200, { items, next_cursor: nextCursor });274 return send(200, { items, next_cursor: nextCursor });
265 });275 });
266}276}
267 277
268export async function startApi(fixtures, options = {}) {278export async function startApi(
279 fixtures: Fixtures,
280 options: { seededBug?: boolean } = {}
281) {
269 const server = createApi({ ...fixtures, ...options });282 const server = createApi({ ...fixtures, ...options });
270 await new Promise((resolve, reject) => {283 await new Promise((resolve, reject) => {
271 server.once("error", reject);284 server.once("error", reject);
288 301
289<details>302<details>
290 <summary>Seeded records and project access fixtures</summary>303 <summary>Seeded records and project access fixtures</summary>
291```javascript304```typescript
292export function createFixtures() {305export function createFixtures() {
293 const tokenA = randomBytes(24).toString("base64url");306 const tokenA = randomBytes(24).toString("base64url");
294 const tokenB = randomBytes(24).toString("base64url");307 const tokenB = randomBytes(24).toString("base64url");
305 ["other", { tenant_id: "tenant_a", name: "Another project" }],318 ["other", { tenant_id: "tenant_a", name: "Another project" }],
306 ["private", { tenant_id: "tenant_b", name: "Private project" }],319 ["private", { tenant_id: "tenant_b", name: "Private project" }],
307 ]);320 ]);
308 const event = (id, created_at, project_id, tenant_id = "tenant_a") => ({321 const event = (
322 id: string,
323 created_at: string,
324 project_id: string,
325 tenant_id = "tenant_a"
326 ) => ({
309 id,327 id,
310 created_at,328 created_at,
311 project_id,329 project_id,
357 375
358<details>376<details>
359 <summary>HTTP contract and regression tests</summary>377 <summary>HTTP contract and regression tests</summary>
360```javascript378```typescript
361test("five-event traversal crosses a timestamp tie and replays the same continuation", async () => {379test("five-event traversal crosses a timestamp tie and replays the same continuation", async () => {
362 const expected = ["evt_105", "evt_104", "evt_103", "evt_102", "evt_101"];380 const expected = ["evt_105", "evt_104", "evt_103", "evt_102", "evt_101"];
363 const pages = await traverse("feed", 2, expected);381 const pages = await traverse("feed", 2, expected);
416 [{}, 25],434 [{}, 25],
417 [{ limit: "1" }, 1],435 [{ limit: "1" }, 1],
418 [{ limit: "100" }, 100],436 [{ limit: "100" }, 100],
419 ]) {437 ] as [Record<string, string>, number][]) {
420 const result = await request("large", parameters);438 const result = await request("large", parameters);
421 assert.equal(result.status, 200);439 assert.equal(result.status, 200);
422 assert.equal(result.body.items.length, expected);440 assert.equal(result.body.items.length, expected);
501 { cursor: "broken" },519 { cursor: "broken" },
502 { cursor: privateCursor },520 { cursor: privateCursor },
503 { limit: "0", cursor: "broken" },521 { limit: "0", cursor: "broken" },
504 ]) {522 ] as Record<string, string>[]) {
505 const result = await request("feed", parameters, token);523 const result = await request("feed", parameters, token);
506 assert.equal(result.status, 401);524 assert.equal(result.status, 401);
507 assert.deepEqual(result.body, unauthenticated);525 assert.deepEqual(result.body, unauthenticated);
517 { cursor: "broken" },535 { cursor: "broken" },
518 { cursor: ownCursor },536 { cursor: ownCursor },
519 { limit: "0", cursor: "broken" },537 { limit: "0", cursor: "broken" },
520 ]) {538 ] as Record<string, string>[]) {
521 const result = await request(project, parameters);539 const result = await request(project, parameters);
522 assert.equal(result.status, 404);540 assert.equal(result.status, 404);
523 assert.deepEqual(result.body, notFound);541 assert.deepEqual(result.body, notFound);
574 created_at: "2026-01-15T12:00:02.123456Z",592 created_at: "2026-01-15T12:00:02.123456Z",
575 id: "evt_104",593 id: "evt_104",
576 };594 };
577 const missing = { ...valid };595 const missing: Partial<typeof valid> = { ...valid };
578 delete missing.id;596 delete missing.id;
579 const cases = [597 const cases: [string, unknown][] = [
580 ["missing ID", missing],598 ["missing ID", missing],
581 ["number ID", { ...valid, id: 104 }],599 ["number ID", { ...valid, id: 104 }],
582 ["empty ID", { ...valid, id: "" }],600 ["empty ID", { ...valid, id: "" }],
689 const operation = specification.paths["/v1/projects/{project_id}/events"].get;707 const operation = specification.paths["/v1/projects/{project_id}/events"].get;
690 assert.equal(operation.operationId, "listProjectEvents");708 assert.equal(operation.operationId, "listProjectEvents");
691 const limit = operation.parameters.find(709 const limit = operation.parameters.find(
692 (parameter) => parameter.name === "limit"710 (parameter: { name: string }) => parameter.name === "limit"
693 ).schema;711 ).schema;
694 assert.deepEqual(limit, {712 assert.deepEqual(limit, {
695 type: "integer",713 type: "integer",
714 732
715<details>733<details>
716 <summary>Evidence capture</summary>734 <summary>Evidence capture</summary>
717```javascript735```typescript
718mkdirSync(output, { recursive: true });736mkdirSync(output, { recursive: true });
719const states = [];737const states = [];
720for (const [name, arguments_] of [738for (const [name, arguments_] of [
723]) {741]) {
724 const result = spawnSync(742 const result = spawnSync(
725 process.execPath,743 process.execPath,
726 [resolve(directory, "test.mjs"), ...arguments_],744 [
745 "--experimental-strip-types",
746 resolve(directory, "test.ts"),
747 ...arguments_,
748 ],
727 {749 {
728 cwd: directory,750 cwd: directory,
729 encoding: "utf8",751 encoding: "utf8",
736 );758 );
737 states.push({759 states.push({
738 name,760 name,
739 command: `node test.mjs${arguments_.length ? " --seeded" : ""}`,761 command: `node --experimental-strip-types test.ts${arguments_.length ? " --seeded" : ""}`,
740 exit_code: result.status,762 exit_code: result.status,
741 signal: result.signal,763 signal: result.signal,
742 error: result.error?.message ?? null,764 error: result.error?.message ?? null,
783 red_exit: states[0].exit_code,805 red_exit: states[0].exit_code,
784 green_exit: states[1].exit_code,806 green_exit: states[1].exit_code,
785 green_pages: observed.green.pages.map((page) =>807 green_pages: observed.green.pages.map((page) =>
786 page.body.items.map((item) => item.id)808 page.body.items.map((item: { id: string }) => item.id)
787 ),809 ),
788 evidence_directory: output,810 evidence_directory: output,
789 },811 },
800An issue link is useful only if Codex can read it. Paste or attach the relevant content when the source is unavailable. Include the following information with the starter prompt.822An issue link is useful only if Codex can read it. Paste or attach the relevant content when the source is unavailable. Include the following information with the starter prompt.
801 823
802| Input | Sample issue |824| Input | Sample issue |
803| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |825| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
804| Issue and outcome | `API-142`: Add `GET /v1/projects/{project_id}/events` so customers can page through an activity feed. |826| Issue and outcome | `API-142`: Add `GET /v1/projects/{project_id}/events` so customers can page through an activity feed. |
805| Repository and base | Put the sample folder in your chosen repository, then record the branch and exact commit selected for the task. |827| Repository and base | Put the sample folder in your chosen repository, then record the branch and exact commit selected for the task. |
806| Relevant code | The sample's `api.mjs`, `fixtures.mjs`, `test.mjs`, and `openapi.json`, plus your repository's `AGENTS.md`. |828| Relevant code | The sample's `api.ts`, `fixtures.ts`, `test.ts`, and `openapi.json`, plus your repository's `AGENTS.md`. |
807| Existing patterns | Keep authentication and project authorization before pagination validation. Use signed cursors and the documented public error envelope. When adapting the issue, follow your repository's existing helpers. |829| Existing patterns | Keep authentication and project authorization before pagination validation. Use signed cursors and the documented public error envelope. When adapting the issue, follow your repository's existing helpers. |
808| Test setup | Fixed in-memory test projects for two tenants, six tenant-A projects, a timestamp tie split across a page boundary, timestamps with fractional precision, empty and exactly full final pages, and 105 events for limit checks. |830| Test setup | Fixed in-memory test projects for two tenants, six tenant-A projects, a timestamp tie split across a page boundary, timestamps with fractional precision, empty and exactly full final pages, and 105 events for limit checks. |
809| Validation | `node test.mjs --seeded` (expected failure), `node test.mjs` (corrected state), and `node reproduce.mjs ./evidence`. Run `node --check` for each `.mjs` file. For your own service, add its actual type, lint, regression, and CI commands. |831| Validation | `node --experimental-strip-types test.ts --seeded` (expected failure), `node --experimental-strip-types test.ts` (corrected state), and `node --experimental-strip-types reproduce.ts ./evidence`. For your own service, add its actual type, lint, regression, and CI commands. |
810| Scope | Endpoint, focused tests, and its OpenAPI documentation. No new dependencies, database migration, frontend, deployment, or auth redesign. |832| Scope | Endpoint, focused tests, and its OpenAPI documentation. No new dependencies, database migration, frontend, deployment, or auth redesign. |
811| Handoff | A draft PR when the available repository integration supports it and you have authorized creation; otherwise a diff and draft PR description. |833| Handoff | A draft PR when the available repository integration supports it and you have authorized creation; otherwise a diff and draft PR description. |
812 834
8572. **Run the starter prompt.** Replace its bracketed inputs with your repository, issue packet, boundaries, and checks. Choose whether Codex should return a diff or create an authorized draft PR. The starter prompt on this page contains the full handoff instructions.8792. **Run the starter prompt.** Replace its bracketed inputs with your repository, issue packet, boundaries, and checks. Choose whether Codex should return a diff or create an authorized draft PR. The starter prompt on this page contains the full handoff instructions.
8583. **Establish the baseline.** Codex should read repository instructions and run the approved baseline checks before editing.8803. **Establish the baseline.** Codex should read repository instructions and run the approved baseline checks before editing.
859 881
860 For the sample, run `node test.mjs` and the syntax checks in `README.md`; `--seeded` is a separate deliberate failure demonstration.882 For the sample, run `node --experimental-strip-types test.ts`; `--seeded` is a separate deliberate failure demonstration.
861 883
862 For your own service, run its existing regression, type, and lint checks. A new endpoint's focused test file may not exist yet; record that as a test to create. Resolve failing existing checks or unavailable test services before attributing later results to the feature.884 For your own service, run its existing regression, type, and lint checks. A new endpoint's focused test file may not exist yet; record that as a test to create. Resolve failing existing checks or unavailable test services before attributing later results to the feature.
863 885
913 935
914### Existing behavior936### Existing behavior
915 937
916The sample checks the existing project-detail route with authorized, unauthorized, and inaccessible-project requests. Run syntax checks for its `.mjs` files. In your service, run its established regression suite, type check, and lint.938The sample checks the existing project-detail route with authorized, unauthorized, and inaccessible-project requests. In your service, run its established regression suite, type check, and lint.
917 939
918### Public response schema940### Public response schema
919 941