Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/**
* Fired when a pull request is detected or updated for a session.
* Consumers should refresh the session UI in response.
*/
readonly
:
<
string
>
;
/**
* Detects a pull request for a session when the user opens it.
* If a PR is found, persists the URL and notifies the UI.
*/
detectPullRequest
(
:
string
)
:
void
;
/**
* Called after a request completes to persist PR metadata on the session.
* If a PR URL is provided, uses that; otherwise attempts detection
* via the GitHub API with exponential-backoff retry.
*/
/**
* Queries the GitHub API to find a pull request whose head branch matches the
* given worktree branch. This covers cases where the MCP tool failed to report
* a PR URL, or the user created the PR externally (e.g., via github.com).
*/
async
function
detectPullRequestFromGitHubAPI
(
:
string
,
:
string
,
:
,
:
,
:
,
)
:
Promise
<
{
:
string
;
:
string
}
|
undefined
>
{
const
=
await
.
getRepository
(
URI
.
file
(
)
)
;
if
(
!
)
{
.
debug
(
`[detectPullRequestFromGitHubAPI] No git repository found for path: ${repositoryPath}`
)
;
return
undefined
;
}
const
=
getGitHubRepoInfoFromContext
(
)
;
if
(
!
)
{
.
debug
(
`[detectPullRequestFromGitHubAPI] Could not extract GitHub repo info from repository at: ${repositoryPath}`
)
;
return
undefined
;
}
.
debug
(
`[detectPullRequestFromGitHubAPI] Querying GitHub API for PR on ${repoInfo.id.org}/${repoInfo.id.repo}, branch=${branchName}`
)
;
const
=
await
.
findPullRequestByHeadBranch
(
.
.
,
.
.
,
,
{
}
,
)
;
if
(
?.
)
{
const
=
derivePullRequestState
(
)
;
.
trace
(
`[detectPullRequestFromGitHubAPI] Detected pull request via GitHub API: ${pr.url}${prState}`
)
;
return
{
:
.
,
:
}
;
}
.
debug
(
`[detectPullRequestFromGitHubAPI] No PR found for ${repoInfo.id.org}/${repoInfo.id.repo}, branch=${branchName}`
)
;
return
undefined
;
}
/**
* Encapsulates all pull-request detection and persistence logic for chat sessions.
*/
export
class
PullRequestDetectionService
extends
Disposable
implements
IPullRequestDetectionService
{
declare
readonly
:
undefined
;
private
readonly
=
this
.
_register
(
new
Emitter<string>
(
)
)
;
readonly
:
<
string
>
=
this
.
.
;
constructor
(
@IChatSessionWorktreeService
private
readonly
:
,
@IGitService
private
readonly
:
,
@IOctoKitService
private
readonly
:
,
@ILogService
private
readonly
:
,
)
{
super
(
)
;
}
/**
* Detects a pull request for a session when the user opens it.
* If a PR is found, persists the URL and notifies the UI.
*/
detectPullRequest
(
:
string
)
:
void
{
this
.
doDetectPullRequestOnSessionOpen
(
)
.
catch
(
=>
this
.
.
error
(
instanceof
Error
?
:
new
Error
(
String
(
)
)
,
`Failed to detect pull request on session open for ${sessionId}`
)
)
;
}
private
async
doDetectPullRequestOnSessionOpen
(
:
string
)
:
Promise
<
void
>
{
const
=
await
this
.
.
getWorktreeProperties
(
)
;
if
(
?.
!==
2
||
.
===
'merged'
||
!
.
||
!
.
)
{
this
.
.
debug
(
`[PullRequestDetectionService] Skipping PR detection on session open for ${sessionId}: version=${worktreeProperties?.version}, prState=${worktreeProperties?.version ===2? worktreeProperties.pullRequestState :'n/a'}, branch=${!!worktreeProperties?.branchName}, repoPath=${!!worktreeProperties?.repositoryPath}`
)
;
return
;
}
this
.
.
debug
(
`[PullRequestDetectionService] Detecting PR on session open for ${sessionId}, branch=${worktreeProperties.branchName}, existingPrUrl=${worktreeProperties.pullRequestUrl ??'none'}`
)
;
const
=
await
this
.
detectPullRequestForSession
(
)
;
if
(
)
{
// Re-read to get the latest information.
const
=
await
this
.
.
getWorktreeProperties
(
)
;
if
(
?.
===
2
&&
(
.
!==
.
||
.
!==
.
)
)
{
await
this
.
.
setWorktreeProperties
(
,
{
...
,
// use fresh copy
:
.
,
:
.
,
:
undefined
,
}
)
;
this
.
.
fire
(
)
;
}
else
{
this
.
.
debug
(
`[PullRequestDetectionService] PR metadata unchanged for ${sessionId}, skipping update`
)
;
}
}
else
{
this
.
.
debug
(
`[PullRequestDetectionService] No PR found via GitHub API for ${sessionId}`
)
;
}
}
/**
* Called after a request completes to persist PR metadata on the session.
* If the session reported a PR URL, uses that; otherwise attempts detection
* via the GitHub API with exponential-backoff retry.
* Fires {@link onDidDetectPullRequest} if a PR is detected and persisted.
*/
handlePullRequestCreated
(
:
string
,
:
string
|
undefined
)
:
void
{
this
.
doHandlePullRequestCreated
(
,
)
.
catch
(
=>
this
.
.
error
(
instanceof
Error
?
:
new
Error
(
String
(
)
)
,
`Failed to handle pull request creation for session ${sessionId}`
)
)
;
}
private
async
doHandlePullRequestCreated
(
:
string
,
:
string
|
undefined
)
:
Promise
<
void
>
{
let
=
;
let
=
''
;
this
.
.
debug
(
`[PullRequestDetectionService] handlePullRequestCreated for ${sessionId}: createdPullRequestUrl=${prUrl ??'none'}`
)
;
const
=
await
this
.
.
getWorktreeProperties
(
)
;
if
(
!
||
.
!==
2
)
{
return
;
}
if
(
!
)
{
if
(
.
&&
.
)
{
this
.
.
debug
(
`[PullRequestDetectionService] No PR URL from session, attempting retry detection for ${sessionId}, branch=${worktreeProperties.branchName}`
)
;
const
=
await
this
.
detectPullRequestWithRetry
(
)
;
=
?.
;
=
?.
??
(
?.
?
'open'
:
''
)
;
}
else
{
this
.
.
debug
(
`[PullRequestDetectionService] Skipping retry detection for ${sessionId}: branch=${worktreeProperties.branchName ??'none'}, repoPath=${!!worktreeProperties.repositoryPath}`
)
;
}
}
if
(
!
)
{
this
.
.
debug
(
`[PullRequestDetectionService] No PR detected for ${sessionId} after all attempts`
)
;
return
;
}
try
{
await
this
.
.
setWorktreeProperties
(
,
{
...
,
:
,
:
,
:
undefined
,
}
)
;
this
.
.
fire
(
)
;
}
catch
(
)
{
this
.
.
error
(
instanceof
Error
?
:
new
Error
(
String
(
)
)
,
`Failed to persist pull request metadata for session ${sessionId}`
)
;
}
}
/**
* Attempts to detect a pull request for a freshly-completed session using
* exponential backoff. The GitHub API may not have indexed the PR immediately
* after `gh pr create` returns, so we retry with increasing delays:
* attempt 1: 2s, attempt 2: 4s, attempt 3: 8s, ...
*/
`[PullRequestDetectionService] PR detected on attempt ${attempt +1} for ${sessionId}: url=${prResult.url}, state=${prResult.state}`
)
;
return
;
}
}
this
.
.
debug
(
`[PullRequestDetectionService] PR detection exhausted all ${PR_DETECTION_RETRY_COUNT} retries for ${sessionId}`
)
;
return
undefined
;
}
/**
* Queries the GitHub API to find a pull request whose head branch matches the
* session's worktree branch.
*/
private
async
detectPullRequestForSession
(
:
string
)
:
Promise
<
{
:
string
;
:
string
}
|
undefined
>
{
try
{
const
=
await
this
.
.
getWorktreeProperties
(
)
;
if
(
!
?.
||
!
.
)
{
this
.
.
debug
(
`[PullRequestDetectionService] detectPullRequestForSession: missing worktree info for ${sessionId}, branch=${worktreeProperties?.branchName ??'none'}, repoPath=${!!worktreeProperties?.repositoryPath}`
)
;
return
undefined
;
}
return
await
detectPullRequestFromGitHubAPI
(
.
,
.
,
this
.
,
this
.
,
this
.
,
)
;
}
catch
(
)
{
this
.
.
debug
(
`[PullRequestDetectionService] Failed to detect pull request via GitHub API: ${error instanceofError? error.message :String(error)}`