devframe 0.4.0 → 0.5.0

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.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/build.d.mts +2 -2
  3. package/dist/adapters/build.mjs +9 -9
  4. package/dist/adapters/cli.d.mts +2 -2
  5. package/dist/adapters/cli.mjs +1 -1
  6. package/dist/adapters/dev.d.mts +2 -2
  7. package/dist/adapters/dev.mjs +1 -1
  8. package/dist/adapters/embedded.d.mts +2 -2
  9. package/dist/adapters/mcp.d.mts +1 -3
  10. package/dist/adapters/mcp.mjs +3 -3
  11. package/dist/client/index.d.mts +28 -42
  12. package/dist/client/index.mjs +27 -23
  13. package/dist/constants.d.mts +10 -10
  14. package/dist/constants.mjs +10 -10
  15. package/dist/{context-Ca70YtrW.d.mts → context-DTRcO_UH.d.mts} +6 -6
  16. package/dist/{storage-CZVTPKsw.mjs → context-DaKmhhHY.mjs} +48 -3
  17. package/dist/{dev-C2wjXjGB.mjs → dev-Cv43GfqM.mjs} +5 -5
  18. package/dist/{devframe-xC8Q-xyt.d.mts → devframe-BuR6n9ZD.d.mts} +95 -46
  19. package/dist/{dump-B1wd4u68.mjs → dump-9lKIJTLh.mjs} +15 -11
  20. package/dist/helpers/vite.d.mts +1 -1
  21. package/dist/helpers/vite.mjs +4 -4
  22. package/dist/{host-h3-Div5Vp8R.mjs → host-h3-Dgpgr1Ul.mjs} +16 -16
  23. package/dist/{index-CTK6fuXs.d.mts → index-C7M1hnvL.d.mts} +2 -2
  24. package/dist/{index-C5PmWqBf.d.mts → index-DH2sBIwd.d.mts} +1 -1
  25. package/dist/index.d.mts +5 -5
  26. package/dist/node/auth.d.mts +5 -5
  27. package/dist/node/auth.mjs +1 -1
  28. package/dist/node/{internal.d.mts → hub-internals.d.mts} +3 -3
  29. package/dist/node/hub-internals.mjs +3 -0
  30. package/dist/node/index.d.mts +34 -34
  31. package/dist/node/index.mjs +4 -4
  32. package/dist/recipes/open-helpers.d.mts +5 -5
  33. package/dist/{human-id-Dq-qgtES.mjs → revoke-CL0LSAN9.mjs} +35 -35
  34. package/dist/rpc/dump.d.mts +1 -1
  35. package/dist/rpc/dump.mjs +1 -1
  36. package/dist/rpc/index.d.mts +2 -2
  37. package/dist/rpc/index.mjs +1 -1
  38. package/dist/rpc/transports/ws-client.d.mts +1 -25
  39. package/dist/rpc/transports/ws-client.mjs +1 -1
  40. package/dist/rpc/transports/ws-server.d.mts +2 -2
  41. package/dist/{server-BO8IDVsJ.mjs → server-BBaBJaUL.mjs} +12 -5
  42. package/dist/{server-FNcskEBD.d.mts → server-wHlpcdZ9.d.mts} +3 -3
  43. package/dist/{shared-state-CasqoUba.mjs → shared-state-BlBNYziY.mjs} +1 -1
  44. package/dist/types/index.d.mts +4 -4
  45. package/dist/{types-BXL7EIDM.d.mts → types-BkkQ0Txg.d.mts} +5 -5
  46. package/dist/utils/events.d.mts +1 -1
  47. package/dist/utils/shared-state.d.mts +1 -1
  48. package/dist/utils/streaming-channel.d.mts +1 -1
  49. package/dist/ws-client-CVYX9niP.d.mts +26 -0
  50. package/dist/{ws-server-DOwLJL23.d.mts → ws-server-C1LjmRnp.d.mts} +6 -6
  51. package/package.json +6 -5
  52. package/skills/devframe/SKILL.md +82 -5
  53. package/dist/index-DTeZXHSi.d.mts +0 -639
  54. package/dist/node/internal.mjs +0 -49
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "devframe",
3
3
  "type": "module",
4
- "version": "0.4.0",
5
- "description": "Framework for building generic DevTools",
4
+ "version": "0.5.0",
5
+ "description": "Framework for building generic devframes",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
8
8
  "homepage": "https://github.com/devframes/devframe#readme",
@@ -30,7 +30,7 @@
30
30
  "./helpers/vite": "./dist/helpers/vite.mjs",
31
31
  "./node": "./dist/node/index.mjs",
32
32
  "./node/auth": "./dist/node/auth.mjs",
33
- "./node/internal": "./dist/node/internal.mjs",
33
+ "./node/hub-internals": "./dist/node/hub-internals.mjs",
34
34
  "./recipes/open-helpers": "./dist/recipes/open-helpers.mjs",
35
35
  "./rpc": "./dist/rpc/index.mjs",
36
36
  "./rpc/client": "./dist/rpc/client.mjs",
@@ -75,8 +75,8 @@
75
75
  "mrmime": "^2.0.1",
76
76
  "nostics": "^0.2.0",
77
77
  "pathe": "^2.0.3",
78
- "valibot": "^1.4.0",
79
- "ws": "^8.20.0"
78
+ "valibot": "^1.4.1",
79
+ "ws": "^8.21.0"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@modelcontextprotocol/sdk": "^1.29.0",
@@ -90,6 +90,7 @@
90
90
  "p-limit": "^7.3.0",
91
91
  "perfect-debounce": "^2.1.0",
92
92
  "structured-clone-es": "^2.0.0",
93
+ "tinyglobby": "^0.2.16",
93
94
  "tsdown": "^0.22.0",
94
95
  "ua-parser-modern": "^0.1.1",
95
96
  "whenexpr": "^0.1.2"
@@ -66,6 +66,83 @@ export default defineDevframe({
66
66
 
67
67
  See `templates/counter-devframe.ts` for a runnable counter example, `templates/spa-devframe.ts` for an SPA-ready shape, and `templates/vite-client.ts` for the author's client entry.
68
68
 
69
+ ## Project layout
70
+
71
+ Once a devframe grows past a handful of RPC functions, split them out — one file per function under `src/rpc/functions/`, with `src/rpc/index.ts` as the barrel. The `functions/` subdirectory leaves room for sibling files like `src/rpc/utils.ts` (helpers, type aliases) as the surface grows. Each function file exports a named const; the barrel collects them into a `const serverFunctions = [...] as const` that feeds the type-safe client registry recipe (`RpcDefinitionsToFunctions<typeof serverFunctions>`).
72
+
73
+ ```ts
74
+ // src/rpc/functions/list-files.ts
75
+ import { defineRpcFunction } from 'devframe'
76
+ import { getMyToolContext } from '../../context'
77
+
78
+ export const listFiles = defineRpcFunction({
79
+ name: 'my-tool:list-files',
80
+ type: 'query',
81
+ jsonSerializable: true,
82
+ setup: (ctx) => {
83
+ const { loaders } = getMyToolContext(ctx)
84
+ return { handler: () => loaders.list() }
85
+ },
86
+ })
87
+ ```
88
+
89
+ ```ts
90
+ // src/rpc/index.ts
91
+ import { getCwd } from './functions/get-cwd'
92
+ import { listFiles } from './functions/list-files'
93
+
94
+ export const serverFunctions = [getCwd, listFiles] as const
95
+
96
+ declare module 'devframe' {
97
+ interface DevframeRpcServerFunctions
98
+ extends import('devframe/rpc').RpcDefinitionsToFunctions<typeof serverFunctions> {}
99
+ }
100
+ ```
101
+
102
+ ```ts
103
+ // src/devframe.ts
104
+ import { defineDevframe } from 'devframe/types'
105
+ import { setMyToolContext } from './context'
106
+ import { serverFunctions } from './rpc'
107
+
108
+ export default defineDevframe({
109
+ id: 'my-tool',
110
+ setup(ctx) {
111
+ setMyToolContext(ctx, { loaders: createLoaders() })
112
+ serverFunctions.forEach(fn => ctx.rpc.register(fn))
113
+ },
114
+ })
115
+ ```
116
+
117
+ ### Sharing setup-time state via `src/context.ts`
118
+
119
+ When per-file RPCs need access to runtime values that `setup(ctx)` constructs once — streaming channels, shared state handles, watchers, loaders, caches — expose them through a `WeakMap<DevframeNodeContext, T>` in a sibling `src/context.ts`. This mirrors the framework's own `internalContextMap` in `packages/devframe/src/node/hub-internals/context.ts`. The WeakMap keys off the existing `DevframeNodeContext` so contexts are garbage-collected automatically when the host tears down.
120
+
121
+ ```ts
122
+ // src/context.ts
123
+ import type { DevframeNodeContext } from 'devframe/types'
124
+
125
+ export interface MyToolContext {
126
+ loaders: { list: () => Promise<string[]> }
127
+ // …channels, shared state handles, watchers, etc.
128
+ }
129
+
130
+ const map = new WeakMap<DevframeNodeContext, MyToolContext>()
131
+
132
+ export function setMyToolContext(ctx: DevframeNodeContext, value: MyToolContext): void {
133
+ map.set(ctx, value)
134
+ }
135
+
136
+ export function getMyToolContext(ctx: DevframeNodeContext): MyToolContext {
137
+ const value = map.get(ctx)
138
+ if (!value)
139
+ throw new Error('my-tool context not initialised — call setMyToolContext in devframe.setup')
140
+ return value
141
+ }
142
+ ```
143
+
144
+ Stateless RPCs and tiny demos can keep the inline shorthand inside `setup(ctx)` — reach for `src/rpc/functions/` and `src/context.ts` once you have more than one or two functions, or any shared setup state.
145
+
69
146
  ## Namespacing
70
147
 
71
148
  **Always prefix** RPC names, dock IDs, command IDs, shared-state keys, and agent tool IDs with the devframe `id`:
@@ -76,7 +153,7 @@ See `templates/counter-devframe.ts` for a runnable counter example, `templates/s
76
153
  'get-modules' // ✗ — may collide with other devframes sharing the host
77
154
  ```
78
155
 
79
- ## DevToolsNodeContext at a glance
156
+ ## DevframeNodeContext at a glance
80
157
 
81
158
  `setup(ctx)` receives the framework-neutral server-side surface. Each host corresponds to a [docs](https://devfra.me/) page:
82
159
 
@@ -340,9 +417,9 @@ const rpc = await connectDevframe()
340
417
  const data = await rpc.call('my-inspector:get-stats', { limit: 10 })
341
418
  ```
342
419
 
343
- `connectDevframe` auto-detects the backend via `/.devtools/.connection.json`:
420
+ `connectDevframe` auto-detects the backend via `/.devframe/.connection.json`:
344
421
 
345
- - **websocket** (dev mode) — full read/write, requires auth handshake. Listen for token updates on the `vite-devtools-auth` BroadcastChannel.
422
+ - **websocket** (dev mode) — full read/write, requires auth handshake. Listen for token updates on the `devframe-auth` BroadcastChannel.
346
423
  - **static** (build / spa output) — read-only, resolves calls from the baked RPC dump.
347
424
 
348
425
  Use `rpc.sharedState.get(key)` for observable state, `rpc.client.register(defineRpcFunction(...))` to receive server broadcasts, and `rpc.callOptional(...)` when a missing handler should resolve to `undefined` instead of throwing.
@@ -373,7 +450,7 @@ At runtime, static clients look up the argument hash in the dump; misses resolve
373
450
 
374
451
  | Subcommand | Action |
375
452
  |------------|--------|
376
- | *(default)* | Dev server on port 9999 (or `--port`) — WebSocket RPC, `cli.distDir` served at `/.devtools/` |
453
+ | *(default)* | Dev server on port 9999 (or `--port`) — WebSocket RPC, `cli.distDir` served at `/.devframe/` |
377
454
  | `build` | Static snapshot → `./dist-static/` (configurable via `--out-dir`) |
378
455
  | `spa` | Deployable SPA → `./dist-spa/` |
379
456
  | `mcp` | stdio MCP server (experimental) |
@@ -405,7 +482,7 @@ For "open file in editor" + "reveal in finder", prefer the prebuilt `openHelpers
405
482
 
406
483
  - Unit-test host classes with fake contexts.
407
484
  - Run `templates/counter-devframe.ts` under each adapter for integration coverage.
408
- - Snapshot the build-static RPC dump (`<outDir>/.devtools/.rpc-dump/index.json`) to catch accidental drift in `static` function outputs.
485
+ - Snapshot the build-static RPC dump (`<outDir>/.devframe/.rpc-dump/index.json`) to catch accidental drift in `static` function outputs.
409
486
 
410
487
  ## Further reading
411
488