@kb-labs/shared-cli-ui 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +342 -0
- package/dist/debug.cjs +765 -0
- package/dist/debug.cjs.map +1 -0
- package/dist/debug.d.cts +151 -0
- package/dist/debug.d.ts +151 -0
- package/dist/debug.js +735 -0
- package/dist/debug.js.map +1 -0
- package/dist/index.cjs +2629 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1037 -0
- package/dist/index.d.ts +1037 -0
- package/dist/index.js +2516 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
package/README.md
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
# @kb-labs/shared-cli-ui
|
|
2
|
+
|
|
3
|
+
> **Shared CLI UI utilities for KB Labs projects - colors, formatting, progress indicators.** Provides command suggestions, validation, multi-CLI support, formatting utilities, and consistent UX components for CLI applications.
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+
[](https://pnpm.io/)
|
|
8
|
+
|
|
9
|
+
## 🎯 Vision & Purpose
|
|
10
|
+
|
|
11
|
+
**@kb-labs/shared-cli-ui** provides shared CLI UI utilities for KB Labs ecosystem. It includes command suggestions, validation, multi-CLI support, formatting utilities, colors, progress indicators, and consistent UX components for all CLI applications.
|
|
12
|
+
|
|
13
|
+
### What Problem Does This Solve?
|
|
14
|
+
|
|
15
|
+
- **CLI UX Consistency**: CLI tools need consistent UI - cli-ui provides shared components
|
|
16
|
+
- **Command Discovery**: Need to discover and suggest commands - cli-ui provides discovery utilities
|
|
17
|
+
- **Formatting**: Need consistent output formatting - cli-ui provides formatting utilities
|
|
18
|
+
- **Multi-CLI Support**: Need to manage multiple CLI packages - cli-ui provides multi-CLI manager
|
|
19
|
+
|
|
20
|
+
### Why Does This Package Exist?
|
|
21
|
+
|
|
22
|
+
- **Unified CLI UX**: All KB Labs CLI tools use the same UI components
|
|
23
|
+
- **Code Reuse**: Avoid duplicating CLI UI code
|
|
24
|
+
- **Consistency**: Ensure consistent user experience across CLI tools
|
|
25
|
+
- **Developer Experience**: Easy-to-use utilities for CLI development
|
|
26
|
+
|
|
27
|
+
### What Makes This Package Unique?
|
|
28
|
+
|
|
29
|
+
- **Comprehensive Utilities**: Wide range of CLI UI utilities
|
|
30
|
+
- **Multi-CLI Support**: Manage suggestions across multiple CLI packages
|
|
31
|
+
- **Command Discovery**: Automatic command discovery from manifests
|
|
32
|
+
- **Formatting**: Rich formatting utilities (tables, boxes, colors)
|
|
33
|
+
|
|
34
|
+
## 🚀 Quick Start
|
|
35
|
+
|
|
36
|
+
### Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pnpm add @kb-labs/shared-cli-ui
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Basic Usage
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { box, table, keyValue } from '@kb-labs/shared-cli-ui';
|
|
46
|
+
|
|
47
|
+
const output = box('Title', ['Line 1', 'Line 2']);
|
|
48
|
+
const tableOutput = table([['A', 'B'], ['1', '2']], ['Col1', 'Col2']);
|
|
49
|
+
const kvOutput = keyValue({ key: 'value' });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## ✨ Features
|
|
53
|
+
|
|
54
|
+
- **Command Suggestions**: Generate contextual suggestions for CLI commands
|
|
55
|
+
- **Command Validation**: Check if commands are available before suggesting them
|
|
56
|
+
- **Multi-CLI Support**: Manage suggestions across multiple CLI packages
|
|
57
|
+
- **Manifest Parsing**: Extract command information from CLI manifests
|
|
58
|
+
- **Consistent UX**: Shared UI components and styling
|
|
59
|
+
|
|
60
|
+
## Command Suggestions
|
|
61
|
+
|
|
62
|
+
### Basic Usage
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import {
|
|
66
|
+
createCommandRegistry,
|
|
67
|
+
generateDevlinkSuggestions
|
|
68
|
+
} from '@kb-labs/shared-cli-ui';
|
|
69
|
+
|
|
70
|
+
// Create a registry of available commands
|
|
71
|
+
const registry = createCommandRegistry([
|
|
72
|
+
'devlink:apply',
|
|
73
|
+
'devlink:clean',
|
|
74
|
+
'devlink:plan'
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
// Generate suggestions based on warnings
|
|
78
|
+
const suggestions = generateDevlinkSuggestions(
|
|
79
|
+
new Set(['LOCK_MISMATCH']),
|
|
80
|
+
{ undo: { available: true } },
|
|
81
|
+
registry
|
|
82
|
+
);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Multi-CLI Integration
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { MultiCLISuggestions } from '@kb-labs/shared-cli-ui';
|
|
89
|
+
|
|
90
|
+
// Create a multi-CLI manager
|
|
91
|
+
const manager = new MultiCLISuggestions();
|
|
92
|
+
|
|
93
|
+
// Register your CLI package
|
|
94
|
+
manager.registerPackage({
|
|
95
|
+
name: 'my-cli',
|
|
96
|
+
group: 'my-cli',
|
|
97
|
+
commands: myCommands,
|
|
98
|
+
priority: 80
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Generate suggestions from all registered packages
|
|
102
|
+
const suggestions = manager.generateAllSuggestions({
|
|
103
|
+
warningCodes: new Set(['MY_WARNING']),
|
|
104
|
+
undo: { available: true }
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Integration Guide
|
|
109
|
+
|
|
110
|
+
### 1. Create CLI Suggestions Module
|
|
111
|
+
|
|
112
|
+
Create a `cli-suggestions.ts` file in your CLI package:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import {
|
|
116
|
+
MultiCLISuggestions,
|
|
117
|
+
type CommandSuggestion
|
|
118
|
+
} from '@kb-labs/shared-cli-ui';
|
|
119
|
+
import { commands } from './cli.manifest.js';
|
|
120
|
+
|
|
121
|
+
export function generateMyCLISuggestions(
|
|
122
|
+
warningCodes: Set<string>,
|
|
123
|
+
context: any
|
|
124
|
+
): CommandSuggestion[] {
|
|
125
|
+
const suggestions: CommandSuggestion[] = [];
|
|
126
|
+
|
|
127
|
+
if (warningCodes.has('MY_WARNING')) {
|
|
128
|
+
suggestions.push({
|
|
129
|
+
id: 'MY_COMMAND',
|
|
130
|
+
command: 'kb my-cli command',
|
|
131
|
+
args: [],
|
|
132
|
+
description: 'Execute my command',
|
|
133
|
+
impact: 'safe',
|
|
134
|
+
when: 'MY_WARNING',
|
|
135
|
+
available: true
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return suggestions;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function createMyCLISuggestions(): MultiCLISuggestions {
|
|
143
|
+
const manager = new MultiCLISuggestions();
|
|
144
|
+
|
|
145
|
+
manager.registerPackage({
|
|
146
|
+
name: 'my-cli',
|
|
147
|
+
group: 'my-cli',
|
|
148
|
+
commands,
|
|
149
|
+
priority: 80
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return manager;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 2. Register with Main CLI
|
|
157
|
+
|
|
158
|
+
In your main CLI (e.g., devlink), register the package:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { MultiCLISuggestions } from '@kb-labs/shared-cli-ui';
|
|
162
|
+
import { createMyCLISuggestions } from '@kb-labs/my-cli/cli-suggestions';
|
|
163
|
+
|
|
164
|
+
const multiCLI = new MultiCLISuggestions();
|
|
165
|
+
|
|
166
|
+
// Register all CLI packages
|
|
167
|
+
multiCLI.registerPackage(devlinkPackage);
|
|
168
|
+
multiCLI.registerPackage(myCLIPackage);
|
|
169
|
+
|
|
170
|
+
// Generate suggestions
|
|
171
|
+
const suggestions = multiCLI.generateAllSuggestions(context);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### 3. Command Priority
|
|
175
|
+
|
|
176
|
+
Set priority for your CLI package:
|
|
177
|
+
- **100**: Core tools (devlink)
|
|
178
|
+
- **80**: Important tools (mind)
|
|
179
|
+
- **70**: Utility tools (tox)
|
|
180
|
+
- **50**: Optional tools (ai-review)
|
|
181
|
+
|
|
182
|
+
## API Reference
|
|
183
|
+
|
|
184
|
+
### CommandSuggestion
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
interface CommandSuggestion {
|
|
188
|
+
id: string;
|
|
189
|
+
command: string;
|
|
190
|
+
args: string[];
|
|
191
|
+
description: string;
|
|
192
|
+
impact: 'safe' | 'disruptive';
|
|
193
|
+
when: string;
|
|
194
|
+
available?: boolean;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### MultiCLISuggestions
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
class MultiCLISuggestions {
|
|
202
|
+
registerPackage(pkg: CLIPackage): void;
|
|
203
|
+
generateAllSuggestions(context: MultiCLIContext): CommandSuggestion[];
|
|
204
|
+
generateGroupSuggestions(group: string, context: MultiCLIContext): CommandSuggestion[];
|
|
205
|
+
getAvailableCommands(group: string): string[];
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Command Registry
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
function createCommandRegistry(commands: string[]): CommandRegistry;
|
|
213
|
+
function isCommandAvailable(command: string, registry: CommandRegistry): boolean;
|
|
214
|
+
function validateSuggestions(suggestions: CommandSuggestion[], registry: CommandRegistry): CommandSuggestion[];
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Artifacts Display
|
|
218
|
+
|
|
219
|
+
The artifacts display system provides consistent, beautiful display of generated files and artifacts across all CLI commands.
|
|
220
|
+
|
|
221
|
+
### Features
|
|
222
|
+
|
|
223
|
+
- **Consistent Formatting**: Unified display format across all CLI packages
|
|
224
|
+
- **Multiple Display Modes**: Compact, detailed, and grouped views
|
|
225
|
+
- **Smart Sorting**: By time (newest first) by default, with type and custom options
|
|
226
|
+
- **Size & Time Info**: Human-readable file sizes and relative timestamps
|
|
227
|
+
- **Path Normalization**: Shows relative paths for better readability
|
|
228
|
+
- **Federal Sorting**: All CLI packages automatically get time-based sorting
|
|
229
|
+
|
|
230
|
+
### Usage
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import {
|
|
234
|
+
displayArtifacts,
|
|
235
|
+
displayArtifactsCompact,
|
|
236
|
+
displaySingleArtifact,
|
|
237
|
+
type ArtifactInfo
|
|
238
|
+
} from '@kb-labs/shared-cli-ui';
|
|
239
|
+
|
|
240
|
+
// Define artifacts
|
|
241
|
+
const artifacts: ArtifactInfo[] = [
|
|
242
|
+
{
|
|
243
|
+
name: 'Plan',
|
|
244
|
+
path: '/path/to/.kb/devlink/last-plan.json',
|
|
245
|
+
size: 1024,
|
|
246
|
+
modified: new Date(),
|
|
247
|
+
description: 'Last generated plan'
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: 'Lock',
|
|
251
|
+
path: '/path/to/.kb/devlink/lock.json',
|
|
252
|
+
size: 2048,
|
|
253
|
+
modified: new Date(Date.now() - 3600000),
|
|
254
|
+
description: 'Dependency lock file'
|
|
255
|
+
}
|
|
256
|
+
];
|
|
257
|
+
|
|
258
|
+
// Display in compact format (for status-like displays)
|
|
259
|
+
const compactDisplay = displayArtifactsCompact(artifacts, {
|
|
260
|
+
maxItems: 5,
|
|
261
|
+
showSize: true
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Display with full details
|
|
265
|
+
const fullDisplay = displayArtifacts(artifacts, {
|
|
266
|
+
showSize: true,
|
|
267
|
+
showTime: true,
|
|
268
|
+
showDescription: true,
|
|
269
|
+
maxItems: 10,
|
|
270
|
+
title: 'Generated Files',
|
|
271
|
+
groupBy: 'type'
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// Display single artifact
|
|
275
|
+
const singleDisplay = displaySingleArtifact(artifacts[0], 'Latest Artifact');
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Display Options
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
interface ArtifactDisplayOptions {
|
|
282
|
+
showSize?: boolean; // Show file sizes (default: true)
|
|
283
|
+
showTime?: boolean; // Show modification times (default: true)
|
|
284
|
+
showDescription?: boolean; // Show descriptions (default: false)
|
|
285
|
+
maxItems?: number; // Maximum items to show (default: 10)
|
|
286
|
+
title?: string; // Section title (default: 'Generated Artifacts')
|
|
287
|
+
groupBy?: 'none' | 'type' | 'time'; // Grouping strategy (default: 'none')
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Integration in CLI Commands
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { displayArtifactsCompact } from '@kb-labs/shared-cli-ui';
|
|
295
|
+
import { discoverArtifacts } from './my-artifact-discovery';
|
|
296
|
+
|
|
297
|
+
export const run: CommandModule['run'] = async (ctx, _argv, flags) => {
|
|
298
|
+
// ... your command logic ...
|
|
299
|
+
|
|
300
|
+
// Show artifacts after operation
|
|
301
|
+
const artifacts = await discoverArtifacts(process.cwd());
|
|
302
|
+
const artifactsInfo = displayArtifactsCompact(artifacts, { maxItems: 5 });
|
|
303
|
+
|
|
304
|
+
const output = box('My Command', [
|
|
305
|
+
...summary,
|
|
306
|
+
...artifactsInfo
|
|
307
|
+
]);
|
|
308
|
+
|
|
309
|
+
ctx.presenter.write(output);
|
|
310
|
+
};
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## 📦 API Reference
|
|
314
|
+
|
|
315
|
+
### Main Exports
|
|
316
|
+
|
|
317
|
+
#### Formatting Functions
|
|
318
|
+
|
|
319
|
+
- `box(title, content)`: Create boxed section
|
|
320
|
+
- `table(rows, headers?)`: Format table
|
|
321
|
+
- `keyValue(pairs, options?)`: Format key-value pairs
|
|
322
|
+
- `indent(lines, level?)`: Add indentation
|
|
323
|
+
- `section(header, content)`: Create section
|
|
324
|
+
|
|
325
|
+
#### Command Utilities
|
|
326
|
+
|
|
327
|
+
- `createCommandRegistry(commands)`: Create command registry
|
|
328
|
+
- `MultiCLISuggestions`: Multi-CLI manager class
|
|
329
|
+
- `displayArtifacts(artifacts, options?)`: Display artifacts
|
|
330
|
+
- `displayArtifactsCompact(artifacts, options?)`: Compact artifact display
|
|
331
|
+
|
|
332
|
+
### Types & Interfaces
|
|
333
|
+
|
|
334
|
+
See detailed API documentation in code comments.
|
|
335
|
+
|
|
336
|
+
## 🤝 Contributing
|
|
337
|
+
|
|
338
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for development guidelines.
|
|
339
|
+
|
|
340
|
+
## 📄 License
|
|
341
|
+
|
|
342
|
+
MIT © KB Labs
|