@allternit/gizzi-code 1.0.0 → 1.0.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 (158) hide show
  1. package/bin/gizzi +4 -0
  2. package/bin/gizzi-ink +5 -0
  3. package/package.json +137 -31
  4. package/src/Tool.ts +26 -0
  5. package/src/bootstrap/state.ts +165 -322
  6. package/src/commands.ts +209 -0
  7. package/src/context/QueuedMessageContext.tsx +63 -0
  8. package/src/context/fpsMetrics.tsx +30 -0
  9. package/src/context/mailbox.tsx +38 -0
  10. package/src/context/modalContext.tsx +58 -0
  11. package/src/context/notifications.tsx +240 -0
  12. package/src/context/overlayContext.tsx +151 -0
  13. package/src/context/promptOverlayContext.tsx +125 -0
  14. package/src/context/stats.tsx +220 -0
  15. package/src/context/voice.tsx +88 -0
  16. package/src/hooks/useCanUseTool.ts +11 -0
  17. package/src/hooks/useExitOnCtrlCD.ts +40 -187
  18. package/src/hooks/useExitOnCtrlCDWithKeybindings.ts +68 -0
  19. package/src/hooks/useKeybinding.ts +68 -209
  20. package/src/hooks/useTerminalSize.ts +31 -99
  21. package/src/hooks.ts +37 -0
  22. package/src/ink.ts +204 -0
  23. package/src/main.ts +7 -0
  24. package/src/types/command.ts +216 -0
  25. package/src/types/connectorText.ts +39 -0
  26. package/src/types/fileSuggestion.ts +15 -0
  27. package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.ts +865 -0
  28. package/src/types/generated/events_mono/common/v1/auth.ts +100 -0
  29. package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.ts +223 -0
  30. package/src/types/generated/google/protobuf/timestamp.ts +187 -0
  31. package/src/types/hooks.ts +319 -0
  32. package/src/types/ids.ts +44 -0
  33. package/src/types/logs.ts +331 -0
  34. package/src/types/merged/index.ts +5 -0
  35. package/src/types/merged/message.ts +552 -0
  36. package/src/types/message.ts +927 -186
  37. package/src/types/messageQueueTypes.ts +21 -0
  38. package/src/types/notebook.ts +72 -0
  39. package/src/types/permissions.ts +447 -0
  40. package/src/types/plugin.ts +363 -0
  41. package/src/types/statusLine.ts +15 -0
  42. package/src/types/textInputTypes.ts +387 -0
  43. package/src/types/tools.ts +149 -0
  44. package/src/types/utils.ts +20 -0
  45. package/src/utils/advisor.ts +12 -0
  46. package/src/utils/api.ts +29 -0
  47. package/src/utils/array.ts +7 -0
  48. package/src/utils/attachments.ts +60 -0
  49. package/src/utils/auth.ts +3 -0
  50. package/src/utils/claudeInChrome/chromeNativeHost.ts +15 -0
  51. package/src/utils/claudeInChrome/common.ts +12 -0
  52. package/src/utils/claudeInChrome/mcpServer.ts +15 -0
  53. package/src/utils/computerUse/common.ts +19 -0
  54. package/src/utils/computerUse/mcpServer.ts +15 -0
  55. package/src/utils/config.ts +35 -0
  56. package/src/utils/context.ts +19 -0
  57. package/src/utils/cwd.ts +3 -0
  58. package/src/utils/debug.ts +3 -0
  59. package/src/utils/earlyInput.ts +7 -0
  60. package/src/utils/effort.ts +13 -0
  61. package/src/utils/embeddedTools.ts +12 -0
  62. package/src/utils/envUtils.ts +3 -0
  63. package/src/utils/errors.ts +3 -0
  64. package/src/utils/execFileNoThrow.ts +24 -0
  65. package/src/utils/feature-flags.ts +112 -0
  66. package/src/utils/file.ts +3 -0
  67. package/src/utils/fileHistory.ts +17 -0
  68. package/src/utils/fingerprint.ts +7 -0
  69. package/src/utils/format.ts +75 -305
  70. package/src/utils/frontmatterParser.ts +33 -0
  71. package/src/utils/fsOperations.ts +31 -0
  72. package/src/utils/fullscreen.ts +40 -350
  73. package/src/utils/git.ts +15 -0
  74. package/src/utils/imageResizer.ts +30 -0
  75. package/src/utils/lazySchema.ts +9 -0
  76. package/src/utils/log.ts +3 -0
  77. package/src/utils/markdownConfigLoader.ts +12 -0
  78. package/src/utils/messages.ts +13 -0
  79. package/src/utils/migration.ts +137 -0
  80. package/src/utils/model/providers.ts +15 -0
  81. package/src/utils/path.ts +3 -0
  82. package/src/utils/permissions/PermissionResult.ts +14 -0
  83. package/src/utils/permissions/autoModeState.ts +12 -0
  84. package/src/utils/permissions/filesystem.ts +12 -0
  85. package/src/utils/plugins/loadPluginOutputStyles.ts +12 -0
  86. package/src/utils/plugins/schemas.ts +25 -0
  87. package/src/utils/process.ts +16 -0
  88. package/src/utils/sandbox/sandbox-adapter.ts +19 -0
  89. package/src/utils/sessionStorage.ts +238 -472
  90. package/src/utils/settings/constants.ts +10 -0
  91. package/src/utils/settings/settings.ts +19 -0
  92. package/src/utils/settings/types.ts +18 -0
  93. package/src/utils/shell/shellToolUtils.ts +9 -0
  94. package/src/utils/sinks.ts +11 -0
  95. package/src/utils/sleep.ts +7 -0
  96. package/src/utils/sliceAnsi.ts +7 -0
  97. package/src/utils/slowOperations.ts +3 -0
  98. package/src/utils/startupProfiler.ts +11 -0
  99. package/src/utils/stringUtils.ts +106 -0
  100. package/src/utils/systemPromptType.ts +9 -0
  101. package/src/utils/teleport/api.ts +15 -0
  102. package/src/utils/textHighlighting.ts +16 -0
  103. package/src/utils/theme.ts +17 -0
  104. package/src/utils/thinking.ts +58 -0
  105. package/src/utils/tokens.ts +11 -0
  106. package/src/utils/toolResultStorage.ts +17 -0
  107. package/src/utils/worktreeModeEnabled.ts +7 -0
  108. package/WORKSPACE_INTEGRATION.md +0 -290
  109. package/chat-sessions/sessions-index.json +0 -98
  110. package/package.json.original +0 -31
  111. package/package.json.publish +0 -47
  112. package/src/bootstrap/state.d.ts +0 -169
  113. package/src/bootstrap/state.js +0 -261
  114. package/src/context/pack-builder.d.ts +0 -24
  115. package/src/context/pack-builder.js +0 -281
  116. package/src/hooks/useExitOnCtrlCD.d.ts +0 -86
  117. package/src/hooks/useExitOnCtrlCD.js +0 -130
  118. package/src/hooks/useKeybinding.d.ts +0 -89
  119. package/src/hooks/useKeybinding.js +0 -163
  120. package/src/hooks/useTerminalSize.d.ts +0 -41
  121. package/src/hooks/useTerminalSize.js +0 -90
  122. package/src/index.d.ts +0 -23
  123. package/src/index.js +0 -24
  124. package/src/runtime/brand/brand.d.ts +0 -488
  125. package/src/runtime/brand/brand.js +0 -464
  126. package/src/runtime/brand/brand.ts +0 -667
  127. package/src/runtime/services/tokenEstimation.d.ts +0 -187
  128. package/src/runtime/services/tokenEstimation.js +0 -423
  129. package/src/runtime/services/tokenEstimation.ts +0 -547
  130. package/src/runtime/tools/Tool.d.ts +0 -239
  131. package/src/runtime/tools/Tool.js +0 -285
  132. package/src/runtime/tools/Tool.ts +0 -524
  133. package/src/scheduler/TaskScheduler.d.ts +0 -98
  134. package/src/scheduler/TaskScheduler.js +0 -201
  135. package/src/scheduler/TaskScheduler.ts +0 -259
  136. package/src/state/AppStateStore.d.ts +0 -347
  137. package/src/state/AppStateStore.js +0 -439
  138. package/src/state/AppStateStore.ts +0 -658
  139. package/src/state/WorkspaceStateStore.d.ts +0 -43
  140. package/src/state/WorkspaceStateStore.js +0 -224
  141. package/src/state/WorkspaceStateStore.ts +0 -297
  142. package/src/types/message.d.ts +0 -190
  143. package/src/types/message.js +0 -77
  144. package/src/utils/format.d.ts +0 -126
  145. package/src/utils/format.js +0 -230
  146. package/src/utils/fullscreen.d.ts +0 -161
  147. package/src/utils/fullscreen.js +0 -277
  148. package/src/utils/sessionStorage.d.ts +0 -210
  149. package/src/utils/sessionStorage.js +0 -435
  150. package/src/watcher/WorkspaceWatcher.d.ts +0 -70
  151. package/src/watcher/WorkspaceWatcher.js +0 -191
  152. package/src/watcher/WorkspaceWatcher.ts +0 -251
  153. package/src/workspace/loader.d.ts +0 -30
  154. package/src/workspace/loader.js +0 -117
  155. package/src/workspace/types.d.ts +0 -91
  156. package/src/workspace/types.js +0 -7
  157. package/threads/thread_1775361175022.json +0 -9
  158. package/tsconfig.json +0 -14
@@ -1,658 +0,0 @@
1
- /**
2
- * @fileoverview Application state store with React integration
3
- * @module state/AppStateStore
4
- *
5
- * Centralized state management using the store pattern with subscription-based
6
- * reactivity. Provides React hooks for component integration.
7
- */
8
-
9
- import { useState, useEffect, useCallback, useSyncExternalStore } from 'react';
10
- import type { Message, TypedMessage } from '../types/message';
11
-
12
- /**
13
- * User preferences and settings
14
- * @interface UserPreferences
15
- */
16
- export interface UserPreferences {
17
- /** UI theme preference */
18
- readonly theme: 'light' | 'dark' | 'system';
19
-
20
- /** Language code */
21
- readonly language: string;
22
-
23
- /** Notification preferences */
24
- readonly notifications: {
25
- readonly enabled: boolean;
26
- readonly sound: boolean;
27
- readonly desktop: boolean;
28
- };
29
-
30
- /** Editor preferences */
31
- readonly editor: {
32
- readonly fontSize: number;
33
- readonly fontFamily: string;
34
- readonly wordWrap: boolean;
35
- readonly lineNumbers: boolean;
36
- readonly tabSize: number;
37
- };
38
- }
39
-
40
- /**
41
- * User session information
42
- * @interface UserSession
43
- */
44
- export interface UserSession {
45
- /** User identifier */
46
- readonly userId: string;
47
-
48
- /** User display name */
49
- readonly displayName: string;
50
-
51
- /** User email */
52
- readonly email: string;
53
-
54
- /** User type/role */
55
- readonly userType: 'free' | 'pro' | 'enterprise' | 'admin';
56
-
57
- /** Session token */
58
- readonly token: string;
59
-
60
- /** Session expiration timestamp */
61
- readonly expiresAt: Date;
62
-
63
- /** Authentication provider */
64
- readonly provider: 'local' | 'oauth' | 'sso';
65
- }
66
-
67
- /**
68
- * Connection status types
69
- * @typedef {'online' | 'offline' | 'connecting' | 'reconnecting'} ConnectionStatus
70
- */
71
- export type ConnectionStatus = 'online' | 'offline' | 'connecting' | 'reconnecting';
72
-
73
- /**
74
- * Complete application state structure
75
- * @interface AppState
76
- */
77
- export interface AppState {
78
- /** Current user session, null if not authenticated */
79
- readonly session: UserSession | null;
80
-
81
- /** User preferences */
82
- readonly preferences: UserPreferences;
83
-
84
- /** Active conversation messages */
85
- readonly messages: readonly TypedMessage[];
86
-
87
- /** Connection status to backend services */
88
- readonly connectionStatus: ConnectionStatus;
89
-
90
- /** Whether the application is currently loading */
91
- readonly isLoading: boolean;
92
-
93
- /** Current loading message or operation description */
94
- readonly loadingMessage: string | null;
95
-
96
- /** Active errors to display */
97
- readonly errors: readonly AppError[];
98
-
99
- /** Current view/route */
100
- readonly currentView: string;
101
-
102
- /** View-specific state data */
103
- readonly viewState: Readonly<Record<string, unknown>>;
104
-
105
- /** Timestamp of last state update */
106
- readonly lastUpdated: Date;
107
- }
108
-
109
- /**
110
- * Application error structure
111
- * @interface AppError
112
- */
113
- export interface AppError {
114
- /** Unique error identifier */
115
- readonly id: string;
116
-
117
- /** Error severity level */
118
- readonly severity: 'info' | 'warning' | 'error' | 'critical';
119
-
120
- /** Error code for programmatic handling */
121
- readonly code: string;
122
-
123
- /** Human-readable error message */
124
- readonly message: string;
125
-
126
- /** Error timestamp */
127
- readonly timestamp: Date;
128
-
129
- /** Whether the error has been dismissed by the user */
130
- readonly dismissed: boolean;
131
-
132
- /** Additional error context */
133
- readonly context?: Readonly<Record<string, unknown>>;
134
- }
135
-
136
- /**
137
- * State change listener callback type
138
- * @typedef {(state: AppState, prevState: AppState) => void} StateListener
139
- */
140
- type StateListener = (state: AppState, prevState: AppState) => void;
141
-
142
- /**
143
- * Selector function type for deriving values from state
144
- * @template T
145
- * @typedef {(state: AppState) => T} StateSelector
146
- */
147
- type StateSelector<T> = (state: AppState) => T;
148
-
149
- /**
150
- * Default user preferences
151
- * @constant {UserPreferences}
152
- */
153
- const DEFAULT_PREFERENCES: UserPreferences = {
154
- theme: 'system',
155
- language: 'en',
156
- notifications: {
157
- enabled: true,
158
- sound: true,
159
- desktop: false,
160
- },
161
- editor: {
162
- fontSize: 14,
163
- fontFamily: 'monospace',
164
- wordWrap: true,
165
- lineNumbers: true,
166
- tabSize: 2,
167
- },
168
- } as const;
169
-
170
- /**
171
- * Initial application state
172
- * @constant {AppState}
173
- */
174
- const INITIAL_STATE: AppState = {
175
- session: null,
176
- preferences: DEFAULT_PREFERENCES,
177
- messages: [],
178
- connectionStatus: 'connecting',
179
- isLoading: false,
180
- loadingMessage: null,
181
- errors: [],
182
- currentView: '/',
183
- viewState: {},
184
- lastUpdated: new Date(),
185
- } as const;
186
-
187
- /**
188
- * Application state store class
189
- * Implements the observable store pattern with subscription-based updates
190
- *
191
- * @example
192
- * ```typescript
193
- * const store = new AppStateStore();
194
- * const unsubscribe = store.subscribe((state, prevState) => {
195
- * console.log('State updated:', state);
196
- * });
197
- * store.setState({ isLoading: true });
198
- * ```
199
- */
200
- export class AppStateStore {
201
- private state: AppState;
202
- private listeners: Set<StateListener> = new Set();
203
- private isBatching = false;
204
- private pendingUpdates: Partial<AppState> = {};
205
-
206
- constructor(initialState: Partial<AppState> = {}) {
207
- this.state = {
208
- ...INITIAL_STATE,
209
- ...initialState,
210
- lastUpdated: new Date(),
211
- };
212
- }
213
-
214
- /**
215
- * Gets the current state
216
- * @returns {Readonly<AppState>} The current application state
217
- */
218
- getState(): Readonly<AppState> {
219
- return Object.freeze({ ...this.state });
220
- }
221
-
222
- /**
223
- * Gets a derived value from state using a selector function
224
- *
225
- * @template T
226
- * @param {StateSelector<T>} selector - Function to extract value from state
227
- * @returns {T} The selected value
228
- * @example
229
- * ```typescript
230
- * const userName = store.select(state => state.session?.displayName);
231
- * ```
232
- */
233
- select<T>(selector: StateSelector<T>): T {
234
- return selector(this.state);
235
- }
236
-
237
- /**
238
- * Updates the state with partial changes
239
- * Automatically notifies all subscribers
240
- *
241
- * @param {Partial<AppState>} updates - Partial state updates
242
- * @param {Object} [options] - Update options
243
- * @param {boolean} [options.silent=false] - If true, does not notify subscribers
244
- * @returns {Readonly<AppState>} The updated state
245
- */
246
- setState(
247
- updates: Partial<AppState>,
248
- options: { silent?: boolean } = {}
249
- ): Readonly<AppState> {
250
- if (this.isBatching) {
251
- this.pendingUpdates = { ...this.pendingUpdates, ...updates };
252
- return this.getState();
253
- }
254
-
255
- const prevState = this.state;
256
- this.state = {
257
- ...this.state,
258
- ...updates,
259
- // Merge nested objects
260
- preferences: updates.preferences
261
- ? { ...this.state.preferences, ...updates.preferences }
262
- : this.state.preferences,
263
- viewState: updates.viewState
264
- ? { ...this.state.viewState, ...updates.viewState }
265
- : this.state.viewState,
266
- lastUpdated: new Date(),
267
- };
268
-
269
- if (!options.silent) {
270
- this.notifyListeners(prevState);
271
- }
272
-
273
- return this.getState();
274
- }
275
-
276
- /**
277
- * Batches multiple state updates into a single notification
278
- *
279
- * @param {() => void} callback - Function containing state updates to batch
280
- * @returns {Readonly<AppState>} The final state after all updates
281
- * @example
282
- * ```typescript
283
- * store.batch(() => {
284
- * store.setState({ isLoading: true });
285
- * store.setState({ loadingMessage: 'Fetching data...' });
286
- * });
287
- * // Subscribers are notified once after both updates
288
- * ```
289
- */
290
- batch(callback: () => void): Readonly<AppState> {
291
- this.isBatching = true;
292
-
293
- try {
294
- callback();
295
- } finally {
296
- this.isBatching = false;
297
- const pending = this.pendingUpdates;
298
- this.pendingUpdates = {};
299
-
300
- if (Object.keys(pending).length > 0) {
301
- return this.setState(pending);
302
- }
303
- }
304
-
305
- return this.getState();
306
- }
307
-
308
- /**
309
- * Subscribes to state changes
310
- *
311
- * @param {StateListener} listener - Callback invoked on state changes
312
- * @returns {() => void} Unsubscribe function
313
- */
314
- subscribe(listener: StateListener): () => void {
315
- this.listeners.add(listener);
316
-
317
- // Immediately notify with current state
318
- listener(this.state, this.state);
319
-
320
- return () => {
321
- this.listeners.delete(listener);
322
- };
323
- }
324
-
325
- /**
326
- * Subscribes to a specific derived value using a selector
327
- * Only notifies when the selected value changes
328
- *
329
- * @template T
330
- * @param {StateSelector<T>} selector - Function to extract value
331
- * @param {(value: T) => void} callback - Callback invoked when value changes
332
- * @returns {() => void} Unsubscribe function
333
- * @example
334
- * ```typescript
335
- * store.subscribeTo(
336
- * state => state.connectionStatus,
337
- * status => console.log('Connection:', status)
338
- * );
339
- * ```
340
- */
341
- subscribeTo<T>(selector: StateSelector<T>, callback: (value: T) => void): () => void {
342
- let lastValue = selector(this.state);
343
-
344
- return this.subscribe((state) => {
345
- const newValue = selector(state);
346
- if (newValue !== lastValue) {
347
- lastValue = newValue;
348
- callback(newValue);
349
- }
350
- });
351
- }
352
-
353
- /**
354
- * Resets the store to initial state
355
- *
356
- * @param {Partial<AppState>} [mergeState] - Optional state to merge after reset
357
- * @returns {Readonly<AppState>} The reset state
358
- */
359
- reset(mergeState: Partial<AppState> = {}): Readonly<AppState> {
360
- const prevState = this.state;
361
- this.state = {
362
- ...INITIAL_STATE,
363
- ...mergeState,
364
- lastUpdated: new Date(),
365
- };
366
- this.notifyListeners(prevState);
367
- return this.getState();
368
- }
369
-
370
- /**
371
- * Adds an error to the state
372
- *
373
- * @param {Omit<AppError, 'id' | 'timestamp' | 'dismissed'>} error - Error details
374
- * @returns {Readonly<AppState>} The updated state
375
- */
376
- addError(error: Omit<AppError, 'id' | 'timestamp' | 'dismissed'>): Readonly<AppState> {
377
- const newError: AppError = {
378
- ...error,
379
- id: `err_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`,
380
- timestamp: new Date(),
381
- dismissed: false,
382
- };
383
-
384
- return this.setState({
385
- errors: [...this.state.errors, newError],
386
- });
387
- }
388
-
389
- /**
390
- * Dismisses an error by ID
391
- *
392
- * @param {string} errorId - The error ID to dismiss
393
- * @returns {Readonly<AppState>} The updated state
394
- */
395
- dismissError(errorId: string): Readonly<AppState> {
396
- return this.setState({
397
- errors: this.state.errors.map((err) =>
398
- err.id === errorId ? { ...err, dismissed: true } : err
399
- ),
400
- });
401
- }
402
-
403
- /**
404
- * Clears all dismissed errors
405
- *
406
- * @returns {Readonly<AppState>} The updated state
407
- */
408
- clearDismissedErrors(): Readonly<AppState> {
409
- return this.setState({
410
- errors: this.state.errors.filter((err) => !err.dismissed),
411
- });
412
- }
413
-
414
- /**
415
- * Adds a message to the conversation
416
- *
417
- * @param {TypedMessage} message - The message to add
418
- * @returns {Readonly<AppState>} The updated state
419
- */
420
- addMessage(message: TypedMessage): Readonly<AppState> {
421
- return this.setState({
422
- messages: [...this.state.messages, message],
423
- });
424
- }
425
-
426
- /**
427
- * Clears all messages
428
- *
429
- * @returns {Readonly<AppState>} The updated state
430
- */
431
- clearMessages(): Readonly<AppState> {
432
- return this.setState({ messages: [] });
433
- }
434
-
435
- /**
436
- * Sets the user session
437
- *
438
- * @param {UserSession | null} session - The session or null to logout
439
- * @returns {Readonly<AppState>} The updated state
440
- */
441
- setSession(session: UserSession | null): Readonly<AppState> {
442
- return this.setState({ session });
443
- }
444
-
445
- /**
446
- * Updates user preferences
447
- *
448
- * @param {Partial<UserPreferences>} prefs - Preference updates
449
- * @returns {Readonly<AppState>} The updated state
450
- */
451
- setPreferences(prefs: Partial<UserPreferences>): Readonly<AppState> {
452
- return this.setState({
453
- preferences: { ...this.state.preferences, ...prefs },
454
- });
455
- }
456
-
457
- /**
458
- * Sets the loading state
459
- *
460
- * @param {boolean} isLoading - Whether loading is active
461
- * @param {string} [message] - Optional loading message
462
- * @returns {Readonly<AppState>} The updated state
463
- */
464
- setLoading(isLoading: boolean, message?: string): Readonly<AppState> {
465
- return this.setState({
466
- isLoading,
467
- loadingMessage: isLoading ? message ?? null : null,
468
- });
469
- }
470
-
471
- /**
472
- * Updates view-specific state
473
- *
474
- * @param {string} view - View identifier
475
- * @param {unknown} data - View state data
476
- * @returns {Readonly<AppState>} The updated state
477
- */
478
- setViewState(view: string, data: unknown): Readonly<AppState> {
479
- return this.setState({
480
- currentView: view,
481
- viewState: { ...this.state.viewState, [view]: data },
482
- });
483
- }
484
-
485
- private notifyListeners(prevState: AppState): void {
486
- queueMicrotask(() => {
487
- this.listeners.forEach((listener) => {
488
- try {
489
- listener(this.state, prevState);
490
- } catch (error) {
491
- console.error('AppStateStore listener error:', error);
492
- }
493
- });
494
- });
495
- }
496
- }
497
-
498
- // Global store instance
499
- let globalStore: AppStateStore | null = null;
500
-
501
- /**
502
- * Gets or creates the global AppStateStore instance
503
- *
504
- * @returns {AppStateStore} The global store instance
505
- */
506
- export function getGlobalStore(): AppStateStore {
507
- if (!globalStore) {
508
- globalStore = new AppStateStore();
509
- }
510
- return globalStore;
511
- }
512
-
513
- /**
514
- * Sets the global store instance (useful for testing)
515
- *
516
- * @param {AppStateStore | null} store - The store instance or null to reset
517
- */
518
- export function setGlobalStore(store: AppStateStore | null): void {
519
- globalStore = store;
520
- }
521
-
522
- /**
523
- * React hook for accessing the app state store
524
- * Provides reactive updates and selector support
525
- *
526
- * @template T
527
- * @param {StateSelector<T>} [selector] - Optional selector function
528
- * @returns {T | AppState} The selected state or full state
529
- * @example
530
- * ```typescript
531
- * // Get full state
532
- * const state = useAppStateStore();
533
- *
534
- * // Get specific value
535
- * const isLoading = useAppStateStore(state => state.isLoading);
536
- *
537
- * // Get derived value
538
- * const messageCount = useAppStateStore(state => state.messages.length);
539
- * ```
540
- */
541
- export function useAppStateStore<T>(selector?: StateSelector<T>): T | AppState {
542
- const store = getGlobalStore();
543
-
544
- return useSyncExternalStore(
545
- (callback) => store.subscribe(() => callback()),
546
- () => {
547
- const state = store.getState();
548
- return selector ? selector(state) : state;
549
- },
550
- () => {
551
- const state = store.getState();
552
- return selector ? selector(state) : state;
553
- }
554
- );
555
- }
556
-
557
- /**
558
- * React hook for accessing a specific slice of state with optional transformation
559
- *
560
- * @template T
561
- * @param {StateSelector<T>} selector - Function to extract value from state
562
- * @param {(left: T, right: T) => boolean} [isEqual] - Custom equality function
563
- * @returns {T} The selected value
564
- * @example
565
- * ```typescript
566
- * const userName = useAppStateSelector(state => state.session?.displayName);
567
- * ```
568
- */
569
- export function useAppStateSelector<T>(
570
- selector: StateSelector<T>,
571
- isEqual: (left: T, right: T) => boolean = Object.is
572
- ): T {
573
- const store = getGlobalStore();
574
- const [selectedState, setSelectedState] = useState<T>(() => selector(store.getState()));
575
-
576
- useEffect(() => {
577
- let lastSelectedState = selectedState;
578
-
579
- return store.subscribe((state) => {
580
- const newSelectedState = selector(state);
581
- if (!isEqual(lastSelectedState, newSelectedState)) {
582
- lastSelectedState = newSelectedState;
583
- setSelectedState(newSelectedState);
584
- }
585
- });
586
- }, [selector, isEqual, store]);
587
-
588
- return selectedState;
589
- }
590
-
591
- /**
592
- * React hook for state setters
593
- * Returns stable callback functions for common state operations
594
- *
595
- * @returns {Object} Object containing state setter callbacks
596
- * @example
597
- * ```typescript
598
- * const { setLoading, addMessage, setSession } = useAppStateActions();
599
- * ```
600
- */
601
- export function useAppStateActions() {
602
- const store = getGlobalStore();
603
-
604
- const setState = useCallback(
605
- (updates: Partial<AppState>) => store.setState(updates),
606
- [store]
607
- );
608
-
609
- const setLoading = useCallback(
610
- (isLoading: boolean, message?: string) => store.setLoading(isLoading, message),
611
- [store]
612
- );
613
-
614
- const addMessage = useCallback(
615
- (message: TypedMessage) => store.addMessage(message),
616
- [store]
617
- );
618
-
619
- const setSession = useCallback(
620
- (session: UserSession | null) => store.setSession(session),
621
- [store]
622
- );
623
-
624
- const addError = useCallback(
625
- (error: Omit<AppError, 'id' | 'timestamp' | 'dismissed'>) => store.addError(error),
626
- [store]
627
- );
628
-
629
- const dismissError = useCallback((errorId: string) => store.dismissError(errorId), [store]);
630
-
631
- const setPreferences = useCallback(
632
- (prefs: Partial<UserPreferences>) => store.setPreferences(prefs),
633
- [store]
634
- );
635
-
636
- const clearMessages = useCallback(() => store.clearMessages(), [store]);
637
-
638
- return {
639
- setState,
640
- setLoading,
641
- addMessage,
642
- setSession,
643
- addError,
644
- dismissError,
645
- setPreferences,
646
- clearMessages,
647
- };
648
- }
649
-
650
- // Default export
651
- export default {
652
- AppStateStore,
653
- getGlobalStore,
654
- setGlobalStore,
655
- useAppStateStore,
656
- useAppStateSelector,
657
- useAppStateActions,
658
- };
@@ -1,43 +0,0 @@
1
- /**
2
- * Gizzi Workspace State Store
3
- *
4
- * Enhanced state management with workspace/agent context integration
5
- * Extends AppStateStore with agent workspace capabilities
6
- */
7
- import { AppStateStore } from './AppStateStore';
8
- import type { AssistantMessage } from '../types/message';
9
- import type { ContextPack, WorkspaceSession } from '../workspace/types';
10
- import type { FileSystem } from '../workspace/loader';
11
- export interface WorkspaceEnhancedState {
12
- session: WorkspaceSession | null;
13
- contextPack: ContextPack | null;
14
- isAgentMode: boolean;
15
- }
16
- export declare class WorkspaceStateStore extends AppStateStore {
17
- private workspaceState;
18
- private fs;
19
- private basePath;
20
- private taskScheduler;
21
- private workspaceWatcher;
22
- constructor();
23
- setFileSystem(fs: FileSystem, basePath: string): void;
24
- activateAgentMode(agentId: string, agentName: string): Promise<boolean>;
25
- sendMessageWithContext(content: string, options?: {
26
- skipContext?: boolean;
27
- onThinking?: (thinking: string) => void;
28
- onResponse?: (response: AssistantMessage) => void;
29
- }): Promise<void>;
30
- getContextPack(): ContextPack | null;
31
- getSystemPrompt(): string;
32
- isAgentMode(): boolean;
33
- requiresPermission(action: string): boolean;
34
- getTrustTiers(): {
35
- tier1: import("../workspace/types").TrustTier;
36
- tier2: import("../workspace/types").TrustTier;
37
- tier3: import("../workspace/types").TrustTier;
38
- } | null;
39
- refreshContext(): Promise<void>;
40
- resetAgentMode(): void;
41
- }
42
- export declare function getWorkspaceStore(): WorkspaceStateStore;
43
- export declare function setWorkspaceStore(store: WorkspaceStateStore | null): void;