tree-cluster-architecture
Skill33 starsChanged 5 days agoMITView on GitHub
Patterns for cluster nodes and tree data providers in vscode-documentdb. Use when adding or changing a cluster tree item, discovery provider, Connections/Azure/Discovery tree hierarchy, tree/list mode, cluster identity, treeId/clusterId lookup, Collection View import/export resolution, reveal behavior, credentials, shell actions, or copy connection string support.
In this repository17 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- detecting-accessibility-issuesSkill
- backportSkill
- documentation-screenshotsSkill
- error-translationSkill
- flagging-fresh-dependenciesSkill
- fluentuiSkill
- leadSkill
- prepare-pull-requestSkill
- previewing-docs-siteSkill
- react-webview-architectureSkill
- review-external-prSkill
- skill-creatorSkill
- telemetry-instrumentationSkill
- ux-pr-reviewSkill
- webview-trpc-messagingSkill
- writing-release-notesSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
19 rules. About 0 are common, 8 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill whenever a tree node represents a database cluster or a hierarchy change can move a cluster node.
- Very specific: line 12
Every browsable cluster node must extend ClusterItemBase<TModel> from src/tree/documentdb/ClusterItemBase.ts.
- Very specific: line 14
Do not implement a cluster as a plain TreeElement or createGenericElement* node.
- Very specific: line 38
Use this.cluster.clusterId for CredentialCache and ClustersClient, never this.id.
- Very specific: line 62
Never cache by treeId or this.id.
- Very specific: line 63
Never assume a stable ID is also a tree path unless the provider explicitly guarantees clusterId === treeId.
- Very specific: line 64
Never change tree construction without checking reverse lookup from clusterId.
- Distinctive: line 68
When adding a cluster hierarchy or a tree/list mode, specify these four functions before coding:
- Very specific: line 100
Do not put feature-specific ID prefixes or synthetic paths into buildFullTreePath().
- Very specific: line 107
Use one helper to build the stable suffix for both clusterId and every tree layout.
- Distinctive: line 109
Test tree and list modes separately.
- Distinctive: line 110
Do not rely on cluster display names alone when uniqueness is scoped by project, namespace, context, or source.
- Distinctive: line 125
Prefer one shared cluster-ID-to-tree-ID resolver so cluster and collection lookup cannot drift.
- Very specific: line 127
Do not silently fall back between providers or storage zones unless identity ownership is explicit.
- Distinctive: line 131
Add focused tests before considering the feature complete.
- Very specific: line 140
Use src/tree/documentdb/ClusterItemBase.test.ts as the base-behavior reference.
- Very specific: line 149
Use src/tree/connections-view/models/ConnectionClusterModel.test.ts as a reference.
- Distinctive: line 183
If a command is intentionally unavailable, gate it explicitly with context values and document why.
- Distinctive: line 187
Before approving a cluster tree change, answer yes to all:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Tree Cluster Architecture
Use this skill whenever a tree node represents a database cluster or a hierarchy change can move a cluster node.
Non-Negotiable Rule
Every browsable cluster node must extend ClusterItemBase<TModel> from src/tree/documentdb/ClusterItemBase.ts.
Do not implement a cluster as a plain TreeElement or createGenericElement* node. Hand-rolled cluster nodes silently lose shared behavior and force each feature to reimplement it:
- database and collection expansion
- credential/client cache integration
- retry and open-shell recovery nodes
- the canonical
treeItem_documentdbclustercontext tag - standard command/menu eligibility
getCredentials()used by Copy Connection String and Save/Add to Connections flows- consistent connection progress, cancellation, and error handling
Generic tree elements are appropriate for structural parents, placeholders, actions, and non-browsable state rows. When a state becomes browsable, render a ClusterItemBase subclass.
Implementing a Cluster Item
- Define a model extending
BaseClusterModel. - Construct a
TreeCluster<TModel>containing both stable identity and tree position. - Extend
ClusterItemBase<TModel>and callsuper(cluster). - Implement:
getCredentials(): Promise<EphemeralClusterCredentials | undefined>authenticateAndConnect(): Promise<ClustersClient | null>
- Optionally override:
beforeCachedClientConnect()for tunnels or reachability preparation- presentation through
descriptionOverride,tooltipOverride,iconPath, or a justifiedgetTreeItem()override
- Preserve the base context value. Add feature tags with
createContextValue([this.contextValue, ...extraTags]); never replace it with a string that omitstreeItem_documentdbcluster. - Use
this.cluster.clusterIdforCredentialCacheandClustersClient, neverthis.id.
Representative subclasses:
- Stored connection:
src/tree/connections-view/DocumentDBClusterItem.ts - Kubernetes discovery:
src/plugins/service-kubernetes/discovery-tree/documentdb/KubernetesResourceItem.ts - Atlas discovery:
src/plugins/service-atlas-mongodb/discovery-tree/AtlasClusterItem.ts - Managed synthetic cluster:
QuickStartClusterIteminsrc/tree/connections-view/LocalQuickStart/LocalQuickStartItem.ts
Dual Identity Contract
A cluster has two IDs with different ownership:
| ID | Meaning | Stability | Valid uses |
clusterId | Stable resource/cache identity | Must survive tree moves and layout changes | credentials, clients, sessions, serialized webview context, reverse lookup input |
treeId | Current hierarchical tree position | May change with folders, parents, or view mode | TreeElement.id, child IDs, reveal/navigation |
Rules:
clusterIdmust not contain/.treeIdmust represent the node's actual rendered path.viewIdmust identify the branch provider that owns the rendered node.- Child IDs derive from
treeId, using helpers such asbuildDatabaseTreeId()andbuildCollectionTreeId(). - Never cache by
treeIdorthis.id. - Never assume a stable ID is also a tree path unless the provider explicitly guarantees
clusterId === treeId. - Never change tree construction without checking reverse lookup from
clusterId.
Design Rendering and Lookup Together
When adding a cluster hierarchy or a tree/list mode, specify these four functions before coding:
- Stable identity: How is
clusterIdbuilt and made collision-safe? - Rendering: How is
treeIdbuilt in every layout? - Ownership: Which branch provider receives
viewIdandclusterIdlater? - Reverse lookup: How does that provider recover the current
treeIdand then the collection node?
The round trip must hold:
rendered cluster
-> { clusterId, treeId, viewId }
-> open Collection View with { clusterId, viewId }
-> owning provider resolves current treeId
-> provider resolves <treeId>/<database>/<collection>Connections View
Persisted connections use clusterId = storageId. Reconstruct the current folder path from storage with buildFullTreePath(); do not persist or guess an old treeId.
Synthetic nodes are not in connection storage. Their feature must own:
- an exact, side-effect-free ownership predicate
- tree path builders used by rendering and reveal code
- stable-ID-to-tree-ID resolution
The Connections provider may dispatch to that feature before falling back to persisted storage. Classify ownership before invoking feature code, so a feature resolver failure cannot break ordinary stored connections. See:
src/tree/connections-view/resolveConnectionsClusterTreeId.tssrc/tree/connections-view/LocalQuickStart/quickStartTreeIdentity.ts
Do not put feature-specific ID prefixes or synthetic paths into buildFullTreePath().
Discovery View
clusterId is provider-prefixed. The current DiscoveryBranchDataProvider removes that prefix and finds a cached tree node by its final suffix. Therefore every layout for that provider must end the cluster treeId with the same stable unprefixed suffix.
- Preserve visible hierarchy in preceding path segments.
- Use one helper to build the stable suffix for both
clusterIdand every tree layout. - Make the suffix collision-safe within the provider.
- Test tree and list modes separately.
- Do not rely on cluster display names alone when uniqueness is scoped by project, namespace, context, or source.
This suffix lookup is a current compatibility contract, not an ideal general identity mechanism. Issue #869 tracks exact stable-identity lookup. Until that changes, new Discovery providers must satisfy the suffix contract.
Azure Resources View
Direct lookup is valid only where the provider intentionally guarantees clusterId === treeId. Document that invariant and test it.
Provider Responsibilities
Branch providers must implement both when their clusters can open Collection View:
findClusterNodeByClusterId(clusterId)findCollectionByClusterId(clusterId, databaseName, collectionName)
Prefer one shared cluster-ID-to-tree-ID resolver so cluster and collection lookup cannot drift. Once the cluster node is known, use scoped child lookup to avoid expanding unrelated branches.
Do not silently fall back between providers or storage zones unless identity ownership is explicit. An owned but currently unavailable synthetic cluster should return undefined, not masquerade as a persisted connection.
Required Tests for New Cluster Nodes or Layouts
Add focused tests before considering the feature complete.
1. Base cluster behavior
- The browsable item is a
ClusterItemBasesubclass. - Its context value retains
treeItem_documentdbclusterplus feature tags. getCredentials()is implemented for commands that need connection material.- Expansion returns database nodes and base failure paths return retry/open-shell nodes as applicable.
Use src/tree/documentdb/ClusterItemBase.test.ts as the base-behavior reference.
2. Identity invariants
clusterIdis stable and slash-free.- Moving folders or switching layout changes only
treeId, notclusterId. - IDs remain unique where display names can repeat.
- Cache operations use
clusterId, nottreeId.
Use src/tree/connections-view/models/ConnectionClusterModel.test.ts as a reference.
3. Render-to-lookup round trip (mandatory)
Construct the cluster through the real parent/root item, not only as a model fixture, then assert:
expect(rendered.cluster.clusterId).toBe(expectedStableId);
expect(rendered.cluster.treeId).toBe(expectedTreePath);
expect(await provider.findClusterNodeByClusterId(rendered.cluster.clusterId)).toBe(rendered);
expect(await provider.findCollectionByClusterId(rendered.cluster.clusterId, databaseName, collectionName)).toBe(
expectedCollection,
);This test must exist for every materially different layout: root/folder, tree/list, or other synthetic hierarchy. It would have caught both the Atlas suffix mismatch and the Quick Start storage-path mismatch.
4. Ownership isolation for synthetic nodes
- Exact owned ID uses the feature resolver.
- Ordinary IDs never invoke the feature resolver.
- Owned-but-unavailable IDs do not fall through to persisted lookup.
- A feature resolver failure cannot affect ordinary persisted lookup.
Use src/tree/connections-view/resolveConnectionsClusterTreeId.test.ts as a reference.
5. Command compatibility
At minimum, verify the context contract and getCredentials() path needed by:
- Copy Connection String
- Open Shell
- Save/Add to Connections when enabled
If a command is intentionally unavailable, gate it explicitly with context values and document why; do not omit base behavior accidentally.
Review Checklist
Before approving a cluster tree change, answer yes to all:
- Browsable cluster extends
ClusterItemBase. - Base cluster context tag is preserved.
clusterId,treeId, andviewIdhave documented owners.- Credentials and clients use
clusterIdonly. - Every rendered layout has a reverse lookup strategy.
- Cluster and collection lookup share one resolver.
- Synthetic ownership is exact and isolated from stored lookup.
- IDs are collision-safe beyond display names.
- A real render-to-lookup round-trip test covers every layout.
- Standard cluster commands work or are explicitly gated off.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

