Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ _Avoid_: unqualified "profile", VS Code profile, persona
### Product surfaces

**Home**:
The Personas sidebar, divided into one section per area, including Profiles & Extensions and PowerShell Profiles.
The Personas sidebar, divided into one section per area, including VS Code Profiles and PowerShell Profiles.
_Avoid_: welcome view, dashboard

**Extension Matrix**:
Expand Down
28 changes: 21 additions & 7 deletions src/core/inventory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { asError } from './errors';
import { disabledProfileIds } from './inventoryQueries';
import { disabledProfileIds, isAgentsWindowProfile } from './inventoryQueries';
import { pathFor, type Platform, type ResolvedPaths, type WatchTarget } from './paths';
import {
type ManifestEntry,
Expand Down Expand Up @@ -42,12 +42,14 @@ export function composeInventory(input: ComposeInput): Inventory {

const profiles: Profile[] = [
{ id: 'default', name: 'Default', isDefault: true, inheritsDefaultExtensions: false },
...input.rawProfiles.map((p) => ({
id: p.location,
name: p.name,
isDefault: false,
inheritsDefaultExtensions: p.inheritsDefaultExtensions,
})),
...input.rawProfiles
.map((p): Profile => ({
id: p.location,
name: p.name,
isDefault: false,
inheritsDefaultExtensions: p.inheritsDefaultExtensions,
}))
.sort(compareProfilesForDisplay),
];

// Fail closed on duplicate names. VS Code's profile editor rejects duplicates
Expand Down Expand Up @@ -217,6 +219,18 @@ export function composeInventory(input: ComposeInput): Inventory {
return { profiles, extensions, warnings };
}

const profileNameCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });

/**
* Orders named profiles for display. The Agents window profile comes first, and the rest follow
* in a case-insensitive natural sort, so "Profile 2" comes before "Profile 10".
*/
function compareProfilesForDisplay(a: Profile, b: Profile): number {
const agentsFirst = Number(isAgentsWindowProfile(b)) - Number(isAgentsWindowProfile(a));
if (agentsFirst !== 0) return agentsFirst;
return profileNameCollator.compare(a.name, b.name);
}

/**
* Defense in depth for package.json `icon` values, which are attacker-controlled data from an
* installed extension's folder: only a plain relative path inside the extension folder is
Expand Down
77 changes: 49 additions & 28 deletions src/panel/homeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { openReadOnly } from './readOnlyProvider';
import { createNonce, homeContentSecurityPolicy, renderContentSecurityPolicyMeta } from './webviewSecurity';

/**
* Home, the Personas sidebar: one section per area, currently only Profiles & Extensions. Owns no
* business logic of its own: counts, orphan detection and sizing all come from pure/core helpers
* (`profileExtensionCounts`, `buildOrphanInfos`) — this class only wires services to the webview
* and reacts to its messages. It reaches the Extension Matrix only through commands, never by
* Home, the Personas sidebar: several sections, one per area (VS Code Profiles and PowerShell
* Profiles). Owns no business logic of its own: counts, orphan detection and sizing all come from
* pure/core helpers (`profileExtensionCounts`, `buildOrphanInfos`) — this class only wires services
* to the webview and reacts to its messages. It reaches the Extension Matrix only through commands, never by
* importing MatrixPanel. The rendering script lives in dist/home.js (built from
* src/webview/home.ts) rather than inline, to keep this file's HTML skeleton small.
*/
Expand Down Expand Up @@ -173,12 +173,6 @@ export class HomeViewProvider implements vscode.WebviewViewProvider {
case 'openMatrix':
await vscode.commands.executeCommand('personas.showMatrix');
return;
case 'openProfileReadOnly': {
const profile = this.profiles.find((p) => p.id === m.profileId);
if (!profile?.filePath) return;
await openReadOnly(`${profile.name} — extensions.json (read-only)`, profile.filePath);
return;
}
case 'editProfileFile': {
const profile = this.profiles.find((p) => p.id === m.profileId);
if (!profile?.filePath) return;
Expand Down Expand Up @@ -220,16 +214,23 @@ ${renderContentSecurityPolicyMeta(homeContentSecurityPolicy(nonce))}
}
/* High-contrast themes can color a button the same as the surface behind it and rely on
* contrastBorder for its edge. Other themes leave contrastBorder unset, so the border stays
* transparent there, and the padding gives back the border's 1px to keep the button's size. */
* transparent there. The shape follows VS Code's own text buttons (.monaco-text-button in
* src/vs/base/browser/ui/button/button.css): a 1px border outside 4px by 8px padding and a 4px
* corner radius. */
button {
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: 1px solid var(--vscode-contrastBorder, transparent);
padding: calc(0.3rem - 1px) calc(0.7rem - 1px);
border-radius: 1rem;
padding: 4px 8px;
border-radius: 4px;
font: inherit;
cursor: pointer;
}
button:hover { background: var(--vscode-button-hoverBackground); }
/* A standard button fills the width up to 300px, the cap VS Code gives the buttons in its views'
* welcome content (.welcome-view-content > .button-container in
* src/vs/workbench/browser/parts/views/media/views.css). */
.standard-button { display: block; box-sizing: border-box; width: 100%; max-width: 300px; }
h2 { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.04em; margin: 0.5rem 0 0.5rem; }
h3 { font-size: 0.95em; margin: 1rem 0 0.25rem; }
.home-section + .home-section { margin-top: 1.25rem; }
Expand All @@ -238,6 +239,7 @@ ${renderContentSecurityPolicyMeta(homeContentSecurityPolicy(nonce))}
#profiles li:last-child { margin-bottom: 0; }
a { color: var(--vscode-textLink-foreground); text-decoration: none; cursor: pointer; }
a:hover, a:focus { text-decoration: underline; }
#launcher { margin-bottom: 0.75rem; }
.profile-line1 { display: flex; align-items: center; gap: 0.3rem; }
.profile-name {
flex: 1 1 auto;
Expand All @@ -246,8 +248,28 @@ ${renderContentSecurityPolicyMeta(homeContentSecurityPolicy(nonce))}
text-overflow: ellipsis;
white-space: nowrap;
}
.edit-icon { margin-left: 0.35rem; flex-shrink: 0; }
.edit-icon:focus { outline: 1px solid var(--vscode-focusBorder); }
/* The pencil is an icon button styled like the actions in VS Code's view toolbars. */
button.edit-icon {
flex: none;
display: inline-flex;
align-items: center;
justify-content: center;
width: 22px;
height: 22px;
margin-left: 0.35rem;
padding: 0;
border: none;
border-radius: 5px;
background: transparent;
color: var(--vscode-icon-foreground);
font: inherit;
}
button.edit-icon:hover {
background: var(--vscode-toolbar-hoverBackground);
outline: 1px dashed var(--vscode-contrastActiveBorder, transparent);
outline-offset: -1px;
}
button.edit-icon:focus-visible { outline: 1px solid var(--vscode-focusBorder); outline-offset: -1px; }
.profile-counts { margin-top: 0.15rem; font-size: 0.85em; color: var(--vscode-descriptionForeground); }
.workspace-card {
width: 100%;
Expand All @@ -271,23 +293,23 @@ ${renderContentSecurityPolicyMeta(homeContentSecurityPolicy(nonce))}
}
.workspace-matrix:hover { background: var(--vscode-list-hoverBackground); }
.workspace-matrix:focus { outline: 1px solid var(--vscode-focusBorder); outline-offset: -1px; }
/* The manifest actions are VS Code's secondary buttons: the same shape as Open Extension Matrix,
* set below it in emphasis, and capped together at the same 300px. */
.workspace-actions {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
box-sizing: border-box;
max-width: 300px;
padding: 0 0.65rem 0.55rem;
}
/* The pair stacks when the sidebar is too narrow to fit both labels on one line. */
.workspace-action {
padding: 0;
border: none;
border-radius: 0;
background: transparent;
color: var(--vscode-textLink-foreground);
font-size: 0.85em;
}
.workspace-action:hover, .workspace-action:focus {
background: transparent;
text-decoration: underline;
flex: 1 1 7rem;
background: var(--vscode-button-secondaryBackground);
color: var(--vscode-button-secondaryForeground);
}
.workspace-action:hover { background: var(--vscode-button-secondaryHoverBackground); }
.workspace-title { font-weight: 600; }
.workspace-name { color: var(--vscode-textLink-foreground); margin-top: 0.15rem; }
.workspace-readonly, .workspace-counts, .workspace-profile {
Expand Down Expand Up @@ -453,12 +475,11 @@ ${renderContentSecurityPolicyMeta(homeContentSecurityPolicy(nonce))}
</head>
<body>
<section class="home-section" aria-labelledby="profiles-extensions-heading">
<h2 id="profiles-extensions-heading">Profiles &amp; Extensions</h2>
<h2 id="profiles-extensions-heading">VS Code Profiles</h2>
<div id="launcher">
<button id="open">Open Extension Matrix</button>
<button id="open" class="standard-button" type="button">Open Extension Matrix</button>
</div>
<div id="profiles-extensions">
<h3>Profiles</h3>
<ul id="profiles"></ul>
<div id="workspace"></div>
<div id="extra"></div>
Expand Down
1 change: 0 additions & 1 deletion src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export type HomeToHost =
| { type: 'powerShellAction'; action: 'refresh' | 'help' | 'resolve' | 'open' | 'delete' | 'copy' | 'reveal'; id?: string }
| { type: 'ready' }
| { type: 'openMatrix' }
| { type: 'openProfileReadOnly'; profileId: string }
| { type: 'editProfileFile'; profileId: string }
| { type: 'openWorkspaceReadOnly' }
| { type: 'editWorkspaceFile' }
Expand Down
35 changes: 8 additions & 27 deletions src/webview/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,16 @@ function render(): void {
for (const p of state.profiles) {
const li = document.createElement('li');
const line1 = el('div', 'profile-line1');
if (p.inheritsDefaultExtensions) {
const nameSpan = el('span', 'profile-name', p.label);
nameSpan.title = p.tooltip ?? p.label;
line1.append(nameSpan);
} else {
const link = el('a', 'profile-name', p.label) as HTMLAnchorElement;
link.href = '#';
link.title = p.tooltip ?? p.label;
link.addEventListener('click', (e) => {
e.preventDefault();
vscode.postMessage({ type: 'openProfileReadOnly', profileId: p.id });
});
line1.append(link);

const edit = el('a', 'edit-icon', '✎') as HTMLAnchorElement;
edit.href = '#';
edit.tabIndex = 0;
const nameSpan = el('span', 'profile-name', p.label);
nameSpan.title = p.tooltip ?? p.label;
line1.append(nameSpan);
// A profile that uses Default's extensions has no file of its own to edit.
if (!p.inheritsDefaultExtensions) {
const edit = el('button', 'edit-icon', '✎') as HTMLButtonElement;
edit.type = 'button';
edit.title = 'Edit raw file — caution: VS Code owns this file';
edit.setAttribute('role', 'button');
edit.setAttribute('aria-label', `Edit raw file for ${p.name} — caution: VS Code owns this file`);
const openEdit = (e: Event) => {
e.preventDefault();
vscode.postMessage({ type: 'editProfileFile', profileId: p.id });
};
edit.addEventListener('click', openEdit);
edit.addEventListener('keydown', (e) => {
const key = (e as KeyboardEvent).key;
if (key === 'Enter' || key === ' ') openEdit(e);
});
edit.addEventListener('click', () => vscode.postMessage({ type: 'editProfileFile', profileId: p.id }));
line1.append(edit);
}
const own = p.agentsWindow
Expand Down
61 changes: 57 additions & 4 deletions test/unit/inventory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
InventoryService,
type InventoryIo,
} from '../../src/core/inventory';
import { withoutAgentsWindowProfile } from '../../src/core/inventoryQueries';
import type { ResolvedPaths } from '../../src/core/paths';
import type { ManifestEntry, RawProfile } from '../../src/core/parsers';
import type { Inventory, Profile } from '../../src/core/types';
Expand Down Expand Up @@ -39,11 +40,11 @@ const baseInput = () => ({
});

describe('composeInventory', () => {
it('lists default profile first, then registry profiles', () => {
it('lists the default profile, then the registry profiles in display order', () => {
const inv = composeInventory(baseInput());
expect(inv.profiles.map((p) => p.id)).toEqual(['default', 'aaa', 'builtin/agents']);
expect(inv.profiles.map((p) => p.id)).toEqual(['default', 'builtin/agents', 'aaa']);
expect(inv.profiles[0]?.isDefault).toBe(true);
expect(inv.profiles[2]?.inheritsDefaultExtensions).toBe(true);
expect(inv.profiles[1]?.inheritsDefaultExtensions).toBe(true);
});

it('disables changes to every profile sharing a name, since the code CLI targets profiles by name', () => {
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('composeInventory', () => {
const inv = composeInventory(baseInput());
const everywhere = inv.extensions.find((e) => e.id === 'pub.everywhere');
expect(everywhere?.applyToAllProfiles).toBe(true);
expect(everywhere?.installedIn).toEqual(['default', 'aaa', 'builtin/agents']);
expect(everywhere?.installedIn).toEqual(['default', 'builtin/agents', 'aaa']);
expect(everywhere?.displayName).toBe('Everywhere!');
});

Expand Down Expand Up @@ -211,6 +212,58 @@ describe('composeInventory', () => {
});
});

describe('composeInventory profile order', () => {
const orderOf = (rawProfiles: RawProfile[]): string[] =>
composeInventory({ ...baseInput(), rawProfiles, profileManifests: new Map() }).profiles.map((p) => p.name);
const named = (location: string, name: string, inheritsDefaultExtensions = false): RawProfile => ({
location,
name,
inheritsDefaultExtensions,
});

it('puts Default first and the Agents window profile second, whatever the registry order', () => {
expect(
orderOf([named('w', 'Work'), named('a', 'Alpha'), named('builtin/agents', 'Agents', true)]),
).toEqual(['Default', 'Agents', 'Alpha', 'Work']);
});

it('sorts numbered profiles in natural order, so "Profile 2" comes before "Profile 10"', () => {
expect(orderOf([named('c', 'Profile 10'), named('a', 'Profile 2'), named('b', 'Profile 1')])).toEqual([
'Default',
'Profile 1',
'Profile 2',
'Profile 10',
]);
});

it('ignores case when sorting names', () => {
expect(orderOf([named('z', 'zeta'), named('b', 'Beta'), named('a', 'alpha')])).toEqual([
'Default',
'alpha',
'Beta',
'zeta',
]);
});

it('keeps Default first and the rest in name order when the Agents window profile is hidden', () => {
const inv = composeInventory({
...baseInput(),
rawProfiles: [named('w', 'Work'), named('builtin/agents', 'Agents', true), named('a', 'alpha')],
profileManifests: new Map(),
});
expect(withoutAgentsWindowProfile(inv).profiles.map((p) => p.name)).toEqual(['Default', 'alpha', 'Work']);
});

it('sorts a user profile named "Agents" with the others, since only the built-in location is the Agents window', () => {
expect(orderOf([named('w', 'Work'), named('x', 'Agents'), named('a', 'Aardvark')])).toEqual([
'Default',
'Aardvark',
'Agents',
'Work',
]);
});
});

describe('InventoryService', () => {
const PATHS: ResolvedPaths = {
userDataDir: '/data',
Expand Down
Loading