@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,224 +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 { loadWorkspace, executeStartupTasks, enhanceSessionWithWorkspace } from '../workspace/loader';
9
- import { shouldRefreshContext } from '../context/pack-builder';
10
- import { TaskScheduler } from '../scheduler/TaskScheduler';
11
- import { getWorkspaceWatcher } from '../watcher/WorkspaceWatcher';
12
- // ============================================================================
13
- // Workspace State Store
14
- // ============================================================================
15
- export class WorkspaceStateStore extends AppStateStore {
16
- constructor() {
17
- super();
18
- this.workspaceState = {
19
- session: null,
20
- contextPack: null,
21
- isAgentMode: false,
22
- };
23
- this.fs = null;
24
- this.basePath = '';
25
- this.workspaceWatcher = null;
26
- this.taskScheduler = new TaskScheduler({
27
- onTaskExecute: async (job) => {
28
- console.log(`[WorkspaceStateStore] Executing scheduled task: ${job.taskId}`);
29
- // Add system message for task execution
30
- this.addMessage({
31
- id: `scheduled-${Date.now()}`,
32
- role: 'system',
33
- content: `[Scheduled Task] Executing: ${job.taskId}`,
34
- systemType: 'info',
35
- });
36
- },
37
- });
38
- }
39
- setFileSystem(fs, basePath) {
40
- this.fs = fs;
41
- this.basePath = basePath;
42
- }
43
- // ========================================================================
44
- // Agent Mode Activation
45
- // ========================================================================
46
- async activateAgentMode(agentId, agentName) {
47
- if (!this.fs || !this.basePath) {
48
- console.error('[WorkspaceStateStore] FileSystem not configured');
49
- return false;
50
- }
51
- console.log(`[WorkspaceStateStore] Activating agent mode: ${agentName}`);
52
- try {
53
- // Load workspace
54
- const workspace = await loadWorkspace({
55
- agentId,
56
- agentName,
57
- sessionId: this.workspaceState.session?.id || `session-${Date.now()}`,
58
- fs: this.fs,
59
- basePath: this.basePath,
60
- });
61
- if (!workspace) {
62
- console.log('[WorkspaceStateStore] No workspace found, using default agent settings');
63
- return false;
64
- }
65
- // Execute startup tasks
66
- await executeStartupTasks(workspace.startupTasks, (content) => {
67
- // Send startup task message if needed
68
- this.addMessage({
69
- id: `system-${Date.now()}`,
70
- role: 'system',
71
- content,
72
- systemType: 'info',
73
- });
74
- });
75
- // Register recurring tasks with scheduler
76
- const recurringTasks = workspace.startupTasks
77
- .filter(t => t.frequency !== 'startup')
78
- .map(t => ({
79
- id: t.id,
80
- action: t.action,
81
- frequency: t.frequency,
82
- completed: false,
83
- }));
84
- if (recurringTasks.length > 0) {
85
- this.taskScheduler.registerTasks(agentId, recurringTasks);
86
- this.taskScheduler.start();
87
- console.log(`[WorkspaceStateStore] Started task scheduler with ${recurringTasks.length} recurring tasks`);
88
- }
89
- // Setup file watcher for auto-refresh
90
- if (this.fs && this.basePath) {
91
- this.workspaceWatcher = getWorkspaceWatcher(agentId, this.basePath, this.fs, {
92
- pollIntervalMs: 5000,
93
- onChange: (changes) => {
94
- console.log(`[WorkspaceStateStore] Workspace changed, refreshing context:`, changes.map(c => c.path).join(', '));
95
- // Refresh context
96
- this.refreshContext();
97
- },
98
- });
99
- this.workspaceWatcher.start();
100
- }
101
- // Update state
102
- this.workspaceState = {
103
- session: enhanceSessionWithWorkspace({ id: `session-${Date.now()}`, name: agentName, mode: 'agent' }, workspace),
104
- contextPack: workspace.contextPack,
105
- isAgentMode: true,
106
- };
107
- // Add system message with agent context
108
- this.addMessage({
109
- id: `context-${Date.now()}`,
110
- role: 'system',
111
- content: `[Agent Context Loaded] ${agentName} is now active with full workspace context.`,
112
- systemType: 'info',
113
- });
114
- console.log('[WorkspaceStateStore] Agent mode activated successfully');
115
- return true;
116
- }
117
- catch (error) {
118
- console.error('[WorkspaceStateStore] Failed to activate agent mode:', error);
119
- return false;
120
- }
121
- }
122
- // ========================================================================
123
- // Message Sending with Context
124
- // ========================================================================
125
- async sendMessageWithContext(content, options = {}) {
126
- // Add user message
127
- const userMessage = {
128
- id: `user-${Date.now()}`,
129
- role: 'user',
130
- content,
131
- timestamp: new Date(),
132
- };
133
- this.addMessage(userMessage);
134
- // Check if we should refresh context
135
- if (this.workspaceState.contextPack && shouldRefreshContext(this.workspaceState.contextPack)) {
136
- console.log('[WorkspaceStateStore] Context expired, refreshing...');
137
- if (this.workspaceState.session?.agentId && this.workspaceState.session?.agentName) {
138
- await this.activateAgentMode(this.workspaceState.session.agentId, this.workspaceState.session.agentName);
139
- }
140
- }
141
- // Build context for AI
142
- const context = this.workspaceState.isAgentMode && !options.skipContext
143
- ? this.workspaceState.contextPack
144
- : null;
145
- // Here you would send to your AI backend with the context
146
- // For now, we'll simulate the response structure
147
- console.log('[WorkspaceStateStore] Sending message with context:', {
148
- content: content.slice(0, 50) + '...',
149
- hasContext: !!context,
150
- trustTiers: context?.trustTiers ? 'included' : 'none',
151
- });
152
- // The actual AI integration would happen here:
153
- // const response = await aiClient.complete({
154
- // messages: [...this.getState().messages, userMessage],
155
- // systemPrompt: context?.systemPrompt,
156
- // trustTiers: context?.trustTiers,
157
- // });
158
- }
159
- // ========================================================================
160
- // Context Utilities
161
- // ========================================================================
162
- getContextPack() {
163
- return this.workspaceState.contextPack;
164
- }
165
- getSystemPrompt() {
166
- return this.workspaceState.contextPack?.systemPrompt ||
167
- 'You are Gizzi, a helpful AI assistant.';
168
- }
169
- isAgentMode() {
170
- return this.workspaceState.isAgentMode;
171
- }
172
- requiresPermission(action) {
173
- if (!this.workspaceState.contextPack)
174
- return false;
175
- // Check Tier 3 rules
176
- const actionLower = action.toLowerCase();
177
- return this.workspaceState.contextPack.trustTiers.tier3.rules.some(rule => actionLower.includes(rule.toLowerCase()));
178
- }
179
- getTrustTiers() {
180
- return this.workspaceState.contextPack?.trustTiers || null;
181
- }
182
- // ========================================================================
183
- // Context Refresh
184
- // ========================================================================
185
- async refreshContext() {
186
- if (!this.workspaceState.session?.agentId || !this.workspaceState.session?.agentName) {
187
- return;
188
- }
189
- console.log('[WorkspaceStateStore] Refreshing context...');
190
- await this.activateAgentMode(this.workspaceState.session.agentId, this.workspaceState.session.agentName);
191
- }
192
- // ========================================================================
193
- // State Reset
194
- // ========================================================================
195
- resetAgentMode() {
196
- // Stop scheduler
197
- this.taskScheduler.stop();
198
- this.taskScheduler.unregisterAgentTasks(this.workspaceState.session?.agentId || '');
199
- // Stop watcher
200
- if (this.workspaceWatcher) {
201
- this.workspaceWatcher.stop();
202
- this.workspaceWatcher = null;
203
- }
204
- this.workspaceState = {
205
- session: null,
206
- contextPack: null,
207
- isAgentMode: false,
208
- };
209
- this.clearMessages();
210
- }
211
- }
212
- // ============================================================================
213
- // Global Instance
214
- // ============================================================================
215
- let workspaceStore = null;
216
- export function getWorkspaceStore() {
217
- if (!workspaceStore) {
218
- workspaceStore = new WorkspaceStateStore();
219
- }
220
- return workspaceStore;
221
- }
222
- export function setWorkspaceStore(store) {
223
- workspaceStore = store;
224
- }
@@ -1,297 +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
-
8
- import { AppStateStore, getGlobalStore } from './AppStateStore';
9
- import type { TypedMessage, AssistantMessage } from '../types/message';
10
- import type { ContextPack, WorkspaceSession } from '../workspace/types';
11
- import { loadWorkspace, executeStartupTasks, enhanceSessionWithWorkspace } from '../workspace/loader';
12
- import type { FileSystem } from '../workspace/loader';
13
- import { buildSystemPrompt, shouldRefreshContext } from '../context/pack-builder';
14
- import { TaskScheduler, taskScheduler, type ScheduledTask } from '../scheduler/TaskScheduler';
15
- import { WorkspaceWatcher, getWorkspaceWatcher, type FileChange } from '../watcher/WorkspaceWatcher';
16
-
17
- // ============================================================================
18
- // Types
19
- // ============================================================================
20
-
21
- export interface WorkspaceEnhancedState {
22
- session: WorkspaceSession | null;
23
- contextPack: ContextPack | null;
24
- isAgentMode: boolean;
25
- }
26
-
27
- // ============================================================================
28
- // Workspace State Store
29
- // ============================================================================
30
-
31
- export class WorkspaceStateStore extends AppStateStore {
32
- private workspaceState: WorkspaceEnhancedState = {
33
- session: null,
34
- contextPack: null,
35
- isAgentMode: false,
36
- };
37
-
38
- private fs: FileSystem | null = null;
39
- private basePath: string = '';
40
- private taskScheduler: TaskScheduler;
41
- private workspaceWatcher: WorkspaceWatcher | null = null;
42
-
43
- constructor() {
44
- super();
45
- this.taskScheduler = new TaskScheduler({
46
- onTaskExecute: async (job) => {
47
- console.log(`[WorkspaceStateStore] Executing scheduled task: ${job.taskId}`);
48
- // Add system message for task execution
49
- this.addMessage({
50
- id: `scheduled-${Date.now()}`,
51
- role: 'system',
52
- content: `[Scheduled Task] Executing: ${job.taskId}`,
53
- systemType: 'info',
54
- } as TypedMessage);
55
- },
56
- });
57
- }
58
-
59
- setFileSystem(fs: FileSystem, basePath: string) {
60
- this.fs = fs;
61
- this.basePath = basePath;
62
- }
63
-
64
- // ========================================================================
65
- // Agent Mode Activation
66
- // ========================================================================
67
-
68
- async activateAgentMode(agentId: string, agentName: string): Promise<boolean> {
69
- if (!this.fs || !this.basePath) {
70
- console.error('[WorkspaceStateStore] FileSystem not configured');
71
- return false;
72
- }
73
-
74
- console.log(`[WorkspaceStateStore] Activating agent mode: ${agentName}`);
75
-
76
- try {
77
- // Load workspace
78
- const workspace = await loadWorkspace({
79
- agentId,
80
- agentName,
81
- sessionId: this.workspaceState.session?.id || `session-${Date.now()}`,
82
- fs: this.fs,
83
- basePath: this.basePath,
84
- });
85
-
86
- if (!workspace) {
87
- console.log('[WorkspaceStateStore] No workspace found, using default agent settings');
88
- return false;
89
- }
90
-
91
- // Execute startup tasks
92
- await executeStartupTasks(workspace.startupTasks, (content) => {
93
- // Send startup task message if needed
94
- this.addMessage({
95
- id: `system-${Date.now()}`,
96
- role: 'system',
97
- content,
98
- systemType: 'info',
99
- } as TypedMessage);
100
- });
101
-
102
- // Register recurring tasks with scheduler
103
- const recurringTasks: ScheduledTask[] = workspace.startupTasks
104
- .filter(t => t.frequency !== 'startup')
105
- .map(t => ({
106
- id: t.id,
107
- action: t.action,
108
- frequency: t.frequency as any,
109
- completed: false,
110
- }));
111
-
112
- if (recurringTasks.length > 0) {
113
- this.taskScheduler.registerTasks(agentId, recurringTasks);
114
- this.taskScheduler.start();
115
- console.log(`[WorkspaceStateStore] Started task scheduler with ${recurringTasks.length} recurring tasks`);
116
- }
117
-
118
- // Setup file watcher for auto-refresh
119
- if (this.fs && this.basePath) {
120
- this.workspaceWatcher = getWorkspaceWatcher(agentId, this.basePath, this.fs, {
121
- pollIntervalMs: 5000,
122
- onChange: (changes) => {
123
- console.log(`[WorkspaceStateStore] Workspace changed, refreshing context:`,
124
- changes.map(c => c.path).join(', '));
125
- // Refresh context
126
- this.refreshContext();
127
- },
128
- });
129
- this.workspaceWatcher.start();
130
- }
131
-
132
- // Update state
133
- this.workspaceState = {
134
- session: enhanceSessionWithWorkspace(
135
- { id: `session-${Date.now()}`, name: agentName, mode: 'agent' },
136
- workspace
137
- ),
138
- contextPack: workspace.contextPack,
139
- isAgentMode: true,
140
- };
141
-
142
- // Add system message with agent context
143
- this.addMessage({
144
- id: `context-${Date.now()}`,
145
- role: 'system',
146
- content: `[Agent Context Loaded] ${agentName} is now active with full workspace context.`,
147
- systemType: 'info',
148
- } as TypedMessage);
149
-
150
- console.log('[WorkspaceStateStore] Agent mode activated successfully');
151
- return true;
152
- } catch (error) {
153
- console.error('[WorkspaceStateStore] Failed to activate agent mode:', error);
154
- return false;
155
- }
156
- }
157
-
158
- // ========================================================================
159
- // Message Sending with Context
160
- // ========================================================================
161
-
162
- async sendMessageWithContext(
163
- content: string,
164
- options: {
165
- skipContext?: boolean;
166
- onThinking?: (thinking: string) => void;
167
- onResponse?: (response: AssistantMessage) => void;
168
- } = {}
169
- ): Promise<void> {
170
- // Add user message
171
- const userMessage: TypedMessage = {
172
- id: `user-${Date.now()}`,
173
- role: 'user',
174
- content,
175
- timestamp: new Date(),
176
- };
177
- this.addMessage(userMessage);
178
-
179
- // Check if we should refresh context
180
- if (this.workspaceState.contextPack && shouldRefreshContext(this.workspaceState.contextPack)) {
181
- console.log('[WorkspaceStateStore] Context expired, refreshing...');
182
- if (this.workspaceState.session?.agentId && this.workspaceState.session?.agentName) {
183
- await this.activateAgentMode(
184
- this.workspaceState.session.agentId,
185
- this.workspaceState.session.agentName
186
- );
187
- }
188
- }
189
-
190
- // Build context for AI
191
- const context = this.workspaceState.isAgentMode && !options.skipContext
192
- ? this.workspaceState.contextPack
193
- : null;
194
-
195
- // Here you would send to your AI backend with the context
196
- // For now, we'll simulate the response structure
197
- console.log('[WorkspaceStateStore] Sending message with context:', {
198
- content: content.slice(0, 50) + '...',
199
- hasContext: !!context,
200
- trustTiers: context?.trustTiers ? 'included' : 'none',
201
- });
202
-
203
- // The actual AI integration would happen here:
204
- // const response = await aiClient.complete({
205
- // messages: [...this.getState().messages, userMessage],
206
- // systemPrompt: context?.systemPrompt,
207
- // trustTiers: context?.trustTiers,
208
- // });
209
- }
210
-
211
- // ========================================================================
212
- // Context Utilities
213
- // ========================================================================
214
-
215
- getContextPack(): ContextPack | null {
216
- return this.workspaceState.contextPack;
217
- }
218
-
219
- getSystemPrompt(): string {
220
- return this.workspaceState.contextPack?.systemPrompt ||
221
- 'You are Gizzi, a helpful AI assistant.';
222
- }
223
-
224
- isAgentMode(): boolean {
225
- return this.workspaceState.isAgentMode;
226
- }
227
-
228
- requiresPermission(action: string): boolean {
229
- if (!this.workspaceState.contextPack) return false;
230
-
231
- // Check Tier 3 rules
232
- const actionLower = action.toLowerCase();
233
- return this.workspaceState.contextPack.trustTiers.tier3.rules.some(
234
- rule => actionLower.includes(rule.toLowerCase())
235
- );
236
- }
237
-
238
- getTrustTiers() {
239
- return this.workspaceState.contextPack?.trustTiers || null;
240
- }
241
-
242
- // ========================================================================
243
- // Context Refresh
244
- // ========================================================================
245
-
246
- async refreshContext(): Promise<void> {
247
- if (!this.workspaceState.session?.agentId || !this.workspaceState.session?.agentName) {
248
- return;
249
- }
250
-
251
- console.log('[WorkspaceStateStore] Refreshing context...');
252
- await this.activateAgentMode(
253
- this.workspaceState.session.agentId,
254
- this.workspaceState.session.agentName
255
- );
256
- }
257
-
258
- // ========================================================================
259
- // State Reset
260
- // ========================================================================
261
-
262
- resetAgentMode(): void {
263
- // Stop scheduler
264
- this.taskScheduler.stop();
265
- this.taskScheduler.unregisterAgentTasks(this.workspaceState.session?.agentId || '');
266
-
267
- // Stop watcher
268
- if (this.workspaceWatcher) {
269
- this.workspaceWatcher.stop();
270
- this.workspaceWatcher = null;
271
- }
272
-
273
- this.workspaceState = {
274
- session: null,
275
- contextPack: null,
276
- isAgentMode: false,
277
- };
278
- this.clearMessages();
279
- }
280
- }
281
-
282
- // ============================================================================
283
- // Global Instance
284
- // ============================================================================
285
-
286
- let workspaceStore: WorkspaceStateStore | null = null;
287
-
288
- export function getWorkspaceStore(): WorkspaceStateStore {
289
- if (!workspaceStore) {
290
- workspaceStore = new WorkspaceStateStore();
291
- }
292
- return workspaceStore;
293
- }
294
-
295
- export function setWorkspaceStore(store: WorkspaceStateStore | null): void {
296
- workspaceStore = store;
297
- }