From 7fb4913fb51ed41b124a5e32a1e6e741192c9b3a Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Mon, 27 Jul 2026 22:13:50 -0400 Subject: [PATCH 1/2] Wire pegma-dev-api health through @pegma/health. Use the shared check/response contract on /health, vendor the pack until npm publish, and register Health on the site. Co-authored-by: Cursor --- README.md | 5 ++-- package-lock.json | 23 +++++++++++++++++++ package.json | 1 + src/data/components.ts | 20 ++++++++++++++++ worker-vendor/README.md | 13 +++++++++++ worker-vendor/pegma-health-0.1.0.tgz | Bin 0 -> 5915 bytes worker/README.md | 33 ++++++++++++++++++++++++--- worker/src/index.ts | 27 ++++++++++++++-------- 8 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 worker-vendor/README.md create mode 100644 worker-vendor/pegma-health-0.1.0.tgz diff --git a/README.md b/README.md index d3827ed..a745e63 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,9 @@ npx wrangler secret put DATADOG_SITE -c worker/wrangler.jsonc npm run worker:tail ``` -`GET /health` on the Worker returns whether each sink is configured and -emits structured lines through the Pegma adapters. +`GET /health` on the Worker uses `@pegma/health` (process + logging sink +booleans), returns the shared JSON shape, and emits `health.ok` / +`health.degraded` / `health.failed` through the Pegma adapters. ## The content rule diff --git a/package-lock.json b/package-lock.json index ad36675..b89f980 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "pegma.dev", "version": "0.1.0", "dependencies": { + "@pegma/health": "file:worker-vendor/pegma-health-0.1.0.tgz", "@pegma/logger-cloudflare": "^0.1.1", "@pegma/logger-datadog": "^0.1.1", "@pegma/logger-tee": "^0.1.1", @@ -1390,6 +1391,19 @@ "dev": true, "license": "MIT" }, + "node_modules/@pegma/health": { + "version": "0.1.0", + "resolved": "file:worker-vendor/pegma-health-0.1.0.tgz", + "integrity": "sha512-AKaBqt4iu65pnd0imMgg3DSfI3Xwnlr3SLTrVCJ6Vzhvi6XKWVowUwYRR74qx3adGAmIt7STWzdQnAlGWZ8LQA==", + "license": "MIT", + "dependencies": { + "@pegma/spine": "0.1.1", + "@pegma/storage-core": "0.3.0" + }, + "engines": { + "node": ">=22" + } + }, "node_modules/@pegma/logger-cloudflare": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@pegma/logger-cloudflare/-/logger-cloudflare-0.1.1.tgz", @@ -1435,6 +1449,15 @@ "node": ">=22" } }, + "node_modules/@pegma/storage-core": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@pegma/storage-core/-/storage-core-0.3.0.tgz", + "integrity": "sha512-XcSIAxjC1JV+Pt3dpSrLZELSejckO/COWLZ03BfYQv0Hem4QL/7XCq5gb5dxEymKVufQuIqGtuDPZi2UPfqnuQ==", + "license": "MIT", + "engines": { + "node": ">=22" + } + }, "node_modules/@poppinss/colors": { "version": "4.1.6", "resolved": "https://registry.npmjs.org/@poppinss/colors/-/colors-4.1.6.tgz", diff --git a/package.json b/package.json index 54f1ea5..76e4da6 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "worker:tail": "wrangler tail pegma-dev-api" }, "dependencies": { + "@pegma/health": "file:worker-vendor/pegma-health-0.1.0.tgz", "@pegma/logger-cloudflare": "^0.1.1", "@pegma/logger-datadog": "^0.1.1", "@pegma/logger-tee": "^0.1.1", diff --git a/src/data/components.ts b/src/data/components.ts index 2fe1f93..cb0b53a 100644 --- a/src/data/components.ts +++ b/src/data/components.ts @@ -249,4 +249,24 @@ export const components: readonly PegmaComponent[] = [ now: '0.1.1 on npm; trusted publishing configured. Host tee wiring next.', plan: 'docs/PROJECT_PLAN.md', }, + { + repo: 'health', + title: 'Health', + packages: ['@pegma/health'], + status: 'in development', + summary: + 'Composable health probes and HTTP responses for public liveness checks.', + owns: [ + 'Check contracts, aggregation, and HTTP status mapping', + 'Process, detail, and injected Store ping helpers', + 'Spine log events health.ok / health.degraded / health.failed', + ], + refuses: [ + 'Owning a storage adapter or inventing domain collections', + 'Autodiscovery of checks — hosts register them at the composition root', + 'Metrics, APM, or alert fan-out', + ], + now: '0.1.0 packaged; wired on pegma.dev Worker and RetireGolden /api/health pending npm publish.', + plan: 'docs/PROJECT_PLAN.md', + }, ]; diff --git a/worker-vendor/README.md b/worker-vendor/README.md new file mode 100644 index 0000000..50bba9c --- /dev/null +++ b/worker-vendor/README.md @@ -0,0 +1,13 @@ +# Vendored Health package + +`pegma-health-0.1.0.tgz` is the exact npm-pack artifact from +`pegma-dev/health` commit `35a878b` (`@pegma/health` 0.1.0). + +Generated with: + +```text +npm ci +npm pack --workspace @pegma/health --pack-destination /worker-vendor +``` + +Remove this bridge when `@pegma/health` has a public npm release. diff --git a/worker-vendor/pegma-health-0.1.0.tgz b/worker-vendor/pegma-health-0.1.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..37e8e2934fd66bfde3599fc318f23b85c2b25607 GIT binary patch literal 5915 zcmV+$7v$(4iwFP!00002|Lr{Oa@#nP`K_nu)o#_QFbz$$?n`mKWq~0Z#23aAc48#UON-M zecH9`-q3#ZTl|{M=Kj;CP}SaSHg}u*yYT4A-hOjuXMex>6dpBqn!EdZ@TmFdEBqEB zapFhK<`+=1*=$1o|9A2`>yF^mcX=pyt!72@W$aI;32eBVu-n|-hXGIgm>)-h$3p{7 zPpw+*oX0a?2tNwJ7ck{9zg)s3cEW^v28?6QAsT}_b>ay(Ac?>UmoVqCh(d@i6UPtz zZ~_jv(R^8p#*j>X0U{bFw@%E#2|aLxh+N-ExCdV3E@nJToCNue{eTPDNTwX>!xW>w zNlZNM1T{Yde3m_eTR)jbiv(gWlGt~Vh5>%)1`7{m$Q}p&%uhKWI+;M!k_Z-p8ziRz zv&i$u_@9$n^TlQ0i>U#gkEAab2{%AsBiYhGJ+`A51P_9m8_j(#fOJ*T5e$kxM}sD* zi3GOXPNP{-6JONEi#YVfloO5@fryCX6?YSCLGW=D1ko+3=0>6Cqeh}ttBs}{oXhBj zlPRI(x$4#Qk(fF`0GB*9827*r!O_%-k-bQqF!7xL=21-i%4#-hwb6+U z!~W6eH5=H_9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!C57RUn3biZVoISSOFo5_>XJBb@&SOCy}a>UPTz+p zVxdD%GmB<{qh#-boLBc$(gc{!qB2S6pCRcd$d`%Hdq9f(B_UG&-uxsPhFO=DIa93Z z=WoIC)im?L33%xxKxC%bPtCU~ULaNt-Su%x&Cp&_lrO#%LqEJM)rCNZS%pV@<-#?R(XbnQ7fHml77sn9fcyl1%m}L9Dvb|4ELc8-_a#Ojv zJ&vN16P3>^sb!n_9nYB~F*@vkV0=7JB@y67Gsh1#1*Lm0qXlj3r&Cm%u$CVfa6#sh zTNWJsC>Ae2Oofo6+YmOQ7!Q*p!R6P$+^bzw+V2AQ_2ehKC|aAp$_l0liacR;E7O@RK?jsDVa|RjdC^}9n9-_B7uk*(!{aDk!nOZ*}XCc~-O=6cc@4?%7*$vxjA+ZEk6UM)B>tGB8Gf z!xm_pnU%}Y@IP!pwsZMzU3Z)$$vn&H>&8Upw1tOqbDiF&nb%0u(a}2z58-l|9b#5h zy4>C8E0k|jawXaDu&hcOYKLM~KhICSD!RkJ|EX;rcZ2i*sdcBfwJKTuuwu<;U-Yc5 zOt6Q}>^jW4WV5AvcKi2pq}Ccu%SUTvdK&qOClBU~>=drULZmAjYGs@h2h+NsgFr0_ zTMi<>#&wVax=)9Xokft)Imj34M92&Bjp{-9f-et?19OEC4zCIlzV{GfT9;Jd7M!md zd#~ASt|I2gr5vt_f~6q*J37v6jVo6lYu2iEv^C@Sw>k-AMdUSSfwa~nW3AfJ^VYNW xzjjyridt*t+Qn>}+g{J$?fW*jfAQUd-+teI-+teI-+o`?_rDq*N<;u=001SrnRWmG literal 0 HcmV?d00001 diff --git a/worker/README.md b/worker/README.md index 9d7b394..ea912f8 100644 --- a/worker/README.md +++ b/worker/README.md @@ -1,6 +1,7 @@ # pegma-dev-api Worker -Thin Cloudflare Worker that proves pegma.dev's Pegma logging composition: +Thin Cloudflare Worker that proves pegma.dev's Pegma logging composition and +hosts the public health endpoint via `@pegma/health`: ```ts createTeeLogger( @@ -39,5 +40,31 @@ token needs **Workers:Edit** in addition to **Pages:Edit**. ## Endpoints -- `GET /` or `GET /health` — JSON health; emits `request.received` and - `health.ok` through the teed Spine logger. +- `GET /` or `GET /health` — JSON from `@pegma/health` + (`createProcessCheck` + logging sink booleans). Emits `request.received` + and `health.ok` / `health.degraded` / `health.failed` through the teed Spine + logger. HTTP `200` when status is `ok` or `degraded`; `503` on `fail`. + No storage probe yet (D1 consumer still gated). + +Example body: + +```json +{ + "ok": true, + "status": "ok", + "service": "pegma-dev-api", + "checkedAt": "2026-07-27T21:00:00.000Z", + "checks": { + "process": { "status": "ok" }, + "logging": { + "status": "ok", + "detail": { "cloudflare": true, "datadog": true } + } + } +} +``` + +## Vendored `@pegma/health` + +Until `@pegma/health` is on npm, the Worker depends on +`worker-vendor/pegma-health-0.1.0.tgz` packed from `pegma-dev/health`. diff --git a/worker/src/index.ts b/worker/src/index.ts index c55920d..81ff458 100644 --- a/worker/src/index.ts +++ b/worker/src/index.ts @@ -1,3 +1,9 @@ +import { + createDetailCheck, + createProcessCheck, + runHealthChecks, + toHealthResponse, +} from '@pegma/health'; import { createAppLogger, type LoggerEnv } from './logger'; export interface Env extends LoggerEnv {} @@ -24,18 +30,19 @@ export default { }); if (request.method === 'GET' && (path === '/' || path === '/health')) { - logger.log('info', 'health.ok', { path }); - return Response.json( - { - ok: true, - service: 'pegma-dev-api', - logging: { + const result = await runHealthChecks({ + service: 'pegma-dev-api', + logger, + checks: [ + createProcessCheck(), + createDetailCheck('logging', { cloudflare: true, datadog: Boolean(env.DATADOG_API_KEY), - }, - }, - { status: 200 }, - ); + }), + ], + }); + const { status, body } = toHealthResponse(result); + return Response.json(body, { status }); } logger.log('warn', 'request.not_found', { method: request.method, path }); From 475f3f52a43b61626b2c8dcb530c64d7b3124248 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Mon, 27 Jul 2026 22:19:56 -0400 Subject: [PATCH 2/2] Clarify health docs and keep registry now aligned with the plan. Document only the events this Worker currently emits, distinguish status fail from health.failed, and use the Health Status stage as the fail-soft now line. Co-authored-by: Cursor --- README.md | 4 ++-- src/data/components.ts | 2 +- worker/README.md | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a745e63..bbdc36a 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ npm run worker:tail ``` `GET /health` on the Worker uses `@pegma/health` (process + logging sink -booleans), returns the shared JSON shape, and emits `health.ok` / -`health.degraded` / `health.failed` through the Pegma adapters. +booleans), returns the shared JSON shape, and emits `health.ok` through the +Pegma adapters with the checks registered today. ## The content rule diff --git a/src/data/components.ts b/src/data/components.ts index cb0b53a..83e0031 100644 --- a/src/data/components.ts +++ b/src/data/components.ts @@ -266,7 +266,7 @@ export const components: readonly PegmaComponent[] = [ 'Autodiscovery of checks — hosts register them at the composition root', 'Metrics, APM, or alert fan-out', ], - now: '0.1.0 packaged; wired on pegma.dev Worker and RetireGolden /api/health pending npm publish.', + now: 'Phase 1 implemented (0.1.0, public API unstable).', plan: 'docs/PROJECT_PLAN.md', }, ]; diff --git a/worker/README.md b/worker/README.md index ea912f8..2b32b4e 100644 --- a/worker/README.md +++ b/worker/README.md @@ -42,8 +42,10 @@ token needs **Workers:Edit** in addition to **Pages:Edit**. - `GET /` or `GET /health` — JSON from `@pegma/health` (`createProcessCheck` + logging sink booleans). Emits `request.received` - and `health.ok` / `health.degraded` / `health.failed` through the teed Spine - logger. HTTP `200` when status is `ok` or `degraded`; `503` on `fail`. + and, with the checks registered today, `health.ok` through the teed Spine + logger (both checks are always `ok`; an absent Datadog key is detail only). + Package mapping for when a check reports otherwise: HTTP `200` for status + `ok`/`degraded`, `503` for status `fail` (log event `health.failed`). No storage probe yet (D1 consumer still gated). Example body: