Skip to content

Add instance management commands and easy setup#98

Draft
clavery wants to merge 3 commits intomainfrom
feature/instance-management
Draft

Add instance management commands and easy setup#98
clavery wants to merge 3 commits intomainfrom
feature/instance-management

Conversation

@clavery
Copy link
Collaborator

@clavery clavery commented Jan 31, 2026

TODO: setup cli or something for initial setup (perhaps trigger when no config can be sourced and setup is run 🤔 )

Summary

  • Rename setup configsetup inspect
  • Add setup instance list to view all configured instances
  • Add setup instance create with interactive prompts for creating instance configs
  • Add setup instance remove to delete instance configurations
  • Add setup instance set-active to set the default instance

Architecture

Two Capabilities Model

The design separates two distinct capabilities that config sources can provide:

Capability Purpose Example Sources
Instance Source Stores full instance config (hostname, name, code-version) dw.json, global registry, cloud config
Credential Source Stores secrets only, linked by instance name Keychain plugin, Vault plugin

At resolution time, values merge: dw.json provides hostname + keychain provides password.

ConfigSource Interface Extension

Sources can now implement optional instance management methods:

interface ConfigSource {
  // Existing
  name: string;
  priority?: number;
  load(options: ResolveConfigOptions): ConfigLoadResult | undefined;

  // Instance Management (for dw.json-style sources)
  listInstances?(options?: ResolveConfigOptions): InstanceInfo[];
  createInstance?(options: CreateInstanceOptions & ResolveConfigOptions): void;
  removeInstance?(name: string, options?: ResolveConfigOptions): void;
  setActiveInstance?(name: string, options?: ResolveConfigOptions): void;

  // Credential Storage (for keychain-style sources)
  credentialFields?: (keyof NormalizedConfig)[];
  storeCredential?(instanceName: string, field: keyof NormalizedConfig, value: string, options?: ResolveConfigOptions): void;
  removeCredential?(instanceName: string, field: keyof NormalizedConfig, options?: ResolveConfigOptions): void;
}

Plugin Extensibility

Plugins can implement these methods to:

  1. Provide instance storage - Store instances in alternative locations (cloud config, global registry)
  2. Provide credential storage - Securely store secrets in keychains, vaults, etc.
  3. Aggregate across sources - InstanceManager class aggregates listInstances() from all sources

Example plugin implementation:

// A keychain plugin can implement:
class KeychainSource implements ConfigSource {
  name = 'keychain';
  credentialFields = ['password', 'clientSecret'];
  
  storeCredential(instanceName, field, value) {
    // Store in OS keychain keyed by instance name
  }
  
  load(options) {
    // Load credentials from keychain for the requested instance
  }
}

This PR implements DwJsonSource as the first instance source. The InstanceManager service aggregates instances from all sources that implement listInstances().

Implementation

  • Extended ConfigSource interface with optional instance management and credential storage methods
  • Implemented CRUD operations in DwJsonSource for managing the configs[] array in dw.json
  • Added InstanceManager service class to aggregate across multiple sources
  • Added mapNormalizedConfigToDwJson() function for reverse mapping
  • Exported DwJsonSource class for direct use by plugins

Test plan

  • Unit tests for dw-json CRUD functions
  • Unit tests for DwJsonSource instance methods
  • Existing tests updated for rename (setup config → setup inspect)
  • Manual testing of CLI commands:
    b2c setup inspect
    b2c setup instance list
    b2c setup instance create staging --hostname staging.example.com
    b2c setup instance set-active staging
    b2c setup instance remove staging --force

- Rename `setup config` to `setup inspect`
- Add `setup instance list` to view configured instances
- Add `setup instance create` with interactive prompts
- Add `setup instance remove` to delete instances
- Add `setup instance set-active` to set default instance

Extends ConfigSource interface with optional instance management
methods and implements CRUD operations in DwJsonSource for
managing the dw.json configs array.
@clavery clavery changed the title Add instance management commands Add instance management commands and easy setup Jan 31, 2026
- Update b2c-config skill with new command name and instance management docs
- Fix reference in b2c-custom-api-development skill
Add documentation for the new optional ConfigSource methods:
- listInstances, createInstance, removeInstance, setActiveInstance
- credentialFields, storeCredential, removeCredential

These enable plugins to provide custom instance storage (cloud config,
global registry) and secure credential storage (keychain, vault).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant