claudeSessionMetadataStore.ts ×7

Frontier kind: Code frontier

unlabeled · c_5fa09c9b42ea

208 tests · 16757 LOC · 57 files · introduces 0 tests · 138 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
8 ranges138 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1270 ranges16757 lines · 57 files · Browse complete extent
All tests (intent)
208 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 138 introduced LOC across 8 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/claude/claudeSessionMetadataStore.ts 101 introduced LOC · 7 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- claudeSessionMetadataStore.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import type { SDKSessionInfo } from '@anthropic-ai/claude-agent-sdk';
7 > import { URI } from '../../../../base/common/uri.js';
8 > import { ClaudePermissionMode, narrowClaudePermissionMode } from '../../common/claudeSessionConfigKeys.js';
9 > import { AgentProvider, AgentSession, IAgentSessionMetadata } from '../../common/agentService.js';
10 > import { ISessionDataService } from '../../common/sessionDataService.js';
11 > import type { AgentSelection, ModelSelection } from '../../common/state/protocol/state.js';
12 >
13 > /**
14 > * Read view of Claude's per-session DB overlay. SDK-supplied fields
15 > * (summary, cwd, timestamps) live on {@link SDKSessionInfo} and are
16 > * combined with the overlay in {@link ClaudeSessionMetadataStore.project}.
17 > */
18 > export interface IClaudeSessionOverlay {
19 > readonly customizationDirectory?: URI;
20 > readonly model?: ModelSelection;
21 > readonly permissionMode?: ClaudePermissionMode;
22 > readonly agent?: AgentSelection;
23 > /**
24 > * Transport the session most recently materialized under (Phase 19).
25 > * Forward-compat only — written at materialize time but NOT read for
26 > * transport resolution in v1 (transport is resolved host-level). Lets a
27 > * future per-session-transport feature land without a data migration.
28 > */
29 > readonly transport?: 'proxy' | 'native';
30 > }
31 >
32 > /**
33 > * Write view: any subset of the overlay fields. Fields left `undefined`
34 > * are not touched (only-write-on-defined semantics). Pass `null` for
35 > * `agent` to clear a previously persisted selection.
36 > */
37 > export interface IClaudeSessionOverlayUpdate {
38 > readonly customizationDirectory?: URI;
39 > readonly model?: ModelSelection;
40 > readonly permissionMode?: ClaudePermissionMode;
41 > readonly agent?: AgentSelection | null;
42 > readonly transport?: 'proxy' | 'native';
43 > }
44 >
45 > /**
46 > * Owns Claude's per-session metadata layer:
47 > *
48 > * - the three `_META_*` DB keys,
49 > * - the {@link ModelSelection} JSON codec used to persist the parallel
50 > * `{ id, config }` shape,
51 > * - the read/write helpers that open a per-call DB ref,
52 > * - the projection from {@link SDKSessionInfo} + overlay onto the
53 > * platform's {@link IAgentSessionMetadata} shape.
54 > *
55 > * One instance per {@link ClaudeAgent}: the {@link AgentProvider} id
56 > * passed at construction is the one stamped on every projected URI.
57 > *
58 > * The SDK is the source of truth for session existence; the overlay
59 > * merely decorates. External Claude CLI sessions have no overlay DB,
60 > * so {@link read} returns `{}` rather than throwing — every caller
61 > * must tolerate an empty overlay.
62 > */
63 > export class ClaudeSessionMetadataStore {
64 >
65 > private static readonly KEY_CUSTOMIZATION_DIRECTORY = 'claude.customizationDirectory';
66 > private static readonly KEY_MODEL = 'claude.model';
67 > private static readonly KEY_PERMISSION_MODE = 'claude.permissionMode';
68 > private static readonly KEY_AGENT = 'claude.agent';
69 > private static readonly KEY_TRANSPORT = 'claude.transport';
70 >
71 > constructor(
72 private readonly _provider: AgentProvider,
73 @ISessionDataService private readonly _sessionDataService: ISessionDataService,
74 ) { }
76 > /**
77 > * Persist the supplied overlay fields to the per-session DB. Mirrors
78 > * CopilotAgent's `_storeSessionMetadata` pattern
79 > * (`copilotAgent.ts:1532`): single `openDatabase` ref, `Promise.all`
80 > * batching, only-write-on-defined.
81 > */
82 > async write(session: URI, fields: IClaudeSessionOverlayUpdate): Promise<void> {
83 const dbRef = this._sessionDataService.openDatabase(session);
84 const db = dbRef.object;
108 }
109 }
111 > /**
112 > * Read all overlay fields from the per-session DB. Returns `{}` when
113 > * no DB is present (external Claude CLI session, fresh install).
114 > * Mirrors CopilotAgent's `_readSessionMetadata` (`copilotAgent.ts:1559`)
115 > * — `tryOpenDatabase` so absence is not an error, single `Promise.all`
116 > * for the parallel reads.
117 > */
118 > async read(session: URI): Promise<IClaudeSessionOverlay> {
119 const ref = await this._sessionDataService.tryOpenDatabase(session);
120 if (!ref) {
140 }
141 }
143 > /**
144 > * Project an SDK-supplied {@link SDKSessionInfo} onto the platform's
145 > * {@link IAgentSessionMetadata} shape. Pure projection — does not touch
146 > * the DB. The per-session overlay no longer contributes any projected
147 > * field, so it is not read here; the store is still consulted on the
148 > * harness's internal restoration paths (see {@link read}).
149 > */
150 > project(entry: SDKSessionInfo): IAgentSessionMetadata {
151 return {
152 session: AgentSession.uri(this._provider, entry.sessionId),
157 };
158 }
160 >
161 function parseAgentSelection(raw: string | undefined): AgentSelection | undefined {
162 if (!raw) {
173 return undefined;
174 }
176 function serializeModelSelection(model: ModelSelection): string {
177 return JSON.stringify(model);
178 }
180 function parseModelSelection(raw: string | undefined): ModelSelection | undefined {
181 if (!raw) {
src/vs/platform/agentHost/common/claudeSessionConfigKeys.ts 37 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- claudeSessionConfigKeys.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > /**
7 > * Well-known session-config keys advertised by the agent-host Claude
8 > * provider in its `resolveSessionConfig` schema.
9 > *
10 > * Claude collapses the platform's two-axis approval model
11 > * (`autoApprove` × `mode`) onto a single `permissionMode` axis matching
12 > * the Claude SDK's native `PermissionMode` (see
13 > * `@anthropic-ai/claude-agent-sdk` typings, `sdk.d.ts:1560`). The five
14 > * values mirror the SDK enum values that VS Code exposes, excluding
15 > * `dontAsk`, so that the value flowing back into `query({ permissionMode })`
16 > * requires no translation layer.
17 > *
18 > * The platform `Permissions` key (allow/deny tool lists) is reused
19 > * unchanged from `platformSessionSchema` because the Claude SDK accepts
20 > * `allowedTools` / `disallowedTools` natively.
21 > */
22 > export const enum ClaudeSessionConfigKey {
23 > /** `'permissionMode'` — Claude SDK approval mode. */
24 > PermissionMode = 'permissionMode',
25 > }
26 >
27 > /**
28 > * Permission-mode values advertised in the Claude session-config schema.
29 > */
30 > export type ClaudePermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | 'auto';
31 >
32 > /**
33 > * Single source of truth for narrowing an arbitrary runtime value to the
34 > * closed {@link ClaudePermissionMode} union. Returns `undefined` for
35 > * non-strings or unmatched strings; callers apply their own fallback.
36 > */
37 > export function narrowClaudePermissionMode(raw: unknown): ClaudePermissionMode | undefined {
38 switch (raw) {
39 case 'default':