@@ -10,13 +10,18 @@ import { TaskRunner } from "./runners/TaskRunner";
1010import { QuickTasksProvider } from "./QuickTasksProvider" ;
1111import { logger } from "./utils/logger" ;
1212import { initDb , disposeDb } from "./db/lifecycle" ;
13- import { summariseAllTasks , registerAllCommands } from "./semantic/summaryPipeline" ;
14- import { createVSCodeFileSystem } from "./semantic/vscodeAdapters" ;
1513import { forceSelectModel } from "./semantic/summariser" ;
1614import { syncTagsFromConfig } from "./tags/tagSync" ;
1715import { setupFileWatchers } from "./watchers" ;
1816import { PrivateTaskDecorationProvider } from "./tree/PrivateTaskDecorationProvider" ;
1917import { appState } from "./state" ;
18+ import {
19+ initAiSummaries ,
20+ registerDiscoveredCommands ,
21+ runSummarisation ,
22+ syncAndSummarise ,
23+ } from "./summaryOrchestration" ;
24+ import type { SummaryDeps } from "./summaryOrchestration" ;
2025
2126const MAKE_EXECUTABLE_COMMAND = "commandtree.makeExecutable" ;
2227const EXECUTE_PERMISSION_BITS = 0o111 ;
@@ -48,6 +53,14 @@ function getTaskRunner(): TaskRunner {
4853 return appState . taskRunner ;
4954}
5055
56+ function getSummaryDeps ( workspaceRoot : string ) : SummaryDeps {
57+ return {
58+ workspaceRoot,
59+ treeProvider : getTreeProvider ( ) ,
60+ quickTasksProvider : getQuickTasksProvider ( ) ,
61+ } ;
62+ }
63+
5164export async function activate ( context : vscode . ExtensionContext ) : Promise < ExtensionExports | undefined > {
5265 const workspaceRoot = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath ;
5366 logger . info ( "Extension activating" , { workspaceRoot } ) ;
@@ -76,7 +89,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<Extens
7689function runBackgroundStartup ( workspaceRoot : string ) : void {
7790 initialDiscovery ( workspaceRoot )
7891 . then ( ( ) => {
79- initAiSummaries ( workspaceRoot ) ;
92+ initAiSummaries ( getSummaryDeps ( workspaceRoot ) ) ;
8093 } )
8194 . catch ( ( e : unknown ) => {
8295 logger . error ( "Initial discovery failed" , {
@@ -96,7 +109,7 @@ function setupWatchers(context: vscode.ExtensionContext, workspaceRoot: string):
96109 setupFileWatchers ( {
97110 context,
98111 onTaskFileChange : ( ) => {
99- syncAndSummarise ( workspaceRoot ) . catch ( ( e : unknown ) => {
112+ syncAndSummarise ( getSummaryDeps ( workspaceRoot ) ) . catch ( ( e : unknown ) => {
100113 logger . error ( "Sync failed" , {
101114 error : e instanceof Error ? e . message : "Unknown" ,
102115 } ) ;
@@ -115,7 +128,7 @@ function setupWatchers(context: vscode.ExtensionContext, workspaceRoot: string):
115128async function initialDiscovery ( workspaceRoot : string ) : Promise < void > {
116129 await syncQuickTasks ( ) ;
117130 logger . info ( "syncQuickTasks complete" , { taskCount : getTreeProvider ( ) . getAllTasks ( ) . length } ) ;
118- await registerDiscoveredCommands ( workspaceRoot ) ;
131+ await registerDiscoveredCommands ( getSummaryDeps ( workspaceRoot ) ) ;
119132 await syncTagsFromJson ( workspaceRoot ) ;
120133}
121134
@@ -192,7 +205,7 @@ function registerFilterCommands(context: vscode.ExtensionContext): void {
192205 vscode . commands . registerCommand ( "commandtree.generateSummaries" , async ( ) => {
193206 const workspaceRoot = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath ;
194207 if ( workspaceRoot !== undefined ) {
195- await runSummarisation ( workspaceRoot ) ;
208+ await runSummarisation ( getSummaryDeps ( workspaceRoot ) ) ;
196209 }
197210 } ) ,
198211 vscode . commands . registerCommand ( "commandtree.selectModel" , async ( ) => {
@@ -201,7 +214,7 @@ function registerFilterCommands(context: vscode.ExtensionContext): void {
201214 vscode . window . showInformationMessage ( `CommandTree: AI model set to ${ result . value } ` ) ;
202215 const workspaceRoot = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath ;
203216 if ( workspaceRoot !== undefined ) {
204- await runSummarisation ( workspaceRoot ) ;
217+ await runSummarisation ( getSummaryDeps ( workspaceRoot ) ) ;
205218 }
206219 } else {
207220 vscode . window . showWarningMessage ( `CommandTree: ${ result . error } ` ) ;
@@ -395,72 +408,6 @@ async function pickOrCreateTag(existingTags: string[], taskLabel: string): Promi
395408 } ) ;
396409}
397410
398- async function registerDiscoveredCommands ( workspaceRoot : string ) : Promise < void > {
399- const tasks = getTreeProvider ( ) . getAllTasks ( ) ;
400- if ( tasks . length === 0 ) {
401- return ;
402- }
403- const result = await registerAllCommands ( {
404- tasks,
405- workspaceRoot,
406- fs : createVSCodeFileSystem ( ) ,
407- } ) ;
408- if ( ! result . ok ) {
409- logger . warn ( "Command registration failed" , { error : result . error } ) ;
410- } else {
411- logger . info ( "Commands registered in DB" , { count : result . value } ) ;
412- }
413- }
414-
415- function initAiSummaries ( workspaceRoot : string ) : void {
416- const aiConfig = vscode . workspace . getConfiguration ( "commandtree" ) . get < boolean > ( "enableAiSummaries" ) ;
417- if ( aiConfig === false ) {
418- return ;
419- }
420- vscode . commands . executeCommand ( "setContext" , "commandtree.aiSummariesEnabled" , true ) ;
421- runSummarisation ( workspaceRoot ) . catch ( ( e : unknown ) => {
422- logger . error ( "AI summarisation failed" , {
423- error : e instanceof Error ? e . message : "Unknown" ,
424- } ) ;
425- } ) ;
426- }
427-
428- async function runSummarisation ( workspaceRoot : string ) : Promise < void > {
429- const tasks = getTreeProvider ( ) . getAllTasks ( ) ;
430- logger . info ( "[SUMMARY] Starting" , { taskCount : tasks . length } ) ;
431- if ( tasks . length === 0 ) {
432- logger . warn ( "[SUMMARY] No tasks to summarise" ) ;
433- return ;
434- }
435- const summaryResult = await summariseAllTasks ( {
436- tasks,
437- workspaceRoot,
438- fs : createVSCodeFileSystem ( ) ,
439- onProgress : ( done , total , label ) => {
440- logger . info ( `[SUMMARY] ${ label } ` , { done, total } ) ;
441- } ,
442- } ) ;
443- if ( ! summaryResult . ok ) {
444- logger . error ( "Summary pipeline failed" , { error : summaryResult . error } ) ;
445- vscode . window . showErrorMessage ( `CommandTree: Summary failed — ${ summaryResult . error } ` ) ;
446- return ;
447- }
448- if ( summaryResult . value > 0 ) {
449- await getTreeProvider ( ) . refresh ( ) ;
450- getQuickTasksProvider ( ) . updateTasks ( getTreeProvider ( ) . getAllTasks ( ) ) ;
451- }
452- vscode . window . showInformationMessage ( `CommandTree: Summarised ${ summaryResult . value } commands` ) ;
453- }
454-
455- async function syncAndSummarise ( workspaceRoot : string ) : Promise < void > {
456- await syncQuickTasks ( ) ;
457- await registerDiscoveredCommands ( workspaceRoot ) ;
458- const aiConfig = vscode . workspace . getConfiguration ( "commandtree" ) . get < boolean > ( "enableAiSummaries" ) ;
459- if ( aiConfig !== false ) {
460- await runSummarisation ( workspaceRoot ) ;
461- }
462- }
463-
464411function updateFilterContext ( ) : void {
465412 vscode . commands . executeCommand ( "setContext" , "commandtree.hasFilter" , getTreeProvider ( ) . hasFilter ( ) ) ;
466413}
0 commit comments