ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / extension / agents / vscode-node / githubOrgChatResourcesService.ts 373 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import * as vscode from 'vscode' ;
import { IAuthenticationService } from '../../../platform/authentication/common/authentication' ;
import { AGENT_FILE_EXTENSION , INSTRUCTION_FILE_EXTENSION , PromptsType } from '../../../platform/customInstructions/common/promptTypes' ;
import { IVSCodeExtensionContext } from '../../../platform/extContext/common/extensionContext' ;
import { IFileSystemService } from '../../../platform/filesystem/common/fileSystemService' ;
import { FileType } from '../../../platform/filesystem/common/fileTypes' ;
import { getGithubRepoIdFromFetchUrl, IGitService
IOctoKitService
ILogService
IWorkspaceService
Disposable DisposableStore IDisposable
createDecorator
intervalMs orgName IDisposable
type PromptsType orgName filename
type PromptsType orgName filename content options checkForChanges
type PromptsType orgName exclude Set
type PromptsType orgName vscode ChatResource
IGitHubOrgChatResourcesService
type PromptsType
type
PromptsType instructions
PromptsType agent
type PromptsType fileName
type
PromptsType instructions
fileName
PromptsType agent
fileName
_cachedPreferredOrgName
authService IAuthenticationService
extensionContext IVSCodeExtensionContext
fileSystem IFileSystemService
gitService IGitService
logService ILogService
octoKitService IOctoKitService
workspaceService IWorkspaceService
workspaceService
logService
_cachedPreferredOrgName
authService
logService
_cachedPreferredOrgName
_cachedPreferredOrgName
_cachedPreferredOrgName
_cachedPreferredOrgName
currentUser Awaited ReturnType octoKitService getCurrentAuthedUser
currentUser octoKitService
error
logService
currentUser
logService
workspaceOrg
logService
workspaceOrg
logService
workspaceOrg
copilotOrganizations authService copilotToken organizationLoginList
logService
copilotOrganizations length
copilotOrg copilotOrganizations
logService
copilotOrg
userOrganizations
userOrganizations octoKitService
logService
userOrganizations length
logService
error
logService
logService
userOrganizations
workspaceFolders workspaceService
workspaceFolders length
repoInfo gitService workspaceFolders
repoInfo remoteFetchUrls length
fetchUrl repoInfo remoteFetchUrls
fetchUrl
repoId fetchUrl
repoId
logService
repoId org
error
logService
intervalMs orgName IDisposable
disposables
isPolling
isPolling
isPolling
orgName
orgName
orgName
error
logService
isPolling
disposables
orgName type PromptsType vscode Uri
sanitizedOrg orgName
subdirectory type
vscode Uri
extensionContext globalStorageUri
GitHubOrgChatResourcesService
sanitizedOrg
subdirectory
orgName type PromptsType filename vscode Uri
vscode Uri orgName type filename
name
name
orgName type PromptsType
cacheDir orgName type
fileSystem cacheDir
logService
fileSystem cacheDir
error
logService error
error
logService
type PromptsType orgName filename
fileUri orgName type filename
content fileSystem fileUri
content
logService
type PromptsType orgName filename content options checkForChanges
orgName type
fileUri orgName type filename
contentBytes content
hasChanges
options checkForChanges
hasChanges
stat fileSystem fileUri
stat size contentBytes length
hasChanges
existingContent fileSystem fileUri
existingText existingContent
existingText content
logService
hasChanges
hasChanges
logService
fileSystem fileUri contentBytes
error
logService error
error
logService
hasChanges
type PromptsType orgName exclude Set
cacheDir orgName type
files fileSystem cacheDir
filename fileType files
fileType FileType File type filename exclude filename
fileSystem vscode Uri cacheDir filename
logService
type PromptsType orgName vscode ChatResource
resources vscode ChatResource
cacheDir orgName type
files fileSystem cacheDir
filename fileType files
fileType FileType File type filename
fileUri vscode Uri cacheDir filename
resources uri fileUri
logService
resources
}
from
'../../../platform/git/common/gitService'
;
import
{
}
from
'../../../platform/github/common/githubService'
;
import
{
}
from
'../../../platform/log/common/logService'
;
import
{
}
from
'../../../platform/workspace/common/workspaceService'
;
import
{
,
,
}
from
'../../../util/vs/base/common/lifecycle'
;
import
{
}
from
'../../../util/vs/platform/instantiation/common/instantiation'
;
export
interface
IGitHubOrgChatResourcesService
extends
IDisposable
{
getPreferredOrganizationName
(
)
:
Promise
<
string
|
undefined
>
;
startPolling
(
:
number
,
callback
:
(
:
string
)
=>
Promise
<
void
>
)
:
;
readCacheFile
(
:
,
:
string
,
:
string
)
:
Promise
<
string
|
undefined
>
;
writeCacheFile
(
:
,
:
string
,
:
string
,
:
string
,
?
:
{
?
:
boolean
}
)
:
Promise
<
boolean
>
;
clearCache
(
:
,
:
string
,
?
:
<
string
>
)
:
Promise
<
void
>
;
listCachedFiles
(
:
,
:
string
)
:
Promise
<
.
[
]
>
;
}
export
const
=
createDecorator < IGitHubOrgChatResourcesService>
(
'IGitHubPromptFileService'
)
;
function
getCacheSubdirectory
(
:
)
:
string
{
switch
(
)
{
case
.
:
return
'instructions'
;
case
.
:
return
'agents'
;
default
:
throw
new
Error
(
` Unsupported PromptsType: ${ type } `
)
;
}
}
function
isValidFile
(
:
,
:
string
)
:
boolean
{
switch
(
)
{
case
.
:
return
.
endsWith
(
INSTRUCTION_FILE_EXTENSION
)
;
case
.
:
return
.
endsWith
(
AGENT_FILE_EXTENSION
)
;
default
:
throw
new
Error
(
` Unsupported PromptsType: ${ type } `
)
;
}
}
export
class
GitHubOrgChatResourcesService
extends
Disposable
implements
IGitHubOrgChatResourcesService
{
private
static
readonly
CACHE_ROOT
=
'github'
;
private
:
Promise
<
string
|
undefined
>
|
undefined
;
constructor
(
@ IAuthenticationService
private
readonly
:
,
@ IVSCodeExtensionContext
private
readonly
:
,
@ IFileSystemService
private
readonly
:
,
@ IGitService
private
readonly
:
,
@ ILogService
private
readonly
:
,
@ IOctoKitService
private
readonly
:
,
@ IWorkspaceService
private
readonly
:
,
)
{
super
(
)
;
this
.
_register
(
this
.
.
onDidChangeWorkspaceFolders
(
(
)
=>
{
this
.
.
trace
(
'[GitHubOrgChatResourcesService] Workspace folders changed, invalidating cached org name'
)
;
this
.
=
undefined
;
}
)
)
;
this
.
_register
(
this
.
.
onDidAuthenticationChange
(
(
)
=>
{
this
.
.
trace
(
'[GitHubOrgChatResourcesService] Authentication changed, invalidating cached org name'
)
;
this
.
=
undefined
;
}
)
)
;
}
async
getPreferredOrganizationName
(
)
:
Promise
<
string
|
undefined
>
{
if
(
!
this
.
)
{
this
.
=
this
.
computePreferredOrganizationName
(
)
;
}
return
this
.
;
}
private
async
computePreferredOrganizationName
(
)
:
Promise
<
string
|
undefined
>
{
let
:
<
<
typeof
this
.
.
>>
;
try
{
=
await
this
.
.
getCurrentAuthedUser
(
)
;
}
catch
(
)
{
this
.
.
error
(
` [GitHubOrgChatResourcesService] Error checking authenticated user: ${ error} `
)
;
return
undefined
;
}
if
(
!
)
{
this
.
.
trace
(
'[GitHubOrgChatResourcesService] User is not signed in'
)
;
return
undefined
;
}
const
=
await
this
.
getWorkspaceRepositoryOrganization
(
)
;
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Workspace organization: ${ workspaceOrg ?? 'none' } `
)
;
if
(
)
{
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Using workspace organization: ${ workspaceOrg} `
)
;
return
;
}
const
=
this
.
.
?.
??
[
]
;
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Copilot organizations: ${ JSON . stringify ( copilotOrganizations) } `
)
;
if
(
.
>
0
)
{
const
=
[
0
]
;
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Using Copilot sign-in organization: ${ copilotOrg} `
)
;
return
;
}
let
:
string
[
]
;
try
{
=
await
this
.
.
getUserOrganizations
(
{
}
,
1
)
;
this
.
.
trace
(
` [GitHubOrgChatResourcesService] User organizations: ${ JSON . stringify ( userOrganizations) } `
)
;
if
(
.
===
0
)
{
this
.
.
trace
(
'[GitHubOrgChatResourcesService] No organizations found for user'
)
;
return
undefined
;
}
}
catch
(
)
{
this
.
.
error
(
` [GitHubOrgChatResourcesService] Error getting user organizations: ${ error} `
)
;
return
undefined
;
}
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Falling back to first user organization: ${ userOrganizations[ 0 ] } `
)
;
return
[
0
]
;
}
private
async
getWorkspaceRepositoryOrganization
(
)
:
Promise
<
string
|
undefined
>
{
const
=
this
.
.
getWorkspaceFolders
(
)
;
if
(
.
===
0
)
{
return
undefined
;
}
try
{
const
=
await
this
.
.
getRepositoryFetchUrls
(
[
0
]
)
;
if
(
!
?.
?.
)
{
return
undefined
;
}
for
(
const
of
.
)
{
if
(
!
)
{
continue
;
}
const
=
getGithubRepoIdFromFetchUrl
(
)
;
if
(
)
{
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Found GitHub repo: ${ repoId. org} / ${ repoId. repo} `
)
;
return
.
;
}
}
}
catch
(
)
{
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Error getting workspace repository: ${ error} `
)
;
}
return
undefined
;
}
startPolling
(
:
number
,
callback
:
(
:
string
)
=>
Promise
<
void
>
)
:
{
const
=
new
DisposableStore
(
)
;
let
=
false
;
const
poll
=
async
(
)
=>
{
if
(
)
{
return
;
}
=
true
;
try
{
const
=
await
this
.
getPreferredOrganizationName
(
)
;
if
(
)
{
try
{
await
callback
(
)
;
}
catch
(
)
{
this
.
.
error
(
` [GitHubOrgChatResourcesService] Error in polling callback: ${ error} `
)
;
}
}
}
finally
{
=
false
;
}
}
;
void
poll
(
)
;
return
;
}
private
getCacheDir
(
:
string
,
:
)
:
.
{
const
=
this
.
sanitizeFilename
(
)
;
const
=
getCacheSubdirectory
(
)
;
return
.
.
joinPath
(
this
.
.
,
.
CACHE_ROOT
,
,
)
;
}
private
getCacheFileUri
(
:
string
,
:
,
:
string
)
:
.
{
return
.
.
joinPath
(
this
.
getCacheDir
(
,
)
,
)
;
}
private
sanitizeFilename
(
:
string
)
:
string
{
return
.
replace
(
/ [ ^ a- z 0- 9 _-] / gi
,
'_'
)
.
toLowerCase
(
)
;
}
private
async
ensureCacheDir
(
:
string
,
:
)
:
Promise
<
void
>
{
const
=
this
.
getCacheDir
(
,
)
;
try
{
await
this
.
.
stat
(
)
;
}
catch
{
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Creating cache directory: ${ cacheDir. toString ( ) } `
)
;
try
{
await
this
.
.
createDirectory
(
)
;
}
catch
(
)
{
this
.
.
error
(
,
'[GitHubOrgChatResourcesService] Failed to create cache directory'
)
;
throw
;
}
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Created cache directory: ${ cacheDir. toString ( ) } `
)
;
}
}
async
readCacheFile
(
:
,
:
string
,
:
string
)
:
Promise
<
string
|
undefined
>
{
try
{
const
=
this
.
getCacheFileUri
(
,
,
)
;
const
=
await
this
.
.
readFile
(
)
;
return
new
TextDecoder
(
)
.
decode
(
)
;
}
catch
{
this
.
.
error
(
` [GitHubOrgChatResourcesService] Cache file not found: ${ filename} `
)
;
return
undefined
;
}
}
async
writeCacheFile
(
:
,
:
string
,
:
string
,
:
string
,
?
:
{
?
:
boolean
}
)
:
Promise
<
boolean
>
{
await
this
.
ensureCacheDir
(
,
)
;
const
=
this
.
getCacheFileUri
(
,
,
)
;
const
=
new
TextEncoder
(
)
.
encode
(
)
;
let
=
true
;
if
(
?.
)
{
try
{
=
false
;
const
=
await
this
.
.
stat
(
)
;
if
(
.
!==
.
)
{
=
true
;
}
const
=
await
this
.
.
readFile
(
)
;
const
=
new
TextDecoder
(
)
.
decode
(
)
;
if
(
!==
)
{
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Skipped writing cache file: ${ fileUri. toString ( ) } `
)
;
=
true
;
}
else
{
return
false
;
}
}
catch
{
=
true
;
}
}
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Writing cache file: ${ fileUri. toString ( ) } `
)
;
try
{
await
this
.
.
writeFile
(
,
)
;
}
catch
(
)
{
this
.
.
error
(
,
'[GitHubOrgChatResourcesService] Failed to write cache file'
)
;
throw
;
}
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Wrote cache file: ${ fileUri. toString ( ) } `
)
;
return
;
}
async
clearCache
(
:
,
:
string
,
?
:
<
string
>
)
:
Promise
<
void
>
{
const
=
this
.
getCacheDir
(
,
)
;
try
{
const
=
await
this
.
.
readDirectory
(
)
;
for
(
const
[
,
]
of
)
{
if
(
===
.
&&
isValidFile
(
,
)
&&
!
?.
has
(
)
)
{
await
this
.
.
delete
(
.
.
joinPath
(
,
)
)
;
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Deleted cache file: ${ filename} `
)
;
}
}
}
catch
{
}
}
async
listCachedFiles
(
:
,
:
string
)
:
Promise
<
.
[
]
>
{
const
:
.
[
]
=
[
]
;
const
=
this
.
getCacheDir
(
,
)
;
try
{
const
=
await
this
.
.
readDirectory
(
)
;
for
(
const
[
,
]
of
)
{
if
(
===
.
&&
isValidFile
(
,
)
)
{
const
=
.
.
joinPath
(
,
)
;
.
push
(
{
:
}
)
;
}
}
}
catch
{
this
.
.
trace
(
` [GitHubOrgChatResourcesService] Cache directory does not exist: ${ cacheDir. toString ( ) } `
)
;
}
return
;
}
}