@hop-top/kit 0.5.0-alpha.4 → 0.5.0-alpha.6
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/CHANGELOG.md +19 -0
- package/README.md +8 -8
- package/dist/chunk-6RFRV4VP.js +128 -0
- package/dist/{chunk-WTYDHXPW.js → chunk-7FDIN5KE.js} +55 -20
- package/dist/chunk-GAZPYCQD.js +120 -0
- package/dist/chunk-W7ERKNSQ.js +171 -0
- package/dist/{cli-8rfITnv4.d.ts → cli-C5B5tnpA.d.ts} +1 -60
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +4 -3
- package/dist/completion-CVnPcWMZ.d.ts +32 -0
- package/dist/completion.d.ts +2 -0
- package/dist/completion.js +13 -0
- package/dist/{index-DEyjGoo2.d.ts → index-DCe1boBz.d.ts} +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +28 -16
- package/dist/log-uKjHsK-c.d.ts +62 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/output.js +4 -4
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/toolspec-DPBr18Ub.d.ts +106 -0
- package/dist/toolspec.d.ts +1 -0
- package/dist/toolspec.js +11 -0
- package/dist/tui/index.d.ts +3 -2
- package/package.json +26 -2
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.test.ts +39 -0
- package/src/cli.ts +54 -9
- package/src/index.ts +3 -0
- package/dist/{chunk-UIOOOK6M.js → chunk-IXVQ62NZ.js} +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hop-top/kit",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/hop-top/poly-kit.git",
|
|
@@ -150,6 +150,21 @@
|
|
|
150
150
|
"types": "./dist/mcp/index.d.ts",
|
|
151
151
|
"require": "./dist/mcp/index.js",
|
|
152
152
|
"default": "./dist/mcp/index.js"
|
|
153
|
+
},
|
|
154
|
+
"./log": {
|
|
155
|
+
"types": "./dist/log.d.ts",
|
|
156
|
+
"require": "./dist/log.js",
|
|
157
|
+
"default": "./dist/log.js"
|
|
158
|
+
},
|
|
159
|
+
"./completion": {
|
|
160
|
+
"types": "./dist/completion.d.ts",
|
|
161
|
+
"require": "./dist/completion.js",
|
|
162
|
+
"default": "./dist/completion.js"
|
|
163
|
+
},
|
|
164
|
+
"./toolspec": {
|
|
165
|
+
"types": "./dist/toolspec.d.ts",
|
|
166
|
+
"require": "./dist/toolspec.js",
|
|
167
|
+
"default": "./dist/toolspec.js"
|
|
153
168
|
}
|
|
154
169
|
},
|
|
155
170
|
"typesVersions": {
|
|
@@ -234,6 +249,15 @@
|
|
|
234
249
|
],
|
|
235
250
|
"mcp": [
|
|
236
251
|
"./dist/mcp/index.d.ts"
|
|
252
|
+
],
|
|
253
|
+
"log": [
|
|
254
|
+
"./dist/log.d.ts"
|
|
255
|
+
],
|
|
256
|
+
"completion": [
|
|
257
|
+
"./dist/completion.d.ts"
|
|
258
|
+
],
|
|
259
|
+
"toolspec": [
|
|
260
|
+
"./dist/toolspec.d.ts"
|
|
237
261
|
]
|
|
238
262
|
}
|
|
239
263
|
},
|
|
@@ -284,7 +308,7 @@
|
|
|
284
308
|
},
|
|
285
309
|
"license": "MIT",
|
|
286
310
|
"scripts": {
|
|
287
|
-
"build": "tsup src/index.ts src/alias.ts src/cli.ts src/output.ts src/xdg.ts src/config.ts src/sqlstore.ts src/upgrade.ts src/llm.ts src/llm-anthropic.ts src/llm-openai.ts src/routellm.ts src/tui/index.ts src/errcorrect.ts src/safety.ts src/provenance.ts src/stream.ts src/progress.ts src/auth.ts src/api.ts src/rpc.ts src/aim.ts src/netpolicy.ts src/scope.ts src/serve.ts src/telemetry/index.ts src/id/index.ts src/mcp/index.ts --format cjs --splitting --dts",
|
|
311
|
+
"build": "tsup src/index.ts src/alias.ts src/cli.ts src/output.ts src/xdg.ts src/config.ts src/sqlstore.ts src/upgrade.ts src/llm.ts src/llm-anthropic.ts src/llm-openai.ts src/routellm.ts src/tui/index.ts src/errcorrect.ts src/safety.ts src/provenance.ts src/stream.ts src/progress.ts src/auth.ts src/api.ts src/rpc.ts src/aim.ts src/netpolicy.ts src/scope.ts src/serve.ts src/telemetry/index.ts src/id/index.ts src/mcp/index.ts src/log.ts src/completion.ts src/toolspec.ts --format cjs --splitting --dts",
|
|
288
312
|
"lint": "eslint src/",
|
|
289
313
|
"lint:fix": "eslint src/ --fix",
|
|
290
314
|
"typecheck": "tsc --noEmit -p tsconfig.json && tsc -p tsconfig.test.json",
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { CommanderError } from 'commander';
|
|
3
|
+
import { createCLI, setCommandGroup } from './cli';
|
|
4
|
+
|
|
5
|
+
// "help <operand...>" resolution, matching the Go root's order:
|
|
6
|
+
// "all", then a fully-resolved command path, then a group ID, else a
|
|
7
|
+
// usage error (exit 2). A command wins over a group of the same name.
|
|
8
|
+
|
|
9
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
10
|
+
|
|
11
|
+
interface Run { out: string; err: string; code: number }
|
|
12
|
+
|
|
13
|
+
function makeCLI() {
|
|
14
|
+
const { program } = createCLI({
|
|
15
|
+
name: 'prog', version: '1.0.0', description: 'root desc',
|
|
16
|
+
groups: [
|
|
17
|
+
{ id: 'management', title: 'MANAGEMENT', hidden: true },
|
|
18
|
+
{ id: 'extras', title: 'EXTRAS' },
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
let out = '';
|
|
22
|
+
let err = '';
|
|
23
|
+
program.exitOverride();
|
|
24
|
+
program.configureOutput({
|
|
25
|
+
writeOut: (s: string) => { out += s; },
|
|
26
|
+
writeErr: (s: string) => { err += s; },
|
|
27
|
+
});
|
|
28
|
+
program.command('map').alias('mp').description('Map things')
|
|
29
|
+
.option('--deep', 'Map recursively');
|
|
30
|
+
const remote = program.command('remote').description('Manage remotes');
|
|
31
|
+
remote.command('add').description('Add a remote')
|
|
32
|
+
.option('--fetch', 'Fetch after adding');
|
|
33
|
+
setCommandGroup(program.command('config').description('Manage config'), 'management');
|
|
34
|
+
// Command sharing its name with a group ID.
|
|
35
|
+
program.command('extras').description('Extras command');
|
|
36
|
+
return {
|
|
37
|
+
program,
|
|
38
|
+
run(args: string[]): Run {
|
|
39
|
+
let code = -1;
|
|
40
|
+
// Group help is signalled through process.argv; keep it local.
|
|
41
|
+
const argv = process.argv;
|
|
42
|
+
process.argv = [...argv];
|
|
43
|
+
try {
|
|
44
|
+
program.parse(args, { from: 'user' });
|
|
45
|
+
code = 0;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
if (!(e instanceof CommanderError)) throw e;
|
|
48
|
+
code = e.exitCode;
|
|
49
|
+
} finally {
|
|
50
|
+
process.argv = argv;
|
|
51
|
+
}
|
|
52
|
+
return { out: out.replace(ANSI, ''), err: err.replace(ANSI, ''), code };
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe('help <command> subcommand', () => {
|
|
58
|
+
it('help <command> prints that command\'s help, not root help', () => {
|
|
59
|
+
const r = makeCLI().run(['help', 'map']);
|
|
60
|
+
expect(r.code).toBe(0);
|
|
61
|
+
expect(r.out).toContain('Usage: prog map');
|
|
62
|
+
expect(r.out).toContain('--deep');
|
|
63
|
+
expect(r.out).not.toContain('COMMANDS:');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('help <alias> resolves to the aliased command', () => {
|
|
67
|
+
const r = makeCLI().run(['help', 'mp']);
|
|
68
|
+
expect(r.code).toBe(0);
|
|
69
|
+
expect(r.out).toContain('Usage: prog map');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('help <a> <b> prints nested command help', () => {
|
|
73
|
+
const r = makeCLI().run(['help', 'remote', 'add']);
|
|
74
|
+
expect(r.code).toBe(0);
|
|
75
|
+
expect(r.out).toContain('Usage: prog remote add');
|
|
76
|
+
expect(r.out).toContain('--fetch');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('help <group> still prints group help', () => {
|
|
80
|
+
const r = makeCLI().run(['help', 'management']);
|
|
81
|
+
expect(r.code).toBe(0);
|
|
82
|
+
expect(r.out).toContain('MANAGEMENT:');
|
|
83
|
+
expect(r.out).toContain('config');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('command wins over a group of the same name', () => {
|
|
87
|
+
const r = makeCLI().run(['help', 'extras']);
|
|
88
|
+
expect(r.code).toBe(0);
|
|
89
|
+
expect(r.out).toContain('Usage: prog extras');
|
|
90
|
+
expect(r.out).not.toContain('EXTRAS:');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('unknown topic is a usage error (exit 2)', () => {
|
|
94
|
+
const r = makeCLI().run(['help', 'nosuch']);
|
|
95
|
+
expect(r.code).toBe(2);
|
|
96
|
+
expect(r.err).toContain('unknown help topic \'nosuch\'');
|
|
97
|
+
expect(r.out).not.toContain('Usage: prog');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('partial path is a usage error, not parent help', () => {
|
|
101
|
+
const r = makeCLI().run(['help', 'remote', 'nosuch']);
|
|
102
|
+
expect(r.code).toBe(2);
|
|
103
|
+
expect(r.err).toContain('unknown help topic \'remote nosuch\'');
|
|
104
|
+
});
|
|
105
|
+
});
|
package/src/cli.test.ts
CHANGED
|
@@ -247,6 +247,45 @@ describe('help structure — line-by-line parity', () => {
|
|
|
247
247
|
});
|
|
248
248
|
});
|
|
249
249
|
|
|
250
|
+
describe('help ARGUMENTS section', () => {
|
|
251
|
+
/** Plain help lines for a `gen` command with the given arguments. */
|
|
252
|
+
function genHelpLines(withDescriptions: boolean): string[] {
|
|
253
|
+
const { program } = createCLI({ name: 'mytool', version: '1.2.3', description: 'A tool' });
|
|
254
|
+
const gen = program.command('gen').description('Generate');
|
|
255
|
+
if (withDescriptions) {
|
|
256
|
+
gen.argument('<shell>', 'shell to generate for')
|
|
257
|
+
.argument('[out]', 'output path');
|
|
258
|
+
} else {
|
|
259
|
+
gen.argument('<shell>').argument('[out]');
|
|
260
|
+
}
|
|
261
|
+
gen.option('--force', 'overwrite');
|
|
262
|
+
return stripANSI(gen.helpInformation()).split('\n');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
it('lists described arguments with their descriptions', () => {
|
|
266
|
+
const lines = genHelpLines(true);
|
|
267
|
+
const argIdx = lines.findIndex(l => l.trim() === 'ARGUMENTS:');
|
|
268
|
+
expect(argIdx).toBeGreaterThanOrEqual(0);
|
|
269
|
+
expect(lines[argIdx + 1]).toMatch(/^\s+shell\s+shell to generate for$/);
|
|
270
|
+
expect(lines[argIdx + 2]).toMatch(/^\s+out\s+output path$/);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('ARGUMENTS: appears after the description and before FLAGS:', () => {
|
|
274
|
+
const lines = genHelpLines(true);
|
|
275
|
+
const descIdx = lines.findIndex(l => l.trim() === 'Generate');
|
|
276
|
+
const argIdx = lines.findIndex(l => l.trim() === 'ARGUMENTS:');
|
|
277
|
+
const flagIdx = lines.findIndex(l => l.trim() === 'FLAGS:');
|
|
278
|
+
expect(descIdx).toBeLessThan(argIdx);
|
|
279
|
+
expect(argIdx).toBeLessThan(flagIdx);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('omits ARGUMENTS: when no argument has a description', () => {
|
|
283
|
+
const lines = genHelpLines(false);
|
|
284
|
+
expect(lines.some(l => l.trim() === 'ARGUMENTS:')).toBe(false);
|
|
285
|
+
expect(lines.some(l => l.trim() === 'Arguments:')).toBe(false);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
250
289
|
describe('CLIConfig disable', () => {
|
|
251
290
|
it('disable.format=true → no format key in opts after parse', () => {
|
|
252
291
|
const { program } = createCLI({
|
package/src/cli.ts
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
import { Command, Help } from 'commander';
|
|
29
29
|
import { parity, type ParityData } from './tui/parity.js';
|
|
30
30
|
import { registerOutputFlags } from './output/flags.js';
|
|
31
|
+
import { EXIT_USAGE } from './output/error.js';
|
|
31
32
|
import { install as installNetPolicy, setProcessOffline } from './netpolicy.js';
|
|
32
33
|
import './output/builtins.js';
|
|
33
34
|
export { ErrOffline, OfflineError, guardFetch, isOffline, isOfflineError,
|
|
@@ -556,6 +557,21 @@ export function applyHelpTheme(
|
|
|
556
557
|
output.push('');
|
|
557
558
|
}
|
|
558
559
|
|
|
560
|
+
// Arguments — only listed when at least one carries a description
|
|
561
|
+
// (Commander's visibleArguments rule); title from parity.json.
|
|
562
|
+
const argList = helper.visibleArguments(cmd);
|
|
563
|
+
if (argList.length > 0) {
|
|
564
|
+
const title = parity.help.sections?.['arguments']?.title ?? 'ARGUMENTS';
|
|
565
|
+
output.push(helper.styleTitle(`${title}:`));
|
|
566
|
+
for (const a of argList) {
|
|
567
|
+
output.push(callFormatItem(
|
|
568
|
+
helper.styleArgumentTerm(helper.argumentTerm(a)),
|
|
569
|
+
helper.styleArgumentDescription(helper.argumentDescription(a)),
|
|
570
|
+
));
|
|
571
|
+
}
|
|
572
|
+
output.push('');
|
|
573
|
+
}
|
|
574
|
+
|
|
559
575
|
// Collect sections in parity order.
|
|
560
576
|
const helpSections: { name: string; items: string[] }[] = [];
|
|
561
577
|
|
|
@@ -691,6 +707,22 @@ export function applyHelpTheme(
|
|
|
691
707
|
});
|
|
692
708
|
}
|
|
693
709
|
|
|
710
|
+
/**
|
|
711
|
+
* Resolves operands as a command path below root, matching names and
|
|
712
|
+
* aliases. Only a fully-resolved path counts: "remote nosuch" names no
|
|
713
|
+
* command rather than falling back to "remote".
|
|
714
|
+
*/
|
|
715
|
+
function findHelpTarget(root: Command, operands: string[]): Command | undefined {
|
|
716
|
+
let cmd: Command | undefined;
|
|
717
|
+
let scope = root;
|
|
718
|
+
for (const word of operands) {
|
|
719
|
+
cmd = scope.commands.find(c => c.name() === word || c.aliases().includes(word));
|
|
720
|
+
if (!cmd) return undefined;
|
|
721
|
+
scope = cmd;
|
|
722
|
+
}
|
|
723
|
+
return cmd;
|
|
724
|
+
}
|
|
725
|
+
|
|
694
726
|
// ---------------------------------------------------------------------------
|
|
695
727
|
// Factory
|
|
696
728
|
// ---------------------------------------------------------------------------
|
|
@@ -810,21 +842,34 @@ export function createCLI(cfg: CLIConfig): CLIResult {
|
|
|
810
842
|
});
|
|
811
843
|
}
|
|
812
844
|
|
|
813
|
-
// help
|
|
845
|
+
// help [command | group] subcommand (hidden from default help).
|
|
846
|
+
// Operands resolve in order: "all", a fully-resolved command path
|
|
847
|
+
// (a command wins over a group of the same name), a group ID; else a
|
|
848
|
+
// usage error (exit 2).
|
|
814
849
|
if (cfg.groups && cfg.groups.length > 0) {
|
|
815
850
|
const groupIds = cfg.groups.map(g => g.id);
|
|
816
|
-
const helpCmd = program.command('help [
|
|
817
|
-
.description('Show help for a command group')
|
|
818
|
-
.action((
|
|
819
|
-
if (
|
|
820
|
-
process.argv.push('--help-all');
|
|
851
|
+
const helpCmd = program.command('help [operands...]')
|
|
852
|
+
.description('Show help for a command or command group')
|
|
853
|
+
.action((operands: string[]) => {
|
|
854
|
+
if (operands.length === 0) {
|
|
821
855
|
program.help();
|
|
822
|
-
}
|
|
823
|
-
|
|
856
|
+
}
|
|
857
|
+
if (operands.length === 1 && operands[0] === 'all') {
|
|
858
|
+
process.argv.push('--help-all');
|
|
824
859
|
program.help();
|
|
825
|
-
}
|
|
860
|
+
}
|
|
861
|
+
const target = findHelpTarget(program, operands);
|
|
862
|
+
if (target) {
|
|
863
|
+
target.help();
|
|
864
|
+
}
|
|
865
|
+
if (operands.length === 1 && groupIds.includes(operands[0]!)) {
|
|
866
|
+
process.argv.push(`--help-${operands[0]}`);
|
|
826
867
|
program.help();
|
|
827
868
|
}
|
|
869
|
+
program.error(
|
|
870
|
+
`error: unknown help topic '${operands.join(' ')}' for '${program.name()}'`,
|
|
871
|
+
{ exitCode: EXIT_USAGE, code: 'commander.unknownCommand' },
|
|
872
|
+
);
|
|
828
873
|
});
|
|
829
874
|
// Hide from default help output.
|
|
830
875
|
(helpCmd as any).hideHelp = true;
|
package/src/index.ts
CHANGED
|
@@ -17,10 +17,12 @@ export * as anthropic from './llm-anthropic.js';
|
|
|
17
17
|
export * as api from './api.js';
|
|
18
18
|
export * as auth from './auth.js';
|
|
19
19
|
export * as cli from './cli.js';
|
|
20
|
+
export * as completion from './completion.js';
|
|
20
21
|
export * as config from './config.js';
|
|
21
22
|
export * as errcorrect from './errcorrect.js';
|
|
22
23
|
export * as id from './id/index.js';
|
|
23
24
|
export * as llm from './llm.js';
|
|
25
|
+
export * as log from './log.js';
|
|
24
26
|
export * as mcp from './mcp/index.js';
|
|
25
27
|
export * as netpolicy from './netpolicy.js';
|
|
26
28
|
export * as openai from './llm-openai.js';
|
|
@@ -34,6 +36,7 @@ export * as scope from './scope.js';
|
|
|
34
36
|
export * as serve from './serve.js';
|
|
35
37
|
export * as stream from './stream.js';
|
|
36
38
|
export * as telemetry from './telemetry/index.js';
|
|
39
|
+
export * as toolspec from './toolspec.js';
|
|
37
40
|
export * as tui from './tui/index.js';
|
|
38
41
|
export * as upgrade from './upgrade.js';
|
|
39
42
|
export * as xdg from './xdg.js';
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
var _chunk72XZWQX7js = require('./chunk-72XZWQX7.js');
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
|
|
@@ -41,7 +42,6 @@
|
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
|
|
@@ -59,7 +59,7 @@ var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
var
|
|
62
|
+
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|