Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/** A single hook command to execute. Platform resolution happens at conversion time. */
export
interface
IParsedHookCommand
{
/** Cross-platform default command. */
readonly
?
:
string
;
/** Windows-specific command. */
readonly
?
:
string
;
/** Linux-specific command. */
readonly
?
:
string
;
/** macOS-specific command. */
readonly
?
:
string
;
/** Working directory. */
readonly
?
:
URI
;
/** Environment variables. */
readonly
?
:
<
string
,
string
>
;
/** Timeout in seconds. */
readonly
?
:
number
;
/** URI of the file this hook was defined in. */
readonly
?
:
URI
;
}
export
namespace
{
export
function
isEquals
(
:
|
undefined
,
:
|
undefined
)
:
boolean
{
if
(
===
)
{
return
true
;
}
if
(
!
||
!
)
{
return
false
;
}
return
.
===
.
&&
.
===
.
&&
.
===
.
&&
.
===
.
&&
isURLEquals
(
.
,
.
)
&&
objectEquals
(
.
,
.
)
&&
.
===
.
&&
isURLEquals
(
.
,
.
)
;
}
}
/** A group of hooks for a single lifecycle event. */
export
interface
IParsedHookGroup
{
/** Canonical hook type identifier (e.g. `'SessionStart'`, `'PreToolUse'`). */
readonly
:
string
;
/** The commands to execute for this hook type. */
readonly
:
readonly
[
]
;
/** URI where this hook is defined. */
readonly
:
URI
;
/** Original key as it appears in the hook file. */
readonly
:
string
;
/**
* Protocol-level projection of this hook group as a child customization.
* Multiple groups parsed from the same file share the same `customization.id`
* so consumers can dedupe by id when collecting customizations.
*/
readonly
:
;
}
export
interface
IMcpServerDefinition
{
readonly
:
string
;
readonly
:
;
readonly
?
:
URI
;
readonly
:
URI
;
/** Protocol-level projection of this MCP server as a child customization. */
readonly
:
;
}
/** A named resource (skill, agent, command, or instruction) within a plugin. */
export
interface
INamedPluginResource
{
readonly
:
URI
;
readonly
:
string
;
/**
* Optional short description, populated for resources whose readers
* parse it from the file's YAML frontmatter (e.g. agents).
*/
readonly
?
:
string
;
}
/** A parsed agent resource with the frontmatter metadata shared by providers. */
export
interface
IAgentPluginResource
extends
INamedPluginResource
{
readonly
?
:
string
;
readonly
?
:
readonly
string
[
]
;
readonly
?
:
boolean
;
readonly
?
:
boolean
;
}
/** A parsed agent paired with its protocol-level child customization. */
export
interface
IParsedAgent
extends
IAgentPluginResource
{
readonly
:
;
}
/** A parsed skill paired with its protocol-level child customization. */
export
interface
IParsedSkill
extends
INamedPluginResource
{
readonly
:
;
}
/** A parsed rule (instruction) paired with its protocol-level child customization. */
export
interface
IParsedRule
extends
INamedPluginResource
{
readonly
:
;
}
/** The result of parsing a single plugin directory. */
/**
* Mints a child-customization id from a source uri plus an optional opaque
* disambiguator. Used when multiple customizations are declared inline in
* a single file (e.g. two MCP servers in one `.mcp.json`, or two hook
* lifecycle groups in one hook file).
*
* Percent-encodes any pre-existing `#` in the URI before appending the
* disambiguating fragment so the resulting id can never collide with a
* URI that happens to already contain a matching fragment.
*/
function
buildChildId
(
:
URI
,
?
:
string
)
:
string
{
const
=
customizationId
(
.
toString
(
)
)
;
if
(
!
)
{
return
;
}
return
`${base.replace(/#/g,'%23')}#${disambiguator}`
;
}
function
makeAgentCustomization
(
:
)
:
{
const
=
.
.
toString
(
)
;
return
{
:
.
,
:
buildChildId
(
.
)
,
,
:
.
,
...
(
.
?
{
:
.
}
:
{
}
)
,
...
(
.
?
{
:
.
}
:
{
}
)
,
...
(
.
?.
?
{
:
[
...
.
]
}
:
{
}
)
,
...
(
.
?
{
:
true
}
:
{
}
)
,
...
(
.
?
{
:
true
}
:
{
}
)
,
}
;
}
function
makeSkillCustomization
(
:
)
:
{
const
=
.
.
toString
(
)
;
return
{
:
.
,
:
buildChildId
(
.
)
,
,
:
.
,
...
(
.
?
{
:
.
}
:
{
}
)
,
}
;
}
function
makeRuleCustomization
(
:
)
:
{
const
=
.
.
toString
(
)
;
return
{
:
.
,
:
buildChildId
(
.
)
,
,
:
.
,
...
(
.
?
{
:
.
}
:
{
}
)
,
}
;
}
function
makeHookCustomization
(
:
URI
)
:
{
return
{
:
.
,
:
buildChildId
(
)
,
:
.
toString
(
)
,
:
basename
(
)
,
}
;
}
/**
* Builds the protocol {@link McpServerCustomization} for an MCP server
* declared at `definitionUri` (the manifest / settings / `.mcp.json` file
* the server is defined in). The id is disambiguated by server `name` so
* multiple servers declared in one file get distinct ids, and the entry
* carries {@link DEFAULT_MCP_APP} so MCP App support is advertised
* consistently with every other MCP customization.
*
* The seed state is {@link McpServerStatus.Stopped}: a declared-but-not-yet
* connected server has not been started by any SDK, so it must not claim to
* be {@link McpServerStatus.Starting}. The live state is enriched from the
* SDK's reported status once a session materializes.
*/
/**
* Parses a manifest component path field into a normalized config.
* Supports `undefined`, `string`, `string[]`, and `{ paths: string[], exclusive?: boolean }`.
*/
export
function
parseComponentPathConfig
(
:
unknown
)
:
{
if
(
===
undefined
||
===
null
)
{
return
;
}
if
(
typeof
===
'string'
)
{
const
=
.
trim
(
)
;
return
?
{
:
[
]
,
:
false
}
:
;
}
if
(
Array
.
isArray
(
)
)
{
const
=
.
filter
(
=>
typeof
===
'string'
)
.
map
(
=>
.
trim
(
)
)
.
filter
(
=>
.
>
0
)
;
return
{
,
:
false
}
;
}
if
(
typeof
===
'object'
)
{
const
=
as
<
string
,
unknown
>
;
if
(
Array
.
isArray
(
[
'paths'
]
)
)
{
const
=
(
[
'paths'
]
as
unknown
[
]
)
.
filter
(
=>
typeof
===
'string'
)
.
map
(
=>
.
trim
(
)
)
.
filter
(
=>
.
>
0
)
;
const
=
[
'exclusive'
]
===
true
;
return
{
,
}
;
}
}
return
;
}
/**
* Resolves the directories to scan for a given component type, combining
* the default directory with any custom paths from the manifest config.
* Paths that resolve outside the boundary are silently ignored.
* @paramboundaryUri The outermost directory that resolved paths must stay within. Defaults to {@link pluginUri}.
*/
` fields to platform-specific overrides.
*/
function normalizeHookCommand(raw: Record<string, unknown>): IParsedHookCommand | undefined {
// Allow omitted type (Claude compatibility) — treat as 'command'
if (raw.type !== undefined && raw.type !== 'command') {
return undefined;
}
const hasCommand = typeof raw.command === 'string' && raw.command.length > 0;
const hasBash = typeof raw.bash === 'string' && (raw.bash as string).length > 0;
const hasPowerShell = typeof raw.powershell === 'string' && (raw.powershell as string).length > 0;
const hasWindows = typeof raw.windows === 'string' && (raw.windows as string).length > 0;
const hasLinux = typeof raw.linux === 'string' && (raw.linux as string).length > 0;
const hasOsx = typeof raw.osx === 'string' && (raw.osx as string).length > 0;
if (!hasCommand && !hasBash && !hasPowerShell && !hasWindows && !hasLinux && !hasOsx) {
return undefined;
}
const windows = hasWindows ? raw.windows as string : (hasPowerShell ? raw.powershell as string : undefined);
const linux = hasLinux ? raw.linux as string : (hasBash ? raw.bash as string : undefined);
const osx = hasOsx ? raw.osx as string : (hasBash ? raw.bash as string : undefined);
const timeout = typeof raw.timeout === 'number'
? raw.timeout
: (typeof raw.timeoutSec === 'number' ? raw.timeoutSec : undefined);
return {
...(hasCommand && { command: raw.command as string }),
...(windows && { windows }),
...(linux && { linux }),
...(osx && { osx }),
...(typeof raw.env === 'object' && raw.env !== null && { env: raw.env as Record<string, string> }),
...(timeout !== undefined && { timeout }),
};
}
/**
* Resolves a raw hook command JSON object into a {@link IParsedHookCommand},
* normalizing fields and resolving the working directory.
*/
function resolveHookCommand(raw: Record<string, unknown>, workspaceRoot: URI | undefined, userHome: URI): IParsedHookCommand | undefined {
const normalized = normalizeHookCommand(raw);
if (!normalized) {
return undefined;
}
let cwdUri: URI | undefined;
const rawCwd = typeof raw.cwd === 'string' ? raw.cwd : undefined;
if (rawCwd) {
if (rawCwd.startsWith('~/')) {
cwdUri = URI.joinPath(userHome, rawCwd.substring(2));
} else if (isAbsolute(rawCwd)) {
cwdUri = URI.file(rawCwd);
} else if (workspaceRoot) {
cwdUri = joinPath(workspaceRoot, rawCwd);
}
} else {
cwdUri = workspaceRoot;
}
return { ...normalized, cwd: cwdUri };
}
/**
* Extracts hook commands from an item that may be a direct command object
* or a nested structure with a `
` (Claude format).
*/
function extractHookCommands(item: unknown, workspaceRoot: URI | undefined, userHome: URI): IParsedHookCommand[] {
if (!item || typeof item !== 'object') {
return [];
}
const itemObj = item as Record<string, unknown>;
const commands: IParsedHookCommand[] = [];
// Nested hooks with matcher (Claude style): { matcher: "...", hooks: [...] }
const nestedHooks = itemObj.hooks;
if (nestedHooks !== undefined && Array.isArray(nestedHooks)) {
for (const nested of nestedHooks) {
if (!nested || typeof nested !== 'object') {
continue;
}
const resolved = resolveHookCommand(nested as Record<string, unknown>, workspaceRoot, userHome);
if (resolved) {
commands.push(resolved);
}
}
} else {
const resolved = resolveHookCommand(itemObj, workspaceRoot, userHome);
if (resolved) {
commands.push(resolved);
}
}
return commands;
}
/**
* Parses hooks from a JSON object (any supported format).
*
* Handles Claude's `
` short-circuit, the `
HOOK_TYPE_MAP
`
* canonicalization, and the nested `
{
,
:
[
...
]
}
` command
* form. Returns one {@link IParsedHookGroup} per recognized lifecycle
* event; all groups parsed from the same file share a single
* {@link IParsedHookGroup.customization} (keyed on `
`), so callers
* that only need the file-level customization can read it off any group.
*/
export function parseHooksJson(
hookUri: URI,
json: unknown,
workspaceRoot: URI | undefined,
userHome: URI,
): IParsedHookGroup[] {
if (!json || typeof json !== 'object') {
return [];
}
const root = json as Record<string, unknown>;
// Claude's disableAllHooks
if (root.disableAllHooks === true) {
return [];
}
const hooks = root.hooks;
const hooksObj = hooks && typeof hooks === 'object' && !Array.isArray(hooks)
? hooks as Record<string, unknown>
: root;
const result: IParsedHookGroup[] = [];
const customization = makeHookCustomization(hookUri);
for (const originalId of Object.keys(hooksObj)) {
const canonicalType = HOOK_TYPE_MAP[originalId];
if (!canonicalType) {
continue;
}
const hookArray = hooksObj[originalId];
if (!Array.isArray(hookArray)) {
continue;
}
const commands: IParsedHookCommand[] = [];
for (const item of hookArray) {
commands.push(...extractHookCommands(item, workspaceRoot, userHome));
}
if (commands.length > 0) {
result.push({ type: canonicalType, commands, uri: hookUri, originalId, customization });
}
}
return result;
}
/**
* Applies plugin-root token interpolation to hook commands for
* Claude and OpenPlugin formats.
*/
export function interpolateHookPluginRoot(
hookUri: URI,
json: unknown,
pluginUri: URI,
workspaceRoot: URI | undefined,
userHome: URI,
token: string,
envVar: string,
): IParsedHookGroup[] {
const fsPath = pluginUri.fsPath;
const typedJson = json as { hooks?: Record<string, unknown[]> };
const mutateHookCommand = (hook: Record<string, unknown>): void => {
for (const field of ['command', 'windows', 'linux', 'osx'] as const) {
if (typeof hook[field] === 'string') {
hook[field] = shellQuotePluginRootInCommand(hook[field] as string, fsPath, token);
}
}
if (!hook.env || typeof hook.env !== 'object') {
hook.env = {};
}
(hook.env as Record<string, string>)[envVar] = fsPath;
};
for (const lifecycle of Object.values(typedJson.hooks ?? {})) {
if (!Array.isArray(lifecycle)) {
continue;
}
for (const lifecycleEntry of lifecycle) {
if (!lifecycleEntry || typeof lifecycleEntry !== 'object') {
continue;
}
const entry = lifecycleEntry as { hooks?: Record<string, unknown>[] } & Record<string, unknown>;
if (Array.isArray(entry.hooks)) {
for (const hook of entry.hooks) {
mutateHookCommand(hook);
}
} else {
mutateHookCommand(entry);
}
}
}
const replacer = (v: unknown): unknown => {
return typeof v === 'string'
? v.replaceAll(token, pluginUri.fsPath)
: undefined;
};
return parseHooksJson(hookUri, cloneAndChange(json, replacer), workspaceRoot, userHome);
}
// ---------------------------------------------------------------------------
// Filesystem helpers
// ---------------------------------------------------------------------------
export async function readJsonFile(uri: URI, fileService: IFileService): Promise<unknown | undefined> {
try {
const fileContents = await fileService.readFile(uri);
return parseJSONC(fileContents.value.toString());
} catch {
return undefined;
}
}
export async function pathExists(resource: URI, fileService: IFileService): Promise<boolean> {
try {
await fileService.resolve(resource);
return true;
} catch {
return false;
}
}
// ---------------------------------------------------------------------------
// Component readers
// ---------------------------------------------------------------------------
const COMMAND_FILE_SUFFIX = '.md';
const RULE_FILE_SUFFIX = '.mdc';
const INSTRUCTION_FILE_SUFFIX = '.instructions.md';
export async function readSkills(
pluginRoot: URI,
dirs: readonly URI[],
fileService: IFileService,
options?: { readonly childDirectoriesOnly?: boolean; readonly containmentRoot?: URI },
): Promise<readonly INamedPluginResource[]> {
const seen = new Set<string>();
const skills: INamedPluginResource[] = [];
const addSkill = async (name: string, skillMd: URI) => {
if (options?.containmentRoot && !await isResolvedWithin(options.containmentRoot, skillMd, fileService)) {
return;
}
let description: string | undefined;
try {
const parsedInfo = await parseSkillFile(skillMd, fileService);
description = parsedInfo.description;
name = parsedInfo.name || name;
} catch {
// Keep the existing best-effort discovery behavior for malformed skills.
}
if (seen.has(name)) {
return;
}
seen.add(name);
skills.push({ uri: skillMd, name, ...(description ? { description } : {}) });
};
await Promise.all(dirs.map(async dir => {
if (!options?.childDirectoriesOnly) {
const skillMd = URI.joinPath(dir, 'SKILL.md');
if (await pathExists(skillMd, fileService)) {
await addSkill(basename(dir), skillMd);
return;
}
}
let stat;
try {
stat = await fileService.resolve(dir);
} catch {
return;
}
if (!stat.isDirectory || !stat.children) {
return;
}
await Promise.all(stat.children.map(async child => {
const childSkillMd = URI.joinPath(child.resource, 'SKILL.md');
if (await pathExists(childSkillMd, fileService)) {
await addSkill(basename(child.resource), childSkillMd);
}
}));
}));
if (!options?.childDirectoriesOnly && skills.length === 0) {
const rootSkillMd = URI.joinPath(pluginRoot, 'SKILL.md');
if (await pathExists(rootSkillMd, fileService)) {
await addSkill(basename(pluginRoot), rootSkillMd);
}
}
skills.sort((a, b) => a.name.localeCompare(b.name));
return skills;
}
export async function readPluginSkills(pluginRoot: URI, dirs: readonly URI[], format: IPluginFormatConfig, fileService: IFileService): Promise<readonly INamedPluginResource[]> {
return readSkills(pluginRoot, dirs, fileService, format.format === PluginFormat.AgentPlugin
? { childDirectoriesOnly: true, containmentRoot: pluginRoot }
: undefined);
}
async function isResolvedWithin(root: URI, resource: URI, fileService: IFileService): Promise<boolean> {
try {
const [resolvedRoot, resolvedResource] = await Promise.all([
fileService.realpath(root),
fileService.realpath(resource),
]);
return isEqualOrParent(resolvedResource ?? normalizePath(resource), resolvedRoot ?? normalizePath(root));
} catch {
return false;
}
}
export async function readMarkdownComponents(
dirs: readonly URI[],
fileService: IFileService,
options?: { readonly containmentRoot?: URI },
): Promise<readonly INamedPluginResource[]> {
const seen = new Set<string>();
const items: INamedPluginResource[] = [];
const addItem = async (name: string, uri: URI) => {
if (options?.containmentRoot && !await isResolvedWithin(options.containmentRoot, uri, fileService)) {
return;
}
if (!seen.has(name)) {
seen.add(name);
items.push({ uri, name });
}
};
for (const dir of dirs) {
let stat;
try {
stat = await fileService.resolve(dir);
} catch {
continue;
}
if (stat.isFile && extname(dir).toLowerCase() === COMMAND_FILE_SUFFIX) {
await addItem(basename(dir).slice(0, -COMMAND_FILE_SUFFIX.length), dir);
continue;
}
if (!stat.isDirectory || !stat.children) {
continue;
}
for (const child of stat.children) {
if (!child.isFile || extname(child.resource).toLowerCase() !== COMMAND_FILE_SUFFIX) {
continue;
}
await addItem(basename(child.resource).slice(0, -COMMAND_FILE_SUFFIX.length), child.resource);
}
}
items.sort((a, b) => a.name.localeCompare(b.name));
return items;
}
function getInstructionFileName(resource: URI): string | undefined {
const fileName = basename(resource);
const lowerName = fileName.toLowerCase();
if (lowerName.endsWith(RULE_FILE_SUFFIX)) {
return fileName.slice(0, -RULE_FILE_SUFFIX.length);
}
if (lowerName.endsWith(INSTRUCTION_FILE_SUFFIX)) {
return fileName.slice(0, -INSTRUCTION_FILE_SUFFIX.length);
}
return undefined;
}
/**
* Reads rule/instruction files from plugin `
` component directories.
*
* Open Plugins rules are conventionally `
.
` files. We also accept
* `
.
.
` for compatibility with VS Code-discovered instructions
* bundled as synthetic plugins.
*/
export async function readInstructionComponents(
dirs: readonly URI[],
fileService: IFileService,
options?: { readonly containmentRoot?: URI },
): Promise<readonlyINamedPluginResource[]> {
const seen = new Set<string>();
const items: INamedPluginResource[] = [];
const addItem = async (name: string, uri: URI) => {
if (options?.containmentRoot && !await isResolvedWithin(options.containmentRoot, uri, fileService)) {
return;
}
if (!seen.has(name)) {
seen.add(name);
items.push({ uri, name });
}
}; for (const dir of dirs) {
let stat;
try {
stat = await fileService.resolve(dir);
} catch {
continue;
} if (stat.isFile) {
const instructionName = getInstructionFileName(dir);
if (instructionName) {
await addItem(instructionName, dir);
}
continue;
} if (!stat.isDirectory || !stat.children) {
continue;
} for (const child of stat.children) {
if (!child.isFile) {
continue;
}
const instructionName = getInstructionFileName(child.resource);
if (instructionName) {
await addItem(instructionName, child.resource);
}
}
} items.sort((a, b) => a.name.localeCompare(b.name));
return items;
}
/*** Reads `
.
` files in agent directories and enriches each entry with
* the optional `
` / `
` from YAML frontmatter. Falls back
* to the file-derived name when frontmatter is missing or unreadable.
*/
export async function readAgentComponents(
dirs: readonly URI[],
fileService: IFileService,
options?: { readonly containmentRoot?: URI },
): Promise<readonly IAgentPluginResource[]> {
const files = await readMarkdownComponents(dirs, fileService, options);
if (files.length === 0) {
return files;
}
const enriched = await Promise.all(files.map(async file => {
try {
const parsed = await parseAgentFile(file.uri, fileService);
return {
uri: file.uri,
name: parsed.name || file.name,
...(parsed.description ? { description: parsed.description } : {}),
...(parsed.model ? { model: parsed.model } : {}),
...(parsed.tools?.length ? { tools: parsed.tools } : {}),
...(parsed.disableModelInvocation ? { disableModelInvocation: true } : {}),
...(parsed.userInvocable === false ? { disableUserInvocation: true } : {}),
} satisfies IAgentPluginResource;
} catch {
return file;
}
}));
// De-dupe again in case frontmatter `
` collides; first-seen wins.
const seen = new Set<string>();
const result: IAgentPluginResource[] = [];
for (const item of enriched) {
if (seen.has(item.name)) {
continue;
}
seen.add(item.name);
result.push(item);
}
result.sort((a, b) => a.name.localeCompare(b.name));
return result;
}
export async function parseAgentFile(uri: URI, fileService: IFileService): Promise<{ name: string; description?: string; userInvocable?: boolean; model?: string; tools?: readonly string[]; disableModelInvocation?: boolean }> {
// Use regex to strip the trailing `
.
.
` or .md before parsing, so we can fall back to a cleaner name if frontmatter is missing or broken.
const nameFromFile = basename(uri).replace(/(\.agent)?\.md$/i, '');
try {
const content = await fileService.readFile(uri);
const frontmatter = parseFrontMatter(content.value.toString());
const name = frontmatter?.getStringValue('name')?.trim() || nameFromFile;
const description = frontmatter?.getStringValue('description')?.trim();
const userInvocable = frontmatter?.getBooleanValue('user-invocable');
const model = frontmatter?.getStringArrayValue('model')?.map(value => value.trim()).find(Boolean);
const tools = frontmatter?.getStringArrayValue('tools')?.map(value => value.trim()).filter(Boolean);
const infer = frontmatter?.getBooleanValue('infer');
const disableModelInvocation = resolveAgentDisableModelInvocation(infer, frontmatter?.getBooleanValue('disable-model-invocation'));
return { name, description, userInvocable, model, tools, disableModelInvocation };
} catch {
return { name: nameFromFile };
}
}
/** Resolves the deprecated `