Skip to content

Commit d1fb83d

Browse files
committed
docs: add helpers, utilities, and services reference pages
1 parent f1bd9b8 commit d1fb83d

5 files changed

Lines changed: 147 additions & 1 deletion

File tree

docs/content/1.guide/19.services.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ description: 'ctx.services lets one devframe expose a typed, namespaced capabili
77

88
`ctx.services` lets one devframe expose a typed, namespaced capability visible to every devframe. Two tiers: in-process services (`provide`/`get`) share live objects between devframes; [wire services](#wire-services) also register RPC and advertise to RPC clients.
99

10+
The [Services reference](/references/services) collects the host methods, the definition/descriptor fields, and the built-in services as lookup tables.
11+
1012
## Providing a service
1113

1214
Augment `DevframeServicesRegistry` with your id and type, then provide in setup:

docs/content/4.helpers/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ Helpers are the optional layer around `defineDevframe`: prebuilt RPC recipes and
1515

1616
Unlike [adapters](/adapters), which deploy a `DevframeDefinition` as a runnable deployment (CLI, dev server, build, MCP), a helper is a recipe or utility composed with one.
1717

18+
For the full lookup tables — every `devframe/utils/*` subpath and `devframe/recipes/*` recipe at a glance — see [Helpers & Utilities](/references/helpers) in the references.
19+
1820
To integrate a devframe or hub with a meta-framework, see the [framework kits](/frameworks).
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: 'Helpers & Utilities'
3+
navigation:
4+
icon: i-lucide-wrench
5+
description: 'Lookup tables for the optional layer around defineDevframe: every devframe/utils/*subpath and every devframe/recipes/* recipe, with its entry and role.'
6+
---
7+
8+
Lookup tables for the optional layer around `defineDevframe` — the bundled utilities and prebuilt recipes of the `devframe` package. Each section links the [Helpers](/helpers) guide page that teaches it.
9+
10+
## Utilities
11+
12+
The subpaths under `devframe/utils/*` — stable wrappers bundled in, no extra `npm install`. [Utilities](/helpers/utilities).
13+
14+
| Subpath | Primary export | Role |
15+
|---------|----------------|------|
16+
| `devframe/utils/colors` | `colors` | Terminal ANSI colors (`green`, `cyan`, `bold`, `dim`, …), callable and tagged-template. |
17+
| `devframe/utils/open` | `open` | Open a URL, file, or target in the OS handler. |
18+
| `devframe/utils/launch-editor` | `launchEditor` | Open a file at `file`/`file:line`/`file:line:column` in the editor. |
19+
| `devframe/utils/hash` | `hash` | Deterministic hash of any structured-cloneable value. |
20+
| `devframe/utils/structured-clone` | `structuredCloneSerialize`, `structuredCloneStringify`, `structuredCloneParse`, `structuredCloneDeserialize` | JSON-safe structured-clone round-trip (`Map`, `Set`, `Date`, `BigInt`, cycles, class instances). |
21+
| `devframe/utils/nanoid` | `nanoid` | URL-safe random ID generator (vendored, zero-dep). |
22+
| `devframe/utils/crypto-token` | `randomToken`, `randomDigits`, `timingSafeEqual` | WebCrypto token, digit-code, and constant-time comparison helpers. |
23+
| `devframe/utils/events` | `createEventEmitter` | Typed event emitter. |
24+
| `devframe/utils/shared-state` | `createSharedState` | The immutable state container behind `ctx.rpc.sharedState` — see [Shared State](/guide/shared-state). |
25+
| `devframe/utils/streaming-channel` | sink/reader primitives | Streamed RPC payloads via `ctx.rpc.streaming` — see [Streaming](/guide/streaming). |
26+
| `devframe/utils/when` | `evaluateWhen`, `resolveContextValue` | Statically-validated when-clause expressions — see [When Clauses](/references/when-clauses). |
27+
| `devframe/utils/simple-schema` | `string`, `number`, `boolean`, `union`, `picklist`, `literal`, `record`, … | Zero-dep [Standard Schema](https://standardschema.dev/) builder for `args`/`returns`/flags. |
28+
| `devframe/utils/nostics` | `defineDiagnostics`, `Diagnostic` | Structured diagnostics pre-wired with devframe's console reporter — see [Diagnostics](/guide/diagnostics). |
29+
| `devframe/utils/get-port` | `getPort` | Resolve an open port (re-export of `get-port-please`). |
30+
| `devframe/utils/serve-static` | `serveStaticHandler`, `mountStaticHandler`, `serveStaticNodeMiddleware` | Serve a built SPA or `RemoteAssetsStore` over HTTP. |
31+
| `devframe/utils/remote-assets` | `resolveStaticAssetsSource` | Resolve a `RemoteAssets` source (local dir, cache, CDN) — see [Remote assets](/guide/client-assets#remote-assets). |
32+
| `devframe/utils/agent-tool-name` | `toAgentToolName` | Map an RPC id to its agent-facing tool name — see [Agent-Native Devframe](/guide/agent-native). |
33+
34+
## Recipes
35+
36+
The prebuilt RPC recipes under `devframe/recipes/*` — composed with a `DevframeDefinition`, not deployed like an [adapter](/adapters).
37+
38+
| Subpath | Entry | Role |
39+
|---------|-------|------|
40+
| `devframe/recipes/common-rpc-functions` | `commonRpcFunctions`, `openInEditor`, `openInFinder` | "Open in editor" / "reveal in Finder" RPC actions — see [Common RPC Functions](/helpers/common-rpc-functions). Superseded by the [`@devframes/service-open`](/references/services#built-in-services) wire service. |
41+
| `devframe/recipes/interactive-auth` | `createInteractiveAuth` | OTP auth layer over the node-side auth primitives: handshake, resolver gate, connect-time trust, banner — see [Interactive Auth](/helpers/interactive-auth). |
42+
43+
### `commonRpcFunctions` exports
44+
45+
The RPC functions the common-rpc-functions recipe registers — [Common RPC Functions](/helpers/common-rpc-functions).
46+
47+
| Export | Registered name | Type | Args |
48+
|--------|------------------|------|------|
49+
| `openInEditor` | `devframe:open-in-editor` | `action` | `[filename: string, editor?: KnownEditor]` |
50+
| `openInFinder` | `devframe:open-in-finder` | `action` | `[path: string]` |
51+
| `commonRpcFunctions` || array | `readonly [openInEditor, openInFinder]` — batch registration. |
52+
| `KNOWN_EDITORS` / `KnownEditor` || value / type | Accepted editor commands and their union type. |
53+
54+
### `createInteractiveAuth` handler
55+
56+
The `DevframeAuthHandler` returned by `createInteractiveAuth(context, options?)`[Interactive Auth](/helpers/interactive-auth).
57+
58+
| Field | Role |
59+
|-------|------|
60+
| `rpcFunctions` | `anonymous:devframe:auth` + `anonymous:devframe:auth:exchange` (handshake), `devframe:auth:revoke` (self-revoke). |
61+
| `authorize(methodName, session)` | Resolver gate: allows `anonymous:` methods, else requires `session.meta.isTrusted`. |
62+
| `onConnect(peer, session)` | Connect-time trust from a bearer on the WS upgrade URL (`?devframe_auth_token=`). |
63+
| `printBanner()` | Prints the one-time code and magic-link URL. |
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: 'Services'
3+
navigation:
4+
icon: i-lucide-share-2
5+
description: 'Lookup tables for ctx.services: the DevframeServicesHost methods, the wire-service definition and descriptor fields, the advertised meta shape, and the first-party built-in services.'
6+
---
7+
8+
Lookup tables for `ctx.services`, the cross-devframe capability registry. Each section links the [Cross-Devframe Services](/guide/services) guide that teaches it.
9+
10+
## `DevframeServicesHost`
11+
12+
The methods on `ctx.services`[Cross-Devframe Services](/guide/services#the-devframeserviceshost-api).
13+
14+
| Method | Signature | Role |
15+
|--------|-----------|------|
16+
| `provide` | `(id, service) => revoke` | Publish an in-process service under a namespaced id. Throws [`DF0037`](/errors/DF0037) if the id is taken. |
17+
| `get` | `(id) => service \| undefined` | The service currently provided under `id` (augmented type, else `unknown`). |
18+
| `has` | `(id) => boolean` | Whether a service is provided under `id`. |
19+
| `whenAvailable` | `(id, cb) => unsubscribe` | Run `cb` as soon as the service exists — now if provided, else on `provide` — and re-fire on revoke/re-provide. |
20+
| `keys` | `() => string[]` | Ids of every currently-provided service. |
21+
| `install` | `(input, options?) => Promise<api \| undefined>` | Install a [wire service](#wire-service-definition-fields) at runtime (the dynamic escape hatch; the common path is declarative). `options.resolveFrom` is the descriptor's resolution base. |
22+
| `ready` | `() => Promise<void>` | **Internal.** Construct every queued wire service before any `setup` runs. Adapters call it; application code uses declarative `services`. |
23+
24+
## Service tiers
25+
26+
The two tiers a service can take — [Cross-Devframe Services](/guide/services).
27+
28+
| Tier | Shared how | Registers RPC | Advertised to clients |
29+
|------|-----------|---------------|-----------------------|
30+
| In-process service (`provide`/`get`) | live object, node side only | No | No |
31+
| [Wire service](/guide/services#wire-services) (`install` / declarative `services`) | npm package, node API + RPC | Yes, under its `scope` | Yes, via `devframe:services` shared state |
32+
33+
## Wire-service definition fields
34+
35+
The fields of a `DevframeServiceDefinition` returned by a service package's `create<X>Service` factory — [Shipping a wire service](/guide/services#shipping-one).
36+
37+
| Field | Type | Description |
38+
|-------|------|-------------|
39+
| `package` | `string` | **Required.** npm package name — also its registry key (`ctx.services.has(pkg)`). |
40+
| `version` | `string` | **Required.** Semver; advertised to clients, checked against declared ranges. |
41+
| `scope` | `string` | **Required.** RPC namespace its functions register under (e.g. `devframes:service:open`); `setup` gets a context pre-scoped to it. |
42+
| `meta` | `Record<string, unknown>` | Extra advertised metadata (feature flags, defaults). Must be JSON-serializable. |
43+
| `options` | `Options` | This instance's own option set, baked in by its factory; joins the merge. |
44+
| `mergeOptions` | `(sets: Options[]) => Options` | Merge multiple installers' option sets. Default: shallow, later wins. |
45+
| `setup` | `(ctx, info) => api` | **Required.** Register RPC on the pre-scoped context; return the node API served from `ctx.services.get(package)`. |
46+
47+
## Wire-service descriptor fields
48+
49+
The declarative reference form on `DevframeDefinition.services` / `initHub({ services })`[Declaring services](/guide/services#declaring).
50+
51+
| Field | Type | Description |
52+
|-------|------|-------------|
53+
| `package` | `string` | **Required.** npm package name; its default export is the factory the host imports. |
54+
| `version` | `string` | Accepted semver range. Unsatisfied warns ([`DF0069`](/errors/DF0069)), or throws ([`DF0068`](/errors/DF0068)) when `required`. |
55+
| `required` | `boolean` | Fail hard on a missing package ([`DF0067`](/errors/DF0067)) or unsatisfied range. Default `false` — a missing service is skipped and clients see `has() === false`. |
56+
| `options` | `Options` | Option set this installer contributes to the merge. |
57+
58+
## Advertised service meta
59+
60+
Each installed service's entry in the `devframe:services` [shared state](/guide/shared-state), mirrored to RPC clients as `rpc.services`[Feature-detecting on the RPC client](/guide/services#feature-detecting-on-the-rpc-client).
61+
62+
| Field | Description |
63+
|-------|-------------|
64+
| `package` | npm package name — the registry key. |
65+
| `version` | Installed version of the service. |
66+
| `scope` | RPC namespace its functions live under. |
67+
| `meta` | Extra service-declared metadata. |
68+
69+
## Built-in services
70+
71+
The first-party wire services (`@devframes/service-*`), each installed once per host and consumed by any devframe or RPC client — [Built-in services](/guide/services#built-in-services).
72+
73+
| Package | Scope | RPC functions | Options |
74+
|---------|-------|---------------|---------|
75+
| `@devframes/service-open` | `devframes:service:open` | `open-in-editor`, `open-in-finder` | `{ editor?, roots? }` — later wins; `roots` union-merged. Refuses paths outside the workspace root plus `roots`, gates editors to `KNOWN_EDITORS`. |
76+
| `@devframes/service-git` | `devframes:service:git` | `status`, `log`, `show`, `readFile`, `diff`, `branches`, `tags`, `stage`, `unstage`, `commit` | `{ cwd? }` — one repo fixed at install. Write ops are exposed; authorization is the host framework's boundary. |
77+
| `@devframes/service-shiki` | `devframes:service:shiki` | `highlight`, `code-to-hast`, `code-to-tokens` | `{ themes?, langs? }` — light/dark pair (defaults `vitesse-light`/`vitesse-dark`, later wins) and preloaded languages (union-merged). Queries are client-`cacheable`, LRU-cached per `(code, lang, themes)`. |

docs/content/8.references/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 'References'
33
navigation:
44
icon: i-lucide-book-marked
5-
description: 'Lookup pages the guides link into: the canonical terms, the when-clause contexts, every event name on the wire, and the API tables for the node side, the browser side, and the hub.'
5+
description: 'Lookup pages the guides link into: the canonical terms, the when-clause contexts, every event name on the wire, the API tables for the node side, the browser side, and the hub, and the helpers, utilities, and services surfaces.'
66
---
77

88
Lookup pages the guides link into:
@@ -13,5 +13,7 @@ Lookup pages the guides link into:
1313
- [Node-Side API](/references/node-api)`DevframeDefinition` fields, CLI options, storage scopes, RPC function types, broadcast options, streaming lifecycle, remote assets, diagnostics prefixes, and the auth surface.
1414
- [Browser-Side API](/references/browser-api)`connectDevframe` options, RPC client events, connection statuses, and in-page channel error codes.
1515
- [Hub API](/references/hub-api) — hub subsystems, launcher fields, duplication strategies, dock categories, the hub UI protocol, the namespace routes, the client runtime, the client context, and dock entry types.
16+
- [Helpers & Utilities](/references/helpers) — every `devframe/utils/*` subpath and every `devframe/recipes/*` recipe, with its entry and role.
17+
- [Services](/references/services) — the `DevframeServicesHost` methods, the wire-service definition and descriptor fields, the advertised meta shape, and the built-in services.
1618

1719
The [error reference](/errors) documents each `DF*` diagnostic code, and [migrations](/migrations) each version step. The adapter, framework-kit, helper, and built-in-devframe pages each carry their own package's options and RPC tables.

0 commit comments

Comments
 (0)