src/vs/platform/agentHost/node/codex/codexCustomizations.ts
153 LOC · 153 covered · 0 uncovered · 18 ranges · 31 concepts · 6 introducers · 19 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
codexCustomizations.ts ×5
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from '../../../../base/common/uri.js';
import { CustomizationLoadStatus, CustomizationType, customizationId, type DirectoryCustomization, type HookCustomization, type SkillCustomization } from '../../common/state/sessionState.js';
import type { HookMetadata } from './protocol/generated/v2/HookMetadata.js';
import type { HooksListResponse } from './protocol/generated/v2/HooksListResponse.js';
import type { SkillMetadata } from './protocol/generated/v2/SkillMetadata.js';
import type { SkillScope } from './protocol/generated/v2/SkillScope.js';
import type { SkillsListResponse } from './protocol/generated/v2/SkillsListResponse.js';
/**
* Codex reports its *effective* skills and hooks through the cwd-scoped
* `skills/list` and `hooks/list` app-server methods (see
* `codex-rs/.../catalog_processor.rs`). Codex natively discovers skills from
* the VS Code `.agents/skills` convention (`<repo>/.agents/skills` at repo
* scope and `~/.agents/skills` at user scope) as well as `.codex` and bundled
* roots. These helpers project those catalogs into the AHP
* {@link DirectoryCustomization} containers that back the workbench
* Customizations surface, so what codex actually loaded is visible alongside
* the MCP servers already surfaced by {@link McpCustomizationController}.
*
* The mappers are pure (no codex round-trip): the {@link CodexAgent} fetches
* the `skills/list` / `hooks/list` responses and feeds them here.
*/
/** Synthetic URI scheme for the per-scope codex skills container. */
const CODEX_SKILLS_SCHEME = 'codex-skills';
/** Synthetic URI scheme for the codex hooks container. */
const CODEX_HOOKS_SCHEME = 'codex-hooks';
/** Human-facing container name for each {@link SkillScope}. */
switch (scope) {
case 'repo': return 'Repository';
case 'user': return 'User';
case 'system': return 'Built-in';
case 'admin': return 'Admin';
default: return scope;
}
}
/** Stable ordering of scopes so the container list is deterministic. */
const SKILL_SCOPE_ORDER: readonly SkillScope[] = ['repo', 'user', 'system', 'admin'];
function skillToCustomization(skill: SkillMetadata): SkillCustomization {
codexCustomizations.ts ×4
const uri = URI.file(skill.path).toString();
return {
type: CustomizationType.Skill,
id: customizationId(uri),
uri,
name: skill.name,
description: skill.description,
enabled: skill.enabled,
};
}
/**
* Projects a codex `skills/list` response into one read-only
* {@link DirectoryCustomization} container per {@link SkillScope}, each
* carrying its skills as {@link SkillCustomization} children. Skills are
* de-duplicated by their `SKILL.md` path (codex can report the same skill
* for several requested cwds). Scopes with no skills are omitted; the result
* is ordered by {@link SKILL_SCOPE_ORDER}.
*/
export function codexSkillsToContainers(response: SkillsListResponse | undefined): DirectoryCustomization[] {
for (const entry of response?.data ?? []) {
for (const skill of entry.skills ?? []) {
if (!scoped) {
scoped = new Map();
byScope.set(skill.scope, scoped);
}
if (!scoped.has(skill.path)) {
scoped.set(skill.path, skill);
}
}
const containers: DirectoryCustomization[] = [];
for (const scope of SKILL_SCOPE_ORDER) {
const scoped = byScope.get(scope);
if (!scoped || scoped.size === 0) {
continue;
}
.sort((a, b) => a.name.localeCompare(b.name))
.map(skillToCustomization);
const containerUri = URI.from({ scheme: CODEX_SKILLS_SCHEME, path: `/${scope}` }).toString();
containers.push({
type: CustomizationType.Directory,
id: customizationId(containerUri),
uri: containerUri,
name: skillScopeContainerName(scope),
enabled: true,
contents: CustomizationType.Skill,
writable: false,
load: { kind: CustomizationLoadStatus.Loaded },
children,
});
}
}
function hookToCustomization(hook: HookMetadata): HookCustomization {
codexCustomizations.ts ×3
// A single source file can declare several hooks, so disambiguate with the
// codex hook `key` in the fragment to keep customization ids unique.
const uri = URI.file(hook.sourcePath).with({ fragment: hook.key }).toString();
return {
type: CustomizationType.Hook,
id: customizationId(uri),
uri,
name: hook.eventName,
enabled: hook.enabled,
};
}
/**
* Projects a codex `hooks/list` response into a single read-only
* {@link DirectoryCustomization} container carrying its hooks as
* {@link HookCustomization} children. Hooks are de-duplicated by their codex
* `key`. Returns an empty array when no hooks are configured.
*/
export function codexHooksToContainers(response: HooksListResponse | undefined): DirectoryCustomization[] {
for (const entry of response?.data ?? []) {
for (const hook of entry.hooks ?? []) {
byKey.set(hook.key, hook);
}
}
if (byKey.size === 0) {
}
.sort((a, b) => Number(a.displayOrder - b.displayOrder) || a.key.localeCompare(b.key))
.map(hookToCustomization);
const containerUri = URI.from({ scheme: CODEX_HOOKS_SCHEME, path: '/hooks' }).toString();
return [{
type: CustomizationType.Directory,
id: customizationId(containerUri),
uri: containerUri,
name: 'Hooks',
enabled: true,
contents: CustomizationType.Hook,
writable: false,
load: { kind: CustomizationLoadStatus.Loaded },
children,
}];
}