@kivacore/devtools 0.0.0 → 0.9.2

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.
package/README.md CHANGED
@@ -1,3 +1,247 @@
1
1
  # @kivacore/devtools
2
2
 
3
- Placeholder. Install the latest version.
3
+ React-first developer tools for Docyrus apps.
4
+
5
+ ## Features
6
+
7
+ - Floating Docyrus trigger button with configurable corner placement
8
+ - Bottom-docked panel with `Network`, `Errors`, `Issues`, `Explore`, `Console`, and `Messages` tabs
9
+ - Request instrumentation for `@kivacore/api-client` and `@kivacore/addin-client`
10
+ - Duplicate request and slow request detection
11
+ - Optional TanStack Query issue tracking
12
+ - Optional Docyrus `fetch` capture
13
+ - OpenAPI-driven request explorer for replaying and testing endpoints with the app's existing authenticated API client
14
+ - Console capture for `log`, `info`, `warn`, `error`, `debug`, plus `window error` and `unhandledrejection`
15
+ - Iframe message capture for both directions (host → app via `window.message`, app → host via the `__DOCYRUS_DEVTOOLS_MESSAGE_TAP__` global hook)
16
+ - Iframe/host bridge for sending errors, issues, and console entries to a host assistant panel
17
+ - In-page API for external tooling and Chrome DevTools Protocol agents to inspect current errors, issues, and console state
18
+ - Inline DOM element picker with per-element feedback collection — works in standalone browser windows without an iframe/host (uses `data-component-name` / `data-component-path` / `data-current-file-path` annotations written by `@kivacore/dom-selector-client`)
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ pnpm add @kivacore/devtools
24
+ ```
25
+
26
+ ## LLM Install Prompt
27
+
28
+ Use this prompt with a coding assistant if you want it to install and wire `@kivacore/devtools` for you:
29
+
30
+ ```text
31
+ Install and integrate @kivacore/devtools into this project.
32
+
33
+ Requirements:
34
+ - Add @kivacore/devtools as a dependency.
35
+ - Wrap the React app with <DocyrusDevtools /> near the root.
36
+ - If the app uses TanStack Query, pass the existing queryClient to DocyrusDevtools.
37
+ - If the app uses @kivacore/signin and useDocyrusClient(), add a small component that calls useRegisterDocyrusClient(useDocyrusClient()) after mount.
38
+ - If an OpenAPI spec is already served by the app, pass its path with openApiSpecPath.
39
+ - Preserve the existing app structure and styling.
40
+ - Do not add unrelated refactors.
41
+ - After integration, run the app/package build or typecheck and summarize what changed.
42
+ ```
43
+
44
+ ## React Usage
45
+
46
+ ```tsx
47
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
48
+ import { DocyrusDevtools, useRegisterDocyrusClient } from '@kivacore/devtools';
49
+ import { DocyrusAuthProvider, useDocyrusClient } from '@kivacore/signin';
50
+
51
+ const queryClient = new QueryClient();
52
+
53
+ function RegisterClient() {
54
+ const client = useDocyrusClient();
55
+
56
+ useRegisterDocyrusClient(client);
57
+
58
+ return null;
59
+ }
60
+
61
+ export function App() {
62
+ return (
63
+ <QueryClientProvider client={queryClient}>
64
+ <DocyrusDevtools
65
+ queryClient={queryClient}
66
+ openApiSpecPath="/openapi-spec.json">
67
+ <DocyrusAuthProvider
68
+ apiUrl="https://api.docyrus.app"
69
+ clientId="your-client-id">
70
+ <RegisterClient />
71
+ <YourRoutes />
72
+ </DocyrusAuthProvider>
73
+ </DocyrusDevtools>
74
+ </QueryClientProvider>
75
+ );
76
+ }
77
+ ```
78
+
79
+ ## API
80
+
81
+ ### `DocyrusDevtools`
82
+
83
+ - `enabled?: boolean`
84
+ - `activationShortcut?: string | false`
85
+ - `clients?: Array<RestApiClient | DocyrusClient | null | undefined>`
86
+ - `queryClient?: QueryClient`
87
+ - `buttonPosition?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'`
88
+ - `slowThresholdMs?: number`
89
+ - `maxEntries?: number`
90
+ - `captureFetch?: boolean`
91
+ - `captureConsole?: boolean`
92
+ - `captureIframeMessages?: boolean`
93
+ - `iframeMessageIgnoreTypes?: string[]`
94
+ - `enableHostBridge?: boolean`
95
+ - `enableElementSelector?: boolean`
96
+ - `docyrusOrigins?: string[]`
97
+ - `hostOrigin?: string`
98
+ - `openApiSpecPath?: string`
99
+ - `onFeedback?(submission: DevtoolsFeedbackSubmission): void`
100
+
101
+ Defaults:
102
+
103
+ - `enabled`: `true`
104
+ - `activationShortcut`: `false`
105
+ - `buttonPosition`: `'bottom-left'`
106
+ - `slowThresholdMs`: `1000`
107
+ - `maxEntries`: `200`
108
+ - `captureFetch`: `false`
109
+ - `captureConsole`: `true`
110
+ - `captureIframeMessages`: `true`
111
+ - `iframeMessageIgnoreTypes`: `['DOCY_DEVTOOLS']`
112
+ - `enableHostBridge`: `true`
113
+ - `enableElementSelector`: `true`
114
+
115
+ ## Enabling / Disabling
116
+
117
+ `enabled` gates everything: the floating button, the overlay, and all instrumentation (clients, query client, fetch, console, host bridge). When `false`, `<DocyrusDevtools>` only renders its children — no listeners are attached and no UI is mounted. Wire it to your build target to keep devtools out of production:
118
+
119
+ ```tsx
120
+ <DocyrusDevtools enabled={import.meta.env.DEV}>
121
+ <App />
122
+ </DocyrusDevtools>
123
+ ```
124
+
125
+ `activationShortcut` lets you ship devtools in production but keep them dormant until a user opts in with a keyboard chord. The shortcut listener is attached even when `enabled={false}`; triggering it flips an internal flag that activates devtools alongside the prop. Triggering again deactivates them.
126
+
127
+ ```tsx
128
+ <DocyrusDevtools
129
+ enabled={import.meta.env.DEV}
130
+ activationShortcut="shift+meta+space space">
131
+ <App />
132
+ </DocyrusDevtools>
133
+ ```
134
+
135
+ Shortcut syntax:
136
+
137
+ - Combine modifiers and a key with `+`: `shift+meta+space`, `ctrl+alt+d`.
138
+ - Separate sequential chords with whitespace for chord sequences: `shift+meta+space space` requires holding `Shift+⌘` and pressing `Space` twice within ~600ms.
139
+ - Modifier aliases: `meta` / `cmd` / `command`, `alt` / `option`, `ctrl` / `control`.
140
+
141
+ ### `useRegisterDocyrusClient(client)`
142
+
143
+ Registers a Docyrus client after mount so auth-managed clients can be instrumented as soon as they exist.
144
+
145
+ ## DOM Element Picker
146
+
147
+ A small circular target button is rendered at the bottom-right of the main devtools trigger. Clicking it enables a crosshair overlay that highlights the element under the pointer. Clicking an element opens a popover that reads the `data-component-name`, `data-component-path`, and `data-current-file-path` attributes (emitted by `@kivacore/dom-selector-client/babel-plugin-component-annotate`) plus a generated unique CSS selector. Users can type per-element feedback and either send immediately, collect more elements (`Continue`), or dismiss.
148
+
149
+ When `onFeedback` is provided, the collected items are passed to that callback. Otherwise the submission is forwarded to the parent window via the host-bridge `sendToCody` action (same schema used by Docyrus clients embedding the app in an iframe/webview):
150
+
151
+ ```ts
152
+ {
153
+ type: 'DOCY_DEVTOOLS',
154
+ action: 'sendToCody',
155
+ payload: {
156
+ items: DevtoolsFeedbackItem[],
157
+ route: string,
158
+ url: string,
159
+ timestamp: number
160
+ }
161
+ }
162
+ ```
163
+
164
+ Pass `enableElementSelector={false}` to hide the picker trigger.
165
+
166
+ ## Host Bridge
167
+
168
+ When running inside an iframe, devtools can send structured events to the parent window with `postMessage`.
169
+
170
+ Outgoing messages use:
171
+
172
+ ```ts
173
+ {
174
+ type: 'DOCY_DEVTOOLS',
175
+ action: 'sendToCody',
176
+ payload: {
177
+ scope: 'errors' | 'issues' | 'console' | 'error' | 'issue' | 'console-entry',
178
+ items: unknown[],
179
+ route: string,
180
+ url: string,
181
+ timestamp: number
182
+ }
183
+ }
184
+ ```
185
+
186
+ The host can also request data from the iframe with:
187
+
188
+ ```ts
189
+ window.postMessage(
190
+ { type: 'DOCY_DEVTOOLS', action: 'getState', requestId: '1' },
191
+ '*'
192
+ );
193
+ ```
194
+
195
+ Supported host request actions:
196
+
197
+ - `getState`
198
+ - `getErrors`
199
+ - `getIssues`
200
+ - `getConsoleEntries`
201
+
202
+ ## Iframe Messages
203
+
204
+ The `Messages` tab logs `postMessage` traffic on both sides of the iframe / WebView boundary so you can debug the host ↔ app protocol used by `@kivacore/signin` (and any other custom messages your app exchanges with its host).
205
+
206
+ - **Inbound (host → app)** is captured automatically by listening on `window`'s `message` event.
207
+ - **Outbound (app → host)** is captured via a global tap. `@kivacore/signin`'s `postToHost` already calls it. If you send your own `postMessage` payloads, call the tap from your sender so devtools can record them too:
208
+
209
+ ```ts
210
+ declare global {
211
+ interface Window {
212
+ __DOCYRUS_DEVTOOLS_MESSAGE_TAP__?: (
213
+ direction: 'in' | 'out',
214
+ payload: unknown,
215
+ meta?: {
216
+ transport?: 'iframe' | 'webview' | 'window';
217
+ origin?: string;
218
+ targetOrigin?: string;
219
+ }
220
+ ) => void;
221
+ }
222
+ }
223
+
224
+ window.__DOCYRUS_DEVTOOLS_MESSAGE_TAP__?.(
225
+ 'out',
226
+ payload,
227
+ { transport: 'iframe', targetOrigin: hostOrigin }
228
+ );
229
+ window.parent.postMessage(payload, hostOrigin);
230
+ ```
231
+
232
+ Each entry records direction, transport (`iframe` / `webview`), `type` (auto-extracted from `payload.type` when present), origin/targetOrigin, payload, and timestamp.
233
+
234
+ Devtools' own host-bridge messages (`type: 'DOCY_DEVTOOLS'`) are filtered out by default — override with `iframeMessageIgnoreTypes`.
235
+
236
+ ## Agent / CDP Access
237
+
238
+ Devtools also exposes an in-page API so external tools can read the current state without UI interaction:
239
+
240
+ ```ts
241
+ window.__DOCYRUS_DEVTOOLS__?.getState();
242
+ window.__DOCYRUS_DEVTOOLS__?.getErrors();
243
+ window.__DOCYRUS_DEVTOOLS__?.getIssues();
244
+ window.__DOCYRUS_DEVTOOLS__?.getConsoleEntries('error');
245
+ ```
246
+
247
+ This is intended for development tooling, host integrations, and Chrome DevTools Protocol-based assistants.
@@ -0,0 +1,145 @@
1
+ import { D as DevtoolsStore, a as DevtoolsStoreOptions, b as DevtoolsStoreSnapshot, c as DevtoolsStartEntryInput, d as DevtoolsFinalizeEntryInput, e as DevtoolsFailEntryInput, f as DevtoolsConsoleEntryInput, g as DevtoolsMessageEntryInput, h as DevtoolsRecordIssueInput, I as InstrumentationOptions, i as InstrumentableApiClient, j as InstrumentableClient, F as FetchInstrumentationOptions, Q as QueryClientAttachmentOptions, C as ConsoleInstrumentationOptions, k as DevtoolsErrorSummary } from '../dom-selector-Dsp7e405.js';
2
+ export { l as DevtoolsButtonPosition, m as DevtoolsConsoleEntry, n as DevtoolsConsoleLevel, o as DevtoolsConsoleSource, p as DevtoolsEntry, q as DevtoolsEntryKind, r as DevtoolsEntrySource, s as DevtoolsFeedbackItem, t as DevtoolsFeedbackSubmission, u as DevtoolsHostBridgeOptions, v as DevtoolsIssue, w as DevtoolsIssueCode, x as DevtoolsIssueSeverity, y as DevtoolsMessageDirection, z as DevtoolsMessageEntry, A as DevtoolsMessageTransport, B as DomSelectorPayload, E as DomSelectorRect, G as EnableDomSelectorOptions, H as IframeMessagesInstrumentationOptions, J as attachHostBridge, K as enableDomSelector, L as instrumentIframeMessages, M as postDevtoolsMessageToHost } from '../dom-selector-Dsp7e405.js';
3
+ import { DocyrusClient } from '@kivacore/addin-client';
4
+ import { RequestConfig } from '@kivacore/api-client';
5
+ import '@tanstack/react-query';
6
+
7
+ declare class DevtoolsStoreImpl implements DevtoolsStore {
8
+ private entries;
9
+ private consoleEntries;
10
+ private messageEntries;
11
+ private issues;
12
+ private pending;
13
+ private listeners;
14
+ private inFlight;
15
+ private recentStarts;
16
+ private maxEntries;
17
+ private slowThresholdMs;
18
+ private cachedSnapshot;
19
+ constructor(options?: DevtoolsStoreOptions);
20
+ getSnapshot(): DevtoolsStoreSnapshot;
21
+ subscribe(listener: () => void): () => void;
22
+ clear(): void;
23
+ updateOptions(options: DevtoolsStoreOptions): void;
24
+ beginEntry(input: DevtoolsStartEntryInput): string;
25
+ finalizeEntry(entryId: string, input?: DevtoolsFinalizeEntryInput): void;
26
+ failEntry(entryId: string, input: DevtoolsFailEntryInput): void;
27
+ recordConsoleEntry(input: DevtoolsConsoleEntryInput): void;
28
+ recordMessageEntry(input: DevtoolsMessageEntryInput): void;
29
+ recordIssue(input: DevtoolsRecordIssueInput): void;
30
+ shouldSkipFetchCapture(input: {
31
+ fingerprint: string;
32
+ routeKey: string;
33
+ startedAt: number;
34
+ }): boolean;
35
+ private pushRecentStart;
36
+ private releaseInFlight;
37
+ private getInFlightKey;
38
+ private trimEntries;
39
+ private trimConsoleEntries;
40
+ private trimMessageEntries;
41
+ private emit;
42
+ }
43
+ declare function createDevtoolsStore(options?: DevtoolsStoreOptions): DevtoolsStore;
44
+
45
+ declare function instrumentApiClient(client: InstrumentableApiClient, options: InstrumentationOptions): () => void;
46
+ declare function instrumentAddinClient(client: DocyrusClient, options: InstrumentationOptions): () => void;
47
+ declare function instrumentClient(client: InstrumentableClient, options: InstrumentationOptions): () => void;
48
+ declare function instrumentFetch(options: FetchInstrumentationOptions): () => void;
49
+
50
+ declare function attachQueryClient(options: QueryClientAttachmentOptions): () => void;
51
+
52
+ declare function instrumentConsole(options: ConsoleInstrumentationOptions): () => void;
53
+
54
+ type OpenApiExplorerMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
55
+ interface OpenApiExampleObject {
56
+ value?: unknown;
57
+ }
58
+ interface OpenApiSchemaObject {
59
+ type?: string;
60
+ format?: string;
61
+ example?: unknown;
62
+ default?: unknown;
63
+ enum?: unknown[];
64
+ properties?: Record<string, OpenApiSchemaObject>;
65
+ items?: OpenApiSchemaObject;
66
+ required?: string[];
67
+ oneOf?: OpenApiSchemaObject[];
68
+ anyOf?: OpenApiSchemaObject[];
69
+ allOf?: OpenApiSchemaObject[];
70
+ additionalProperties?: boolean | OpenApiSchemaObject;
71
+ }
72
+ interface OpenApiMediaTypeObject {
73
+ schema?: OpenApiSchemaObject;
74
+ example?: unknown;
75
+ examples?: Record<string, OpenApiExampleObject>;
76
+ }
77
+ interface OpenApiRequestBodyObject {
78
+ content?: Record<string, OpenApiMediaTypeObject>;
79
+ }
80
+ interface OpenApiResponseObject {
81
+ content?: Record<string, OpenApiMediaTypeObject>;
82
+ }
83
+ interface OpenApiParameterObject {
84
+ name: string;
85
+ in: 'path' | 'query' | 'header' | 'cookie';
86
+ required?: boolean;
87
+ description?: string;
88
+ schema?: OpenApiSchemaObject;
89
+ example?: unknown;
90
+ }
91
+ interface OpenApiOperationObject {
92
+ summary?: string;
93
+ description?: string;
94
+ operationId?: string;
95
+ tags?: string[];
96
+ parameters?: OpenApiParameterObject[];
97
+ requestBody?: OpenApiRequestBodyObject;
98
+ responses?: Record<string, OpenApiResponseObject>;
99
+ }
100
+ interface OpenApiPathItemObject {
101
+ parameters?: OpenApiParameterObject[];
102
+ get?: OpenApiOperationObject;
103
+ post?: OpenApiOperationObject;
104
+ put?: OpenApiOperationObject;
105
+ patch?: OpenApiOperationObject;
106
+ delete?: OpenApiOperationObject;
107
+ head?: OpenApiOperationObject;
108
+ options?: OpenApiOperationObject;
109
+ }
110
+ interface OpenApiDocument {
111
+ openapi?: string;
112
+ paths?: Record<string, OpenApiPathItemObject>;
113
+ }
114
+ interface OpenApiExplorerOperation {
115
+ id: string;
116
+ method: OpenApiExplorerMethod;
117
+ path: string;
118
+ summary: string;
119
+ description?: string;
120
+ tags: string[];
121
+ parameters: OpenApiParameterObject[];
122
+ requestContentTypes: string[];
123
+ preferredRequestContentType?: string;
124
+ preferredResponseType: RequestConfig['responseType'];
125
+ defaultPathParams: Record<string, string>;
126
+ defaultQueryParams: Record<string, unknown>;
127
+ defaultHeaderParams: Record<string, unknown>;
128
+ defaultBodyText: string;
129
+ }
130
+ interface OpenApiOperationMatch {
131
+ operation: OpenApiExplorerOperation;
132
+ pathParams: Record<string, string>;
133
+ }
134
+ declare function buildOpenApiExplorerOperations(document: OpenApiDocument): OpenApiExplorerOperation[];
135
+ declare function getOpenApiNamespace(path: string): string;
136
+ declare function matchOpenApiOperation(operations: OpenApiExplorerOperation[], method: OpenApiExplorerMethod, path: string): OpenApiOperationMatch | null;
137
+ declare function replaceOpenApiPathParams(path: string, pathParams: Record<string, string>): string;
138
+ declare function prepareOpenApiRequestBody(bodyText: string, contentType?: string): unknown;
139
+
140
+ declare function sanitizeForDevtools(value: unknown, seen?: WeakSet<object>, depth?: number): unknown;
141
+ declare function stableStringify(value: unknown): string;
142
+ declare function normalizeError(error: unknown): DevtoolsErrorSummary;
143
+
144
+ export { ConsoleInstrumentationOptions, DevtoolsConsoleEntryInput, DevtoolsErrorSummary, DevtoolsFailEntryInput, DevtoolsFinalizeEntryInput, DevtoolsMessageEntryInput, DevtoolsRecordIssueInput, DevtoolsStartEntryInput, DevtoolsStore, DevtoolsStoreImpl, DevtoolsStoreOptions, DevtoolsStoreSnapshot, FetchInstrumentationOptions, InstrumentableApiClient, InstrumentableClient, InstrumentationOptions, QueryClientAttachmentOptions, attachQueryClient, buildOpenApiExplorerOperations, createDevtoolsStore, getOpenApiNamespace, instrumentAddinClient, instrumentApiClient, instrumentClient, instrumentConsole, instrumentFetch, matchOpenApiOperation, normalizeError, prepareOpenApiRequestBody, replaceOpenApiPathParams, sanitizeForDevtools, stableStringify };
145
+ export type { OpenApiDocument, OpenApiExplorerMethod, OpenApiExplorerOperation, OpenApiOperationMatch, OpenApiParameterObject };