Skip to content

Commit 0b19df3

Browse files
authored
feat(devframe): re-export nostics via devframe/utils/nostics (#243)
1 parent ee0a799 commit 0b19df3

41 files changed

Lines changed: 160 additions & 189 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Any change to one lands in the other in the same PR: adding a dock, wiring a new
9292

9393
## Structured Diagnostics (Error Codes)
9494

95-
All node-side warnings and errors use structured diagnostics via [`nostics`](https://www.npmjs.com/package/nostics). Never use raw `console.warn`, `console.error`, or `throw new Error` with ad-hoc messages in node-side code - always define a coded diagnostic.
95+
All node-side warnings and errors use structured diagnostics via [`nostics`](https://www.npmjs.com/package/nostics). Never use raw `console.warn`, `console.error`, or `throw new Error` with ad-hoc messages in node-side code - always define a coded diagnostic. Import `defineDiagnostics` (and `Diagnostic` for `instanceof` checks) from `devframe/utils/nostics` rather than from `nostics` directly - it pre-wires devframe's ANSI console reporter, so a plugin's `diagnostics.ts` never builds its own reporter (`colors`, `ansiFormatter`) or depends on `nostics` itself.
9696

9797
Prefix: **`DF`**. Codes are sequential 4-digit numbers (e.g. `DF0033`). Check the existing diagnostics file to find the next available number.
9898

alias.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const alias = {
2929
'devframe/utils/hash': r('devframe/src/utils/hash.ts'),
3030
'devframe/utils/launch-editor': r('devframe/src/utils/launch-editor.ts'),
3131
'devframe/utils/nanoid': r('devframe/src/utils/nanoid.ts'),
32+
'devframe/utils/nostics': r('devframe/src/utils/nostics.ts'),
3233
'devframe/utils/open': r('devframe/src/utils/open.ts'),
3334
'devframe/utils/remote-assets': r('devframe/src/utils/remote-assets.ts'),
3435
'devframe/utils/simple-schema': r('devframe/src/utils/simple-schema.ts'),

packages/devframe/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"./utils/hash": "./dist/utils/hash.mjs",
5252
"./utils/launch-editor": "./dist/utils/launch-editor.mjs",
5353
"./utils/nanoid": "./dist/utils/nanoid.mjs",
54+
"./utils/nostics": "./dist/utils/nostics.mjs",
5455
"./utils/open": "./dist/utils/open.mjs",
5556
"./utils/remote-assets": "./dist/utils/remote-assets.mjs",
5657
"./utils/simple-schema": "./dist/utils/simple-schema.mjs",

packages/devframe/src/adapters/mcp/__tests__/stringify.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Diagnostic } from 'nostics'
1+
import { Diagnostic } from 'devframe/utils/nostics'
22
import { describe, expect, it } from 'vitest'
33
import { formatMcpError, stringifyForMcp } from '../stringify'
44

packages/devframe/src/adapters/mcp/stringify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Diagnostic } from 'nostics'
1+
import { Diagnostic } from 'devframe/utils/nostics'
22

33
/**
44
* JSON-coercing serializer for MCP text payloads.

packages/devframe/src/cli/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Tool } from '@modelcontextprotocol/server'
22
import type { DevframeInstanceRecord } from '../node/instance-registry'
33
import process from 'node:process'
44
import { toAgentToolName } from 'devframe/utils/agent-tool-name'
5-
import { Diagnostic } from 'nostics'
5+
import { Diagnostic } from 'devframe/utils/nostics'
66
import { joinURL } from 'ufo'
77
import { diagnostics } from '../node/diagnostics'
88
import { listLiveDevframeInstances, probeDevframeOrigin } from '../node/instance-registry'

packages/devframe/src/node/diagnostics.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { defineDiagnostics } from 'nostics'
2-
import { devframeReporter } from '../utils/diagnostics-reporter'
1+
import { defineDiagnostics } from 'devframe/utils/nostics'
32

43
// DF00xx codes are allocated across packages (e.g. @devframes/json-render
54
// owns DF0037–DF0041), so this file alone doesn't show the next free
65
// number — check `docs/errors/` for the full allocation before adding one.
76
export const diagnostics = defineDiagnostics({
87
docsBase: 'https://devfra.me/errors',
9-
reporters: [devframeReporter],
108
codes: {
119
DF0006: {
1210
why: (p: { name: string }) => `RPC function "${p.name}" is not registered`,

packages/devframe/src/node/host-diagnostics.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DevframeDiagnosticsHost as DevframeDiagnosticsHostType, DevframeDiagnosticsLogger, DevframeNodeContext } from 'devframe/types'
2-
import { defineDiagnostics } from 'nostics'
3-
import { devframeReporter } from '../utils/diagnostics-reporter'
2+
import { defineDiagnostics } from 'devframe/utils/nostics'
43

54
export class DevframeDiagnosticsHost implements DevframeDiagnosticsHostType {
65
private _registry: Record<string, unknown> = {}
@@ -9,16 +8,9 @@ export class DevframeDiagnosticsHost implements DevframeDiagnosticsHostType {
98
get: (_, code: string) => this._registry[code],
109
})
1110

12-
readonly defineDiagnostics: DevframeDiagnosticsHostType['defineDiagnostics'] = (opts) => {
13-
const merged = {
14-
...opts,
15-
reporters: [devframeReporter, ...(opts.reporters ?? [])],
16-
} as Parameters<typeof defineDiagnostics>[0]
17-
// Runtime passthrough: the per-call `Codes` generic can't be threaded
18-
// through this assigned arrow, so the narrow return type is restored by
19-
// the property's declared signature at every call site.
20-
return defineDiagnostics(merged) as any
21-
}
11+
// Already pre-wires devframe's ANSI console reporter — no extra merging
12+
// needed here, the host's `defineDiagnostics` just is the shared one.
13+
readonly defineDiagnostics: DevframeDiagnosticsHostType['defineDiagnostics'] = defineDiagnostics
2214

2315
constructor(
2416
public readonly context: DevframeNodeContext,

packages/devframe/src/rpc/diagnostics.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { defineDiagnostics } from 'nostics'
2-
import { devframeReporter } from '../utils/diagnostics-reporter'
1+
import { defineDiagnostics } from 'devframe/utils/nostics'
32

43
export const diagnostics = defineDiagnostics({
54
docsBase: 'https://devfra.me/errors',
6-
reporters: [devframeReporter],
75
codes: {
86
DF0019: {
97
why: (p: { name: string }) =>

packages/devframe/src/types/diagnostics.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { defineDiagnostics, Diagnostic, DiagnosticDefinition } from 'nostics'
1+
import type { defineDiagnostics } from 'devframe/utils/nostics'
22

33
/**
44
* The shared diagnostics lookup exposed by the host. A `Proxy` that resolves
@@ -10,15 +10,14 @@ import type { defineDiagnostics, Diagnostic, DiagnosticDefinition } from 'nostic
1010
export type DevframeDiagnosticsLogger = Record<string, any>
1111

1212
/**
13-
* Options accepted by the host's `defineDiagnostics()` factory — mirrors
14-
* `nostics`'s shape but the host pre-wires its ANSI console reporter, so
15-
* plugins typically omit `reporters`.
13+
* Options accepted by the host's `defineDiagnostics()` factory. Re-exported
14+
* from `devframe/utils/nostics` — the same shape every module-level
15+
* `diagnostics.ts` (devframe core, `@devframes/hub`, the built-in plugins)
16+
* accepts, since `host.defineDiagnostics()` and the top-level
17+
* `defineDiagnostics` from `devframe/utils/nostics` pre-wire the identical
18+
* ANSI console reporter.
1619
*/
17-
export interface DevframeDefineDiagnosticsOptions<Codes extends Record<string, DiagnosticDefinition>> {
18-
docsBase?: string | ((code: keyof Codes) => string | undefined)
19-
codes: Codes
20-
reporters?: ReadonlyArray<(d: Diagnostic, o?: any) => void>
21-
}
20+
export type { DevframeDefineDiagnosticsOptions } from 'devframe/utils/nostics'
2221

2322
/**
2423
* Host for structured diagnostics — a thin layer over `nostics` that lets
@@ -64,10 +63,9 @@ export interface DevframeDiagnosticsHost {
6463

6564
/**
6665
* Build a typed diagnostics object with the host's ANSI console reporter
67-
* pre-wired. Mirrors `nostics`'s `defineDiagnostics` so integrations don't
68-
* need to take a direct dependency on `nostics`.
66+
* pre-wired. The same `devframe/utils/nostics` `defineDiagnostics` every
67+
* built-in plugin's module-level `diagnostics.ts` uses, so integrations
68+
* don't need to take a direct dependency on `nostics`.
6969
*/
70-
defineDiagnostics: <const Codes extends Record<string, DiagnosticDefinition>>(
71-
options: DevframeDefineDiagnosticsOptions<Codes>,
72-
) => ReturnType<typeof defineDiagnostics<Codes, any>>
70+
defineDiagnostics: typeof defineDiagnostics
7371
}

0 commit comments

Comments
 (0)