Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/content/1.guide/16.hub.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ The reference hub UI (`@devframes/hub-ui`) lets users reach a group member in on
- **Reorder.** Drag a tool up or down in the group sidebar to change its place. Keyboard users press Alt+ArrowUp or Alt+ArrowDown on a focused tool. A tool moves only inside its own sub-category. The order is stored in the `docksCustomOrder` user setting, the same one **Settings > Docks** edits.
- **Recent.** When a user opens a tool from a group popover or the overflow menu, the float bar keeps it in a slot after the bar items, newest first. The slots are added on top of the bar's capacity, so opening a tool never pushes another button into the overflow. A tool that is already on the bar (for example a pinned member) does not take a slot. The list is kept per browser tab, in the `recentDockIds` field of the session store.

### Where the layout persists

`devframe:user-settings` is per-checkout private state: the hub keeps it in the host's `project` storage dir as `settings.json`, and every write goes there.

Earlier versions kept that file in one machine-wide project directory, shared by every project. When a checkout has no `settings.json` yet, the hub seeds the initial value once from the file in the host's legacy project dir (`host.getLegacyStorageDir('project')`, read through `resolveLegacyStorageDir()` from `devframe/node`), so an existing layout survives the move. The fallback is temporary and is removed in a later release.

The `docksRecentLimit` user setting sets how many recent slots the bar keeps. The default is `3`. `0` turns the slots off. Users change it under **Settings > Appearance > Recent tools on the dock bar**. The edge-mode toolbar shows pinned entries but no recent slots.

### The dual role of `category`
Expand Down
4 changes: 4 additions & 0 deletions docs/content/1.guide/7.scoped-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const off = await settings.global.onChange((value) => {

Every method is async; the store resolves on first access.

### One-time shared-scope notice

Before the scopes were split, `project` and `global` wrote the same file, so every project on a machine read one shared configuration and the surviving value's scope is unknowable. Values written back then now read as `global`. The built-in `devframe:settings:legacy-notice` RPC reports the namespaces that have such a file, and `devframe:settings:legacy-notice-dismiss` writes a per-machine marker so a viewer can show the notice once and hide it. Nothing is migrated or split: the history is gone, so a new `project` override only affects the project it was saved in.

### Typed settings

Augment `DevframeSettingsRegistry` to type a namespace's settings once; the scope types `settings.global` and `settings.project`:
Expand Down
22 changes: 22 additions & 0 deletions docs/content/6.errors/DF0087.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: 'DF0087: Settings Notice Marker Not Written'
description: 'Could not write the settings notice marker "{filepath}"'
---

## Message

> Could not write the settings notice marker "`{filepath}`"

## Cause

Dismissing the one-time shared-scope settings notice writes a marker file into the global settings directory (`<global>/settings/.shared-scope-notice`). The directory could not be created, or the file could not be written, usually because the global storage directory is not writable or the disk is full.

The dismissal itself is not an error: the notice disappears for the current session. The marker only makes it stay gone.

## Fix

Check that the global storage directory is writable and has free space. Until the marker lands, the notice shows again the next time a viewer opens settings.

## Source

- [`packages/devframe/src/node/settings-legacy-notice.ts`](https://github.com/devframes/devframe/blob/main/packages/devframe/src/node/settings-legacy-notice.ts): `dismissLegacySharedSettingsNotice()` reports this when creating the directory or writing the marker fails. The `devframe:settings:legacy-notice-dismiss` RPC calls it.
22 changes: 22 additions & 0 deletions docs/content/6.errors/DF8112.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: 'DF8112: Legacy Dock Settings Unreadable'
description: 'Could not read the legacy dock settings file "{filepath}"'
---

## Message

> Could not read the legacy dock settings file "`{filepath}`"

## Cause

The hub seeds its initial dock layout once from the `settings.json` an earlier version kept in the old machine-wide project directory. That file exists, but it is not valid JSON, or it could not be read (permissions, or a directory in its place).

The one-time fallback is temporary and goes away in a later release. Writes always go to the new per-checkout `settings.json`.

## Fix

The hub starts from default dock settings. Delete or fix the legacy file to silence the warning: nothing else reads it, and the new per-checkout file is authoritative once it exists.

## Source

- [`packages/hub/src/node/host-docks.ts`](https://github.com/devframes/devframe/blob/main/packages/hub/src/node/host-docks.ts): `readLegacyUserSettings()` reports this when reading or parsing the legacy file fails, and `DevframeDocksHost.init()` then keeps `DEFAULT_STATE_USER_SETTINGS()`.
2 changes: 2 additions & 0 deletions docs/content/6.errors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Emitted by `devframe`: the framework-neutral host, RPC, streaming, assets, servi
| [DF0084](/errors/DF0084) | error | Invalid MCP Resource Template |
| [DF0085](/errors/DF0085) | error | Repeated MCP Prompt Name |
| [DF0086](/errors/DF0086) | warn | Tracing Channels Unavailable |
| [DF0087](/errors/DF0087) | warn | Settings Notice Marker Not Written |

## Hub: context & lifecycle (DF80xx)

Expand Down Expand Up @@ -120,6 +121,7 @@ Emitted by `@devframes/hub` while assembling and mounting the unified surface.
| [DF8109](/errors/DF8109) | error | Renderer Module File Missing |
| [DF8110](/errors/DF8110) | error | Renderer Type Is Not URL-Safe |
| [DF8111](/errors/DF8111) | warn | Bare-Specifier Client Script Without Host Resolution |
| [DF8112](/errors/DF8112) | warn | Legacy Dock Settings Unreadable |

## Hub: terminals (DF82xx)

Expand Down
2 changes: 2 additions & 0 deletions docs/content/8.references/4.node-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ The three classes `ctx.host.getStorageDir(scope)` places persisted state in: [St
| `project` | per-checkout, `<cwd>/node_modules/.<app>/devframe/` | caches, personal settings |
| `global` | per-user, `~/.<app>/devframe/` | auth tokens, machine-wide prefs |

`resolveLegacyStorageDir(host, scope)` (from `devframe/node`) reads the optional `host.getLegacyStorageDir(scope)` capability: where an earlier version of that host kept the scope. It returns `undefined` when the host does not implement it, and exists only for one-time reads of state written before a storage move. It is not part of `DevframeHost`.

## RPC function types

The `type` field of `defineRpcFunction`: [RPC](/guide/rpc).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type { DevframeHost } from '../../types/host'
import type { DevframeHostLegacyStorage } from '../legacy-storage'
import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { createHostContext } from '../context'
import { resolveLegacyStorageDir } from '../legacy-storage'

function storageHost(root: string, legacy?: string): DevframeHost {
return {
mountStatic: () => { /* no-op */ },
resolveOrigin: () => 'http://localhost:0',
getStorageDir: (scope: string) => join(root, scope),
...(legacy
? {
getLegacyStorageDir: (scope: string) => join(legacy, scope),
}
: {}),
} as DevframeHost
}

async function contextWith(root: string) {
return createHostContext({
cwd: root,
mode: 'dev',
host: storageHost(root),
})
}

function writeGlobalSettings(root: string, namespace: string, value: Record<string, unknown>): void {
const dir = join(root, 'global', 'settings')
mkdirSync(dir, { recursive: true })
writeFileSync(join(dir, `${namespace}.json`), JSON.stringify(value))
}

describe('shared-scope settings notice', () => {
it('lists the namespaces that already hold a global settings file', async () => {
const root = mkdtempSync(join(tmpdir(), 'devframe-settings-notice-'))
writeGlobalSettings(root, 'data-inspector', { theme: 'dark' })
writeGlobalSettings(root, 'json-render', {})

const ctx = await contextWith(root)
const notice = await ctx.rpc.invokeLocal('devframe:settings:legacy-notice')
expect(notice).toEqual({
namespaces: ['data-inspector', 'json-render'],
})
})

it('reports nothing when the machine never wrote a settings file', async () => {
const root = mkdtempSync(join(tmpdir(), 'devframe-settings-notice-'))
const ctx = await contextWith(root)
expect(await ctx.rpc.invokeLocal('devframe:settings:legacy-notice')).toEqual({ namespaces: [] })
})

it('keeps the notice dismissed after the marker is written', async () => {
const root = mkdtempSync(join(tmpdir(), 'devframe-settings-notice-'))
writeGlobalSettings(root, 'data-inspector', { theme: 'dark' })

const ctx = await contextWith(root)
await ctx.rpc.invokeLocal('devframe:settings:legacy-notice-dismiss')
expect(existsSync(join(root, 'global', 'settings', '.shared-scope-notice'))).toBe(true)
expect(await ctx.rpc.invokeLocal('devframe:settings:legacy-notice')).toEqual({ namespaces: [] })

// A later start on the same machine reads the marker, not the notice.
const restarted = await contextWith(root)
expect(await restarted.rpc.invokeLocal('devframe:settings:legacy-notice')).toEqual({ namespaces: [] })
})
})

describe('resolveLegacyStorageDir', () => {
it('returns undefined for a host without the optional capability', () => {
expect(resolveLegacyStorageDir(storageHost('/root'), 'project')).toBeUndefined()
})

it('reads the legacy directory a host exposes', () => {
expect(resolveLegacyStorageDir(storageHost('/root', '/legacy'), 'project')).toBe('/legacy/project')

Check failure on line 77 in packages/devframe/src/node/__tests__/settings-legacy-notice.test.ts

View workflow job for this annotation

GitHub Actions / unit-test / test (windows-latest, 22)

[devframe] src/node/__tests__/settings-legacy-notice.test.ts > resolveLegacyStorageDir > reads the legacy directory a host exposes

AssertionError: expected '\legacy\project' to be '/legacy/project' // Object.is equality Expected: "/legacy/project" Received: "\legacy\project" ❯ src/node/__tests__/settings-legacy-notice.test.ts:77:81

Check failure on line 77 in packages/devframe/src/node/__tests__/settings-legacy-notice.test.ts

View workflow job for this annotation

GitHub Actions / unit-test / test (windows-latest, latest)

[devframe] src/node/__tests__/settings-legacy-notice.test.ts > resolveLegacyStorageDir > reads the legacy directory a host exposes

AssertionError: expected '\legacy\project' to be '/legacy/project' // Object.is equality Expected: "/legacy/project" Received: "\legacy\project" ❯ src/node/__tests__/settings-legacy-notice.test.ts:77:81

Check failure on line 77 in packages/devframe/src/node/__tests__/settings-legacy-notice.test.ts

View workflow job for this annotation

GitHub Actions / unit-test / test (windows-latest, 24)

[devframe] src/node/__tests__/settings-legacy-notice.test.ts > resolveLegacyStorageDir > reads the legacy directory a host exposes

AssertionError: expected '\legacy\project' to be '/legacy/project' // Object.is equality Expected: "/legacy/project" Received: "\legacy\project" ❯ src/node/__tests__/settings-legacy-notice.test.ts:77:81

Check failure on line 77 in packages/devframe/src/node/__tests__/settings-legacy-notice.test.ts

View workflow job for this annotation

GitHub Actions / unit-test / test (windows-latest, 26)

[devframe] src/node/__tests__/settings-legacy-notice.test.ts > resolveLegacyStorageDir > reads the legacy directory a host exposes

AssertionError: expected '\legacy\project' to be '/legacy/project' // Object.is equality Expected: "/legacy/project" Received: "\legacy\project" ❯ src/node/__tests__/settings-legacy-notice.test.ts:77:81
})

it('treats a throwing or non-string host method as no legacy data', () => {
const throwing: DevframeHost & DevframeHostLegacyStorage = {
...storageHost('/root'),
getLegacyStorageDir: () => {
throw new Error('unsupported scope')
},
}
expect(resolveLegacyStorageDir(throwing, 'project')).toBeUndefined()
const empty: DevframeHost & DevframeHostLegacyStorage = {
...storageHost('/root'),
getLegacyStorageDir: () => '',
}
expect(resolveLegacyStorageDir(empty, 'project')).toBeUndefined()
})
})
7 changes: 7 additions & 0 deletions packages/devframe/src/node/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DevframeServicesHostImpl } from './host-services'
import { DevframeTracingHostImpl } from './host-tracing'
import { DevframeViewHost } from './host-views'
import { BUILTIN_AGENT_RPC } from './rpc'
import { BUILTIN_SETTINGS_RPC } from './rpc/settings-legacy-notice'
import { createScopedNodeContext } from './scope'

export interface CreateHostContextOptions {
Expand Down Expand Up @@ -95,6 +96,12 @@ export async function createHostContext(options: CreateHostContextOptions): Prom
rpcHost.register(fn)
}

// Settings state is core, so its notice RPCs ship with every context: a
// viewer renders the notice without the host adding anything.
for (const fn of BUILTIN_SETTINGS_RPC) {
rpcHost.register(fn)
}

for (const fn of builtinRpcDeclarations) {
rpcHost.register(fn)
}
Expand Down
5 changes: 5 additions & 0 deletions packages/devframe/src/node/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,10 @@ export const diagnostics = defineDiagnostics({
`Tracing Channels are unavailable: this runtime (${p.runtime}) does not provide \`node:diagnostics_channel\`'s \`tracingChannel\`, so \`ctx.tracing\` records nothing.`,
fix: 'Run under Node.js 22+ or Bun to record Tracing Channels. Every `ctx.tracing` and `createTracingRecorder()` method is a no-op here.',
},
DF0087: {
why: (p: { filepath: string }) =>
`Could not write the settings notice marker "${p.filepath}".`,
fix: 'Make the global storage directory writable. Until the marker can be written, the one-time shared-scope settings notice shows again on the next start.',
},
},
})
3 changes: 3 additions & 0 deletions packages/devframe/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ export * from './context'
// `RpcFunctionsHost` type so consumers can type/cast `ctx.rpc` without
// pulling in the implementation's `@internal` members.
export type { RpcFunctionsHost } from './host-functions'
// Optional host capability for a one-time read of state written before a host
// moved a storage scope. New state always goes to `ctx.host.getStorageDir`.
export { resolveLegacyStorageDir } from './legacy-storage'
export * from './storage'
export { createTracingRecorder } from './tracing-recorder'
38 changes: 38 additions & 0 deletions packages/devframe/src/node/legacy-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { DevframeHost, DevframeStorageScope } from '../types/host'

/**
* Optional host capability: where earlier versions of the host kept a storage
* scope.
*
* A host that moved a scope's directory exposes it, so a devframe can read
* state written before the move once (an import, a settings fallback). It is
* NOT part of {@link DevframeHost}: a host that never moved its storage omits
* it, and callers MUST treat the absence as "no legacy data here".
*/
export interface DevframeHostLegacyStorage {
getLegacyStorageDir?: (scope: DevframeStorageScope) => string
}

/**
* Read the legacy directory a host may still expose for `scope`, duck-typed so
* the capability stays optional. Returns `undefined` when the host does not
* implement it, returns a non-string, or throws.
*
* Use it for a read-only one-time migration only. New state goes to
* `host.getStorageDir(scope)`.
*/
export function resolveLegacyStorageDir(host: DevframeHost, scope: DevframeStorageScope): string | undefined {
const getLegacyStorageDir = (host as DevframeHost & DevframeHostLegacyStorage).getLegacyStorageDir
if (typeof getLegacyStorageDir !== 'function')
return undefined
try {
const dir = getLegacyStorageDir.call(host, scope)
return typeof dir === 'string' && dir.length > 0
? dir
: undefined
}
catch {
// A host that throws for an unsupported scope simply has no legacy data.
return undefined
}
}
44 changes: 44 additions & 0 deletions packages/devframe/src/node/rpc/settings-legacy-notice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { LegacySharedSettingsNotice } from '../settings-legacy-notice'
import { defineRpcFunction } from 'devframe'
import { dismissLegacySharedSettingsNotice, readLegacySharedSettingsNotice } from '../settings-legacy-notice'

/**
* Built-in RPC functions behind the one-time shared-scope settings notice.
* Registered automatically by `createHostContext`, so any viewer can render
* the notice without the host exposing a settings UI of its own.
*/
export const BUILTIN_SETTINGS_RPC = [
defineRpcFunction({
name: 'devframe:settings:legacy-notice',
type: 'query',
jsonSerializable: true,
setup: ctx => ({
/**
* Namespaces whose settings file predates the project/global split. An
* empty list means there is nothing to tell the user, or they dismissed
* the notice already.
*/
async handler(): Promise<LegacySharedSettingsNotice> {
return readLegacySharedSettingsNotice(ctx)
},
}),
}),
defineRpcFunction({
name: 'devframe:settings:legacy-notice-dismiss',
type: 'action',
jsonSerializable: true,
setup: ctx => ({
/** Record the dismissal once per machine, in the global storage dir. */
async handler(): Promise<void> {
dismissLegacySharedSettingsNotice(ctx)
},
}),
}),
] as const

declare module 'devframe/types' {
interface DevframeRpcServerFunctions {
'devframe:settings:legacy-notice': () => Promise<LegacySharedSettingsNotice>
'devframe:settings:legacy-notice-dismiss': () => Promise<void>
}
}
62 changes: 62 additions & 0 deletions packages/devframe/src/node/settings-legacy-notice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { DevframeNodeContext } from 'devframe/types'
import fs from 'node:fs'
import { join } from 'pathe'
import { diagnostics } from './diagnostics'
import { settingsDirectory } from './settings'

/**
* Marker recording that the user dismissed the shared-scope settings notice.
* It sits next to the global settings files, so one machine dismisses once.
* It does not end in `.json`, so it is never mistaken for a namespace file.
*/
const NOTICE_MARKER = '.shared-scope-notice'

export interface LegacySharedSettingsNotice {
/** Namespaces whose global settings file predates the scope split. */
namespaces: string[]
}

/**
* Detect settings written before `project` and `global` got separate files.
*
* Earlier versions persisted both scopes into `global`'s
* `settings/<namespace>.json` with per-key last-write-wins, so a surviving
* value's scope is unknowable. Any namespace file in the global directory is
* evidence of that history. There is nothing to migrate and nothing to split:
* the notice only tells the user that the two scopes now diverge from here on.
*
* Empty once the user dismissed it, once the directory holds no namespace
* file, or when the global settings directory is unreadable.
*/
export function readLegacySharedSettingsNotice(context: DevframeNodeContext): LegacySharedSettingsNotice {
const dir = settingsDirectory(context, 'global')
if (fs.existsSync(join(dir, NOTICE_MARKER)))
return { namespaces: [] }
let entries: string[]
try {
entries = fs.readdirSync(dir)
}
catch {
// No settings directory yet: the machine never wrote a settings file.
return { namespaces: [] }
}
return {
namespaces: entries
.filter(name => name.endsWith('.json') && !name.startsWith('.'))
.map(name => name.slice(0, -'.json'.length))
.sort(),
}
}

/** Write the dismissal marker, so the notice never shows again on this machine. */
export function dismissLegacySharedSettingsNotice(context: DevframeNodeContext): void {
const dir = settingsDirectory(context, 'global')
const filepath = join(dir, NOTICE_MARKER)
try {
fs.mkdirSync(dir, { recursive: true })
fs.writeFileSync(filepath, `${new Date().toISOString()}\n`)
}
catch (error) {
diagnostics.DF0087({ filepath, cause: error })
}
}
7 changes: 6 additions & 1 deletion packages/devframe/src/node/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ import { createStorage } from './storage'
// host's ignored `project` dir (not the committable `workspace` one).
const STORAGE_SCOPE = { global: 'global', project: 'project' } as const

/** Directory holding the per-namespace settings files of a scope. */
export function settingsDirectory(context: DevframeNodeContext, scope: 'global' | 'project'): string {
return join(context.host.getStorageDir(STORAGE_SCOPE[scope]), 'settings')
}

/** Resolve reserved settings keys before the sync protocol creates an in-memory state. */
export function resolveSettingsState(context: DevframeNodeContext, key: string): SharedState<Record<string, any>> | undefined {
const match = /^devframe:settings:(global|project):(.+)$/.exec(key)
if (!match)
return
const scope = match[1] as keyof typeof STORAGE_SCOPE
const namespace = match[2]!
const dir = join(context.host.getStorageDir(STORAGE_SCOPE[scope]), 'settings')
const dir = settingsDirectory(context, scope)
const filepath = join(dir, `${namespace}.json`)
const path = relative(dir, filepath)
// Keys arrive from RPC clients, so they must stay within the settings directory.
Expand Down
Loading
Loading