Skip to content

Commit 324bf75

Browse files
fix: HAI Tasks state issue (#212)
* feat: implemented hai tasks * feat: added mark as completed feature for hai tasks execution and enhanced speciai-mcp description * fix: fixed the html issue when performing action during fuzzy search * doc: added changeset * chore: updated description * chore: removed console logs * fix: maintaining hai task in workspace level state instaed of global --------- Co-authored-by: Magesh <mageshmscss@gmail.com>
1 parent 07e6a29 commit 324bf75

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

src/core/controller/ui/initializeWebview.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,22 @@ export async function initializeWebview(controller: Controller, _request: EmptyR
223223
// Silently refresh MCP marketplace catalog
224224
controller.silentlyRefreshMcpMarketplace()
225225

226+
// TAG:HAI - Restore HAI tasks if available
227+
const haiConfig = controller.cacheService.getWorkspaceStateKey("haiConfig")
228+
if (haiConfig?.folder) {
229+
// Import loadHaiTasks to restore tasks
230+
const { loadHaiTasks } = await import("./loadHaiTasks")
231+
try {
232+
await loadHaiTasks(controller, {
233+
metadata: {},
234+
folderPath: haiConfig.folder,
235+
loadDefault: true,
236+
})
237+
} catch (error) {
238+
console.error("Failed to restore HAI tasks on initialization:", error)
239+
}
240+
}
241+
226242
// Initialize telemetry service with user's current setting
227243
controller.getStateToPostToWebview().then((state) => {
228244
const { telemetrySetting } = state

src/core/controller/ui/loadHaiTasks.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,12 @@ function getFormattedDateTime(): string {
2323
*/
2424
export async function loadHaiTasks(controller: Controller, request: HaiTasksLoadRequest): Promise<Empty> {
2525
try {
26-
const { folderPath, loadDefault } = request
26+
const { folderPath } = request
27+
let selectedFolderPath: string | undefined
2728

28-
if (loadDefault && folderPath) {
29-
// Load from the provided path (refresh case)
30-
const ts = getFormattedDateTime()
31-
await fetchTaskFromSelectedFolder(controller, folderPath, ts)
32-
await controller.context.globalState.update("haiConfig", { folder: folderPath, ts })
33-
} else if (folderPath) {
34-
// Load from specific path
35-
const ts = getFormattedDateTime()
36-
await fetchTaskFromSelectedFolder(controller, folderPath, ts)
37-
await controller.context.globalState.update("haiConfig", { folder: folderPath, ts })
29+
if (folderPath) {
30+
// Load from the provided path (either refresh case or specific path)
31+
selectedFolderPath = folderPath
3832
} else {
3933
// Show folder picker
4034
const options: vscode.OpenDialogOptions = {
@@ -46,12 +40,16 @@ export async function loadHaiTasks(controller: Controller, request: HaiTasksLoad
4640

4741
const fileUri = await vscode.window.showOpenDialog(options)
4842
if (fileUri && fileUri[0]) {
49-
const ts = getFormattedDateTime()
50-
await fetchTaskFromSelectedFolder(controller, fileUri[0].fsPath, ts)
51-
await controller.context.globalState.update("haiConfig", { folder: fileUri[0].fsPath, ts })
43+
selectedFolderPath = fileUri[0].fsPath
5244
}
5345
}
5446

47+
if (selectedFolderPath) {
48+
const ts = getFormattedDateTime()
49+
await fetchTaskFromSelectedFolder(controller, selectedFolderPath, ts)
50+
controller.cacheService.setWorkspaceState("haiConfig", { folder: selectedFolderPath, ts })
51+
}
52+
5553
return Empty.create({})
5654
} catch (error) {
5755
console.error(`Failed to load HAI tasks: ${error}`)

src/core/controller/ui/resetHaiTasks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { sendHaiTaskDataUpdate } from "./subscribeToHaiTaskData"
1111
*/
1212
export async function resetHaiTasks(controller: Controller, _request: EmptyRequest): Promise<Empty> {
1313
try {
14-
// Clear the HAI config
15-
await controller.context.globalState.update("haiConfig", {})
14+
// Clear the HAI config using workspace state
15+
controller.cacheService.setWorkspaceState("haiConfig", undefined)
1616

1717
// Send empty task data to all subscribed clients
1818
sendHaiTaskDataUpdate({

src/core/storage/CacheService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ export class CacheService {
10951095
// TAG:HAI - HAI-specific workspace state fields
10961096
buildContextOptions: buildContextOptions,
10971097
buildIndexProgress: buildIndexProgress,
1098+
haiConfig: state.haiConfig,
10981099
} satisfies Partial<LocalState>
10991100

11001101
Object.assign(this.workspaceStateCache, workspaceStateFields)

src/core/storage/state-keys.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export type LocalStateKey =
213213
| "workflowToggles"
214214
| "buildContextOptions"
215215
| "buildIndexProgress"
216+
| "haiConfig"
216217

217218
export interface GlobalState {
218219
awsRegion: string | undefined
@@ -418,4 +419,5 @@ export interface LocalState {
418419
// TAG:HAI
419420
buildContextOptions: HaiBuildContextOptions
420421
buildIndexProgress: HaiBuildIndexProgress
422+
haiConfig: { folder?: string; ts?: string } | undefined
421423
}

src/core/storage/utils/state-helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export async function readStateFromDisk(context: ExtensionContext) {
189189
// TAG:HAI - Get HAI-specific workspace state values
190190
const buildContextOptions = context.workspaceState.get("buildContextOptions") as any | undefined
191191
const buildIndexProgress = context.workspaceState.get("buildIndexProgress") as any | undefined
192+
const haiConfig = context.workspaceState.get("haiConfig") as { folder?: string; ts?: string } | undefined
192193

193194
// Get mode-related configurations
194195
const mode = context.globalState.get("mode") as Mode | undefined
@@ -465,6 +466,7 @@ export async function readStateFromDisk(context: ExtensionContext) {
465466
expertName,
466467
isDeepCrawlEnabled,
467468
},
469+
haiConfig,
468470

469471
// Embedding configuration
470472
embeddingConfiguration: {

0 commit comments

Comments
 (0)