Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/** Пустой файл-эталон для диффов новых/удалённых файлов (кэш на процесс). */
private
?
:
.
;
constructor
(
private
readonly
:
.
)
{
const
=
.
.
getExtension<GitExtension>
(
'vscode.git'
)
;
if
(
!
?.
?.
)
{
throw
new
Error
(
.
.
t
(
'The built-in Git extension is unavailable.'
)
)
;
}
this
.
=
.
.
getAPI
(
1
)
;
}
get
repository
(
)
:
|
undefined
{
return
this
.
.
[
0
]
;
}
registerGitHubCredentials
(
:
.
)
:
.
{
return
this
.
.
registerCredentialsProvider
(
{
getCredentials
:
async
=>
{
if
(
.
!==
'github.com'
)
{
return
undefined
;
}
const
=
await
.
.
get
(
'auraTeam.githubToken'
)
;
return
?
{
:
'x-access-token'
,
:
}
:
undefined
;
}
}
)
;
}
async
getProject
(
:
string
)
:
Promise
<
void
>
{
this
.
log
(
`git clone ${url}`
)
;
const
=
await
this
.
.
clone
(
.
.
parse
(
)
)
;
if
(
)
{
await
.
.
executeCommand
(
'vscode.openFolder'
,
)
;
}
}
/** Снимок состояния репозитория для git-панели вкладки. */
async
getSnapshot
(
)
:
Promise
<
|
undefined
>
{
const
=
this
.
;
if
(
!
)
{
return
undefined
;
}
const
=
[
...
.
.
.
map
(
=>
(
{
:
.
.
asRelativePath
(
.
,
false
)
,
:
'index'
as
const
}
)
)
,
...
.
.
.
map
(
=>
(
{
:
.
.
asRelativePath
(
.
,
false
)
,
:
'working'
as
const
}
)
)
,
...
.
.
.
map
(
=>
(
{
:
.
.
asRelativePath
(
.
,
false
)
,
:
'untracked'
as
const
}
)
)
]
;
let
:
[
'commits'
]
=
[
]
;
try
{
=
(
await
.
log
(
{
:
15
}
)
)
.
map
(
=>
(
{
:
.
,
:
.
.
split
(
'\n'
)
[
0
]
,
:
.
,
:
.
?.
toISOString
(
)
}
)
)
;
}
catch
{
/* лог недоступен */
}
let
:
[
]
|
undefined
;
try
{
=
await
this
.
branchInfo
(
)
;
}
catch
{
/* нет веток */
}
return
{
:
.
.
,
:
.
.
HEAD
?.
??
''
,
:
.
.
.
map
(
=>
.
)
,
,
,
,
:
?.
find
(
=>
.
)
?.
,
:
?.
find
(
=>
.
)
?.
}
;
}
/**
* Дифф файла против HEAD.
*
* Раньше для новых файлов строился git-URI с ref `/dev/null` — провайдер
* `git:` знает только реальные refs и пустое дерево, поэтому чтение падало
* с «Unable to resolve nonexistent file 'git:…'» (именно эта ошибка открывалась
* вместо сравнения). Теперь левая сторона для отсутствующей версии — настоящий
* пустой файл, а правая берётся с диска обычным `Uri.file`, который корректно
* переживает кириллицу, пробелы и скобки в пути.
*/
async
showDiff
(
:
string
)
:
Promise
<
void
>
{
const
=
this
.
requireRepository
(
)
;
const
=
join
(
.
.
,
)
;
const
=
.
.
file
(
)
;
const
=
.
.
HEAD
?.
??
'HEAD'
;
const
=
existsSync
(
)
;
if
(
!
)
{
// Файл удалён: слева — версия из HEAD, справа — пусто.
const
=
this
.
.
toGitUri
(
.
.
file
(
)
,
'HEAD'
)
;
await
.
.
executeCommand
(
'vscode.diff'
,
,
await
this
.
emptyFileUri
(
)
,
`${filePath} (удалён · ${branch})`
)
;
return
;
}
const
=
.
.
.
some
(
=>
.
.
asRelativePath
(
.
,
false
)
===
)
;
if
(
)
{
await
.
.
executeCommand
(
'vscode.diff'
,
await
this
.
emptyFileUri
(
)
,
,
`${filePath} (новый · ${branch})`
)
;
return
;
}
const
=
this
.
.
toGitUri
(
,
'HEAD'
)
;
await
.
.
executeCommand
(
'vscode.diff'
,
,
,
`${filePath} (${branch})`
)
;
}
/** Пустой файл-эталон во временной папке: сторона «до» для новых и удалённых файлов. */
private
async
emptyFileUri
(
)
:
Promise
<
.
>
{
if
(
this
.
)
{
return
this
.
;
}
const
=
.
.
joinPath
(
.
.
file
(
tmpdir
(
)
)
,
'aura-team-empty.txt'
)
;
try
{
await
.
.
.
writeFile
(
,
new
Uint8Array
(
)
)
;
}
catch
{
/* файл могли создать раньше */
}
this
.
=
;
return
;
}
async
listBranches
(
)
:
Promise
<
string
[
]
>
{
const
=
this
.
requireRepository
(
)
;
const
=
await
execFileAsync
(
this
.
.
?.
??
'git'
,
[
'branch'
,
'--format'
,
'%(refname:short)'
]
,
{
:
.
.
}
)
;
return
.
.
split
(
/\r?\n/
)
.
map
(
=>
.
trim
(
)
)
.
filter
(
)
;
}
/** Ветки с флагом текущей и ahead/behind относительно upstream. */
async
branchInfo
(
)
:
Promise
<
[
]
>
{
const
=
this
.
requireRepository
(
)
;
const
=
.
.
HEAD
?.
??
''
;
const
=
await
execFileAsync
(
this
.
.
?.
??
'git'
,
[
'branch'
,
'--format'
,
'%(refname:short)%09%(upstream:track)'
]
,
{
:
.
.
}
)
;
return
.
.
split
(
/\r?\n/
)
.
map
(
=>
.
trim
(
)
)
.
filter
(
)
.
map
(
=>
{
const
[
,
=
''
]
=
.
split
(
'\t'
)
;
const
=
/ahead (\d+)/
.
exec
(
)
?.
[
1
]
;
const
=
/behind (\d+)/
.
exec
(
)
?.
[
1
]
;
return
{
,
:
===
,
:
?
Number
(
)
:
undefined
,
:
?
Number
(
)
:
undefined
}
;
}
)
;
}
async
createBranch
(
:
string
)
:
Promise
<
void
>
{
const
=
this
.
requireRepository
(
)
;
if
(
!
/^[\w.\-/]{1,80}$/
.
test
(
)
)
{
throw
new
Error
(
.
.
t
(
'Invalid branch name.'
)
)
;
}
this
.
log
(
`git checkout -b ${name}`
)
;
await
this
.
runGit
(
,
[
'checkout'
,
'-b'
,
]
)
;
}
async
deleteBranch
(
:
string
)
:
Promise
<
void
>
{
const
=
this
.
requireRepository
(
)
;
// Аргумент-инъекция: branch='--force' превратил бы `git branch -d` в `git branch -d --force`.
if
(
!
isValidBranchName
(
)
)
{
throw
new
Error
(
.
.
t
(
'Invalid branch name.'
)
)
;
}
this
.
log
(
`git branch -d ${name}`
)
;
await
this
.
runGit
(
,
[
'branch'
,
'-d'
,
]
)
;
}
/** git stash push (с untracked) — перед пулом при грязном дереве. */
async
stashPush
(
=
'aura-team autostash'
)
:
Promise
<
boolean
>
{
const
=
this
.
requireRepository
(
)
;
const
=
[
...
.
.
,
...
.
.
,
...
.
.
]
;
if
(
.
===
0
)
{
return
false
;
}
this
.
log
(
'git stash push -u'
)
;
await
this
.
runGit
(
,
[
'stash'
,
'push'
,
'-u'
,
'-m'
,
]
)
;
return
true
;
}
/** Вернуть последний stash (pop). */
async
stashPop
(
)
:
Promise
<
void
>
{
const
=
this
.
requireRepository
(
)
;
this
.
log
(
'git stash pop'
)
;
await
this
.
runGit
(
,
[
'stash'
,
'pop'
]
)
;
}
async
checkout
(
:
string
)
:
Promise
<
void
>
{
const
=
this
.
requireRepository
(
)
;
// Аргумент-инъекция: branch='--force' молча сносил бы незакоммиченные правки.
if
(
!
isValidBranchName
(
)
)
{
throw
new
Error
(
.
.
t
(
'Invalid branch name.'
)
)
;
}
this
.
log
(
`git checkout ${branch}`
)
;
await
this
.
runGit
(
,
[
'checkout'
,
]
)
;
}
/** Закоммитить всё (включая новые файлы) и запушить с pull-rebase при отклонении. */
async
commitAll
(
:
string
)
:
Promise
<
{
:
string
;
:
string
;
?
:
string
}
>
{
const
=
this
.
requireRepository
(
)
;
const
=
await
this
.
commitOnly
(
,
)
;
await
this
.
pushWithRetry
(
)
;
return
;
}
/** Коммит без пуша — пуш делается отдельно, чтобы ошибка отправки не маскировала успешный коммит. */
async
commitOnly
(
:
string
,
?
:
)
:
Promise
<
{
:
string
;
:
string
;
?
:
string
}
>
{
const
=
??
this
.
requireRepository
(
)
;
const
=
[
...
.
.
,
...
.
.
]
.
map
(
=>
.
.
)
;
if
(
.
===
0
&&
.
.
.
===
0
)
{
throw
new
Error
(
.
.
t
(
'There are no changes to save.'
)
)
;
}
if
(
.
>
0
)
{
this
.
log
(
`git add -- ${paths.join(' ')}`
)
;
await
.
add
(
)
;
}
this
.
log
(
`git commit -m ${JSON.stringify(message)}`
)
;
await
.
commit
(
)
;
const
=
await
.
getCommit
(
'HEAD'
)
;
return
{
:
.
,
,
:
.
.
.
find
(
=>
.
===
'origin'
)
?.
}
;
}
/** Коммит только выбранных файлов: сначала снимаем staged, добавляем выбранные, коммитим. */
async
commitSelected
(
:
string
,
:
string
[
]
)
:
Promise
<
{
:
string
;
:
string
;
?
:
string
}
>
{
const
=
this
.
requireRepository
(
)
;
if
(
.
===
0
)
{
throw
new
Error
(
.
.
t
(
'No files were selected.'
)
)
;
}
// Всё, что уже в индексе, но не выбрано — временно снимаем, чтобы не попало в коммит.
/** Основная ветка команды: origin/HEAD → main → master → текущая. */
async
defaultBranch
(
)
:
Promise
<
string
>
{
try
{
const
=
(
await
this
.
runGitOut
(
[
'symbolic-ref'
,
'--short'
,
'refs/remotes/origin/HEAD'
]
)
)
.
trim
(
)
;
if
(
.
startsWith
(
'origin/'
)
)
{
return
.
slice
(
'origin/'
.
)
;
}
}
catch
{
/* origin/HEAD не выставлен — ищем по именам */
}
for
(
const
of
[
'main'
,
'master'
,
'develop'
]
)
{
if
(
await
this
.
refExists
(
`origin/${name}`
)
||
await
this
.
refExists
(
)
)
{
return
;
}
}
return
this
.
?.
.
HEAD
?.
||
'main'
;
}
/** Ref основной ветки для сравнения: удалённая версия, если она есть. */
async
baseRef
(
?
:
string
)
:
Promise
<
{
:
string
;
:
string
}
>
{
const
=
??
await
this
.
defaultBranch
(
)
;
return
{
:
,
:
await
this
.
refExists
(
`origin/${name}`
)
?
`origin/${name}`
:
}
;
}
hasOrigin
(
)
:
boolean
{
return
Boolean
(
this
.
?.
.
.
some
(
=>
.
===
'origin'
)
)
;
}
originUrl
(
)
:
string
|
undefined
{
return
this
.
?.
.
.
find
(
=>
.
===
'origin'
)
?.
;
}
isDirty
(
)
:
boolean
{
const
=
this
.
requireRepository
(
)
;
return
.
.
.
+
.
.
.
+
.
.
.
>
0
;
}
private
async
fetchOrigin
(
)
:
Promise
<
void
>
{
if
(
!
this
.
hasOrigin
(
)
)
{
return
;
}
this
.
log
(
'git fetch origin --prune'
)
;
try
{
await
this
.
runGit
(
this
.
requireRepository
(
)
,
[
'fetch'
,
'origin'
,
'--prune'
]
)
;
}
catch
(
)
{
this
.
log
(
`fetch failed: ${String(error)}`
)
;
}
}
/** Насколько ветка ушла от main: ahead — моих коммитов, behind — новых в main. */
async
divergence
(
)
:
Promise
<
{
:
string
;
:
number
;
:
number
}
>
{
const
{
,
}
=
await
this
.
baseRef
(
)
;
try
{
const
=
parseLeftRight
(
await
this
.
runGitOut
(
[
'rev-list'
,
'--left-right'
,
'--count'
,
`${ref}...HEAD`
]
)
)
;
return
{
,
...
}
;
}
catch
{
return
{
,
:
0
,
:
0
}
;
}
}
/** Перейти в свою ветку: локальную, удалённую (с трекингом) или новую от свежего main. */
async
startBranch
(
:
string
)
:
Promise
<
{
:
string
;
:
boolean
}
>
{
const
=
this
.
requireRepository
(
)
;
if
(
!
isValidBranchName
(
)
)
{
throw
new
Error
(
.
.
t
(
'Invalid branch name.'
)
)
;
}
if
(
.
.
HEAD
?.
===
)
{
return
{
:
,
:
false
}
;
}
await
this
.
fetchOrigin
(
)
;
if
(
await
this
.
refExists
(
`refs/heads/${name}`
)
)
{
this
.
log
(
`git checkout ${name}`
)
;
await
this
.
runGit
(
,
[
'checkout'
,
]
)
;
return
{
:
,
:
false
}
;
}
if
(
await
this
.
refExists
(
`origin/${name}`
)
)
{
this
.
log
(
`git checkout -b ${name} --track origin/${name}`
)
;
await
this
.
runGit
(
,
[
'checkout'
,
'-b'
,
,
'--track'
,
`origin/${name}`
]
)
;
return
{
:
,
:
false
}
;
}
const
{
}
=
await
this
.
baseRef
(
)
;
const
=
await
this
.
refExists
(
)
?
:
'HEAD'
;
this
.
log
(
`git checkout -b ${name}${from}`
)
;
await
this
.
runGit
(
,
[
'checkout'
,
'--no-track'
,
'-b'
,
,
]
)
;
return
{
:
,
:
true
}
;
}
/** Подтянуть свежий main в текущую ветку (merge), локальные правки — через stash. */
async
syncWithBase
(
)
:
Promise
<
{
:
string
;
:
boolean
;
:
number
}
>
{
const
=
this
.
requireRepository
(
)
;
await
this
.
fetchOrigin
(
)
;
const
{
,
}
=
await
this
.
baseRef
(
)
;
const
=
await
this
.
divergence
(
)
;
if
(
.
===
0
)
{
return
{
,
:
true
,
:
0
}
;
}
const
=
await
this
.
stashPush
(
'aura-team: перед слиянием main'
)
;
try
{
if
(
.
.
HEAD
?.
===
)
{
this
.
log
(
`git merge --ff-only ${ref}`
)
;
await
this
.
runGit
(
,
[
'merge'
,
'--ff-only'
,
]
)
;
}
else
{
this
.
log
(
`git merge --no-edit ${ref}`
)
;
try
{
await
this
.
runGit
(
,
[
'merge'
,
'--no-edit'
,
]
)
;
}
catch
(
)
{
await
this
.
waitForState
(
)
;
await
this
.
handleConflicts
(
)
;
throw
;
}
}
}
finally
{
if
(
)
{
try
{
await
this
.
stashPop
(
)
;
}
catch
(
)
{
this
.
log
(
`stash pop failed: ${String(error)}`
)
;
.
.
showWarningMessage
(
.
.
t
(
'Your stashed changes could not be applied automatically — run "git stash pop" manually.'
)
)
;
}
}
}
return
{
,
:
false
,
:
.
}
;
}
/** Даём git-расширению обновить state (mergeChanges) после внешней команды. */
private
async
waitForState
(
)
:
Promise
<
void
>
{
await
new
Promise
(
=>
setTimeout
(
,
600
)
)
;
}
/** Что ветка принесёт в main: дифф от точки ответвления до HEAD. */
async
diffAgainstBase
(
)
:
Promise
<
{
:
string
;
:
string
;
:
string
}
>
{
await
this
.
fetchOrigin
(
)
;
const
{
,
}
=
await
this
.
baseRef
(
)
;
const
=
await
this
.
runGitOut
(
[
'diff'
,
'--no-color'
,
'--no-ext-diff'
,
'-M'
,
`${ref}...HEAD`
]
)
;
return
{
,
,
}
;
}
/** Несохранённые изменения: tracked против HEAD + новые файлы целиком. */
async
diffWorking
(
)
:
Promise
<
string
>
{
const
=
this
.
requireRepository
(
)
;
let
=
await
this
.
runGitOut
(
[
'diff'
,
'--no-color'
,
'--no-ext-diff'
,
'-M'
,
'HEAD'
]
)
.
catch
(
(
)
=>
this
.
runGitOut
(
[
'diff'
,
'--no-color'
,
'--no-ext-diff'
,
'--cached'
]
)
)
;
for
(
const
of
.
.
.
slice
(
0
,
40
)
)
{
const
=
.
.
asRelativePath
(
.
,
false
)
.
replaceAll
(
'\\'
,
'/'
)
;
+=
'\n'
+
await
this
.
runGitOut
(
[
'diff'
,
'--no-color'
,
'--no-ext-diff'
,
'--no-index'
,
'--'
,
'/dev/null'
,
.
.
]
,
[
1
]
)
.
then
(
=>
.
replace
(
/^diff --git .*$/m
,
`diff --git a/${relative} b/${relative}`
)
.
replace
(
/^\+\+\+.*$/m
,
`+++ b/${relative}`
)
)
.
catch
(
(
)
=>
''
)
;
}
return
;
}
private
static
assertHash
(
:
string
)
:
string
{
const
=
String
(
??
''
)
.
trim
(
)
;
if
(
!
/^[0-9a-f]{4,40}$/i
.
test
(
)
)
{
throw
new
Error
(
.
.
t
(
'Invalid commit hash.'
)
)
;
}
return
;
}
private
async
parentCount
(
:
string
)
:
Promise
<
number
>
{
const
=
(
await
this
.
runGitOut
(
[
'rev-list'
,
'--parents'
,
'-n'
,
'1'
,
]
)
)
.
trim
(
)
;
return
.
max
(
0
,
.
split
(
/\s+/
)
.
-
1
)
;
}
/** Дифф одного коммита (для merge-коммита — против первого родителя). */
async
commitDiff
(
:
string
)
:
Promise
<
{
:
string
;
:
string
;
:
string
;
:
string
}
>
{
const
=
.
assertHash
(
)
;
const
=
(
await
this
.
runGitOut
(
[
'show'
,
'-s'
,
'--format=%s%x1f%an%x1f%aI'
,
]
)
)
.
trim
(
)
.
split
(
'\x1f'
)
;
const
=
await
this
.
parentCount
(
)
;
const
=
===
0
?
await
this
.
runGitOut
(
[
'show'
,
'--format='
,
'--no-color'
,
'--no-ext-diff'
,
'-M'
,
]
)
:
await
this
.
runGitOut
(
[
'diff'
,
'--no-color'
,
'--no-ext-diff'
,
'-M'
,
`${ref}^1`
,
]
)
;
return
{
,
:
[
0
]
??
''
,
:
[
1
]
??
''
,
:
[
2
]
??
''
}
;
}
/** Откатить конкретный коммит новым коммитом (merge-коммит — относительно main, -m 1). */
async
revertCommit
(
:
string
)
:
Promise
<
{
:
string
}
>
{
const
=
this
.
requireRepository
(
)
;
const
=
.
assertHash
(
)
;
if
(
this
.
isDirty
(
)
)
{
throw
new
Error
(
.
.
t
(
'Save or discard your changes before reverting a commit.'
)
)
;
}
const
=
(
await
this
.
parentCount
(
)
)
>
1
?
[
'revert'
,
'--no-edit'
,
'-m'
,
'1'
,
]
:
[
'revert'
,
'--no-edit'
,
]
;
this
.
log
(
`git ${args.join(' ')}`
)
;
try
{
await
this
.
runGit
(
,
)
;
}
catch
(
)
{
await
this
.
waitForState
(
)
;
await
this
.
handleConflicts
(
)
;
throw
;
}
return
{
:
(
await
this
.
runGitOut
(
[
'rev-parse'
,
'HEAD'
]
)
)
.
trim
(
)
}
;
}
/** Отправить текущую ветку и выставить upstream (нужно перед созданием PR). */
async
pushCurrentBranch
(
)
:
Promise
<
string
>
{
const
=
this
.
requireRepository
(
)
;
const
=
.
.
HEAD
?.
;
if
(
!
)
{
throw
new
Error
(
.
.
t
(
'Check out a branch first.'
)
)
;
}
if
(
!
this
.
hasOrigin
(
)
)
{
throw
new
Error
(
.
.
t
(
'The repository has no origin remote.'
)
)
;
}
this
.
log
(
`git push -u origin ${branch}`
)
;
try
{
await
.
push
(
'origin'
,
,
true
)
;
}
catch
(
)
{
if
(
!
isPushRejected
(
)
)
{
throw
;
}
this
.
log
(
'git pull --rebase'
)
;
await
this
.
runGit
(
,
[
'pull'
,
'--rebase'
,
'origin'
,
]
)
;
await
this
.
handleConflicts
(
)
;
await
.
push
(
'origin'
,
,
true
)
;
}
return
;
}
/**
* Слить ветку в main без GitHub (локально): main ← merge --no-ff ветки → push → назад.
* Только на чистом дереве: смешивать слияние с несохранённой работой опасно.
*/