@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.
- package/bin/gizzi +4 -0
- package/bin/gizzi-ink +5 -0
- package/package.json +137 -31
- package/src/Tool.ts +26 -0
- package/src/bootstrap/state.ts +165 -322
- package/src/commands.ts +209 -0
- package/src/context/QueuedMessageContext.tsx +63 -0
- package/src/context/fpsMetrics.tsx +30 -0
- package/src/context/mailbox.tsx +38 -0
- package/src/context/modalContext.tsx +58 -0
- package/src/context/notifications.tsx +240 -0
- package/src/context/overlayContext.tsx +151 -0
- package/src/context/promptOverlayContext.tsx +125 -0
- package/src/context/stats.tsx +220 -0
- package/src/context/voice.tsx +88 -0
- package/src/hooks/useCanUseTool.ts +11 -0
- package/src/hooks/useExitOnCtrlCD.ts +40 -187
- package/src/hooks/useExitOnCtrlCDWithKeybindings.ts +68 -0
- package/src/hooks/useKeybinding.ts +68 -209
- package/src/hooks/useTerminalSize.ts +31 -99
- package/src/hooks.ts +37 -0
- package/src/ink.ts +204 -0
- package/src/main.ts +7 -0
- package/src/types/command.ts +216 -0
- package/src/types/connectorText.ts +39 -0
- package/src/types/fileSuggestion.ts +15 -0
- package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.ts +865 -0
- package/src/types/generated/events_mono/common/v1/auth.ts +100 -0
- package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.ts +223 -0
- package/src/types/generated/google/protobuf/timestamp.ts +187 -0
- package/src/types/hooks.ts +319 -0
- package/src/types/ids.ts +44 -0
- package/src/types/logs.ts +331 -0
- package/src/types/merged/index.ts +5 -0
- package/src/types/merged/message.ts +552 -0
- package/src/types/message.ts +927 -186
- package/src/types/messageQueueTypes.ts +21 -0
- package/src/types/notebook.ts +72 -0
- package/src/types/permissions.ts +447 -0
- package/src/types/plugin.ts +363 -0
- package/src/types/statusLine.ts +15 -0
- package/src/types/textInputTypes.ts +387 -0
- package/src/types/tools.ts +149 -0
- package/src/types/utils.ts +20 -0
- package/src/utils/advisor.ts +12 -0
- package/src/utils/api.ts +29 -0
- package/src/utils/array.ts +7 -0
- package/src/utils/attachments.ts +60 -0
- package/src/utils/auth.ts +3 -0
- package/src/utils/claudeInChrome/chromeNativeHost.ts +15 -0
- package/src/utils/claudeInChrome/common.ts +12 -0
- package/src/utils/claudeInChrome/mcpServer.ts +15 -0
- package/src/utils/computerUse/common.ts +19 -0
- package/src/utils/computerUse/mcpServer.ts +15 -0
- package/src/utils/config.ts +35 -0
- package/src/utils/context.ts +19 -0
- package/src/utils/cwd.ts +3 -0
- package/src/utils/debug.ts +3 -0
- package/src/utils/earlyInput.ts +7 -0
- package/src/utils/effort.ts +13 -0
- package/src/utils/embeddedTools.ts +12 -0
- package/src/utils/envUtils.ts +3 -0
- package/src/utils/errors.ts +3 -0
- package/src/utils/execFileNoThrow.ts +24 -0
- package/src/utils/feature-flags.ts +112 -0
- package/src/utils/file.ts +3 -0
- package/src/utils/fileHistory.ts +17 -0
- package/src/utils/fingerprint.ts +7 -0
- package/src/utils/format.ts +75 -305
- package/src/utils/frontmatterParser.ts +33 -0
- package/src/utils/fsOperations.ts +31 -0
- package/src/utils/fullscreen.ts +40 -350
- package/src/utils/git.ts +15 -0
- package/src/utils/imageResizer.ts +30 -0
- package/src/utils/lazySchema.ts +9 -0
- package/src/utils/log.ts +3 -0
- package/src/utils/markdownConfigLoader.ts +12 -0
- package/src/utils/messages.ts +13 -0
- package/src/utils/migration.ts +137 -0
- package/src/utils/model/providers.ts +15 -0
- package/src/utils/path.ts +3 -0
- package/src/utils/permissions/PermissionResult.ts +14 -0
- package/src/utils/permissions/autoModeState.ts +12 -0
- package/src/utils/permissions/filesystem.ts +12 -0
- package/src/utils/plugins/loadPluginOutputStyles.ts +12 -0
- package/src/utils/plugins/schemas.ts +25 -0
- package/src/utils/process.ts +16 -0
- package/src/utils/sandbox/sandbox-adapter.ts +19 -0
- package/src/utils/sessionStorage.ts +238 -472
- package/src/utils/settings/constants.ts +10 -0
- package/src/utils/settings/settings.ts +19 -0
- package/src/utils/settings/types.ts +18 -0
- package/src/utils/shell/shellToolUtils.ts +9 -0
- package/src/utils/sinks.ts +11 -0
- package/src/utils/sleep.ts +7 -0
- package/src/utils/sliceAnsi.ts +7 -0
- package/src/utils/slowOperations.ts +3 -0
- package/src/utils/startupProfiler.ts +11 -0
- package/src/utils/stringUtils.ts +106 -0
- package/src/utils/systemPromptType.ts +9 -0
- package/src/utils/teleport/api.ts +15 -0
- package/src/utils/textHighlighting.ts +16 -0
- package/src/utils/theme.ts +17 -0
- package/src/utils/thinking.ts +58 -0
- package/src/utils/tokens.ts +11 -0
- package/src/utils/toolResultStorage.ts +17 -0
- package/src/utils/worktreeModeEnabled.ts +7 -0
- package/WORKSPACE_INTEGRATION.md +0 -290
- package/chat-sessions/sessions-index.json +0 -98
- package/package.json.original +0 -31
- package/package.json.publish +0 -47
- package/src/bootstrap/state.d.ts +0 -169
- package/src/bootstrap/state.js +0 -261
- package/src/context/pack-builder.d.ts +0 -24
- package/src/context/pack-builder.js +0 -281
- package/src/hooks/useExitOnCtrlCD.d.ts +0 -86
- package/src/hooks/useExitOnCtrlCD.js +0 -130
- package/src/hooks/useKeybinding.d.ts +0 -89
- package/src/hooks/useKeybinding.js +0 -163
- package/src/hooks/useTerminalSize.d.ts +0 -41
- package/src/hooks/useTerminalSize.js +0 -90
- package/src/index.d.ts +0 -23
- package/src/index.js +0 -24
- package/src/runtime/brand/brand.d.ts +0 -488
- package/src/runtime/brand/brand.js +0 -464
- package/src/runtime/brand/brand.ts +0 -667
- package/src/runtime/services/tokenEstimation.d.ts +0 -187
- package/src/runtime/services/tokenEstimation.js +0 -423
- package/src/runtime/services/tokenEstimation.ts +0 -547
- package/src/runtime/tools/Tool.d.ts +0 -239
- package/src/runtime/tools/Tool.js +0 -285
- package/src/runtime/tools/Tool.ts +0 -524
- package/src/scheduler/TaskScheduler.d.ts +0 -98
- package/src/scheduler/TaskScheduler.js +0 -201
- package/src/scheduler/TaskScheduler.ts +0 -259
- package/src/state/AppStateStore.d.ts +0 -347
- package/src/state/AppStateStore.js +0 -439
- package/src/state/AppStateStore.ts +0 -658
- package/src/state/WorkspaceStateStore.d.ts +0 -43
- package/src/state/WorkspaceStateStore.js +0 -224
- package/src/state/WorkspaceStateStore.ts +0 -297
- package/src/types/message.d.ts +0 -190
- package/src/types/message.js +0 -77
- package/src/utils/format.d.ts +0 -126
- package/src/utils/format.js +0 -230
- package/src/utils/fullscreen.d.ts +0 -161
- package/src/utils/fullscreen.js +0 -277
- package/src/utils/sessionStorage.d.ts +0 -210
- package/src/utils/sessionStorage.js +0 -435
- package/src/watcher/WorkspaceWatcher.d.ts +0 -70
- package/src/watcher/WorkspaceWatcher.js +0 -191
- package/src/watcher/WorkspaceWatcher.ts +0 -251
- package/src/workspace/loader.d.ts +0 -30
- package/src/workspace/loader.js +0 -117
- package/src/workspace/types.d.ts +0 -91
- package/src/workspace/types.js +0 -7
- package/threads/thread_1775361175022.json +0 -9
- package/tsconfig.json +0 -14
package/src/bootstrap/state.ts
CHANGED
|
@@ -1,371 +1,214 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Manages application initialization state, loading phases, and bootstrap
|
|
6
|
-
* lifecycle events. Provides centralized state tracking during application startup.
|
|
2
|
+
* Bootstrap state management
|
|
3
|
+
* Core application state and signals
|
|
7
4
|
*/
|
|
8
5
|
|
|
9
|
-
import type
|
|
6
|
+
import { createSignal, type Signal } from '../runtime/util/signal.js'
|
|
7
|
+
import { log } from '../runtime/util/log.js'
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
| 'initializing'
|
|
18
|
-
| 'loading_config'
|
|
19
|
-
| 'connecting'
|
|
20
|
-
| 'authenticating'
|
|
21
|
-
| 'ready'
|
|
22
|
-
| 'error';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Valid loading phase transitions
|
|
26
|
-
* @constant {Record<LoadingPhase, readonly LoadingPhase[]>}
|
|
27
|
-
*/
|
|
28
|
-
export const VALID_PHASE_TRANSITIONS: Readonly<Record<LoadingPhase, readonly LoadingPhase[]>> = {
|
|
29
|
-
idle: ['initializing'],
|
|
30
|
-
initializing: ['loading_config', 'error'],
|
|
31
|
-
loading_config: ['connecting', 'error'],
|
|
32
|
-
connecting: ['authenticating', 'error'],
|
|
33
|
-
authenticating: ['ready', 'error'],
|
|
34
|
-
ready: ['idle', 'initializing'],
|
|
35
|
-
error: ['idle', 'initializing'],
|
|
36
|
-
} as const;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Bootstrap error structure
|
|
40
|
-
* @interface BootstrapError
|
|
41
|
-
*/
|
|
42
|
-
export interface BootstrapError {
|
|
43
|
-
/** Error code for programmatic handling */
|
|
44
|
-
readonly code: string;
|
|
45
|
-
|
|
46
|
-
/** Human-readable error message */
|
|
47
|
-
readonly message: string;
|
|
48
|
-
|
|
49
|
-
/** Error timestamp */
|
|
50
|
-
readonly timestamp: Date;
|
|
51
|
-
|
|
52
|
-
/** Optional error details or stack trace */
|
|
53
|
-
readonly details?: string;
|
|
54
|
-
|
|
55
|
-
/** Phase where the error occurred */
|
|
56
|
-
readonly phase: LoadingPhase;
|
|
9
|
+
// Model settings
|
|
10
|
+
export interface ModelSetting {
|
|
11
|
+
model: string
|
|
12
|
+
provider: string
|
|
13
|
+
temperature?: number
|
|
14
|
+
maxTokens?: number
|
|
57
15
|
}
|
|
58
16
|
|
|
59
|
-
|
|
60
|
-
* Bootstrap state interface tracking initialization progress
|
|
61
|
-
* @interface BootstrapState
|
|
62
|
-
*/
|
|
63
|
-
export interface BootstrapState {
|
|
64
|
-
/** Current loading phase */
|
|
65
|
-
readonly phase: LoadingPhase;
|
|
17
|
+
export type SessionId = string & { readonly __brand: 'SessionId' }
|
|
66
18
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
readonly hasError: boolean;
|
|
75
|
-
|
|
76
|
-
/** Current error if any */
|
|
77
|
-
readonly error: BootstrapError | null;
|
|
19
|
+
// Session management
|
|
20
|
+
interface SessionState {
|
|
21
|
+
id: SessionId
|
|
22
|
+
createdAt: Date
|
|
23
|
+
lastActiveAt: Date
|
|
24
|
+
modelSetting: ModelSetting
|
|
25
|
+
}
|
|
78
26
|
|
|
79
|
-
|
|
80
|
-
|
|
27
|
+
// Global bootstrap state
|
|
28
|
+
let currentSession: SessionState | null = null
|
|
29
|
+
const slowOperations: { description: string; duration: number; timestamp: Date }[] = []
|
|
30
|
+
|
|
31
|
+
// Signals for reactive state
|
|
32
|
+
const sessionSignal = createSignal<SessionState | null>(null)
|
|
33
|
+
const modelSettingSignal = createSignal<ModelSetting | null>(null)
|
|
34
|
+
|
|
35
|
+
// Session management
|
|
36
|
+
export function createSession(modelSetting: ModelSetting): SessionId {
|
|
37
|
+
const id = `sess_${Date.now()}_${Math.random().toString(36).slice(2, 11)}` as SessionId
|
|
38
|
+
const session: SessionState = {
|
|
39
|
+
id,
|
|
40
|
+
createdAt: new Date(),
|
|
41
|
+
lastActiveAt: new Date(),
|
|
42
|
+
modelSetting,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
currentSession = session
|
|
46
|
+
sessionSignal.set(session)
|
|
47
|
+
modelSettingSignal.set(modelSetting)
|
|
48
|
+
|
|
49
|
+
log('info', 'Session created', { sessionId: id, model: modelSetting.model })
|
|
50
|
+
return id
|
|
51
|
+
}
|
|
81
52
|
|
|
82
|
-
|
|
83
|
-
|
|
53
|
+
export function getCurrentSession(): SessionState | null {
|
|
54
|
+
return currentSession
|
|
55
|
+
}
|
|
84
56
|
|
|
85
|
-
|
|
86
|
-
|
|
57
|
+
export function getSessionId(): SessionId | null {
|
|
58
|
+
return currentSession?.id || null
|
|
59
|
+
}
|
|
87
60
|
|
|
88
|
-
|
|
89
|
-
|
|
61
|
+
export function setSessionId(id: SessionId): void {
|
|
62
|
+
if (currentSession) {
|
|
63
|
+
currentSession.id = id
|
|
64
|
+
sessionSignal.set(currentSession)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
90
67
|
|
|
91
|
-
|
|
92
|
-
|
|
68
|
+
export function updateSessionActivity(): void {
|
|
69
|
+
if (currentSession) {
|
|
70
|
+
currentSession.lastActiveAt = new Date()
|
|
71
|
+
sessionSignal.set(currentSession)
|
|
72
|
+
}
|
|
93
73
|
}
|
|
94
74
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
progress: 0,
|
|
102
|
-
isComplete: false,
|
|
103
|
-
hasError: false,
|
|
104
|
-
error: null,
|
|
105
|
-
startTime: null,
|
|
106
|
-
endTime: null,
|
|
107
|
-
messages: [],
|
|
108
|
-
config: {},
|
|
109
|
-
services: [],
|
|
110
|
-
} as const;
|
|
75
|
+
export function clearSession(): void {
|
|
76
|
+
currentSession = null
|
|
77
|
+
sessionSignal.set(null)
|
|
78
|
+
modelSettingSignal.set(null)
|
|
79
|
+
log('info', 'Session cleared')
|
|
80
|
+
}
|
|
111
81
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
type StateChangeListener = (state: BootstrapState) => void;
|
|
82
|
+
// Model settings
|
|
83
|
+
export function getModelSetting(): ModelSetting | null {
|
|
84
|
+
return currentSession?.modelSetting || modelSettingSignal.get()
|
|
85
|
+
}
|
|
117
86
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
87
|
+
export function setModelSetting(setting: ModelSetting): void {
|
|
88
|
+
if (currentSession) {
|
|
89
|
+
currentSession.modelSetting = setting
|
|
90
|
+
sessionSignal.set(currentSession)
|
|
91
|
+
}
|
|
92
|
+
modelSettingSignal.set(setting)
|
|
93
|
+
}
|
|
121
94
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const state = getBootstrapState();
|
|
128
|
-
* if (state.phase === 'ready') {
|
|
129
|
-
* console.log('Application is ready');
|
|
130
|
-
* }
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
export function getBootstrapState(): Readonly<BootstrapState> {
|
|
134
|
-
return Object.freeze({ ...currentState });
|
|
95
|
+
// Session subscriptions
|
|
96
|
+
export function subscribeToSession(listener: (session: SessionState | null) => void): () => void {
|
|
97
|
+
return sessionSignal.subscribe(() => listener(sessionSignal.get()))
|
|
135
98
|
}
|
|
136
99
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*
|
|
141
|
-
* @param {Partial<BootstrapState>} updates - Partial state updates to apply
|
|
142
|
-
* @returns {Readonly<BootstrapState>} The updated state
|
|
143
|
-
* @throws {Error} If attempting an invalid phase transition
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* setBootstrapState({ phase: 'initializing', progress: 10 });
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
export function setBootstrapState(updates: Partial<BootstrapState>): Readonly<BootstrapState> {
|
|
150
|
-
// Validate phase transition if phase is being updated
|
|
151
|
-
if (updates.phase && updates.phase !== currentState.phase) {
|
|
152
|
-
if (!isValidPhaseTransition(currentState.phase, updates.phase)) {
|
|
153
|
-
throw new Error(
|
|
154
|
-
`Invalid phase transition from '${currentState.phase}' to '${updates.phase}'. ` +
|
|
155
|
-
`Valid transitions: ${VALID_PHASE_TRANSITIONS[currentState.phase].join(', ')}`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
100
|
+
export function subscribeToModelSetting(listener: (setting: ModelSetting | null) => void): () => void {
|
|
101
|
+
return modelSettingSignal.subscribe(() => listener(modelSettingSignal.get()))
|
|
102
|
+
}
|
|
159
103
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
currentState = {
|
|
173
|
-
...currentState,
|
|
174
|
-
isComplete: currentState.phase === 'ready',
|
|
175
|
-
hasError: currentState.phase === 'error' || currentState.error !== null,
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// Notify listeners (async to avoid blocking)
|
|
179
|
-
queueMicrotask(() => {
|
|
180
|
-
listeners.forEach((listener) => {
|
|
181
|
-
try {
|
|
182
|
-
listener(currentState);
|
|
183
|
-
} catch (error) {
|
|
184
|
-
console.error('Bootstrap state listener error:', error);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// Log state change in development
|
|
190
|
-
if (process.env.NODE_ENV === 'development') {
|
|
191
|
-
console.debug('[BootstrapState]', previousState.phase, '->', currentState.phase);
|
|
104
|
+
// Slow operation tracking
|
|
105
|
+
export function addSlowOperation(description: string, duration: number): void {
|
|
106
|
+
slowOperations.push({
|
|
107
|
+
description,
|
|
108
|
+
duration,
|
|
109
|
+
timestamp: new Date(),
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
// Keep only recent operations
|
|
113
|
+
const cutoff = Date.now() - 5 * 60 * 1000 // 5 minutes
|
|
114
|
+
while (slowOperations.length > 0 && slowOperations[0].timestamp.getTime() < cutoff) {
|
|
115
|
+
slowOperations.shift()
|
|
192
116
|
}
|
|
117
|
+
|
|
118
|
+
log('warn', `Slow operation detected: ${description} (${duration.toFixed(1)}ms)`)
|
|
119
|
+
}
|
|
193
120
|
|
|
194
|
-
|
|
121
|
+
export function getSlowOperations(): typeof slowOperations {
|
|
122
|
+
return [...slowOperations]
|
|
195
123
|
}
|
|
196
124
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
* @param {StateChangeListener} listener - Callback function to invoke on state changes
|
|
201
|
-
* @returns {() => void} Unsubscribe function
|
|
202
|
-
* @example
|
|
203
|
-
* ```typescript
|
|
204
|
-
* const unsubscribe = subscribeToBootstrapState((state) => {
|
|
205
|
-
* console.log('Phase:', state.phase);
|
|
206
|
-
* });
|
|
207
|
-
* // Later: unsubscribe();
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
export function subscribeToBootstrapState(listener: StateChangeListener): () => void {
|
|
211
|
-
listeners.add(listener);
|
|
125
|
+
export function clearSlowOperations(): void {
|
|
126
|
+
slowOperations.length = 0
|
|
127
|
+
}
|
|
212
128
|
|
|
213
|
-
|
|
214
|
-
|
|
129
|
+
// Working directory management
|
|
130
|
+
let originalCwd = process.cwd()
|
|
131
|
+
let kairosActive = false
|
|
132
|
+
let isRemoteMode = false
|
|
215
133
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
};
|
|
134
|
+
export function setOriginalCwd(cwd: string): void {
|
|
135
|
+
originalCwd = cwd
|
|
219
136
|
}
|
|
220
137
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
* Useful for testing or re-initializing the application
|
|
224
|
-
*
|
|
225
|
-
* @param {boolean} [notifyListeners=true] - Whether to notify listeners of the reset
|
|
226
|
-
* @returns {Readonly<BootstrapState>} The reset state
|
|
227
|
-
*/
|
|
228
|
-
export function resetBootstrapState(notifyListeners = true): Readonly<BootstrapState> {
|
|
229
|
-
currentState = { ...INITIAL_STATE };
|
|
230
|
-
|
|
231
|
-
if (notifyListeners) {
|
|
232
|
-
queueMicrotask(() => {
|
|
233
|
-
listeners.forEach((listener) => {
|
|
234
|
-
try {
|
|
235
|
-
listener(currentState);
|
|
236
|
-
} catch (error) {
|
|
237
|
-
console.error('Bootstrap state listener error:', error);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return Object.freeze({ ...currentState });
|
|
138
|
+
export function getOriginalCwd(): string {
|
|
139
|
+
return originalCwd
|
|
244
140
|
}
|
|
245
141
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
* Sets phase to 'initializing' and records start time
|
|
249
|
-
*
|
|
250
|
-
* @returns {Readonly<BootstrapState>} The updated state
|
|
251
|
-
*/
|
|
252
|
-
export function startBootstrap(): Readonly<BootstrapState> {
|
|
253
|
-
return setBootstrapState({
|
|
254
|
-
phase: 'initializing',
|
|
255
|
-
startTime: new Date(),
|
|
256
|
-
progress: 5,
|
|
257
|
-
});
|
|
142
|
+
export function setKairosActive(active: boolean): void {
|
|
143
|
+
kairosActive = active
|
|
258
144
|
}
|
|
259
145
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
* Sets phase to 'error' and records error details
|
|
263
|
-
*
|
|
264
|
-
* @param {string} code - Error code
|
|
265
|
-
* @param {string} message - Error message
|
|
266
|
-
* @param {string} [details] - Optional error details
|
|
267
|
-
* @returns {Readonly<BootstrapState>} The updated state
|
|
268
|
-
*/
|
|
269
|
-
export function setBootstrapError(
|
|
270
|
-
code: string,
|
|
271
|
-
message: string,
|
|
272
|
-
details?: string
|
|
273
|
-
): Readonly<BootstrapState> {
|
|
274
|
-
const error: BootstrapError = {
|
|
275
|
-
code,
|
|
276
|
-
message,
|
|
277
|
-
timestamp: new Date(),
|
|
278
|
-
details,
|
|
279
|
-
phase: currentState.phase,
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
return setBootstrapState({
|
|
283
|
-
phase: 'error',
|
|
284
|
-
error,
|
|
285
|
-
endTime: new Date(),
|
|
286
|
-
});
|
|
146
|
+
export function getKairosActive(): boolean {
|
|
147
|
+
return kairosActive
|
|
287
148
|
}
|
|
288
149
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
* Sets phase to 'ready' and records completion time
|
|
292
|
-
*
|
|
293
|
-
* @returns {Readonly<BootstrapState>} The updated state
|
|
294
|
-
*/
|
|
295
|
-
export function completeBootstrap(): Readonly<BootstrapState> {
|
|
296
|
-
return setBootstrapState({
|
|
297
|
-
phase: 'ready',
|
|
298
|
-
progress: 100,
|
|
299
|
-
endTime: new Date(),
|
|
300
|
-
});
|
|
150
|
+
export function setIsRemoteMode(remote: boolean): void {
|
|
151
|
+
isRemoteMode = remote
|
|
301
152
|
}
|
|
302
153
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
*
|
|
306
|
-
* @param {LoadingPhase} from - Current phase
|
|
307
|
-
* @param {LoadingPhase} to - Target phase
|
|
308
|
-
* @returns {boolean} Whether the transition is valid
|
|
309
|
-
*/
|
|
310
|
-
function isValidPhaseTransition(from: LoadingPhase, to: LoadingPhase): boolean {
|
|
311
|
-
return VALID_PHASE_TRANSITIONS[from].includes(to);
|
|
154
|
+
export function getIsRemoteMode(): boolean {
|
|
155
|
+
return isRemoteMode
|
|
312
156
|
}
|
|
313
157
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
*
|
|
317
|
-
* @returns {number | null} Estimated milliseconds remaining, or null if not available
|
|
318
|
-
*/
|
|
319
|
-
export function getEstimatedTimeRemaining(): number | null {
|
|
320
|
-
if (!currentState.startTime || currentState.progress === 0) {
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
158
|
+
// Permission mode
|
|
159
|
+
export type PermissionMode = 'ask' | 'acceptEdits' | 'bypassPermissions' | 'acceptAll'
|
|
323
160
|
|
|
324
|
-
|
|
325
|
-
const progressRemaining = 100 - currentState.progress;
|
|
326
|
-
const estimatedTotal = (elapsed / currentState.progress) * 100;
|
|
161
|
+
let currentPermissionMode: PermissionMode = 'ask'
|
|
327
162
|
|
|
328
|
-
|
|
163
|
+
export function setPermissionMode(mode: PermissionMode): void {
|
|
164
|
+
currentPermissionMode = mode
|
|
165
|
+
log('info', `Permission mode set to: ${mode}`)
|
|
329
166
|
}
|
|
330
167
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
*
|
|
334
|
-
* @param {TypedMessage} message - The message to add
|
|
335
|
-
* @returns {Readonly<BootstrapState>} The updated state
|
|
336
|
-
*/
|
|
337
|
-
export function addBootstrapMessage(message: TypedMessage): Readonly<BootstrapState> {
|
|
338
|
-
return setBootstrapState({
|
|
339
|
-
messages: [...currentState.messages, message],
|
|
340
|
-
});
|
|
168
|
+
export function getPermissionMode(): PermissionMode {
|
|
169
|
+
return currentPermissionMode
|
|
341
170
|
}
|
|
342
171
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
172
|
+
// Debug mode
|
|
173
|
+
let debugMode = false
|
|
174
|
+
|
|
175
|
+
export function setDebugMode(enabled: boolean): void {
|
|
176
|
+
debugMode = enabled
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function isDebugMode(): boolean {
|
|
180
|
+
return debugMode
|
|
181
|
+
}
|
|
353
182
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
183
|
+
// Initialization
|
|
184
|
+
export function initializeBootstrapState(): void {
|
|
185
|
+
log('info', 'Bootstrap state initialized')
|
|
357
186
|
}
|
|
358
187
|
|
|
359
188
|
// Default export
|
|
360
189
|
export default {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
190
|
+
createSession,
|
|
191
|
+
getCurrentSession,
|
|
192
|
+
getSessionId,
|
|
193
|
+
setSessionId,
|
|
194
|
+
updateSessionActivity,
|
|
195
|
+
clearSession,
|
|
196
|
+
getModelSetting,
|
|
197
|
+
setModelSetting,
|
|
198
|
+
subscribeToSession,
|
|
199
|
+
subscribeToModelSetting,
|
|
200
|
+
addSlowOperation,
|
|
201
|
+
getSlowOperations,
|
|
202
|
+
clearSlowOperations,
|
|
203
|
+
setOriginalCwd,
|
|
204
|
+
getOriginalCwd,
|
|
205
|
+
setKairosActive,
|
|
206
|
+
getKairosActive,
|
|
207
|
+
setIsRemoteMode,
|
|
208
|
+
getIsRemoteMode,
|
|
209
|
+
setPermissionMode,
|
|
210
|
+
getPermissionMode,
|
|
211
|
+
setDebugMode,
|
|
212
|
+
isDebugMode,
|
|
213
|
+
initializeBootstrapState,
|
|
214
|
+
}
|