@pulse-compute/runtime 0.0.0 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,126 @@
1
- # @pulse-compute/runtime
1
+ # `@pulse-compute/runtime`
2
2
 
3
- This is an inert namespace-bootstrap package. It contains no executable code.
3
+ <!-- pulse-package-status:start -->
4
+ > **Support tier:** Canonical application surface<br>
5
+ > **Audience:** Pulse application authors and library authors who type portable handlers and static routers.<br>
6
+ > **Install directly:** Yes. Install it in every Pulse application.<br>
7
+ > **Supported entry points:** `@pulse-compute/runtime`<br>
8
+ > **Stability:** Supported application authoring and execution contract.<br>
9
+ > **Canonical documentation:** [Package guide](https://pulsecompute.io/v1.0.0-beta.1/packages/runtime/)
10
+ >
11
+ > This release-status block is generated from the synchronized `Pulse 1.0.0-beta.1` package policy.
12
+ <!-- pulse-package-status:end -->
13
+
14
+ `@pulse-compute/runtime` is the low-level, provider-neutral Pulse application contract.
15
+
16
+ ```ts
17
+ import { Router } from '@pulse-compute/runtime'
18
+
19
+ const app = new Router()
20
+
21
+ app.get('/health', async (ctx) => {
22
+ return ctx.json({ ok: true })
23
+ })
24
+
25
+ export default app
26
+ ```
27
+
28
+ The source grammar distinguishes:
29
+
30
+ - synchronous metadata, route parameters, response construction, and `ctx.state`;
31
+ - awaited request-body and capability effects;
32
+ - terminal unawaited `return next()` and `return next(error)` transfers.
33
+
34
+ `ctx.state` is a request-local string map exposed through `get` and `set`. Canonical Node and native Wasm execution preserve it across effect continuation resume and isolate it between requests.
35
+
36
+ ## TypeScript semantic authority
37
+
38
+ The package-internal JavaScript dispatcher and the native compiler implement the
39
+ same public authoring contract. The public root does not publish `handle()`,
40
+ lifecycle, raw host access, or provider authority. Both realizations retain route
41
+ ordering, path/mount behavior, request-local state sharing, Web Request/Response
42
+ boundaries, and error recovery under the current contracts:
43
+
44
+ - `next()` is terminal and forward-only;
45
+ - authored throws and implicit fallthrough remain rejected;
46
+ - lifecycle belongs to providers;
47
+ - dynamic context decoration and generic session/gateway state do not return to
48
+ the portable core;
49
+ - effects, package operations, and provider requirements remain owned by their
50
+ sealed contracts.
51
+
52
+ The active package remains the one core type authority. Pulse-prefixed handler
53
+ aliases refer to the existing handler algebra rather than introducing parallel
54
+ interfaces.
55
+
56
+
57
+ ## Package-internal JavaScript realization
58
+
59
+ The package contains a live Router/context implementation used by package-local
60
+ contract tests and the explicit Node and Fastly JavaScript targets. It supports registration,
61
+ scoped middleware, mounts, parameters, terminal forward transfer, error recovery,
62
+ request-local string state, response helpers, and provider-injected effects.
63
+
64
+ This is deliberately not a new public application execution method. `Router` still
65
+ exposes only the portable authoring surface, and providers remain responsible for
66
+ request adaptation, lifecycle, and capability injection.
67
+
68
+ The provider-maintainer subpath `@pulse-compute/runtime/host` validates and executes
69
+ a Router, Pulse application, or managed handler without adding `handle`, `bind`,
70
+ `listen`, or `serve` to the application object. JavaScript providers plan and
71
+ load source applications, adapt their request boundary, and own their development
72
+ lifecycle. The runtime root still exposes no lifecycle methods.
73
+
74
+
75
+ ## Synchronous logging
76
+
77
+ Every context exposes string-only `ctx.log.error`, `warn`, `info`, and `debug`
78
+ methods. The flat profile `reporting` threshold defaults to `info`. Native
79
+ lowering removes disabled calls and emits enabled messages through `pulse_log`;
80
+ JavaScript targets filter through the same level contract at runtime. Logging is
81
+ not an effect, never suspends a handler, and a provider sink failure does not fail
82
+ the request. Known request secrets are redacted before managed emission.
83
+
84
+
85
+ ## Shared effect adapter and portable concurrency
86
+
87
+ JavaScript host operations route through one request-owned effect adapter. The
88
+ adapter owns deterministic request-local identities, cancellation,
89
+ settlement, pending-work containment, bounded observations, and one-time cleanup.
90
+ Provider and package implementations use this internal boundary; applications do
91
+ not import it.
92
+
93
+ Use a fixed keyed object with `ctx.parallel({ ... })` when concurrency itself is
94
+ portable application behavior:
95
+
96
+ ```ts
97
+ const { profile, flags } = await ctx.parallel({
98
+ profile: ctx.fetch('https://api.example.test/profile').json<Profile>(),
99
+ flags: ctx.fetch('https://api.example.test/flags').json<Flags>(),
100
+ })
101
+ ```
102
+
103
+ The initial contract requires a nonempty inline object literal with fixed,
104
+ non-index string keys and Pulse effect expressions as values. Property order owns
105
+ dispatch identity, result reconstruction, trace order, and deterministic primary
106
+ failure selection. Every member settles before continuation. Arrays, spreads,
107
+ computed keys, methods, accessors, dynamic records, arbitrary promises, reused
108
+ effect roots, and nested groups are outside the portable shape.
109
+
110
+ Separate JavaScript awaits retain ordinary sequential JavaScript behavior. Native
111
+ lowering may still group adjacent eligible effects for performance; that implicit
112
+ grouping is not the portable concurrency contract. General JavaScript target
113
+ availability is owned by the explicit target-support gates.
114
+
115
+ ## Provider-maintainer host bridge
116
+
117
+ `@pulse-compute/runtime/host` is a non-root provider-maintainer subpath. It
118
+ validates managed application exports and executes the same live
119
+ Router implementation through Web `Request`/`Response` boundaries. The root
120
+ runtime export remains unchanged, and application objects still expose no
121
+ `handle`, `bind`, `listen`, or `serve` methods.
122
+
123
+ The host bridge is substrate for provider realizations. It is not a public
124
+ application lifecycle API. Node and Fastly request adapters and provider-owned
125
+ development servers use it under the current four-mode parity and target-support
126
+ gates.
package/docs/API.md ADDED
@@ -0,0 +1,539 @@
1
+ # Pulse runtime contract
2
+
3
+ For source eligibility, use [Managed handler TypeScript and
4
+ JavaScript](https://pulsecompute.io/v1.0.0-beta.1/reference/handler-authoring/). For provider and target
5
+ differences, use the [compatibility
6
+ matrix](https://pulsecompute.io/v1.0.0-beta.1/reference/compatibility-matrix/). For CLI and runtime failures,
7
+ use the stable codes in the [diagnostics
8
+ reference](https://pulsecompute.io/v1.0.0-beta.1/reference/diagnostics/).
9
+
10
+ This document describes the provider-neutral TypeScript application contract compiled by Pulse. Low-level authoring types and the static `Router` come from `@pulse-compute/runtime`. The public `@pulse-compute/pulse` package owns the conventional `Pulse` application root, deferred project configuration, and schema declarations, while `@pulse-compute/cli` owns workspace orchestration.
11
+
12
+ `@pulse-compute/runtime` is the low-level portable application surface and
13
+ `@pulse-compute/pulse` is the conventional project surface. Both belong to the
14
+ 14-package public release catalog. Native and JavaScript execution remain
15
+ explicitly selected targets over the same canonical runtime contract.
16
+
17
+ ## Context at a glance
18
+
19
+ `ctx` is the complete application authority. There is no ambient request,
20
+ process, provider SDK, or global network surface behind it.
21
+
22
+ | Surface | Available in | Purpose |
23
+ |---|---|---|
24
+ | [`ctx.req`](#ctxreq) | HTTP handlers and middleware | Method, URL, path, ordered headers, and bounded body reads. |
25
+ | [`ctx.req.header(name)`](#request-metadata-and-headers) | HTTP handlers and middleware | Case-insensitive first-value header lookup. |
26
+ | [`ctx.param(name)`](#ctxparam) | Matched route handlers | Named parameters from the static route pattern. |
27
+ | [`ctx.state`](#ctxstate) | HTTP and event handlers | Invocation-local string state shared across one execution. |
28
+ | [`ctx.fetch`](#ctxfetch) | HTTP and event handlers | Explicit outbound HTTP effect and structured or opaque response ownership. |
29
+ | [`ctx.parallel`](#ctxparallel) | HTTP and event handlers | Statically keyed concurrent Pulse effects. |
30
+ | [`ctx.emit`](#ctxemit) | HTTP and event handlers | One-way, schema-bound event acceptance effect. |
31
+ | [`ctx.log`](#ctxlog) | HTTP and event handlers | Synchronous thresholded logging. |
32
+ | [`ctx.config`, `ctx.secret`](#config-and-secrets) | HTTP and event handlers | Explicit configured binding reads. |
33
+ | [`ctx.kv(name)`](#kv) | HTTP and event handlers | Bound `get` and `put` storage effects. |
34
+ | [`ctx.json`, `ctx.text`, `ctx.response`](#response-builders) | HTTP handlers and middleware | Synchronous response construction. |
35
+ | `ctx.event` | Event handlers only | Exact event type and immutable validated payload. |
36
+
37
+ ## Handler
38
+
39
+ ```ts
40
+ import type { Handler, PulseContext } from '@pulse-compute/runtime'
41
+
42
+ const handler: Handler = async (ctx: PulseContext) => ctx.json({ ok: true })
43
+ export default handler
44
+ ```
45
+
46
+ Every managed handler is async-shaped:
47
+
48
+ ```ts
49
+ type Handler = (ctx: PulseContext) => Promise<PulseResult | PulseFetchResponse>
50
+ ```
51
+
52
+ For native targets the compiler erases the async wrapper. Awaited Pulse effects lower into the existing explicit effect and continuation state machine; no Promise runtime or Asyncify transform is linked. Awaiting a proven synchronous `ctx` expression is redundant and may warn, while arbitrary non-Pulse awaits mark the native eligibility boundary. The canonical [handler authoring reference](https://pulsecompute.io/v1.0.0-beta.1/reference/handler-authoring/) defines the static language subset; the [compatibility matrix](https://pulsecompute.io/v1.0.0-beta.1/reference/compatibility-matrix/) owns the tested four-mode claims.
53
+
54
+ ## Static `Router`
55
+
56
+ ```ts
57
+ import { Router } from '@pulse-compute/runtime'
58
+
59
+ const api = new Router()
60
+ const app = new Router()
61
+
62
+ api.use(async (ctx, next) => {
63
+ if (ctx.req.header('authorization') === undefined) {
64
+ return ctx.text('Unauthorized', { status: 401 })
65
+ }
66
+ return next()
67
+ })
68
+
69
+ api.get('/health', async (ctx) => ctx.json({ ok: true }))
70
+ api.get('/users/:id', async (ctx, next) => {
71
+ if (ctx.param('id') === '0') return next()
72
+ return ctx.json({ id: ctx.param('id') })
73
+ })
74
+ api.get('/users/:id', async (ctx) => ctx.json({ fallback: ctx.param('id') }))
75
+
76
+ api.error(async (error, ctx, next) => {
77
+ const routedError = error as { code?: string }
78
+ if (routedError.code === 'NOT_FOUND') return ctx.text('Missing', { status: 404 })
79
+ return next(error)
80
+ })
81
+
82
+ app.mount('/api', api)
83
+ export default app
84
+ ```
85
+
86
+ `Router` is a compile-time marker. Canonical v2 supports `get`, `head`, `post`, exact paths, named parameters, a trailing wildcard, static mounts, global/path-scoped/mounted middleware, route fallthrough, and error middleware. `ctx.param(name)` returns the matched named parameter inside route handlers.
87
+
88
+ `next()` is a terminal control transfer. `return next()` advances the normal Router cursor and permanently ends the current handler scope. `return next(error)` enters or advances the error lane. There is no onion-style downstream return or post-`next()` resume. Normal and error exhaustion produce compiler-owned 404 and 500 responses respectively.
89
+
90
+ The flattened execution graph, route table, and entry-owned effects/continuations are reported by `pulse inspect`. See the [routing guide](./guides/routing.md).
91
+
92
+ ## Static event handlers
93
+
94
+ `Pulse.on` declares an exact event entry beside, not inside, Router topology:
95
+
96
+ ```ts
97
+ import { Pulse } from '@pulse-compute/pulse'
98
+
99
+ const app = new Pulse({ auto: true })
100
+
101
+ app.on('device.reading', { schema: 'events.DeviceReading' }, async (ctx) => {
102
+ const mode = await ctx.config.get('MODE')
103
+ ctx.state.set('mode', mode)
104
+ void ctx.event.payload
105
+ })
106
+
107
+ app.on('system.tick', { schema: null }, async (ctx) => {
108
+ void ctx.event.type
109
+ })
110
+ ```
111
+
112
+ The type and schema are literal compiler inputs, every type has one owner, and
113
+ non-null schemas resolve through the project registry. `ctx.event.type` is the
114
+ exact registered type; `ctx.event.payload` is an immutable schema-validated
115
+ value, or `null` for a no-payload registration. Event handlers share state,
116
+ logging, fetch, config, secret, KV, and keyed-parallel authority, but expose no
117
+ request, route, response, middleware, or Router-transfer surface and complete
118
+ with `void`.
119
+
120
+ Eligible handlers lower into plane-neutral application entries and execute
121
+ through the conditional provider-neutral `pulse.native-event-abi.v1`
122
+ extension. Event-only and mixed HTTP/event artifacts are supported, while
123
+ HTTP-only Native output remains byte-identical and has no event ABI. This does
124
+ not by itself activate a provider transport. The Node provider now has an
125
+ invocation-scoped bounded FIFO reference ingress/acceptance adapter for direct
126
+ JavaScript and Native parity evidence; it is not a public event bus or a
127
+ deployment listener.
128
+
129
+ Conventional project harnesses can exercise this reference boundary with an
130
+ explicit `kind: 'event'` case, a canonical input frame, and an ordered exact
131
+ `expect.emitted` frame list. Node JavaScript and Node Native support that test
132
+ workflow. `pulse inspect` and `pulse doctor` report the event catalog,
133
+ registrations, schemas, outbound callsites, host requirements, and selected
134
+ target support; eligible build and compile output includes `event-catalog.json`
135
+ and `event-inspection.json`. Compile-only `none` reports inspection-only
136
+ eligibility. Fastly targets fail closed because no event ingress/emit adapter is
137
+ claimed. There is no public event injection command, no event-aware development
138
+ listener, no HTTP/GRIP translation, and no automatic target fallback.
139
+
140
+ The [static events guide](https://pulsecompute.io/v1.0.0-beta.1/guides/events/) owns the complete frame,
141
+ queue, target-eligibility, diagnostic, and Native-extension contract. The
142
+ source-bound [event example](https://pulsecompute.io/v1.0.0-beta.1/examples/11-events/) runs the same mixed project
143
+ on Node JavaScript and Node Native.
144
+
145
+ ## `ctx.req`
146
+
147
+ ```ts
148
+ interface PulseRequest {
149
+ readonly method: string
150
+ readonly url: string
151
+ readonly path: string
152
+ readonly headers: readonly [string, string][]
153
+ header(name: string): string | undefined
154
+ text(): PulseEffect<string>
155
+ json<T = unknown>(schemaId?: string): PulseEffect<T>
156
+ }
157
+ ```
158
+
159
+ Structured request bodies are bounded runtime-owned snapshots. Repeated `text()` and `json()` reads are memoized immutable transforms.
160
+
161
+ ### Request metadata and headers
162
+
163
+ ```ts
164
+ const requestId = ctx.req.header('x-request-id')
165
+ const authorization = ctx.req.header('Authorization')
166
+ ```
167
+
168
+ `header(name)` compares names case-insensitively, returns the first matching
169
+ value, and returns `undefined` when the header is absent. Use
170
+ `ctx.req.headers` when order or repeated fields matter: it is an immutable,
171
+ ordered array of `[name, value]` pairs and preserves repeated pairs. Pulse does
172
+ not expose an ambient `Request` or mutable `Headers` object to application
173
+ code.
174
+
175
+ `method` is normalized to uppercase, `url` is the complete request URL, and
176
+ `path` is its pathname.
177
+
178
+ When a schema ID is supplied, it must be a literal declared by the selected `.pulse/config.ts` profile:
179
+
180
+ ```ts
181
+ const input = await ctx.req.json<Input>('app.Input')
182
+ ```
183
+
184
+ ## `ctx.param`
185
+
186
+ ```ts
187
+ app.get('/users/:id', async (ctx) => {
188
+ const id = ctx.param('id')
189
+ return id === undefined
190
+ ? ctx.text('missing route parameter', { status: 500 })
191
+ : ctx.json({ id })
192
+ })
193
+ ```
194
+
195
+ `ctx.param(name)` is synchronous and is available only to a matched route
196
+ handler. It returns the decoded value owned by the static route match or
197
+ `undefined` when the named parameter is not present. Middleware and event
198
+ handlers do not receive route-parameter authority.
199
+
200
+ ## `ctx.state`
201
+
202
+ ```ts
203
+ ctx.state.set('request-id', 'r1')
204
+ const requestId = ctx.state.get('request-id') // string | undefined
205
+ ```
206
+
207
+ State is a synchronous, invocation-local string map. One HTTP execution shares
208
+ it across forward middleware, mounted Routers, error recovery, and effect
209
+ continuation resume. An event handler retains its state across continuation
210
+ resume. State is isolated between requests and event invocations; it is not
211
+ durable storage and does not cross an invocation boundary.
212
+
213
+ ## `ctx.fetch`
214
+
215
+ ```ts
216
+ interface PulseFetchInit {
217
+ readonly method?: 'GET' | 'HEAD' | 'POST'
218
+ readonly headers?: Readonly<Record<string, string>> | readonly [string, string][]
219
+ readonly body?: string
220
+ readonly json?: unknown
221
+ readonly timeoutMs?: number
222
+ }
223
+
224
+ ctx.fetch(url: string, init?: PulseFetchInit): PulseFetchOperation
225
+ ```
226
+
227
+ HTTP status is response data. Network and timeout failures are runtime failures.
228
+
229
+ ```ts
230
+ const user = await ctx.fetch('https://api.example.test/user').json<User>('app.User')
231
+ return ctx.json({ found: true, user })
232
+ ```
233
+
234
+ Consecutive independent fetches may lower into a deterministic effect group. Results are presented in declaration order, not host completion order.
235
+
236
+
237
+ ## `ctx.parallel`
238
+
239
+ Use `ctx.parallel({ ... })` to make concurrent Pulse effects an explicit,
240
+ key-preserving cross-target contract:
241
+
242
+ ```ts
243
+ const { user, permissions } = await ctx.parallel({
244
+ user: ctx.fetch('https://api.example.test/user').json<User>(),
245
+ permissions: ctx.fetch('https://api.example.test/permissions').json<Permissions>(),
246
+ })
247
+ ```
248
+
249
+ Its TypeScript result preserves every input key and the independently inferred
250
+ result type of that effect. The initial portable form accepts exactly one nonempty
251
+ inline object literal with fixed identifier or string-literal keys and directly
252
+ recognizable Pulse effects as values. Array-index keys, `__proto__`, arrays,
253
+ spreads, computed keys, shorthand properties, methods, accessors, dynamic records,
254
+ arbitrary promises, reused effect roots, and nested parallel groups are rejected.
255
+
256
+ Source property order defines effect registration, deterministic identity, result
257
+ reconstruction, trace order, and primary-failure ownership. Operations may finish
258
+ in any order, but all settle before the continuation proceeds. When multiple
259
+ members fail, the first failure in property order is primary and bounded keyed
260
+ failure evidence identifies the others.
261
+
262
+ The JavaScript runtime executes every member through one execution-owned shared
263
+ effect adapter. Native lowering erases the call into one canonical effect group
264
+ and reconstructs an ordinary keyed object after one continuation. Separate awaits
265
+ remain sequential in direct JavaScript execution; the Native compiler may still
266
+ implicitly group adjacent eligible effects as a performance optimization.
267
+
268
+ ## `ctx.emit`
269
+
270
+ HTTP and event handlers share a one-way outbound event effect:
271
+
272
+ ```ts
273
+ await ctx.emit('device.led.set', {
274
+ schema: 'events.DeviceLedSet',
275
+ payload: { enabled: true },
276
+ })
277
+
278
+ await ctx.emit('system.tick', { schema: null })
279
+ ```
280
+
281
+ The event type and schema are literal compiler inputs. A non-null schema must
282
+ resolve through the project registry and requires `payload`; `schema: null`
283
+ forbids it. JavaScript and Native runtimes validate and detach the same
284
+ canonical frame before passing it to the execution-owned adapter. Public effect
285
+ evidence redacts the payload.
286
+
287
+ The effect is valid as a fresh member of an awaited `ctx.parallel` group and
288
+ resolves to `undefined` after bounded host acceptance. It does not return a
289
+ delivery receipt, correlation ID, or handler result, and it never invokes a
290
+ matching local event handler. Native lowering uses the ordinary canonical
291
+ effect/continuation protocol and adds no JavaScript or Asyncify imports. The
292
+ invocation-scoped Node reference adapter provides bounded host acceptance and
293
+ exact-frame evidence in JavaScript and Native modes; it provides no delivery,
294
+ retry, persistence, public event bus, or automatic loopback. Other provider
295
+ realizations remain unclaimed.
296
+
297
+ There is no `ctx.call`, `app.call`, generic call effect, request/reply bus, or
298
+ reserved compiler/runtime opcode for reflexive routing. `ctx.emit` cannot
299
+ observe or invoke a local handler. A future call mechanism requires a separate
300
+ host and lifecycle contract.
301
+
302
+ ## `ctx.log`
303
+
304
+ Logging is synchronous, string-only, and provider-neutral:
305
+
306
+ ```ts
307
+ ctx.log.error('failed to publish event')
308
+ ctx.log.warn('retrying origin request')
309
+ ctx.log.info('user created')
310
+ ctx.log.debug('decoded request body')
311
+ ```
312
+
313
+ The fixed levels are `error = 1`, `warn = 2`, `info = 3`, and `debug = 4`.
314
+ `off = 0` is configuration-only. A statement emits when its level is less than
315
+ or equal to the selected profile’s resolved `reporting` level; the default is
316
+ `info`.
317
+
318
+ `ctx.log` is not an effect, continuation, or asynchronous operation. Native
319
+ lowering erases statements disabled by the resolved build threshold. JavaScript
320
+ targets filter at runtime, so a disabled JavaScript call may still evaluate its
321
+ message expression; application-significant side effects do not belong in log
322
+ expressions. Provider formatting and destination are intentionally outside the
323
+ portable contract.
324
+
325
+ Logging failures do not fail the request. Known request secrets pass through the
326
+ same redaction boundary before provider emission and evidence capture. The
327
+ initial contract accepts only strings; structured logging and dynamic level
328
+ registration are not supported.
329
+
330
+ ## Fetch responses
331
+
332
+ Structured responses expose:
333
+
334
+ ```ts
335
+ response.status
336
+ response.ok
337
+ response.headers
338
+ response.header(name)
339
+ response.text()
340
+ response.json<T>(schemaId?)
341
+ ```
342
+
343
+ `response.header(name)` uses the same case-insensitive, first-value lookup as
344
+ `ctx.req.header(name)`. `response.headers` retains immutable ordered pairs when
345
+ repeated response fields must be observed. HTTP status is always response data;
346
+ only transport and timeout failures reject the fetch effect.
347
+
348
+ Opaque responses preserve a host-owned body handle and may be returned directly:
349
+
350
+ <!-- pulse-doc-source: examples/07-opaque-proxy/src/index.ts -->
351
+ ```ts
352
+ import { Pulse } from '@pulse-compute/pulse'
353
+
354
+ const app = new Pulse({ auto: true })
355
+
356
+ app.get('/archive', async (ctx) => {
357
+ return ctx.fetch('https://assets.example.com/archive.bin')
358
+ })
359
+
360
+ export default app
361
+ ```
362
+ <!-- /pulse-doc-source -->
363
+
364
+ Opaque bodies cannot be decoded, copied into Wasm, mutated, iterated, or transformed in user scope.
365
+
366
+ ## Response builders
367
+
368
+ ```ts
369
+ ctx.json(value, options?)
370
+ ctx.text(value, options?)
371
+ ctx.response({ status?, headers?, body? })
372
+ ```
373
+
374
+ JSON responses may use an explicit output schema:
375
+
376
+ ```ts
377
+ return ctx.json(output, {
378
+ status: 201,
379
+ headers: { 'x-schema': 'app.Output' },
380
+ schema: 'app.Output',
381
+ })
382
+ ```
383
+
384
+ ## Config and secrets
385
+
386
+ ```ts
387
+ ctx.config.get(name: string): PulseEffect<string | undefined>
388
+ ctx.secret.get(name: string): PulseEffect<string | undefined>
389
+ ```
390
+
391
+ Reads use exact, provider-injected names. Missing values resolve to `undefined`; Pulse does not enumerate bindings, consult inherited properties, or fall back to `process.env`. Names and returned strings are UTF-8 byte-bounded.
392
+
393
+ Resolved secret values are registered with the execution-owned redaction boundary. Pulse removes known secret substrings and sensitive fields from its own observations, traces, diagnostics, and managed errors. This is not taint tracking: application responses are never silently rewritten, and ordinary config values are not automatically treated as secrets.
394
+
395
+ ## KV
396
+
397
+ ```ts
398
+ const sessions = ctx.kv<Session>('sessions')
399
+ const value = await sessions.get('current')
400
+ if (value !== undefined) await sessions.put('last', value)
401
+ ```
402
+
403
+ The Beta supports `get` and `put`. Store names and keys are
404
+ provider-neutral logical bindings. Values are bounded, detached, deeply frozen
405
+ JSON-compatible trees; accessors, symbols, sparse arrays, repeated references,
406
+ cycles, class instances, nonfinite numbers, and nested `undefined` are rejected.
407
+ `put` resolves to an explicit boolean acknowledgement. Durability, consistency,
408
+ and cross-request lifetime remain provider capabilities rather than properties
409
+ of the common API.
410
+
411
+ ## Explicit JSON schemas
412
+
413
+ <!-- pulse-doc-source: examples/02-request-schema/.pulse/config.ts -->
414
+ ```ts
415
+ import { defineConfig } from '@pulse-compute/pulse'
416
+
417
+ export default defineConfig((_scope) => ({
418
+ pulse: {
419
+ entry: 'src/index.ts',
420
+ schema: 'src/schemas.ts',
421
+ tests: 'tests/pulse.harness.ts',
422
+ defaultProfile: 'local',
423
+ strict: true,
424
+ },
425
+ local: {
426
+ host: 'node',
427
+ target: 'native',
428
+ outDir: 'dist',
429
+ schemas: { contentTypePolicy: 'require-json', maxBytes: 1024 },
430
+ },
431
+ }))
432
+ ```
433
+ <!-- /pulse-doc-source -->
434
+
435
+ Pulse compiles declared TypeScript interfaces and type aliases into a registry and direct codecs. It does not discover arbitrary types automatically.
436
+
437
+ ## GRIP
438
+
439
+ The canonical GRIP application surface is the package root:
440
+
441
+ ```ts
442
+ import { grip } from '@pulse-compute/grip'
443
+ ```
444
+
445
+ Pure request classification and response framing use `grip.isWebSocket`,
446
+ `grip.subscribe`, and `grip.handoff`. Configured outbound work is the
447
+ request-bound `await grip.broadcast(ctx, message)` effect. Supported Native
448
+ forms lower into canonical package operations; JavaScript targets execute the
449
+ real package implementation.
450
+
451
+ Older `/pulsewasm` imports are compatibility-only and are isolated in the
452
+ [migration guide](https://pulsecompute.io/v1.0.0-beta.1/guides/compatibility-imports/). See the
453
+ [GRIP package guide](https://pulsecompute.io/v1.0.0-beta.1/packages/grip/) for the complete current surface.
454
+
455
+ ## Entities API
456
+
457
+ `@pulse-compute/entities` is part of the synchronized `1.0.0-beta.1` package
458
+ set. The application surface has two runtime values:
459
+
460
+ ```ts
461
+ import { EntityRouter, jsonRpc } from '@pulse-compute/entities'
462
+
463
+ const rpc = new EntityRouter({ adapter: jsonRpc({ namedParamsOnly: true }) })
464
+
465
+ rpc.on('customer.lookup', {
466
+ input: 'tools.CustomerLookupInput',
467
+ output: 'tools.CustomerLookupOutput',
468
+ }, lookupCustomer)
469
+
470
+ export default function handler(ctx: unknown) {
471
+ return rpc.handle(ctx as never)
472
+ }
473
+ ```
474
+
475
+ ```ts
476
+ interface EntityRouterOptions {
477
+ readonly adapter: JsonRpcAdapter
478
+ }
479
+
480
+ interface EntityDeclaration {
481
+ readonly input: string | null
482
+ readonly output: string | null
483
+ readonly metadata?: StaticEntityMetadata
484
+ }
485
+
486
+ type EntityHandler<Input, Output> = (
487
+ ctx: PulseContext,
488
+ input: DeepReadonly<Input>,
489
+ ) => Output | Promise<Output>
490
+
491
+ class EntityRouter {
492
+ constructor(options: EntityRouterOptions)
493
+ on<Input, Output>(
494
+ discriminator: string,
495
+ declaration: EntityDeclaration,
496
+ handler: EntityHandler<Input, Output>,
497
+ ): this
498
+ handle(ctx: PulseContext): Promise<Response>
499
+ }
500
+
501
+ interface JsonRpcOptions {
502
+ readonly namedParamsOnly?: true
503
+ readonly acceptEmptyObjectForNoInput?: boolean
504
+ }
505
+
506
+ function jsonRpc(options?: JsonRpcOptions): JsonRpcAdapter
507
+ ```
508
+
509
+ `StaticJsonPrimitive`, `StaticJsonValue`, `StaticJsonObject`,
510
+ `StaticEntityMetadata`, `EntitySchemaId`, `DeepReadonly`,
511
+ `EntityHandlerResult`, `EntityAdapter`, and `JsonRpcAdapter` are also exported
512
+ as types. The package exposes no public runtime registry, schema codecs, raw
513
+ JSON access, provider objects, or third-party adapter registration.
514
+
515
+ Registrations and the terminal binding must use the supported static form. The
516
+ first-party JSON-RPC adapter accepts bounded JSON-RPC 2.0 request objects and
517
+ named params, validates declared schemas, uses stable error framing, and
518
+ acknowledges notifications with HTTP `204`. See the [package
519
+ guide](https://pulsecompute.io/v1.0.0-beta.1/packages/entities/), [entity/adapter
520
+ model](https://pulsecompute.io/v1.0.0-beta.1/concepts/entities-and-adapters/), and [executable
521
+ example](https://pulsecompute.io/v1.0.0-beta.1/examples/10-entities-tools/).
522
+
523
+ ## Project workflow
524
+
525
+ ```text
526
+ pulse init
527
+ pulse doctor
528
+ pulse test
529
+ pulse dev
530
+ pulse build
531
+ ```
532
+
533
+ These normal lifecycle commands resolve the same authoritative workspace,
534
+ selected profile, handler entry, schema declarations, provider bindings, and
535
+ output directory through `.pulse/config.ts`. `pulse inspect` is optional
536
+ observability, and `pulse compile` is the advanced provider-neutral Native
537
+ artifact command; neither is required before `pulse build`. See the [project
538
+ lifecycle guide](https://pulsecompute.io/v1.0.0-beta.1/guides/project-lifecycle/) and [CLI
539
+ reference](https://pulsecompute.io/v1.0.0-beta.1/reference/cli/).