@notis_ai/cli 0.2.0-beta.16.1 → 0.2.0-beta.161.1

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 (161) hide show
  1. package/README.md +435 -133
  2. package/bin/check-runtime.js +15 -0
  3. package/bin/notis.js +2 -0
  4. package/config/notis_app_boundary_rules.json +50 -0
  5. package/config/notis_app_design_rules.json +135 -0
  6. package/dist/agent-hooks/notis-agent-hook.mjs +19008 -0
  7. package/dist/base-skills/notis-apps/SKILL.md +70 -0
  8. package/dist/base-skills/notis-apps/references/architecture.md +164 -0
  9. package/dist/base-skills/notis-apps/references/context.md +81 -0
  10. package/dist/base-skills/notis-apps/references/design.md +165 -0
  11. package/dist/base-skills/notis-apps/references/reading.md +89 -0
  12. package/dist/base-skills/notis-apps/references/release.md +99 -0
  13. package/dist/base-skills/notis-apps/references/sdk.md +62 -0
  14. package/dist/base-skills/notis-apps/references/troubleshooting.md +23 -0
  15. package/dist/base-skills/notis-cli/SKILL.md +140 -0
  16. package/dist/base-skills/notis-cli/references/app-delivery.md +18 -0
  17. package/dist/base-skills/notis-cli/references/native-databases.md +20 -0
  18. package/dist/base-skills/notis-cli/references/tool-examples.md +56 -0
  19. package/dist/base-skills/notis-cli/references/troubleshooting.md +39 -0
  20. package/dist/base-skills/notis-query/SKILL.md +67 -0
  21. package/dist/base-skills/notis-query/references/database-discovery.md +59 -0
  22. package/dist/base-skills/notis-query/references/documents.md +50 -0
  23. package/dist/base-skills/notis-query/references/query.md +543 -0
  24. package/dist/skill-sync/index.js +1626 -0
  25. package/dist/skill-sync/index.js.map +7 -0
  26. package/dist/skill-sync-worker.mjs +2990 -0
  27. package/package.json +18 -7
  28. package/skills/notis-apps/cli.md +313 -0
  29. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +39 -0
  30. package/skills/notis-onboarding/BRIEF.md +129 -0
  31. package/skills/notis-query/cli.md +39 -0
  32. package/src/agent-hook-entry.js +5 -0
  33. package/src/cli.js +294 -25
  34. package/src/command-specs/agents.js +392 -0
  35. package/src/command-specs/apps.js +1470 -202
  36. package/src/command-specs/auth.js +114 -137
  37. package/src/command-specs/diagnostics.js +729 -0
  38. package/src/command-specs/handover.js +374 -0
  39. package/src/command-specs/helpers.js +84 -82
  40. package/src/command-specs/index.js +25 -6
  41. package/src/command-specs/meta.js +150 -18
  42. package/src/command-specs/onboarding.js +290 -0
  43. package/src/command-specs/profile.js +358 -0
  44. package/src/command-specs/reports.js +86 -0
  45. package/src/command-specs/skills.js +75 -0
  46. package/src/command-specs/smoke.js +386 -0
  47. package/src/command-specs/tools.js +455 -139
  48. package/src/runtime/agent-browser.js +632 -0
  49. package/src/runtime/agent-memory-state.js +126 -0
  50. package/src/runtime/agent-setup.js +383 -0
  51. package/src/runtime/app-boundary-validator.js +404 -0
  52. package/src/runtime/app-changelog.js +79 -0
  53. package/src/runtime/app-platform.js +2633 -210
  54. package/src/runtime/app-registry-scaffolds.js +367 -0
  55. package/src/runtime/app-test-server.js +292 -0
  56. package/src/runtime/assets/store-screenshot-dark.png +0 -0
  57. package/src/runtime/auth-recovery.js +110 -0
  58. package/src/runtime/base-skills.d.ts +20 -0
  59. package/src/runtime/base-skills.js +167 -0
  60. package/src/runtime/channel.js +133 -0
  61. package/src/runtime/delegated-context.js +68 -0
  62. package/src/runtime/errors.js +1 -0
  63. package/src/runtime/git.js +233 -0
  64. package/src/runtime/login-listener.js +15 -0
  65. package/src/runtime/oauth.js +2622 -0
  66. package/src/runtime/output.js +37 -5
  67. package/src/runtime/ports.js +31 -0
  68. package/src/runtime/profiles.js +906 -55
  69. package/src/runtime/skill-sync/cloud-client.ts +99 -0
  70. package/src/runtime/skill-sync/index.ts +697 -0
  71. package/src/runtime/skill-sync/local-scanner.ts +1046 -0
  72. package/src/runtime/skill-sync/symlink-manager.ts +433 -0
  73. package/src/runtime/skill-sync/sync-plan.ts +22 -0
  74. package/src/runtime/skill-sync/types.ts +110 -0
  75. package/src/runtime/skill-sync/write-cloud-skill.ts +50 -0
  76. package/src/runtime/skill-sync-service.js +109 -0
  77. package/src/runtime/store-screenshot.js +143 -0
  78. package/src/runtime/sync-skills.d.ts +37 -0
  79. package/src/runtime/sync-skills.js +231 -0
  80. package/src/runtime/telemetry.js +92 -0
  81. package/src/runtime/transport.js +324 -45
  82. package/src/skill-sync-worker-entry.js +2 -0
  83. package/src/skill-sync-worker.js +50 -0
  84. package/template/.harness/index.html.tmpl +430 -0
  85. package/template/CHANGELOG.md +5 -0
  86. package/template/app/globals.css +28 -3
  87. package/template/app/layout.tsx +6 -3
  88. package/template/app/page.tsx +49 -42
  89. package/template/components/page-heading.tsx +23 -0
  90. package/template/components/ui/badge.tsx +7 -4
  91. package/template/components/ui/button.tsx +1 -1
  92. package/template/components/ui/card.tsx +24 -11
  93. package/template/components/ui/native-select.tsx +24 -0
  94. package/template/notis.config.ts +24 -6
  95. package/template/package-lock.json +3642 -0
  96. package/template/package.json +19 -16
  97. package/template/packages/{notis-sdk → sdk}/package.json +14 -4
  98. package/template/packages/sdk/src/agentContext.ts +36 -0
  99. package/template/packages/sdk/src/components/DocumentEditor.tsx +103 -0
  100. package/template/packages/sdk/src/components/Markdown.tsx +60 -0
  101. package/template/packages/sdk/src/components/MarkdownEditor.tsx +121 -0
  102. package/template/packages/sdk/src/components/MultiSelectActionBar.tsx +285 -0
  103. package/template/packages/sdk/src/components/MultiSelectCheckbox.tsx +97 -0
  104. package/template/packages/sdk/src/components/MultiSelectDragOverlay.tsx +39 -0
  105. package/template/packages/sdk/src/components/NotisCommentBoundary.tsx +172 -0
  106. package/template/packages/sdk/src/components/NotisSelectionBoundary.tsx +59 -0
  107. package/template/packages/sdk/src/components/ShortcutHints.tsx +56 -0
  108. package/template/packages/sdk/src/components/Skeleton.tsx +24 -0
  109. package/template/packages/sdk/src/config.ts +257 -0
  110. package/template/packages/sdk/src/documents.ts +256 -0
  111. package/template/packages/sdk/src/hooks/useActiveResource.ts +19 -0
  112. package/template/packages/sdk/src/hooks/useAgentContext.ts +23 -0
  113. package/template/packages/sdk/src/hooks/useCloudComputer.ts +64 -0
  114. package/template/packages/sdk/src/hooks/useCollectionInteractions.ts +836 -0
  115. package/template/packages/sdk/src/hooks/useDatabaseSchema.ts +49 -0
  116. package/template/packages/sdk/src/hooks/useDatabaseSubscription.ts +76 -0
  117. package/template/packages/sdk/src/hooks/useDocument.ts +43 -0
  118. package/template/packages/sdk/src/hooks/useDocuments.ts +84 -0
  119. package/template/packages/sdk/src/hooks/useHandover.ts +78 -0
  120. package/template/packages/sdk/src/hooks/useLongPressSelection.ts +79 -0
  121. package/template/packages/sdk/src/hooks/useMultiSelect.ts +95 -0
  122. package/template/packages/{notis-sdk → sdk}/src/hooks/useNotis.ts +10 -4
  123. package/template/packages/{notis-sdk → sdk}/src/hooks/useNotisNavigation.ts +11 -8
  124. package/template/packages/sdk/src/hooks/useQuery.ts +71 -0
  125. package/template/packages/sdk/src/hooks/useTool.ts +65 -0
  126. package/template/packages/sdk/src/hooks/useToolQuery.ts +12 -0
  127. package/template/packages/sdk/src/hooks/useTopBarSearch.ts +81 -0
  128. package/template/packages/sdk/src/hooks/useUpsertDocument.ts +95 -0
  129. package/template/packages/sdk/src/index.ts +161 -0
  130. package/template/packages/sdk/src/interactions/actions.ts +59 -0
  131. package/template/packages/sdk/src/interactions/shortcuts.tsx +694 -0
  132. package/template/packages/sdk/src/interactions/visibility.ts +13 -0
  133. package/template/packages/sdk/src/interactions.ts +45 -0
  134. package/template/packages/sdk/src/provider.tsx +44 -0
  135. package/template/packages/sdk/src/queryCache.ts +170 -0
  136. package/template/packages/sdk/src/runtime.ts +451 -0
  137. package/template/packages/sdk/src/styles.css +247 -0
  138. package/template/packages/sdk/src/tailwind.ts +66 -0
  139. package/template/packages/sdk/src/vite.ts +73 -0
  140. package/template/packages/{notis-sdk → sdk}/tsconfig.json +1 -0
  141. package/template/postcss.config.mjs +1 -1
  142. package/template/tailwind.config.ts +1 -6
  143. package/template/tsconfig.json +1 -0
  144. package/src/command-specs/db.js +0 -163
  145. package/src/runtime/app-preview-server.js +0 -312
  146. package/template/packages/notis-sdk/src/config.ts +0 -48
  147. package/template/packages/notis-sdk/src/helpers.ts +0 -131
  148. package/template/packages/notis-sdk/src/hooks/useAppState.ts +0 -50
  149. package/template/packages/notis-sdk/src/hooks/useCollectionItem.ts +0 -58
  150. package/template/packages/notis-sdk/src/hooks/useDatabase.ts +0 -87
  151. package/template/packages/notis-sdk/src/hooks/useDocument.ts +0 -61
  152. package/template/packages/notis-sdk/src/hooks/useTool.ts +0 -49
  153. package/template/packages/notis-sdk/src/hooks/useUpsertDocument.ts +0 -57
  154. package/template/packages/notis-sdk/src/index.ts +0 -47
  155. package/template/packages/notis-sdk/src/provider.tsx +0 -44
  156. package/template/packages/notis-sdk/src/runtime.ts +0 -159
  157. package/template/packages/notis-sdk/src/styles.css +0 -123
  158. package/template/packages/notis-sdk/src/vite.ts +0 -54
  159. /package/template/packages/{notis-sdk → sdk}/src/hooks/useBackend.ts +0 -0
  160. /package/template/packages/{notis-sdk → sdk}/src/hooks/useTools.ts +0 -0
  161. /package/template/packages/{notis-sdk → sdk}/src/ui.ts +0 -0
@@ -0,0 +1,694 @@
1
+ 'use client';
2
+
3
+ import React, {
4
+ createContext,
5
+ useCallback,
6
+ useContext,
7
+ useEffect,
8
+ useMemo,
9
+ useRef,
10
+ useState,
11
+ type ReactNode,
12
+ } from 'react';
13
+
14
+ export type ShortcutScope = 'app' | 'route' | 'collection' | 'detail' | 'modal';
15
+
16
+ export const SHORTCUT_SCOPE_PRIORITY: Record<ShortcutScope, number> = {
17
+ app: 0,
18
+ route: 100,
19
+ collection: 200,
20
+ detail: 300,
21
+ modal: 400,
22
+ };
23
+
24
+ export interface ShortcutDefinition {
25
+ id: string;
26
+ /** A chord (`Mod+A`) or timed sequence (`G I`). */
27
+ keys: string | string[];
28
+ label?: string;
29
+ enabled?: boolean;
30
+ allowInEditable?: boolean;
31
+ allowRepeat?: boolean;
32
+ preventDefault?: boolean;
33
+ stopPropagation?: boolean;
34
+ onTrigger: (event: KeyboardEvent) => void | Promise<void>;
35
+ }
36
+
37
+ export interface UseShortcutsOptions {
38
+ enabled?: boolean;
39
+ scope?: ShortcutScope;
40
+ /** Added to the scope priority for local precedence within a scope. */
41
+ priority?: number;
42
+ sequenceTimeoutMs?: number;
43
+ /** Internal owner used to route collection shortcuts to the last interacted collection. */
44
+ collectionOwnerId?: string;
45
+ /** Evaluated at dispatch time, including for retained hidden app views. */
46
+ isAvailable?: () => boolean;
47
+ }
48
+
49
+ interface ShortcutRegistration {
50
+ id: number;
51
+ order: number;
52
+ scope: ShortcutScope;
53
+ priority: number;
54
+ enabled: boolean;
55
+ sequenceTimeoutMs: number;
56
+ collectionOwnerId?: string;
57
+ /** Evaluated at dispatch time, including for retained hidden app views. */
58
+ isAvailable?: () => boolean;
59
+ getShortcuts: () => ShortcutDefinition[];
60
+ }
61
+
62
+ interface ShortcutRegistry {
63
+ register: (registration: Omit<ShortcutRegistration, 'id' | 'order'>) => () => void;
64
+ }
65
+
66
+ const SHORTCUT_CONTEXT_SYMBOL = Symbol.for('notis.sdk.shortcut_context');
67
+ type ShortcutContextGlobal = typeof globalThis & {
68
+ [SHORTCUT_CONTEXT_SYMBOL]?: React.Context<ShortcutRegistry | null>;
69
+ };
70
+
71
+ function getShortcutContext(): React.Context<ShortcutRegistry | null> {
72
+ const scope = globalThis as ShortcutContextGlobal;
73
+ if (!scope[SHORTCUT_CONTEXT_SYMBOL]) {
74
+ scope[SHORTCUT_CONTEXT_SYMBOL] = createContext<ShortcutRegistry | null>(null);
75
+ }
76
+ return scope[SHORTCUT_CONTEXT_SYMBOL]!;
77
+ }
78
+
79
+ const ShortcutContext = getShortcutContext();
80
+
81
+ const SHORTCUT_COLLECTION_STATE_SYMBOL = Symbol.for('notis.sdk.shortcut_collection_state');
82
+ type ShortcutCollectionGlobal = typeof globalThis & {
83
+ [SHORTCUT_COLLECTION_STATE_SYMBOL]?: { activeOwnerId: string | null; nextOwnerId: number };
84
+ };
85
+
86
+ function getShortcutCollectionState() {
87
+ const scope = globalThis as ShortcutCollectionGlobal;
88
+ if (!scope[SHORTCUT_COLLECTION_STATE_SYMBOL]) {
89
+ scope[SHORTCUT_COLLECTION_STATE_SYMBOL] = { activeOwnerId: null, nextOwnerId: 1 };
90
+ }
91
+ return scope[SHORTCUT_COLLECTION_STATE_SYMBOL]!;
92
+ }
93
+
94
+ export function createShortcutCollectionOwner(): string {
95
+ const state = getShortcutCollectionState();
96
+ return `collection-${state.nextOwnerId++}`;
97
+ }
98
+
99
+ export function releaseShortcutCollection(ownerId: string): void {
100
+ const state = getShortcutCollectionState();
101
+ if (state.activeOwnerId === ownerId) state.activeOwnerId = null;
102
+ }
103
+
104
+ export function activateShortcutCollection(ownerId: string): void {
105
+ getShortcutCollectionState().activeOwnerId = ownerId;
106
+ }
107
+
108
+ interface ParsedChord {
109
+ key: string;
110
+ mod: boolean;
111
+ shift: boolean;
112
+ alt: boolean;
113
+ }
114
+
115
+ interface ParsedShortcut {
116
+ definition: ShortcutDefinition;
117
+ sequence: ParsedChord[];
118
+ }
119
+
120
+ interface SequenceState {
121
+ chords: string[];
122
+ at: number;
123
+ }
124
+
125
+ function normalizeKey(key: string): string {
126
+ const lower = key.trim().toLowerCase();
127
+ if (lower === 'esc') return 'escape';
128
+ if (lower === 'return') return 'enter';
129
+ if (lower === 'space') return ' ';
130
+ if (lower === 'arrowup' || lower === 'up') return 'arrowup';
131
+ if (lower === 'arrowdown' || lower === 'down') return 'arrowdown';
132
+ if (lower === 'arrowleft' || lower === 'left') return 'arrowleft';
133
+ if (lower === 'arrowright' || lower === 'right') return 'arrowright';
134
+ return lower;
135
+ }
136
+
137
+ function parseChord(raw: string): ParsedChord | null {
138
+ const parts = raw.split('+').map((part) => part.trim()).filter(Boolean);
139
+ if (parts.length === 0) return null;
140
+ let key = '';
141
+ let mod = false;
142
+ let shift = false;
143
+ let alt = false;
144
+ for (const part of parts) {
145
+ const lower = part.toLowerCase();
146
+ if (lower === 'mod' || lower === 'cmd' || lower === 'ctrl' || lower === 'meta') {
147
+ mod = true;
148
+ } else if (lower === 'shift') {
149
+ shift = true;
150
+ } else if (lower === 'alt' || lower === 'option') {
151
+ alt = true;
152
+ } else {
153
+ key = normalizeKey(part);
154
+ }
155
+ }
156
+ return key ? { key, mod, shift, alt } : null;
157
+ }
158
+
159
+ function parseShortcut(definition: ShortcutDefinition): ParsedShortcut[] {
160
+ const values = Array.isArray(definition.keys) ? definition.keys : [definition.keys];
161
+ return values.flatMap((value) => {
162
+ const sequence = value
163
+ .trim()
164
+ .split(/\s+/)
165
+ .map(parseChord)
166
+ .filter((chord): chord is ParsedChord => chord !== null);
167
+ return sequence.length > 0 ? [{ definition, sequence }] : [];
168
+ });
169
+ }
170
+
171
+ function chordToken(chord: ParsedChord): string {
172
+ return `${chord.mod ? 'm' : '-'}${chord.shift ? 's' : '-'}${chord.alt ? 'a' : '-'}:${chord.key}`;
173
+ }
174
+
175
+ function eventChord(event: KeyboardEvent): ParsedChord {
176
+ let key = normalizeKey(event.key);
177
+ let shift = event.shiftKey;
178
+ if (key === '3' && shift) key = '#';
179
+ if (key === '#' || key === '?') shift = false;
180
+ return {
181
+ key,
182
+ mod: Boolean(event.metaKey || event.ctrlKey),
183
+ shift,
184
+ alt: event.altKey,
185
+ };
186
+ }
187
+
188
+ export function isEditableShortcutEvent(event: Event): boolean {
189
+ const path = event.composedPath?.() ?? [event.target];
190
+ return path.some((target) => {
191
+ if (!(target instanceof HTMLElement)) return false;
192
+ if (target.isContentEditable || target.getAttribute('contenteditable') === 'true') return true;
193
+ const tag = target.tagName;
194
+ if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || tag === 'BUTTON' || tag === 'SUMMARY') {
195
+ return true;
196
+ }
197
+ if (tag === 'A' && target.hasAttribute('href')) return true;
198
+ return ['button', 'link', 'menuitem', 'switch', 'tab'].includes(
199
+ target.getAttribute('role') || '',
200
+ );
201
+ });
202
+ }
203
+
204
+ function matchPrefix(tokens: string[], candidate: ParsedShortcut): boolean {
205
+ if (tokens.length > candidate.sequence.length) return false;
206
+ return tokens.every((token, index) => token === chordToken(candidate.sequence[index]!));
207
+ }
208
+
209
+ function consumeShortcut(event: KeyboardEvent, definition: ShortcutDefinition): void {
210
+ if (definition.preventDefault !== false) event.preventDefault();
211
+ if (definition.stopPropagation !== false) {
212
+ event.stopPropagation();
213
+ event.stopImmediatePropagation?.();
214
+ }
215
+ void definition.onTrigger(event);
216
+ }
217
+
218
+ export function ShortcutProvider({ children }: { children: ReactNode }) {
219
+ const parentRegistry = useContext(ShortcutContext);
220
+ if (parentRegistry) return <>{children}</>;
221
+ return <ShortcutProviderRoot>{children}</ShortcutProviderRoot>;
222
+ }
223
+
224
+ export interface ShortcutHelpEntry {
225
+ id: string;
226
+ keys: string[];
227
+ label: string;
228
+ scope: ShortcutScope;
229
+ }
230
+
231
+ const HELP_SCOPE_LABELS: Record<ShortcutScope, string> = {
232
+ modal: 'Dialog',
233
+ detail: 'Detail',
234
+ collection: 'Collection',
235
+ route: 'This view',
236
+ app: 'App',
237
+ };
238
+
239
+ const HELP_SCOPE_ORDER: ShortcutScope[] = ['modal', 'detail', 'collection', 'route', 'app'];
240
+
241
+ function applicableRegistrations(
242
+ registrations: Iterable<ShortcutRegistration>,
243
+ ): ShortcutRegistration[] {
244
+ const ordered = Array.from(registrations)
245
+ .filter((registration) => registration.enabled && registration.isAvailable?.() !== false)
246
+ .sort((a, b) => b.priority - a.priority || b.order - a.order);
247
+ const activeCollectionOwner = getShortcutCollectionState().activeOwnerId;
248
+ const hasActiveCollection = Boolean(
249
+ activeCollectionOwner
250
+ && ordered.some((registration) => registration.collectionOwnerId === activeCollectionOwner),
251
+ );
252
+ return hasActiveCollection
253
+ ? ordered.filter(
254
+ (registration) => !registration.collectionOwnerId
255
+ || registration.collectionOwnerId === activeCollectionOwner,
256
+ )
257
+ : ordered;
258
+ }
259
+
260
+ // Standalone app verification and legacy hosts may not install a provider.
261
+ // They must still arbitrate shortcuts together, not by effect/listener order.
262
+ const FALLBACK_REGISTRIES_SYMBOL = Symbol.for('notis.sdk.fallback_shortcut_registries');
263
+ interface FallbackShortcutRegistry {
264
+ registrations: Map<number, ShortcutRegistration>;
265
+ nextId: number;
266
+ dispatch: (event: KeyboardEvent) => void;
267
+ }
268
+ type FallbackShortcutGlobal = typeof globalThis & {
269
+ [FALLBACK_REGISTRIES_SYMBOL]?: WeakMap<Document, FallbackShortcutRegistry>;
270
+ };
271
+
272
+ function registerFallbackShortcut(input: Omit<ShortcutRegistration, 'id' | 'order'>): () => void {
273
+ const scope = globalThis as FallbackShortcutGlobal;
274
+ const registries = scope[FALLBACK_REGISTRIES_SYMBOL] ??= new WeakMap();
275
+ const ownerDocument = document;
276
+ let registry = registries.get(ownerDocument);
277
+ if (!registry) {
278
+ const registrations = new Map<number, ShortcutRegistration>();
279
+ registry = {
280
+ registrations,
281
+ nextId: 1,
282
+ dispatch: (event) => {
283
+ if (event.defaultPrevented) return;
284
+ const editable = isEditableShortcutEvent(event);
285
+ const token = chordToken(eventChord(event));
286
+ for (const registration of applicableRegistrations(registrations.values())) {
287
+ for (const shortcut of registration.getShortcuts()) {
288
+ if (shortcut.enabled === false || (editable && !shortcut.allowInEditable) || (event.repeat && !shortcut.allowRepeat)) continue;
289
+ const match = parseShortcut(shortcut).some(
290
+ (candidate) => candidate.sequence.length === 1 && chordToken(candidate.sequence[0]!) === token,
291
+ );
292
+ if (match) {
293
+ consumeShortcut(event, shortcut);
294
+ return;
295
+ }
296
+ }
297
+ }
298
+ },
299
+ };
300
+ registries.set(ownerDocument, registry);
301
+ ownerDocument.addEventListener('keydown', registry.dispatch, true);
302
+ }
303
+ const id = registry.nextId++;
304
+ registry.registrations.set(id, { ...input, id, order: id });
305
+ return () => {
306
+ registry.registrations.delete(id);
307
+ if (registry.registrations.size === 0) {
308
+ ownerDocument.removeEventListener('keydown', registry.dispatch, true);
309
+ registries.delete(ownerDocument);
310
+ }
311
+ };
312
+ }
313
+
314
+ function shortcutToken(raw: string): string | null {
315
+ const definition: ShortcutDefinition = { id: '', keys: raw, onTrigger: () => undefined };
316
+ const parsed = parseShortcut(definition)[0];
317
+ return parsed ? parsed.sequence.map(chordToken).join(' ') : null;
318
+ }
319
+
320
+ function collectShortcutHelpEntries(
321
+ registrations: Iterable<ShortcutRegistration>,
322
+ ): ShortcutHelpEntry[] {
323
+ const claimed = new Set<string>();
324
+ const entries: ShortcutHelpEntry[] = [];
325
+ for (const registration of applicableRegistrations(registrations)) {
326
+ for (const shortcut of registration.getShortcuts()) {
327
+ if (shortcut.enabled === false || !shortcut.label) continue;
328
+ const values = Array.isArray(shortcut.keys) ? shortcut.keys : [shortcut.keys];
329
+ const keys = values.filter((value) => {
330
+ const token = shortcutToken(value);
331
+ if (!token || claimed.has(token)) return false;
332
+ claimed.add(token);
333
+ return true;
334
+ });
335
+ if (keys.length > 0) {
336
+ entries.push({ id: shortcut.id, keys, label: shortcut.label, scope: registration.scope });
337
+ }
338
+ }
339
+ }
340
+ return entries;
341
+ }
342
+
343
+ function ShortcutProviderRoot({ children }: { children: ReactNode }) {
344
+ const registrationsRef = useRef(new Map<number, ShortcutRegistration>());
345
+ const nextIdRef = useRef(1);
346
+ const nextOrderRef = useRef(1);
347
+ const sequenceRef = useRef<SequenceState>({ chords: [], at: 0 });
348
+ const [helpOpen, setHelpOpen] = useState(false);
349
+ const helpOpenRef = useRef(false);
350
+ const [, setRegistryVersion] = useState(0);
351
+
352
+ const updateHelpOpen = useCallback((open: boolean) => {
353
+ helpOpenRef.current = open;
354
+ setHelpOpen(open);
355
+ }, []);
356
+
357
+ const register = useCallback((input: Omit<ShortcutRegistration, 'id' | 'order'>) => {
358
+ const id = nextIdRef.current++;
359
+ registrationsRef.current.set(id, {
360
+ ...input,
361
+ id,
362
+ order: nextOrderRef.current++,
363
+ });
364
+ if (helpOpenRef.current) setRegistryVersion((version) => version + 1);
365
+ return () => {
366
+ registrationsRef.current.delete(id);
367
+ if (helpOpenRef.current) setRegistryVersion((version) => version + 1);
368
+ };
369
+ }, []);
370
+
371
+ useEffect(() => {
372
+ const handleKeyDown = (event: KeyboardEvent) => {
373
+ const editable = isEditableShortcutEvent(event);
374
+ if (!editable && !event.repeat && event.key === '?' && !event.metaKey && !event.ctrlKey && !event.altKey) {
375
+ event.preventDefault();
376
+ event.stopPropagation();
377
+ event.stopImmediatePropagation?.();
378
+ updateHelpOpen(!helpOpenRef.current);
379
+ return;
380
+ }
381
+ if (helpOpenRef.current) {
382
+ if (event.key === 'Escape') {
383
+ event.preventDefault();
384
+ event.stopPropagation();
385
+ event.stopImmediatePropagation?.();
386
+ updateHelpOpen(false);
387
+ }
388
+ return;
389
+ }
390
+
391
+ const registrations = applicableRegistrations(registrationsRef.current.values());
392
+ if (registrations.length === 0) return;
393
+ const token = chordToken(eventChord(event));
394
+ const now = Date.now();
395
+
396
+ for (const registration of registrations) {
397
+ const candidates = registration.getShortcuts()
398
+ .filter((shortcut) => shortcut.enabled !== false)
399
+ .filter((shortcut) => !editable || shortcut.allowInEditable)
400
+ .filter((shortcut) => !event.repeat || shortcut.allowRepeat)
401
+ .flatMap(parseShortcut);
402
+ if (candidates.length === 0) continue;
403
+
404
+ const previous = now - sequenceRef.current.at <= registration.sequenceTimeoutMs
405
+ ? sequenceRef.current.chords
406
+ : [];
407
+ const attempts = previous.length > 0 ? [[...previous, token], [token]] : [[token]];
408
+
409
+ for (const attempt of attempts) {
410
+ const matches = candidates.filter((candidate) => matchPrefix(attempt, candidate));
411
+ if (matches.length === 0) continue;
412
+ const exact = matches.find((candidate) => candidate.sequence.length === attempt.length);
413
+ const hasLonger = matches.some((candidate) => candidate.sequence.length > attempt.length);
414
+ if (exact && !hasLonger) {
415
+ sequenceRef.current = { chords: [], at: 0 };
416
+ consumeShortcut(event, exact.definition);
417
+ return;
418
+ }
419
+ sequenceRef.current = { chords: attempt, at: now };
420
+ event.preventDefault();
421
+ return;
422
+ }
423
+ }
424
+
425
+ sequenceRef.current = { chords: [], at: 0 };
426
+ };
427
+
428
+ document.addEventListener('keydown', handleKeyDown, true);
429
+ return () => document.removeEventListener('keydown', handleKeyDown, true);
430
+ }, [updateHelpOpen]);
431
+
432
+ const registry = useMemo<ShortcutRegistry>(() => ({ register }), [register]);
433
+ const helpEntries = helpOpen ? collectShortcutHelpEntries(registrationsRef.current.values()) : [];
434
+ return (
435
+ <ShortcutContext.Provider value={registry}>
436
+ {children}
437
+ {helpOpen ? <ShortcutHelpDialog entries={helpEntries} onClose={() => updateHelpOpen(false)} /> : null}
438
+ </ShortcutContext.Provider>
439
+ );
440
+ }
441
+
442
+ function ShortcutHelpDialog({
443
+ entries,
444
+ onClose,
445
+ }: {
446
+ entries: ShortcutHelpEntry[];
447
+ onClose: () => void;
448
+ }) {
449
+ const closeRef = useRef<HTMLButtonElement>(null);
450
+ const previousFocusRef = useRef<HTMLElement | null>(
451
+ typeof document !== 'undefined' && document.activeElement instanceof HTMLElement
452
+ ? document.activeElement
453
+ : null,
454
+ );
455
+ useEffect(() => {
456
+ closeRef.current?.focus({ preventScroll: true });
457
+ return () => previousFocusRef.current?.focus({ preventScroll: true });
458
+ }, []);
459
+ const grouped = HELP_SCOPE_ORDER.map((scope) => ({
460
+ scope,
461
+ entries: entries.filter((entry) => entry.scope === scope),
462
+ })).filter((group) => group.entries.length > 0);
463
+
464
+ return (
465
+ <div
466
+ role="presentation"
467
+ data-notis-shortcut-help-backdrop=""
468
+ onMouseDown={(event) => {
469
+ if (event.target === event.currentTarget) onClose();
470
+ }}
471
+ style={helpBackdropStyle}
472
+ >
473
+ <section
474
+ role="dialog"
475
+ aria-modal="true"
476
+ aria-labelledby="notis-shortcut-help-title"
477
+ data-notis-shortcut-help=""
478
+ onKeyDown={(event) => {
479
+ // The help surface has one interactive control. Keep keyboard focus
480
+ // in the modal instead of allowing Tab to escape into app chrome.
481
+ if (event.key === 'Tab') {
482
+ event.preventDefault();
483
+ closeRef.current?.focus({ preventScroll: true });
484
+ }
485
+ }}
486
+ style={helpDialogStyle}
487
+ >
488
+ <header style={helpHeaderStyle}>
489
+ <div>
490
+ <h2 id="notis-shortcut-help-title" style={helpTitleStyle}>Keyboard shortcuts</h2>
491
+ <p style={helpSubtitleStyle}>Available in this view</p>
492
+ </div>
493
+ <button
494
+ ref={closeRef}
495
+ type="button"
496
+ aria-label="Close keyboard shortcuts"
497
+ onClick={onClose}
498
+ style={helpCloseStyle}
499
+ >
500
+ Esc
501
+ </button>
502
+ </header>
503
+ <div style={helpBodyStyle}>
504
+ {grouped.map((group) => (
505
+ <section key={group.scope} aria-label={HELP_SCOPE_LABELS[group.scope]}>
506
+ <h3 style={helpGroupTitleStyle}>{HELP_SCOPE_LABELS[group.scope]}</h3>
507
+ <div style={helpListStyle}>
508
+ {group.entries.map((entry) => (
509
+ <div key={`${group.scope}:${entry.id}`} style={helpRowStyle}>
510
+ <span>{entry.label}</span>
511
+ <span style={helpKeysStyle}>
512
+ {entry.keys.map((keys) => (
513
+ <kbd key={keys} style={helpKeyStyle}>{shortcutDisplay(keys)}</kbd>
514
+ ))}
515
+ </span>
516
+ </div>
517
+ ))}
518
+ </div>
519
+ </section>
520
+ ))}
521
+ <section aria-label="Help">
522
+ <h3 style={helpGroupTitleStyle}>Help</h3>
523
+ <div style={helpListStyle}>
524
+ <div style={helpRowStyle}>
525
+ <span>Show keyboard shortcuts</span>
526
+ <kbd style={helpKeyStyle}>?</kbd>
527
+ </div>
528
+ </div>
529
+ </section>
530
+ </div>
531
+ </section>
532
+ </div>
533
+ );
534
+ }
535
+
536
+ const helpBackdropStyle: React.CSSProperties = {
537
+ position: 'fixed',
538
+ inset: 0,
539
+ zIndex: 1000,
540
+ display: 'grid',
541
+ placeItems: 'center',
542
+ padding: '1.5rem',
543
+ background: 'rgba(0, 0, 0, 0.42)',
544
+ backdropFilter: 'blur(3px)',
545
+ };
546
+
547
+ const helpDialogStyle: React.CSSProperties = {
548
+ width: 'min(34rem, 100%)',
549
+ maxHeight: 'min(42rem, calc(100dvh - 3rem))',
550
+ overflow: 'hidden',
551
+ border: '1px solid hsl(var(--border))',
552
+ borderRadius: '0.875rem',
553
+ background: 'hsl(var(--background))',
554
+ color: 'hsl(var(--foreground))',
555
+ boxShadow: '0 24px 70px rgba(0, 0, 0, 0.28)',
556
+ fontFamily: 'inherit',
557
+ };
558
+
559
+ const helpHeaderStyle: React.CSSProperties = {
560
+ display: 'flex',
561
+ alignItems: 'flex-start',
562
+ justifyContent: 'space-between',
563
+ gap: '1rem',
564
+ padding: '1.25rem 1.25rem 1rem',
565
+ borderBottom: '1px solid hsl(var(--border))',
566
+ };
567
+
568
+ const helpTitleStyle: React.CSSProperties = { margin: 0, fontSize: '1rem', fontWeight: 650 };
569
+ const helpSubtitleStyle: React.CSSProperties = {
570
+ margin: '0.2rem 0 0',
571
+ color: 'hsl(var(--muted-foreground))',
572
+ fontSize: '0.75rem',
573
+ };
574
+ const helpCloseStyle: React.CSSProperties = {
575
+ border: '1px solid hsl(var(--border))',
576
+ borderRadius: '0.35rem',
577
+ background: 'hsl(var(--muted))',
578
+ color: 'hsl(var(--muted-foreground))',
579
+ padding: '0.2rem 0.45rem',
580
+ cursor: 'pointer',
581
+ font: 'inherit',
582
+ fontSize: '0.7rem',
583
+ };
584
+ const helpBodyStyle: React.CSSProperties = {
585
+ display: 'grid',
586
+ gap: '1.1rem',
587
+ maxHeight: 'calc(min(42rem, 100dvh - 3rem) - 5rem)',
588
+ overflowY: 'auto',
589
+ padding: '1rem 1.25rem 1.25rem',
590
+ };
591
+ const helpGroupTitleStyle: React.CSSProperties = {
592
+ margin: '0 0 0.35rem',
593
+ color: 'hsl(var(--muted-foreground))',
594
+ fontSize: '0.68rem',
595
+ fontWeight: 650,
596
+ letterSpacing: '0.06em',
597
+ textTransform: 'uppercase',
598
+ };
599
+ const helpListStyle: React.CSSProperties = { display: 'grid' };
600
+ const helpRowStyle: React.CSSProperties = {
601
+ display: 'flex',
602
+ minHeight: '2rem',
603
+ alignItems: 'center',
604
+ justifyContent: 'space-between',
605
+ gap: '1rem',
606
+ borderBottom: '1px solid color-mix(in srgb, hsl(var(--border)) 65%, transparent)',
607
+ fontSize: '0.8rem',
608
+ };
609
+ const helpKeysStyle: React.CSSProperties = {
610
+ display: 'inline-flex',
611
+ flexWrap: 'wrap',
612
+ justifyContent: 'flex-end',
613
+ gap: '0.3rem',
614
+ };
615
+ const helpKeyStyle: React.CSSProperties = {
616
+ minWidth: '1.6rem',
617
+ border: '1px solid hsl(var(--border))',
618
+ borderBottomWidth: '2px',
619
+ borderRadius: '0.35rem',
620
+ background: 'hsl(var(--muted))',
621
+ color: 'hsl(var(--foreground))',
622
+ padding: '0.15rem 0.4rem',
623
+ textAlign: 'center',
624
+ font: 'inherit',
625
+ fontSize: '0.72rem',
626
+ };
627
+
628
+ export function useShortcuts(
629
+ shortcuts: ShortcutDefinition[],
630
+ options: UseShortcutsOptions = {},
631
+ ): void {
632
+ const registry = useContext(ShortcutContext);
633
+ const shortcutsRef = useRef(shortcuts);
634
+ shortcutsRef.current = shortcuts;
635
+ const {
636
+ enabled = true,
637
+ scope = 'route',
638
+ priority = 0,
639
+ sequenceTimeoutMs = 1500,
640
+ collectionOwnerId,
641
+ isAvailable,
642
+ } = options;
643
+ const availableRef = useRef(isAvailable);
644
+ availableRef.current = isAvailable;
645
+
646
+ useEffect(() => {
647
+ if (!registry || !enabled) return;
648
+ return registry.register({
649
+ enabled,
650
+ scope,
651
+ priority: SHORTCUT_SCOPE_PRIORITY[scope] + priority,
652
+ sequenceTimeoutMs,
653
+ collectionOwnerId,
654
+ isAvailable: () => availableRef.current?.() !== false,
655
+ getShortcuts: () => availableRef.current?.() === false ? [] : shortcutsRef.current,
656
+ });
657
+ }, [collectionOwnerId, enabled, priority, registry, scope, sequenceTimeoutMs]);
658
+
659
+ // Compatibility fallback for SDK components rendered outside a provider.
660
+ useEffect(() => {
661
+ if (registry || !enabled) return;
662
+ return registerFallbackShortcut({
663
+ enabled,
664
+ scope,
665
+ priority: SHORTCUT_SCOPE_PRIORITY[scope] + priority,
666
+ sequenceTimeoutMs,
667
+ collectionOwnerId,
668
+ isAvailable: () => availableRef.current?.() !== false,
669
+ getShortcuts: () => shortcutsRef.current,
670
+ });
671
+ }, [collectionOwnerId, enabled, priority, registry, scope, sequenceTimeoutMs]);
672
+ }
673
+
674
+ export function shortcutDisplay(raw: string): string {
675
+ return raw
676
+ .trim()
677
+ .split(/\s+/)
678
+ .map((chord) => chord
679
+ .split('+')
680
+ .map((part) => {
681
+ const lower = part.toLowerCase();
682
+ if (lower === 'mod' || lower === 'cmd' || lower === 'meta') return '⌘';
683
+ if (lower === 'ctrl') return '⌃';
684
+ if (lower === 'shift') return '⇧';
685
+ if (lower === 'alt' || lower === 'option') return '⌥';
686
+ if (lower === 'arrowup' || lower === 'up') return '↑';
687
+ if (lower === 'arrowdown' || lower === 'down') return '↓';
688
+ if (lower === 'arrowleft' || lower === 'left') return '←';
689
+ if (lower === 'arrowright' || lower === 'right') return '→';
690
+ return part.length === 1 ? part.toUpperCase() : part;
691
+ })
692
+ .join(''))
693
+ .join(' ');
694
+ }
@@ -0,0 +1,13 @@
1
+ /** Visibility across light and Shadow DOM, without relying on layout (virtual rows may have no rect). */
2
+ export function isInteractionElementVisible(element: HTMLElement | null): boolean {
3
+ if (!element?.isConnected) return false;
4
+ let current: Element | null = element;
5
+ while (current) {
6
+ if (current.hasAttribute('hidden') || current.hasAttribute('inert') || current.getAttribute('aria-hidden') === 'true') return false;
7
+ const style = current.ownerDocument.defaultView?.getComputedStyle(current);
8
+ if (style?.display === 'none' || style?.visibility === 'hidden') return false;
9
+ const root: Node = current.getRootNode();
10
+ current = current.parentElement ?? ('host' in root ? (root as ShadowRoot).host : null);
11
+ }
12
+ return true;
13
+ }