Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
'The Copilot home directory is not trusted. Please trust the directory to open this file.'
)
;
/**
*
* We keep parsing in two phases to mirror VS Code's shape:
* 1) detect suffixes (e.g. :12:3, (12, 3)) and resolve the path before them
* 2) detect path-only links (no suffix)
*/
/**
* Returns session-state directories to try for a terminal.
*/
export
type
SessionDirResolver
=
(
:
)
=>
Promise
<
[
]
>
;
/**
* Resolves relative file links in Copilot CLI terminal output.
*
* Copilot CLI paths are relative to the session-state directory, not the
* workspace root. VS Code's built-in detector cannot resolve that context.
*/
export
class
CopilotCLITerminalLinkProvider
implements
TerminalLinkProvider<CopilotCLITerminalLink>
{
private
readonly
=
new
WeakSet<Terminal>
(
)
;
private
readonly
=
new
WeakMap<Terminal, Uri>
(
)
;
private
:
|
undefined
;
constructor
(
private
readonly
:
,
private
readonly
?
:
,
)
{
}
/**
* Marks a terminal as a Copilot CLI terminal.
*/
registerTerminal
(
:
)
:
void
{
this
.
.
add
(
)
;
}
/**
* Sets a terminal's session-state directory for relative path resolution.
*/
setSessionDir
(
:
,
:
)
:
void
{
this
.
.
set
(
,
)
;
}
/**
* Sets a resolver used when no session directory is cached.
*/
setSessionDirResolver
(
:
)
:
void
{
this
.
=
;
}
async
provideTerminalLinks
(
:
,
:
)
:
Promise
<
[
]
>
{
const
=
.
;
// Match VS Code's built-in MaxLineLength limit (terminalLocalLinkDetector.ts).
if
(
!
.
trim
(
)
||
.
>
2000
)
{
return
[
]
;
}
const
=
await
this
.
_getSessionDirs
(
.
)
;
if
(
!
this
.
.
has
(
.
)
&&
.
===
0
)
{
return
[
]
;
}
const
:
[
]
=
[
]
;
for
(
const
of
this
.
_detectLinkCandidates
(
)
)
{
// Match VS Code's built-in MaxResolvedLinksInLine (terminalLocalLinkDetector.ts).
if
(
.
||
.
>=
10
)
{
break
;
}
let
=
.
;
if
(
!
||
.
<
3
)
{
continue
;
}
// Strip trailing punctuation that is unlikely part of the path.
// Mirrors VS Code's specialEndCharRegex (terminalLocalLinkDetector.ts).
let
=
0
;
while
(
.
>
1
&&
/[\[\]"'.]$/
.
test
(
)
)
{
=
.
slice
(
0
,
-
1
)
;
++
;
}
// Skip URLs.
if
(
.
includes
(
'://'
)
)
{
continue
;
}
if
(
this
.
_looksLikeNumericVersion
(
)
)
{
continue
;
}
const
=
.
;
const
=
.
;
// Tilde paths: expand ~ to home directory (~/... or ~\... on Windows).
if
(
.
startsWith
(
'~/'
)
||
.
startsWith
(
'~\\'
)
)
{
const
=
.
file
(
homedir
(
)
+
.
substring
(
1
)
)
;
.
push
(
{
:
.
,
:
.
-
,
:
.
toString
(
true
)
,
:
,
:
.
,
,
:
,
:
,
}
)
;
continue
;
}
// Skip absolute paths; the built-in detector handles them.
// Unix: /foo, Windows: C:\foo or \Users\foo
if
(
.
startsWith
(
'/'
)
||
.
startsWith
(
'\\'
)
||
/^[a-zA-Z]:[/\\]/
.
test
(
)
)
{
continue
;
}
const
=
await
this
.
_resolvePath
(
,
,
)
;
if
(
!
)
{
continue
;
}
.
push
(
{
:
.
,
:
.
-
,
:
.
toString
(
true
)
,
:
,
:
.
,
,
:
,
:
,
}
)
;
}
return
;
}
async
handleTerminalLink
(
:
)
:
Promise
<
void
>
{
try
{
const
=
await
this
.
_getSessionDirs
(
.
)
;
const
=
await
this
.
_resolveAllPaths
(
.
,
)
;
let
=
.
??
[
0
]
??
this
.
_getFallbackUri
(
.
,
)
;
if
(
.
>
1
)
{
const
=
await
.
showQuickPick
(
.
map
(
=>
(
{
:
this
.
_labelCandidate
(
,
)
,
:
this
.
_describeCandidate
(
,
)
,
,
}
)
)
,
{
:
.
t
(
"Select which '{0}' to open"
,
.
)
}
)
;
if
(
!
)
{
return
;
}
=
.
;
}
if
(
!
)
{
return
;
}
if
(
this
.
&&
this
.
_isInCopilotHome
(
)
)
{
const
=
await
this
.
.
requestResourceTrust
(
{
:
.
file
(
getCopilotHome
(
)
)
,
:
UNTRUSTED_COPILOT_HOME_MESSAGE
,
}
)
;
if
(
!
)
{
return
;
}
}
await
.
showTextDocument
(
,
{
:
.
!==
undefined
?
new
Range
(
.
-
1
,
(
.
??
1
)
-
1
,
.
-
1
,
(
.
??
1
)
-
1
)
:
undefined
,
}
)
;
}
catch
(
)
{
this
.
.
error
(
'Failed to open terminal link'
,
)
;
}
}
/**
* Returns candidate session directories for a terminal.
*
* Resolver results (from active sessions) are tried first because the
* resolver can order them by terminal affinity — sessions that belong to
* THIS terminal come before unrelated sessions. A cached dir from
* {@link setSessionDir} is appended only as a last-resort fallback when it
* is no longer among the active sessions (i.e. the session ended but its
* files may still be on disk). See https://github.com/microsoft/vscode/issues/301594.
*/
private
_isInCopilotHome
(
:
)
:
boolean
{
return
.
isEqualOrParent
(
,
.
file
(
getCopilotHome
(
)
)
)
;
}
private
async
_getSessionDirs
(
:
)
:
Promise
<
[
]
>
{
const
=
this
.
.
get
(
)
;
if
(
this
.
)
{
const
=
await
this
.
_sessionDirResolver
(
)
;
const
=
?.
;
// Resolver results are already ordered by terminal affinity.
const
=
[
...
]
;
// If the cached dir is not among the active sessions it is stale
// (the session ended). Append it as a fallback instead of
// putting it first where it would shadow the current session.
if
(
&&
!
.
some
(
=>
.
===
)
)
{
.
push
(
)
;
}
return
;
}
return
?
[
]
:
[
]
;
}
/**
* Resolves a relative path to the first existing file on disk. Used by
* {@link provideTerminalLinks} on hover where we only need to know that a
* match exists to underline the text. Returns early on first hit.
*
* Search order must stay consistent with {@link _resolveAllPaths}:
* 1. Each session-state directory (e.g., `~/.copilot/session-state/{uuid}/
`)
* 2. Workspace folders
* 3. `
/
` under each session dir (non-bare paths only)
*/
private async _resolvePath(pathText: string, sessionDirs: readonly Uri[], token?: CancellationToken): Promise<Uri | undefined> {
const isBareFilename = !pathText.includes('/') && !pathText.includes('\\');
const isDotRelative = pathText.startsWith('./') || pathText.startsWith('.\\') || pathText.startsWith('../') || pathText.startsWith('..\\');
const alreadyFilesRelative = pathText.startsWith('files/') || pathText.startsWith('files\\');
const shouldTryFilesFallback = !isBareFilename && !isDotRelative && !alreadyFilesRelative;
// Session-state directories first; CLI paths are relative to them.
for (const sessionDir of sessionDirs) {
if (token?.isCancellationRequested) {
return undefined;
}
if (await this._exists(Uri.joinPath(sessionDir, pathText))) {
return Uri.joinPath(sessionDir, pathText);
}
if (isBareFilename && await this._exists(Uri.joinPath(sessionDir, 'files', pathText))) {
return Uri.joinPath(sessionDir, 'files', pathText);
}
if (isBareFilename) {
const nested = await this._findNestedBareFilenameInSessionDir(sessionDir, pathText, token);
if (nested) {
return nested;
}
}
}
// Workspace folders.
for (const folder of workspace.workspaceFolders ?? []) {
if (token?.isCancellationRequested) {
return undefined;
}
if (await this._exists(Uri.joinPath(folder.uri, pathText))) {
return Uri.joinPath(folder.uri, pathText);
}
}
// files/<path> under session dirs for non-bare paths (the CLI sometimes
// emits workspace-relative paths that actually live under the session's
// files/ mirror).
if (shouldTryFilesFallback) {
for (const sessionDir of sessionDirs) {
if (token?.isCancellationRequested) {
return undefined;
}
if (await this._exists(Uri.joinPath(sessionDir, 'files', pathText))) {
return Uri.joinPath(sessionDir, 'files', pathText);
}
}
}
return undefined;
}
/**
* Resolves a relative path to every existing file on disk. Used by
* {@link handleTerminalLink} on click to populate a picker when the path
* is ambiguous (e.g. `
.
` exists in both the session-state directory
* and the workspace root).
** Same search order as {@link _resolvePath} but collects all hits.
*/
private async _resolveAllPaths(pathText: string, sessionDirs: readonly Uri[]): Promise<Uri[]> {
const isBareFilename = !pathText.includes('/') && !pathText.includes('\\');
const isDotRelative = pathText.startsWith('./') || pathText.startsWith('.\\') || pathText.startsWith('../') || pathText.startsWith('..\\');
const alreadyFilesRelative = pathText.startsWith('files/') || pathText.startsWith('files\\');
const shouldTryFilesFallback = !isBareFilename && !isDotRelative && !alreadyFilesRelative;
const resolved: Uri[] = [];
const seen = new Set<string>();
const addIfExists = async (candidate: Uri): Promise<void> => {
if (seen.has(candidate.fsPath)) {
return;
}
seen.add(candidate.fsPath);
if (await this._exists(candidate)) {
resolved.push(candidate);
}
}; // Session-state directories first; CLI paths are relative to them.
for (const sessionDir of sessionDirs) {
await addIfExists(Uri.joinPath(sessionDir, pathText));
if (isBareFilename) {
await addIfExists(Uri.joinPath(sessionDir, 'files', pathText));
const nested = await this._findNestedBareFilenameInSessionDir(sessionDir, pathText);
if (nested && !seen.has(nested.fsPath)) {
seen.add(nested.fsPath);
resolved.push(nested);
}
}
} // Workspace folders.
for (const folder of workspace.workspaceFolders ?? []) {
await addIfExists(Uri.joinPath(folder.uri, pathText));
} // files/<path> under session dirs for non-bare paths.
if (shouldTryFilesFallback) {
for (const sessionDir of sessionDirs) {
await addIfExists(Uri.joinPath(sessionDir, 'files', pathText));
}
} return resolved;
} private async _exists(uri: Uri): Promise<boolean> {
try {
await workspace.fs.stat(uri);
return true;
} catch {
return false;
}
} private _labelCandidate(uri: Uri, sessionDirs: readonly Uri[]): string {
return this._relativeTo(uri, sessionDirs)
?? this._relativeTo(uri, workspace.workspaceFolders?.map(f => f.uri) ?? [])
?? uri.fsPath.split(/[\\/]/).pop()
?? uri.fsPath;
} private _describeCandidate(uri: Uri, sessionDirs: readonly Uri[]): string {
const normalizedCandidatePath = uri.fsPath.replace(/\\/g, '/');
for (const sessionDir of sessionDirs) {
const normalizedSessionPath = sessionDir.fsPath.replace(/\\/g, '/').replace(/\/$/, '');
if (normalizedCandidatePath.startsWith(`