@@ -6,50 +6,51 @@ import { execSync } from 'child_process';
6
6
7
7
let gooseTerminal : vscode . Terminal | undefined ;
8
8
const terminalName = '🪿 goose chat 🪿' ;
9
- const tempFilePath = path . join ( os . tmpdir ( ) , 'goose_open_files.txt' ) ;
10
- const tempFilePathDirty = path . join ( os . tmpdir ( ) , 'goose_unsaved_files.txt' ) ;
11
- const FALLBACK_COMMAND = "goose session start"
12
9
13
10
export function activate ( context : vscode . ExtensionContext ) {
14
-
15
11
16
12
// Check if goose CLI is installed
17
13
const config = vscode . workspace . getConfiguration ( 'goose' ) ;
18
- let defaultCommand = config . get ( 'defaultCommand' , FALLBACK_COMMAND ) ;
19
-
14
+ let defaultCommand = config . get ( 'defaultCommand' , "goose session start" ) ;
20
15
try {
21
- execSync ( 'goose' ) ;
16
+ execSync ( 'goose version ' ) ;
22
17
} catch ( error ) {
23
18
try {
24
- execSync ( 'sq' ) ;
25
- if ( defaultCommand == FALLBACK_COMMAND ) {
26
- defaultCommand = 'sq goose session start'
27
- }
19
+ execSync ( 'sq goose version' ) ;
20
+ defaultCommand = 'sq goose session start'
28
21
} catch ( error ) {
29
22
vscode . window . showWarningMessage ( 'If goose isn\'t working, please check the goose command line tool is installed and working.' ) ;
30
23
}
31
24
}
32
25
33
- vscode . window . showInformationMessage ( 'goose agent starting, this may take a minute.. ⏰' ) ;
26
+ vscode . window . showInformationMessage ( 'goose agent starting, this may take a minute.. ⏰' ) ;
27
+
28
+ let getTerminal = ( ) => {
29
+ if ( ! gooseTerminal || gooseTerminal . exitStatus !== undefined ) {
30
+ gooseTerminal = vscode . window . createTerminal ( {
31
+ name : terminalName ,
32
+ location : { viewColumn : vscode . ViewColumn . Beside } ,
33
+ message : 'Loading Goose Session...' , // Add a message to make it clear what terminal is for
34
+ } ) ;
35
+ gooseTerminal . sendText ( defaultCommand ) ;
36
+ }
34
37
38
+ console . log ( 'Goose terminal created:' , gooseTerminal . name ) ;
39
+ gooseTerminal . show ( ) ; // Delayed terminal show
40
+
41
+ return gooseTerminal
35
42
36
-
37
-
43
+ }
38
44
39
45
let openTerminalDisposable = vscode . commands . registerCommand ( 'extension.openGooseTerminal' , ( ) => {
40
- gooseTerminal = vscode . window . createTerminal ( {
41
- name : terminalName ,
42
- location : { viewColumn : vscode . ViewColumn . Beside }
43
- } ) ;
44
- gooseTerminal . sendText ( defaultCommand + '\n\n' ) ;
45
-
46
- gooseTerminal . show ( ) ;
46
+ getTerminal ( ) ;
47
47
} ) ;
48
48
context . subscriptions . push ( openTerminalDisposable ) ;
49
-
50
- // Automatically open the terminal when the extension activates
49
+
50
+ // Automatically open the terminal when the extension activates
51
51
vscode . commands . executeCommand ( 'extension.openGooseTerminal' ) ;
52
-
52
+
53
+
53
54
let sendToGooseDisposable = vscode . commands . registerCommand ( 'extension.sendToGoose' , async ( ) => {
54
55
const editor = vscode . window . activeTextEditor ;
55
56
if ( ! editor ) {
@@ -85,8 +86,7 @@ export function activate(context: vscode.ExtensionContext) {
85
86
86
87
}
87
88
editor . document . save ( ) ;
88
- gooseTerminal ?. sendText ( textToAskGoose ) ;
89
- gooseTerminal ?. show ( ) ;
89
+ getTerminal ( ) . sendText ( textToAskGoose ) ;
90
90
} ) ;
91
91
92
92
context . subscriptions . push ( sendToGooseDisposable ) ;
@@ -156,9 +156,8 @@ export function activate(context: vscode.ExtensionContext) {
156
156
157
157
document . save ( ) ;
158
158
159
- gooseTerminal ? .sendText ( `There is some unfinished code at line: ${ startLine } in file: ${ filePath } . ` +
159
+ getTerminal ( ) . sendText ( `There is some unfinished code at line: ${ startLine } in file: ${ filePath } . ` +
160
160
`Complete the code based on the context, from that line onwards. Do not delete content.` ) ;
161
- gooseTerminal ?. show ( ) ;
162
161
} ) ;
163
162
context . subscriptions . push ( askGooseToFinishItCommand ) ;
164
163
@@ -175,17 +174,10 @@ export function activate(context: vscode.ExtensionContext) {
175
174
176
175
document . save ( ) ;
177
176
178
- gooseTerminal ?. sendText ( `Can you look at the code on line: ${ startLine } in file: ${ filePath } . ` +
179
- `and fix any problems you see on this line and near it. Try not to delete content.` ) ;
180
- gooseTerminal ?. show ( ) ;
177
+ getTerminal ( ) . sendText ( `Can you look at the code on line: ${ startLine } in file: ${ filePath } . ` +
178
+ `and fix any problems you see on this line and near it. Try not to delete content.` ) ;
181
179
} ) ;
182
180
context . subscriptions . push ( askGooseToFix ) ;
183
181
184
182
}
185
183
186
- export function deactivate ( ) {
187
- if ( gooseTerminal ) {
188
- gooseTerminal . sendText ( 'exit' ) ;
189
- gooseTerminal . dispose ( ) ;
190
- }
191
- }
0 commit comments