Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/**
* Redirect destinations that do not result in a write to an arbitrary file
* on disk: the /dev sinks that discard output (`/dev/null`) or write back to
* the same terminal (`/dev/stdout`, `/dev/stderr`, `/dev/tty`).
*/
const
SAFE_POSIX_REDIRECT_TARGETS
:
<
string
>
=
new
Set
(
[
'/dev/null'
,
'/dev/stdout'
,
'/dev/stderr'
,
'/dev/tty'
,
]
)
;
/**
* Returns true when the given redirection destination is known to be safe:
* either the shell's null/output sink or a file-descriptor duplication target
* like `&1` (used in `2>&1`).
*/
function
isSafeRedirectDestination
(
:
string
,
?
:
boolean
)
:
boolean
{
let
=
.
trim
(
)
;
if
(
.
===
0
)
{
return
false
;
}
// `$null` discards output in PowerShell like /dev/null; variable names are
// case-insensitive. Quoted forms are strings rather than the null sink.
if
(
&&
.
toLowerCase
(
)
===
'$null'
)
{
return
true
;
}
if
(
(
.
startsWith
(
`'`
)
&&
.
endsWith
(
`'`
)
)
||
(
.
startsWith
(
'"'
)
&&
.
endsWith
(
'"'
)
)
)
{
=
.
slice
(
1
,
-
1
)
;
}
// File-descriptor duplication: `&N`, optionally followed by `-` to close.
if
(
/^&[0-9]+-?$/
.
test
(
)
)
{
return
true
;
}
// PowerShell uses `$null` as its null sink. In particular, `/dev/null`
// resolves as a filesystem path on Windows.
return
!
&&
SAFE_POSIX_REDIRECT_TARGETS
.
has
(
)
;
}
/**
* Classification of a tree-sitter `file_redirect` node.
* - `read`: input-only redirect (`<`, `<&N`) — never writes.
* - `safeWrite`: write to a known-safe sink (`/dev/null`, fd duplication, ...).
* - `unsafeWrite`: write to an arbitrary destination. The destination string
* (with surrounding quotes stripped) is included when it could be parsed,
* so the caller may decide whether the target is acceptable.
*/
type
FileRedirectClassification
=
|
{
:
'read'
}
|
{
:
'safeWrite'
}
|
{
:
'unsafeWrite'
;
:
string
|
undefined
}
;
function
classifyFileRedirect
(
:
string
,
?
:
boolean
)
:
{
if
(
!
.
includes
(
'>'
)
)
{
return
{
:
'read'
}
;
}
const
=
.
match
(
/(?:[0-9]+|&|\*)?>>?\|?\s*(.+)$/
)
;
if
(
!
)
{
return
{
:
'unsafeWrite'
,
:
undefined
}
;
}
const
=
[
1
]
.
trim
(
)
;
if
(
isSafeRedirectDestination
(
,
)
)
{
return
{
:
'safeWrite'
}
;
}
let
=
;
if
(
(
.
startsWith
(
`'`
)
&&
.
endsWith
(
`'`
)
)
||
(
.
startsWith
(
'"'
)
&&
.
endsWith
(
'"'
)
)
)
{
=
.
slice
(
1
,
-
1
)
;
}
return
{
:
'unsafeWrite'
,
}
;
}
/**
* Matches a PowerShell command token of the form `-flag=` or `--flag=` at the
* start of input or following whitespace. Used to work around a tree-sitter
* PowerShell grammar limitation where POSIX-style `--flag=value` arguments
* (e.g. `git log --format="a|b"`) are parsed as assignment expressions and
* truncate the surrounding command. Mirrors the workbench's
* `TreeSitterCommandParser` workaround.
*
* See https://github.com/microsoft/vscode/issues/294010
* TODO: Remove once upstream tree-sitter PowerShell grammar is updated.
*/
const
=
/(^|\s)(-{1,2}[\w-]+)=/g
;
// TODO: Remove once upstream tree-sitter PowerShell grammar is updated.
function
maskPwshFlagEquals
(
:
string
)
:
string
{
return
.
replace
(
,
(
,
,
)
=>
`${pre}${flag}`
)
;
}
/**
* Matches PowerShell redirects glued to their target (`2>$null`, `>out.txt`,
* `*>>log.txt`). The grammar parses these as `generic_token` command arguments
* rather than `redirection` nodes, which only cover the spaced form.
*/
const
=
/^[0-9*]?>>?/
;
/**
* Result of a command auto-approval check.
* - `approved`: all sub-commands match allow rules and none are denied
* - `denied`: at least one sub-command matches a deny rule
* - `noMatch`: no rule matched — requires user confirmation
*/
export
type
CommandApprovalResult
=
'approved'
|
'denied'
|
'noMatch'
;
/** Structured outcome of {@link CommandAutoApprover.evaluate}. */
export
interface
ICommandApprovalEvaluation
{
/** Final approval outcome, identical to {@link CommandAutoApprover.shouldAutoApprove}. */
readonly
:
;
/** Whether a missing allow rule is the only reason confirmation is required. */
readonly
:
boolean
;
}
/** Options for {@link CommandAutoApprover.shouldAutoApprove}. */
export
interface
IShouldAutoApproveOptions
{
/**
* Predicate that decides whether a write redirection to the given
* destination is acceptable. Called once per write-redirect destination
* found in the command line; the destination is the raw string the user
* typed (with surrounding quotes stripped). The predicate is responsible
* for resolving relative paths and applying its own policy.
*
* When omitted, any write redirect to a destination outside the known-safe
* sinks (e.g. `/dev/null`) downgrades the result to `noMatch`.
*/
readonly
?
:
(
:
string
)
=>
boolean
;
/**
* Effective VS Code `chat.tools.terminal.autoApprove` rules forwarded from
* the renderer. When omitted, the agent host falls back to its bundled
* default rules for compatibility with older clients.
*/
readonly
?
:
;
/**
* Shell grammar to parse the command line with. PowerShell commands are
* parsed with the PowerShell grammar. Sub-command rules are matched
* case-insensitively, like PowerShell itself; full-command rules retain
* their configured casing. Defaults to `bash`.
*/
readonly
?
:
'bash'
|
'powershell'
;
}
interface
IAutoApproveRule
{
readonly
:
;
/** Case-insensitive variant of {@link regex}, used for PowerShell matching. */
readonly
:
;
}
interface
IAutoApproveRules
{
readonly
:
[
]
;
readonly
:
[
]
;
readonly
:
[
]
;
readonly
:
[
]
;
}
const
=
/(?!.*)/
;
const
=
/^[A-Z_][A-Z0-9_]*=/i
;
const
=
new
SedFileWriteParser
(
)
;
interface
ITreeSitterResources
{
readonly
:
typeof
;
readonly
:
typeof
;
readonly
:
<
>
;
readonly
:
<
>
;
}
let
:
Promise
<
>
|
undefined
;
function
getTreeSitterResources
(
)
:
Promise
<
>
{
// Parser.init and Language.load mutate process-global WASM state, so load them once.
return
??=
loadTreeSitterResources
(
)
;
}
async
function
loadTreeSitterResources
(
)
:
Promise
<
>
{
const
{
default
:
}
=
await
import
(
'@vscode/tree-sitter-wasm'
)
;
const
=
URI
.
joinPath
(
.
asFileUri
(
getAppNodeModulesPath
(
)
)
,
'@vscode'
,
'tree-sitter-wasm'
,
'wasm'
)
;
const
=
URI
.
joinPath
(
,
'tree-sitter.wasm'
)
.
;
await
.
.
init
(
{
locateFile
(
)
{
return
;
}
}
)
;
const
loadGrammar
=
async
(
:
string
)
=>
{
const
=
await
.
.
readFile
(
URI
.
joinPath
(
,
)
.
)
;
return
.
.
load
(
new
Uint8Array
(
.
,
.
,
.
)
)
;
}
;
const
[
,
]
=
await
Promise
.
allSettled
(
[
loadGrammar
(
'tree-sitter-bash.wasm'
)
,
loadGrammar
(
'tree-sitter-powershell.wasm'
)
,
]
)
;
return
{
:
.
,
:
.
,
,
,
}
;
}
/**
* Auto-approves or denies shell commands based on terminal auto-approve rules.
*
* Uses tree-sitter to parse compound commands (`foo && bar`) into
* sub-commands that are individually checked against allow/deny lists.
* The rules are normally forwarded from VS Code's
* `chat.tools.terminal.autoApprove` setting. A bundled default table is kept
* as a compatibility fallback for clients that have not forwarded rules yet.
*
* Tree-sitter is initialized eagerly; call {@link initialize} and await the
* result before using {@link shouldAutoApprove} to guarantee synchronous
* parsing. If tree-sitter fails to load or parse the command,
* {@link shouldAutoApprove} returns `noMatch` so the user is prompted for
* confirmation rather than auto-approving based on the command name alone.
*/
export
class
CommandAutoApprover
extends
Disposable
{
private
:
|
undefined
;
private
:
|
undefined
;
private
:
|
undefined
;
private
:
|
undefined
;
private
:
|
undefined
;
private
:
|
undefined
;
private
:
typeof
|
undefined
;
private
readonly
:
Promise
<
void
>
;
constructor
(
private
readonly
:
,
)
{
super
(
)
;
this
.
=
this
.
_initTreeSitter
(
)
;
}
/**
* Returns a promise that resolves once tree-sitter WASM has been loaded.
* Await this before processing any events to guarantee that
* {@link shouldAutoApprove} can parse commands synchronously.
*/
initialize
(
)
:
Promise
<
void
>
{
return
this
.
;
}
/**
* Synchronously check whether the given command line should be auto-approved.
* Uses tree-sitter (if loaded) to parse compound commands into sub-commands.
*
* When the command contains write redirections, `options.isWriteDestApproved`
* is consulted for each destination. If every destination is approved by the
* predicate, write redirections do not block auto-approval.
*/
shouldAutoApprove
(
:
string
,
?
:
)
:
{
return
this
.
evaluate
(
,
)
.
;
}
/** Evaluates the command and reports whether adding a persistent allow rule could resolve the result. */
evaluate
(
:
string
,
?
:
)
:
{
const
=
.
trimStart
(
)
;
if
(
.
===
0
)
{
return
{
:
'approved'
,
:
false
}
;
}
const
=
this
.
_compileRules
(
?.
)
;
const
=
?.
===
'powershell'
;
if
(
this
.
_matchesCommandLineRule
(
,
.
)
)
{
return
{
:
'denied'
,
:
false
}
;
}
const
=
this
.
_extractSubCommands
(
,
)
;
if
(
!
)
{
this
.
.
trace
(
'[CommandAutoApprover] Command line could not be analyzed, requiring confirmation'
)
;
return
{
:
'noMatch'
,
:
false
}
;
}
const
hasUnapprovedRedirect
=
(
)
=>
.
.
some
(
=>
===
undefined
||
!
?.
?.
(
)
)
;
let
=
this
.
_matchSubCommands
(
.
,
,
)
;
if
(
!==
'denied'
&&
this
.
_matchesCommandLineRule
(
,
.
)
)
{
=
'approved'
;
}
if
(
===
'approved'
&&
hasUnapprovedRedirect
(
)
)
{
this
.
.
trace
(
'[CommandAutoApprover] Write redirection to non-approved destination, requiring confirmation'
)
;
return
{
:
'noMatch'
,
:
false
}
;
}
return
{
,
:
===
'noMatch'
&&
!
hasUnapprovedRedirect
(
)
}
;
}
private
_matchSubCommands
(
:
string
[
]
,
:
,
:
boolean
)
:
{
let
=
true
;
for
(
const
of
)
{
if
(
.
canHandle
(
)
)
{
return
'denied'
;
}
// Deny transient env var assignments
if
(
.
test
(
)
)
{
return
'denied'
;
}
const
=
this
.
_matchSingleCommand
(
,
,
)
;
if
(
===
'denied'
)
{
return
'denied'
;
}
if
(
!==
'approved'
)
{
=
false
;
}
}
return
?
'approved'
:
'noMatch'
;
}
private
_matchSingleCommand
(
:
string
,
:
,
:
boolean
)
:
{
// Check deny rules first
if
(
this
.
_matchesRule
(
,
.
,
)
)
{
return
'denied'
;
}
// Then check allow rules
if
(
this
.
_matchesRule
(
,
.
,
)
)
{
return
'approved'
;
}
return
'noMatch'
;
}
private
_matchesCommandLineRule
(
:
string
,
:
readonly
[
]
)
:
boolean
{
return
.
some
(
=>
.
.
test
(
)
)
;
}
private
_matchesRule
(
:
string
,
:
readonly
[
]
,
?
:
boolean
)
:
boolean
{
for
(
const
of
)
{
// PowerShell rule matching is case-insensitive, like the shell itself.
if
(
(
?
.
:
.
)
.
test
(
)
)
{
return
true
;
}
// Ignore a leading ( for PowerShell commands: it's a command pattern
// operating on the output of a command, e.g. `(Get-Content README.md) ...`.