Cli Extension — Kernel Protocol reference
Defines the contract for plugins that extend the ObjectStack CLI with custom commands.
CLI Extension Protocol
Defines the contract for plugins that extend the ObjectStack CLI with custom commands. This enables third-party packages (e.g., marketplace, cloud deployment tools) to register new CLI commands via oclif's built-in plugin system.
How It Works (oclif Plugin Model)
- Declare — Plugin's
package.jsonincludes anoclifconfig section declaring its commands directory and any topics. - Discover — oclif loads a plugin that the CLI's own
package.jsonlists in bothoclif.pluginsanddependencies.@objectstack/clilists none and ships no plugin manager, soos pluginsis not a command. To add a plugin's commands toos, build anosdistribution: a package whose ownpackage.jsonlists the plugin in both places. - Load — oclif automatically discovers and registers all Command classes exported from the plugin's commands directory.
Plugin Package Contract
The plugin must be a valid oclif plugin:
// package.json of the plugin
{
"name": "@acme/plugin-marketplace",
"oclif": {
"commands": {
"strategy": "pattern",
"target": "./dist/commands",
"glob": "**\/*.js"
}
}
}Commands are standard oclif Command classes:
// src/commands/marketplace/search.ts
import { Args, Command, Flags } from '@oclif/core';
export default class MarketplaceSearch extends Command {
static override description = 'Search marketplace apps';
static override args = {
query: Args.string({ description: 'Search query', required: true }),
};
async run() {
const { args } = await this.parse(MarketplaceSearch);
// ...
}
}Migration from Commander.js
The previous plugin model required contributes.commands in the manifest
and exported Commander.js Command instances. The new model uses oclif's
native plugin system for automatic command discovery and registration.
The objectstack.config.ts plugins array no longer determines CLI commands.
Source: packages/spec/src/kernel/cli-extension.zod.ts
TypeScript Usage
import { OclifPluginConfigSchema } from '@objectstack/spec/kernel';
import type { OclifPluginConfig } from '@objectstack/spec/kernel';
// Validate data
const result = OclifPluginConfigSchema.parse(data);OclifPluginConfig
oclif plugin configuration section
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| commands | { strategy?: Enum<'pattern' | 'explicit' | 'single'>; target?: string; glob?: string } | optional | Command discovery configuration |
| topicSeparator | string | optional | Character separating topic and command names |
Nested Shape: OclifPluginConfig.commands
| Property | Type | Required | Description |
|---|---|---|---|
| strategy | Enum<'pattern' | 'explicit' | 'single'> | optional | Command discovery strategy |
| target | string | optional | Target directory for command files |
| glob | string | optional | Glob pattern for command file matching |