Skip to content

Commit 0458941

Browse files
antfubotopencode
andcommitted
refactor(devframe)!: move remaining low-level node exports to devframe/internal
Reduce the public `devframe/node` barrel to the server-assembly surface only (`createHostContext`, `createH3DevframeHost`, `startHttpAndWs`, `createStorage`, `RpcFunctionsHost`). Relocate the low-level primitives that only first-party integrations use to the unstable `devframe/internal` surface: - the instance registry (`registerDevframeInstance` / `listLiveDevframeInstances` + `DevframeInstanceRecord` / `DevframeInstanceRegistration`) - `isObject`, `normalizeHttpServerUrl` `startHttpAndWs` stays on `devframe/node` — it's the primary programmatic server entry (used as real code by several plugins, examples, and the hub), not a low-level util. The inspect plugin and the hub host examples now import the instance registry from `devframe/internal`; `@vitejs/devtools` picks up `isObject`/`normalizeHttpServerUrl` from there too. Co-authored-by: opencode <noreply@opencode.ai>
1 parent b44ac51 commit 0458941

12 files changed

Lines changed: 83 additions & 72 deletions

File tree

‎docs/guide/migration-0.9.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ The other `devframe/utils/*` helpers — `colors`, `open`, `launch-editor`, `has
127127

128128
## `devframe/node` is slimmed to the server-assembly surface
129129

130-
`devframe/node` keeps the API that hosts wiring up their own runtime actually use — `createHostContext`, `createH3DevframeHost`, `startHttpAndWs`, `createStorage`, `registerDevframeInstance` / `listLiveDevframeInstances`, `isObject`, `normalizeHttpServerUrl`, and the `RpcFunctionsHost` / instance-record types.
130+
`devframe/node` keeps the server-assembly API hosts actually use — `createHostContext`, `createH3DevframeHost`, `startHttpAndWs` (+ `StartedServer`), `createStorage`, and the `RpcFunctionsHost` type.
131131

132132
The internal host implementations and low-level factories are no longer exported:
133133

@@ -140,15 +140,17 @@ The internal host implementations and low-level factories are no longer exported
140140

141141
## Cross-package internals move to `devframe/internal`
142142

143-
The low-level primitives that only exist for the `devframe` ↔ `@devframes/hub` boundary now live at the new `devframe/internal` entry point, which is explicitly **unstable** (it can change in any minor release). They were previously on `devframe/node`:
143+
The low-level primitives shared between `devframe` and its first-party integrations (`@devframes/hub`, the inspect plugin, `@vitejs/devtools`, custom hosts) now live at the new `devframe/internal` entry point, which is explicitly **unstable** (it can change in any minor release). They were previously on `devframe/node`:
144144

145145
| Moved | From | To |
146146
|---|---|---|
147147
| `createContextRpcServer` (+ `ContextRpcServer`, `CreateContextRpcServerOptions`) | `devframe/node` | `devframe/internal` |
148148
| `DevframeAgentHost` (class) | `devframe/node` | `devframe/internal` |
149149
| `coerceAgentPositionalArgs` (+ `AgentArgsFallback`) | `devframe/node` | `devframe/internal` |
150+
| `registerDevframeInstance` / `listLiveDevframeInstances` (+ `DevframeInstanceRecord`, `DevframeInstanceRegistration`) | `devframe/node` | `devframe/internal` |
151+
| `isObject`, `normalizeHttpServerUrl` | `devframe/node` | `devframe/internal` |
150152

151-
A host that binds its own transport composes from `createContextRpcServer` (`devframe/internal`) plus `devframe/rpc/server`, `devframe/rpc/transports/*`, and `devframe/node/hub-internals` — the path `@devframes/hub`'s `initHub` takes. Application code should prefer the adapters and `devframe/node`.
153+
A host that binds its own transport composes from `createContextRpcServer` (`devframe/internal`) plus `devframe/rpc/server`, `devframe/rpc/transports/*`, and `devframe/node/hub-internals` — the path `@devframes/hub`'s `initHub` takes. A custom host advertises itself with `registerDevframeInstance`, and a devtool enumerates running instances with `listLiveDevframeInstances`. Application code should prefer the adapters and `devframe/node`.
152154

153155
## `@devframes/hub` category order lives only on `/constants`
154156

‎examples/a11y-messages-playground/src/a11y-messages-playground.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { DevframeHubContext } from '@devframes/hub/node'
22
import type { ClientScriptEntry } from '@devframes/hub/types'
33
import type { DevframeDefinition, DevframeHost } from 'devframe'
4-
import type { DevframeInstanceRegistration } from 'devframe/node'
4+
import type { DevframeInstanceRegistration } from 'devframe/internal'
55
import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
66
import { homedir } from 'node:os'
77
import process from 'node:process'
88
import { createHubContext, mountDevframe } from '@devframes/hub/node'
99
import { DEVFRAME_CONNECTION_META_FILENAME } from 'devframe/constants'
10-
import { registerDevframeInstance, startHttpAndWs } from 'devframe/node'
10+
import { registerDevframeInstance } from 'devframe/internal'
11+
import { startHttpAndWs } from 'devframe/node'
1112
import { serveStaticNodeMiddleware } from 'devframe/utils/serve-static'
1213
import { getPort } from 'get-port-please'
1314
import { join } from 'pathe'

‎examples/hub-next/src/client/devframe/next-devframe-hub.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { HubDevframeEntry, HubInstance } from '@devframes/hub/initiate'
22
import type { DevframeHubContext } from '@devframes/hub/node'
33
import type { DevframeDefinition } from 'devframe'
4-
import type { DevframeInstanceRegistration } from 'devframe/node'
4+
import type { DevframeInstanceRegistration } from 'devframe/internal'
55
import { homedir } from 'node:os'
66
import process from 'node:process'
77
import { fileURLToPath } from 'node:url'
88
import { defineHubRpcFunction } from '@devframes/hub'
99
import { DEVFRAMES_HUB_BASE, initHub } from '@devframes/hub/initiate'
1010
import { toJsonRenderDockEntry } from '@devframes/json-render/hub'
11-
import { registerDevframeInstance } from 'devframe/node'
11+
import { registerDevframeInstance } from 'devframe/internal'
1212
import { createDashboardView } from 'json-render/dashboard'
1313
import { dirname, join } from 'pathe'
1414
import demoDevframe from './demo-devframe'

‎examples/hub-vite/src/vite-devframe-hub.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import type { HubDevframeEntry, HubInstance } from '@devframes/hub/initiate'
22
import type { DevframeHubContext } from '@devframes/hub/node'
33
import type { ClientScriptEntry } from '@devframes/hub/types'
44
import type { DevframeDefinition } from 'devframe'
5-
import type { DevframeInstanceRegistration } from 'devframe/node'
5+
import type { DevframeInstanceRegistration } from 'devframe/internal'
66
import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
77
import { Server as NodeHttpServer } from 'node:http'
88
import { homedir } from 'node:os'
99
import process from 'node:process'
1010
import { defineHubRpcFunction } from '@devframes/hub'
1111
import { DEVFRAMES_HUB_BASE, initHub } from '@devframes/hub/initiate'
12-
import { registerDevframeInstance } from 'devframe/node'
12+
import { registerDevframeInstance } from 'devframe/internal'
1313
import { join } from 'pathe'
1414

1515
export interface ViteDevframeHubOptions {
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Internal cross-package surface: low-level host primitives shared between
2-
// `devframe` and `@devframes/hub` (and any first-party host built on the same
3-
// wiring). These are NOT part of the stable public API — they can change in any
4-
// minor release. Application code should use `devframe/node` and the adapters
5-
// instead.
1+
// Internal cross-package surface: low-level primitives shared between
2+
// `devframe` and its first-party integrations (`@devframes/hub`, the inspect
3+
// plugin, `@vitejs/devtools`, custom hosts). These are NOT part of the stable
4+
// public API — they can change in any minor release. Application code should
5+
// use `devframe/node` and the adapters instead.
66
//
77
// - `createContextRpcServer` — the transport-agnostic RPC core; a host that
88
// binds its own transport (e.g. the hub's `initHub`) reuses the exact
@@ -11,8 +11,16 @@
1111
// its own commands host.
1212
// - `coerceAgentPositionalArgs` — positional-arg coercion the hub applies when
1313
// invoking agent tools as commands.
14+
// - `registerDevframeInstance` / `listLiveDevframeInstances` — the instance
15+
// registry: a custom host advertises itself; a devtool (the inspect plugin's
16+
// Instances tab, the connector) enumerates what's running.
17+
// - `isObject` / `normalizeHttpServerUrl` — small host-side helpers a
18+
// hand-rolled host reuses to match devframe's own config/URL handling.
1419
export { coerceAgentPositionalArgs } from '../node/agent-args'
1520
export type { AgentArgsFallback } from '../node/agent-args'
1621
export { DevframeAgentHost } from '../node/host-agent'
22+
export { listLiveDevframeInstances, registerDevframeInstance } from '../node/instance-registry'
23+
export type { DevframeInstanceRecord, DevframeInstanceRegistration } from '../node/instance-registry'
1724
export { createContextRpcServer } from '../node/rpc-core'
1825
export type { ContextRpcServer, CreateContextRpcServerOptions } from '../node/rpc-core'
26+
export { isObject, normalizeHttpServerUrl } from '../node/utils'
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
// Node-side public API for hosts that wire up their own runtime — the
2-
// server-assembly surface (`createHostContext` → `startHttpAndWs`), the
3-
// instance registry, storage, and the two URL/host helpers consumers use.
2+
// server-assembly surface (`createHostContext` → `createH3DevframeHost` →
3+
// `startHttpAndWs`) and storage.
44
//
5-
// The diagnostics/services/views hosts, the streaming/shared-state/scope/
6-
// settings factories, and the internal host helpers (`toDialableHost`,
7-
// `formatHostForUrl`) stay internal. `toAgentToolName` lives at
8-
// `devframe/utils/agent-tool-name` (a client-safe string transform).
9-
//
10-
// The low-level primitives shared only between `devframe` and `@devframes/hub`
11-
// — `createContextRpcServer`, `DevframeAgentHost`, `coerceAgentPositionalArgs`
12-
// — live at `devframe/internal` (an explicitly-unstable cross-package surface),
13-
// not here.
5+
// Everything lower-level lives at `devframe/internal` (an explicitly-unstable
6+
// cross-package surface): the transport-agnostic RPC core, the agent host, the
7+
// instance registry (host self-registration + live discovery), and the
8+
// `isObject` / `normalizeHttpServerUrl` helpers. The diagnostics/services/views
9+
// hosts, the streaming/shared-state/scope/settings factories, and the internal
10+
// host-URL helpers stay fully internal (relative imports only).
11+
// `toAgentToolName` lives at `devframe/utils/agent-tool-name`.
1412
export * from './context'
1513
// `RpcFunctionsHostImpl` stays internal; expose only the structural
1614
// `RpcFunctionsHost` type so consumers can type/cast `ctx.rpc` without
1715
// pulling in the implementation's `@internal` members.
1816
export type { RpcFunctionsHost } from './host-functions'
1917
export * from './host-h3'
20-
// Registration is public — custom hosts (e.g. @devframes/next) record
21-
// themselves — and live discovery is public too, so surfaces like the
22-
// inspect plugin's Instances tab can enumerate running instances. The
23-
// lower-level read/probe/prune helpers stay internal to the connector.
24-
export { listLiveDevframeInstances, registerDevframeInstance } from './instance-registry'
25-
export type { DevframeInstanceRecord, DevframeInstanceRegistration } from './instance-registry'
2618
export * from './server'
2719
export * from './storage'
28-
export { isObject, normalizeHttpServerUrl } from './utils'

‎plans/032-0.9-public-api-surface-reduction.md‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,18 @@ Net effect (after maintainer follow-ups):
9595
- Dead-subpath removals are `utils/promise` and `utils/scope` only. `ws-bun` is
9696
kept (hub uses it); `utils/hash` is kept (maintainer request); `embedded` is
9797
kept (maintainer request — a named, discoverable adapter).
98-
- The `devframe/node` trim drops **12** exports again — but the three
99-
hub-only low-level APIs (`createContextRpcServer`, `DevframeAgentHost`,
100-
`coerceAgentPositionalArgs`) are **relocated** to a new **`devframe/internal`**
101-
entry (an explicitly-unstable cross-package surface) rather than kept on the
102-
public `devframe/node`, and the hub imports them from there. The other 9 stay
103-
fully internal (relative imports only).
98+
- The public `devframe/node` barrel is reduced to the server-assembly surface
99+
only: `createHostContext`, `createH3DevframeHost`, `startHttpAndWs`
100+
(+ `StartedServer`), `createStorage`, and the `RpcFunctionsHost` type.
101+
- A new **`devframe/internal`** entry (an explicitly-unstable cross-package
102+
surface) holds the low-level primitives first-party integrations need:
103+
`createContextRpcServer`, `DevframeAgentHost`, `coerceAgentPositionalArgs`,
104+
the instance registry (`registerDevframeInstance` / `listLiveDevframeInstances`
105+
+ types), and `isObject` / `normalizeHttpServerUrl`. The hub, the inspect
106+
plugin, and the host examples import from there. The remaining node internals
107+
(diagnostics/services/views hosts, the streaming/shared-state/scope/settings
108+
factories, `toDialableHost`/`formatHostForUrl`) stay fully internal (relative
109+
imports only).
104110

105111
### ⚠️ One item to confirm during review
106112

‎plugins/inspect/src/rpc/functions/list-instances.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DevframeInspectInstanceInfo } from '../../types'
22
import process from 'node:process'
3-
import { listLiveDevframeInstances } from 'devframe/node'
3+
import { listLiveDevframeInstances } from 'devframe/internal'
44
import { defineInspectRpc } from './_define'
55

66
/**

‎tests/__snapshots__/tsnapi/devframe/internal.snapshot.d.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
/**
22
* Generated by tsnapi — public API snapshot of `devframe/internal`
33
*/
4+
// #region Interfaces
5+
export interface DevframeInstanceRecord {
6+
pid: number;
7+
port: number;
8+
origin: string;
9+
basePath: string;
10+
id: string;
11+
name?: string;
12+
rootDir: string;
13+
mcp: {
14+
path: string;
15+
} | null;
16+
startedAt: number;
17+
}
18+
export interface DevframeInstanceRegistration {
19+
readonly file: string;
20+
unregister: () => void;
21+
}
22+
// #endregion
23+
424
// #region Types
525
export type AgentArgsFallback = 'wrap' | 'drop';
626
// #endregion
@@ -35,6 +55,18 @@ export declare class DevframeAgentHost implements DevframeAgentHost$1 {
3555

3656
// #region Functions
3757
export declare function coerceAgentPositionalArgs(_: unknown, _: readonly unknown[] | undefined, _?: AgentArgsFallback): unknown[];
58+
export declare function isObject(_: unknown): value is Record<string, any>;
59+
export declare function listLiveDevframeInstances(_?: {
60+
instancesDir?: string;
61+
timeoutMs?: number;
62+
}): Promise<{
63+
live: DevframeInstanceRecord[];
64+
pruned: DevframeInstanceRecord[];
65+
}>;
66+
export declare function normalizeHttpServerUrl(_: string, _: number | string): string;
67+
export declare function registerDevframeInstance(_: DevframeInstanceRecord, _?: {
68+
instancesDir?: string;
69+
}): DevframeInstanceRegistration;
3870
// #endregion
3971

4072
// #region Other

‎tests/__snapshots__/tsnapi/devframe/internal.snapshot.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
export { coerceAgentPositionalArgs }
66
export { createContextRpcServer }
77
export { DevframeAgentHost }
8+
export { isObject }
9+
export { listLiveDevframeInstances }
10+
export { normalizeHttpServerUrl }
11+
export { registerDevframeInstance }
812
// #endregion

0 commit comments

Comments
 (0)