@hop-top/kit 0.5.0-alpha.10 → 0.5.0-alpha.12
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 +42 -0
- package/README.md +4 -4
- package/dist/alias.js +3 -3
- package/dist/{chunk-T46YPHKN.js → chunk-4FMALWYB.js} +45 -45
- package/dist/{chunk-JZ22ZUFA.js → chunk-65VPWMPV.js} +4 -1
- package/dist/{chunk-YGYQUFGY.js → chunk-BXJ2J27B.js} +10 -10
- package/dist/chunk-CXBZTONY.js +65 -0
- package/dist/{chunk-K7VCKJ27.js → chunk-EE4M2UOF.js} +8 -4
- package/dist/{chunk-72XZWQX7.js → chunk-GFRAYYRD.js} +475 -162
- package/dist/{chunk-2JV3A7OP.js → chunk-IVQHLI56.js} +6 -10
- package/dist/{chunk-NLMS7HGP.js → chunk-IZ6Q4SE3.js} +3 -3
- package/dist/chunk-MFVUENZR.js +1549 -0
- package/dist/{chunk-BLS2OBIQ.js → chunk-ML7D5DWY.js} +2 -2
- package/dist/chunk-P3Y46PYF.js +138 -0
- package/dist/{chunk-GGWJRWWA.js → chunk-RYKLVOVK.js} +7 -7
- package/dist/{chunk-QPUCXQXT.js → chunk-T6OZMPPV.js} +2 -1
- package/dist/{chunk-MUIQVU6E.js → chunk-VGOA5Y7S.js} +11 -11
- package/dist/{chunk-ABQSE7AI.js → chunk-VWGP4NVJ.js} +38 -38
- package/dist/chunk-X4E5QGEB.js +171 -0
- package/dist/cli-RSRk1M36.d.ts +707 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +60 -5
- package/dist/completion.js +2 -2
- package/dist/id/index.d.ts +1 -1
- package/dist/id/index.js +4 -2
- package/dist/{index-DCe1boBz.d.ts → index-CGE5yLBj.d.ts} +1 -1
- package/dist/{index-VLDcI5NF.d.ts → index-D9zpUrpE.d.ts} +18 -6
- package/dist/index.d.ts +4 -4
- package/dist/index.js +23 -23
- package/dist/llm-anthropic.js +5 -5
- package/dist/llm-openai.js +5 -5
- package/dist/llm.js +3 -3
- package/dist/log.js +3 -3
- package/dist/mcp/index.js +3 -2
- package/dist/output.js +2 -4
- package/dist/routellm.js +6 -6
- package/dist/toolspec.js +4 -4
- package/dist/tui/index.d.ts +2 -2
- package/dist/tui/index.js +3 -3
- package/dist/{upgrade-p_zh3pvV.d.ts → upgrade-BJ2z6Oqf.d.ts} +58 -4
- package/dist/upgrade.d.ts +1 -1
- package/dist/upgrade.js +4 -2
- package/package.json +9 -9
- package/src/cli.root.conformance.test.ts +166 -0
- package/src/cli.ts +39 -0
- package/src/completion.conformance.test.ts +3 -2
- package/src/completion.test.ts +12 -0
- package/src/completion.ts +8 -3
- package/src/delegation.test.ts +299 -0
- package/src/delegation.ts +807 -0
- package/src/id/README.md +2 -2
- package/src/id/contract.test.ts +11 -8
- package/src/id/differential.test.ts +54 -0
- package/src/id/index.ts +123 -17
- package/src/mcp/bridge.test.ts +28 -0
- package/src/mcp/bridge.ts +5 -10
- package/src/plan.ts +89 -0
- package/src/policy.ts +472 -0
- package/src/sideeffect.ts +105 -0
- package/src/toolspec-manifest.ts +7 -2
- package/src/upgrade.test.ts +393 -1
- package/src/upgrade.ts +183 -25
- package/dist/chunk-GHPJJV5L.js +0 -613
- package/dist/chunk-IXVQ62NZ.js +0 -334
- package/dist/chunk-L23O2FFE.js +0 -51
- package/dist/chunk-WWUKGJB5.js +0 -90
- package/dist/cli-C5B5tnpA.d.ts +0 -400
- package/dist/{chunk-PSFYJGDG.js → chunk-K7E34Q3A.js} +2 -2
|
@@ -17,14 +17,25 @@
|
|
|
17
17
|
* ### Error handling philosophy
|
|
18
18
|
* Version checking is a best-effort, non-critical operation. Any failure —
|
|
19
19
|
* network error, bad JSON, HTTP error, filesystem error, invalid semver — is
|
|
20
|
-
* silently discarded
|
|
21
|
-
*
|
|
20
|
+
* silently discarded by `notifyIfAvailable`, which always resolves without
|
|
21
|
+
* throwing. `check()` is the strict variant: it rejects with an
|
|
22
|
+
* {@link UpgradeCheckError} so callers (e.g. `upgrade --check`) can tell a
|
|
23
|
+
* failed lookup from "up to date".
|
|
22
24
|
*
|
|
23
25
|
* ### Notice format
|
|
24
26
|
* ```
|
|
25
27
|
* \nA new release of {name} is available: v{current} → v{latest}\nhttps://github.com/{owner}/{repo}/releases/latest\n
|
|
26
28
|
* ```
|
|
27
29
|
*
|
|
30
|
+
* ### Component tags and prereleases
|
|
31
|
+
* By default the check reads `releases/latest` and strips a leading `v`.
|
|
32
|
+
* Set `tagPrefix` (e.g. `xray/v`) for a monorepo whose tags carry a
|
|
33
|
+
* component: releases are listed, tags without the prefix are ignored, and
|
|
34
|
+
* the notice links to the matching release. Set `includePrereleases` to
|
|
35
|
+
* consider prereleases; without it, prereleases are never offered. Both
|
|
36
|
+
* options list at most 3 pages of 100 releases, newest first, drafts
|
|
37
|
+
* skipped; the highest semver wins.
|
|
38
|
+
*
|
|
28
39
|
* ### Usage example
|
|
29
40
|
* ```ts
|
|
30
41
|
* import { createChecker } from '@hop-top/kit/upgrade';
|
|
@@ -67,12 +78,52 @@ interface CheckerOptions {
|
|
|
67
78
|
* @defaultValue 10_000
|
|
68
79
|
*/
|
|
69
80
|
timeout?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Tag prefix identifying this tool's releases, stripped before the semver
|
|
83
|
+
* comparison (e.g. `'xray/v'` for tags like `xray/v0.2.0`). Tags without
|
|
84
|
+
* the prefix are not candidates. Setting it lists releases instead of
|
|
85
|
+
* reading `releases/latest`, which may belong to another component.
|
|
86
|
+
* @defaultValue `''` (no prefix; `releases/latest`)
|
|
87
|
+
*/
|
|
88
|
+
tagPrefix?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Offer prereleases (e.g. `0.1.0-rc.1`) as upgrades. Setting it lists
|
|
91
|
+
* releases instead of reading `releases/latest`, which skips prereleases.
|
|
92
|
+
* @defaultValue false
|
|
93
|
+
*/
|
|
94
|
+
includePrereleases?: boolean;
|
|
95
|
+
}
|
|
96
|
+
/** Outcome of {@link Checker.check}. */
|
|
97
|
+
interface UpgradeCheckResult {
|
|
98
|
+
/** Running version, as configured. */
|
|
99
|
+
current: string;
|
|
100
|
+
/** Latest release version (no leading `v` / tag prefix). */
|
|
101
|
+
latest: string;
|
|
102
|
+
/** True when `latest` is strictly greater than `current`. */
|
|
103
|
+
updateAvailable: boolean;
|
|
104
|
+
/** Release page to link to. */
|
|
105
|
+
url: string;
|
|
106
|
+
}
|
|
107
|
+
/** Rejection of {@link Checker.check}; the underlying error is in `cause`. */
|
|
108
|
+
declare class UpgradeCheckError extends Error {
|
|
109
|
+
constructor(message: string, options?: {
|
|
110
|
+
cause?: unknown;
|
|
111
|
+
});
|
|
70
112
|
}
|
|
71
113
|
/**
|
|
72
114
|
* Returned by {@link createChecker}. Call {@link Checker.notifyIfAvailable}
|
|
73
115
|
* at the end of a CLI command to surface upgrade notices non-intrusively.
|
|
74
116
|
*/
|
|
75
117
|
interface Checker {
|
|
118
|
+
/**
|
|
119
|
+
* Looks up the latest release and resolves with the outcome. Unlike
|
|
120
|
+
* {@link Checker.notifyIfAvailable} it never swallows failures: network,
|
|
121
|
+
* HTTP, parse and "no matching release" errors reject with an
|
|
122
|
+
* {@link UpgradeCheckError}, so callers can tell a failed lookup from
|
|
123
|
+
* "up to date". Honours `tagPrefix`, `includePrereleases` and the cache;
|
|
124
|
+
* pass `cacheTTL: 0` to bypass the cache.
|
|
125
|
+
*/
|
|
126
|
+
check(): Promise<UpgradeCheckResult>;
|
|
76
127
|
/**
|
|
77
128
|
* Checks for a newer GitHub release and writes a one-line notice to `out`
|
|
78
129
|
* if one is available. Silently swallows all errors.
|
|
@@ -94,9 +145,12 @@ declare function createChecker(opts: CheckerOptions): Checker;
|
|
|
94
145
|
|
|
95
146
|
type upgrade_Checker = Checker;
|
|
96
147
|
type upgrade_CheckerOptions = CheckerOptions;
|
|
148
|
+
type upgrade_UpgradeCheckError = UpgradeCheckError;
|
|
149
|
+
declare const upgrade_UpgradeCheckError: typeof UpgradeCheckError;
|
|
150
|
+
type upgrade_UpgradeCheckResult = UpgradeCheckResult;
|
|
97
151
|
declare const upgrade_createChecker: typeof createChecker;
|
|
98
152
|
declare namespace upgrade {
|
|
99
|
-
export { type upgrade_Checker as Checker, type upgrade_CheckerOptions as CheckerOptions, upgrade_createChecker as createChecker };
|
|
153
|
+
export { type upgrade_Checker as Checker, type upgrade_CheckerOptions as CheckerOptions, upgrade_UpgradeCheckError as UpgradeCheckError, type upgrade_UpgradeCheckResult as UpgradeCheckResult, upgrade_createChecker as createChecker };
|
|
100
154
|
}
|
|
101
155
|
|
|
102
|
-
export { type Checker as C, type CheckerOptions as a, createChecker as c, upgrade as u };
|
|
156
|
+
export { type Checker as C, UpgradeCheckError as U, type CheckerOptions as a, type UpgradeCheckResult as b, createChecker as c, upgrade as u };
|
package/dist/upgrade.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as Checker, a as CheckerOptions, c as createChecker } from './upgrade-
|
|
1
|
+
export { C as Checker, a as CheckerOptions, U as UpgradeCheckError, b as UpgradeCheckResult, c as createChecker } from './upgrade-BJ2z6Oqf.js';
|
package/dist/upgrade.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
var _chunkX4E5QGEBjs = require('./chunk-X4E5QGEB.js');
|
|
4
5
|
require('./chunk-R5U7XKVJ.js');
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
exports.UpgradeCheckError = _chunkX4E5QGEBjs.UpgradeCheckError; exports.createChecker = _chunkX4E5QGEBjs.createChecker;
|
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.12",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/hop-top/poly-kit.git",
|
|
@@ -291,18 +291,17 @@
|
|
|
291
291
|
"@connectrpc/connect": "^2.2.0",
|
|
292
292
|
"@connectrpc/connect-web": "^2.2.0",
|
|
293
293
|
"@hop-top/cite": "^0.1.2",
|
|
294
|
-
"@modelcontextprotocol/core": "2.
|
|
295
|
-
"@modelcontextprotocol/server": "2.
|
|
294
|
+
"@modelcontextprotocol/core": "2.4.0",
|
|
295
|
+
"@modelcontextprotocol/server": "2.4.0",
|
|
296
296
|
"better-sqlite3": "^12.11.1",
|
|
297
297
|
"commander": "15.0.0",
|
|
298
298
|
"csv-stringify": "^6.9.0",
|
|
299
299
|
"eta": "^4.6.0",
|
|
300
|
-
"hono": "^4.13.
|
|
300
|
+
"hono": "^4.13.16",
|
|
301
301
|
"js-yaml": "^4.3.2",
|
|
302
302
|
"picomatch": "^4.0.7",
|
|
303
303
|
"pino": "^10.4.0",
|
|
304
304
|
"semver": "^7.8.5",
|
|
305
|
-
"typeid-js": "^1.2.0",
|
|
306
305
|
"zod": "^4.6.7"
|
|
307
306
|
},
|
|
308
307
|
"devDependencies": {
|
|
@@ -312,12 +311,13 @@
|
|
|
312
311
|
"@types/picomatch": "^4.0.3",
|
|
313
312
|
"@types/semver": "^7.8.0",
|
|
314
313
|
"esbuild": "^0.28.2",
|
|
315
|
-
"eslint": "^10.
|
|
314
|
+
"eslint": "^10.13.0",
|
|
316
315
|
"tsup": "^8",
|
|
316
|
+
"typeid-js": "^1.2.0",
|
|
317
317
|
"typescript": "^5",
|
|
318
|
-
"typescript-eslint": "^8.
|
|
319
|
-
"vite": "^8.3.
|
|
320
|
-
"vitest": "^5.0.
|
|
318
|
+
"typescript-eslint": "^8.72.1",
|
|
319
|
+
"vite": "^8.3.5",
|
|
320
|
+
"vitest": "^5.0.5"
|
|
321
321
|
},
|
|
322
322
|
"engines": {
|
|
323
323
|
"node": ">=22.12"
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Runs the delegation slice of the shared corpus in contracts/cli-root-v1.
|
|
2
|
+
// The vectors are the source of truth: a failure means this port drifted
|
|
3
|
+
// from the contract (Go is canonical), not that a vector should be edited.
|
|
4
|
+
//
|
|
5
|
+
// This port implements the delegation gates (--confirm, --confirm-token,
|
|
6
|
+
// --max-ops, --policy, --dry-run) and the side-effect inference. Every case
|
|
7
|
+
// is either replayed or listed in a skip table with a reason; a case that
|
|
8
|
+
// is neither fails the run, so nothing is skipped silently.
|
|
9
|
+
|
|
10
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { tmpdir } from 'node:os';
|
|
12
|
+
import { dirname, join } from 'node:path';
|
|
13
|
+
import { Command, CommanderError } from 'commander';
|
|
14
|
+
import { describe, expect, it } from 'vitest';
|
|
15
|
+
|
|
16
|
+
import { createCLI } from './cli';
|
|
17
|
+
import { dryRunApplied, noPrompt, scriptedPrompt } from './delegation';
|
|
18
|
+
import { defaultPolicyLoader } from './policy';
|
|
19
|
+
|
|
20
|
+
const CORPUS = join(__dirname, '..', '..', '..', 'contracts', 'cli-root-v1', 'vectors.json');
|
|
21
|
+
|
|
22
|
+
interface Flag { long: string; help?: string; type?: string }
|
|
23
|
+
interface Cmd {
|
|
24
|
+
name: string;
|
|
25
|
+
about: string;
|
|
26
|
+
side_effect?: string;
|
|
27
|
+
annotations?: Record<string, string>;
|
|
28
|
+
dry_run?: string;
|
|
29
|
+
kind?: string;
|
|
30
|
+
flags?: Flag[];
|
|
31
|
+
commands?: Cmd[];
|
|
32
|
+
}
|
|
33
|
+
interface Tree {
|
|
34
|
+
program: string;
|
|
35
|
+
commands: Cmd[];
|
|
36
|
+
fixtures?: Record<string, string>;
|
|
37
|
+
policy?: boolean;
|
|
38
|
+
}
|
|
39
|
+
interface Case {
|
|
40
|
+
name: string;
|
|
41
|
+
tree: string;
|
|
42
|
+
args: string[];
|
|
43
|
+
exit: number;
|
|
44
|
+
stdout?: string | null;
|
|
45
|
+
stdout_contains?: string[];
|
|
46
|
+
stderr_contains?: string[];
|
|
47
|
+
stderr_json?: Record<string, unknown>;
|
|
48
|
+
prompt_answer?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const file = JSON.parse(readFileSync(CORPUS, 'utf8')) as { version: string; trees: Record<string, Tree>; cases: Case[] };
|
|
52
|
+
|
|
53
|
+
/** Trees the delegation slice replays; every other tree is skipped whole. */
|
|
54
|
+
const REPLAYED = new Set(['ops', 'infer']);
|
|
55
|
+
|
|
56
|
+
const TREE_SKIP =
|
|
57
|
+
'outside the delegation slice: needs root-flag, alias, validate, signature or config features this port lacks';
|
|
58
|
+
|
|
59
|
+
/** Cases of a replayed tree that need a feature the TS CLI lacks. */
|
|
60
|
+
const CASE_SKIP: Array<[RegExp, string]> = [
|
|
61
|
+
[/^(chdir|no chdir)/, '-C/--chdir resolver not ported'],
|
|
62
|
+
[/^config /, '-c/--config layering and the cfg command not ported'],
|
|
63
|
+
[/^flag validator/, 'flag validators not ported'],
|
|
64
|
+
[
|
|
65
|
+
/^a malformed annotation is not inferred over$/,
|
|
66
|
+
'TS validates side-effect tiers at run time with no disable_validate; Go runs this tree with validation off',
|
|
67
|
+
],
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
function skipReason(c: Case): string | undefined {
|
|
71
|
+
if (!REPLAYED.has(c.tree)) return TREE_SKIP;
|
|
72
|
+
return CASE_SKIP.find(([re]) => re.test(c.name))?.[1];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function addCmd(parent: Command, c: Cmd, prefix: string, ran: { value: boolean }): void {
|
|
76
|
+
const path = `${prefix} ${c.name}`.trim();
|
|
77
|
+
const cmd = parent.command(c.name).description(c.about);
|
|
78
|
+
cmd.exitOverride();
|
|
79
|
+
for (const f of c.flags ?? []) cmd.option(f.type === 'bool' ? `--${f.long}` : `--${f.long} <v>`, f.help ?? '');
|
|
80
|
+
const ann: Record<string, string> = { ...(c.annotations ?? {}) };
|
|
81
|
+
if (c.side_effect) ann['kit/side-effect'] = c.side_effect;
|
|
82
|
+
if (c.dry_run === 'opted-out') ann['kit/dry-run'] = 'opted-out';
|
|
83
|
+
(cmd as unknown as { annotations: Record<string, string> }).annotations = ann;
|
|
84
|
+
if ((c.commands ?? []).length > 0) {
|
|
85
|
+
for (const s of c.commands ?? []) addCmd(cmd, s, path, ran);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
cmd.argument('[args...]');
|
|
89
|
+
cmd.action(() => {
|
|
90
|
+
ran.value = true;
|
|
91
|
+
cmd.configureOutput().writeOut?.(`${JSON.stringify({ dry_run: dryRunApplied(cmd), path })}\n`);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function run(c: Case): { code: number; out: string; err: string } {
|
|
96
|
+
const t = file.trees[c.tree]!;
|
|
97
|
+
const tmp = mkdtempSync(join(tmpdir(), 'cli-root-'));
|
|
98
|
+
const sub = (s: string): string => s.split('{tmp}').join(tmp);
|
|
99
|
+
const saved = process.env['XDG_CONFIG_HOME'];
|
|
100
|
+
try {
|
|
101
|
+
for (const [name, body] of Object.entries(t.fixtures ?? {})) {
|
|
102
|
+
const p = join(tmp, name);
|
|
103
|
+
if (name.endsWith('/')) mkdirSync(p, { recursive: true });
|
|
104
|
+
else {
|
|
105
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
106
|
+
writeFileSync(p, sub(body));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
process.env['XDG_CONFIG_HOME'] = join(tmp, 'xdg');
|
|
110
|
+
const { program } = createCLI({
|
|
111
|
+
name: t.program,
|
|
112
|
+
version: '1.2.3',
|
|
113
|
+
description: 'Kit app',
|
|
114
|
+
promptSource: c.prompt_answer !== undefined ? scriptedPrompt([c.prompt_answer]) : noPrompt,
|
|
115
|
+
policy: t.policy ? defaultPolicyLoader(t.program) : undefined,
|
|
116
|
+
});
|
|
117
|
+
let out = '';
|
|
118
|
+
let err = '';
|
|
119
|
+
program.exitOverride();
|
|
120
|
+
program.configureOutput({ writeOut: (s) => { out += s; }, writeErr: (s) => { err += s; } });
|
|
121
|
+
const ran = { value: false };
|
|
122
|
+
for (const cc of t.commands) addCmd(program, cc, '', ran);
|
|
123
|
+
let code = 0;
|
|
124
|
+
try {
|
|
125
|
+
program.parse(['node', t.program, ...c.args.map(sub)]);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
if (!(e instanceof CommanderError)) throw e;
|
|
128
|
+
code = e.exitCode;
|
|
129
|
+
}
|
|
130
|
+
return { code, out, err };
|
|
131
|
+
} finally {
|
|
132
|
+
if (saved === undefined) delete process.env['XDG_CONFIG_HOME'];
|
|
133
|
+
else process.env['XDG_CONFIG_HOME'] = saved;
|
|
134
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
describe('cli-root-v1 corpus (delegation slice)', () => {
|
|
139
|
+
it('is version v1', () => expect(file.version).toBe('v1'));
|
|
140
|
+
|
|
141
|
+
const skipped: Array<[string, string]> = [];
|
|
142
|
+
for (const c of file.cases) {
|
|
143
|
+
const reason = skipReason(c);
|
|
144
|
+
if (reason) {
|
|
145
|
+
skipped.push([c.name, reason]);
|
|
146
|
+
it.skip(`${c.tree}: ${c.name} [skip: ${reason}]`, () => {});
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
it(`${c.tree}: ${c.name}`, () => {
|
|
150
|
+
const r = run(c);
|
|
151
|
+
expect(r.code, `exit (stderr ${r.err})`).toBe(c.exit);
|
|
152
|
+
if (typeof c.stdout === 'string') expect(r.out).toBe(c.stdout);
|
|
153
|
+
if (c.stdout === null) expect(r.out).toBe('');
|
|
154
|
+
for (const s of c.stdout_contains ?? []) expect(r.out).toContain(s);
|
|
155
|
+
for (const s of c.stderr_contains ?? []) expect(r.err).toContain(s.replace('{tmp}', ''));
|
|
156
|
+
if (c.stderr_json) {
|
|
157
|
+
const j = JSON.parse(r.err) as Record<string, unknown>;
|
|
158
|
+
for (const [k, v] of Object.entries(c.stderr_json)) expect(j[k]).toEqual(v);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
it('every skip carries a reason', () => {
|
|
164
|
+
for (const [, reason] of skipped) expect(reason.length).toBeGreaterThan(0);
|
|
165
|
+
});
|
|
166
|
+
});
|
package/src/cli.ts
CHANGED
|
@@ -32,6 +32,21 @@ import { EXIT_USAGE } from './output/error.js';
|
|
|
32
32
|
import { install as installNetPolicy, setProcessOffline } from './netpolicy.js';
|
|
33
33
|
import { installCompletionRequest } from './completion.js';
|
|
34
34
|
import './output/builtins.js';
|
|
35
|
+
import { installDelegation, type PromptSource } from './delegation.js';
|
|
36
|
+
import type { PolicyLoader } from './policy.js';
|
|
37
|
+
export { controllingTTY, destructiveToken, dryRunApplied, installConfirmTokenFlag,
|
|
38
|
+
isDryRun, noPrompt, resolveConfirmMode, resolveDryRunPolicy,
|
|
39
|
+
scriptedPrompt } from './delegation.js';
|
|
40
|
+
export type { ConfirmMode, DryRunPolicy, PromptSource, Prompter } from './delegation.js';
|
|
41
|
+
export { Engine, KIT_DEFAULT_NAME, MaxOpsExceededError, defaultPolicyLoader,
|
|
42
|
+
kitDefault, loadNamedPolicy, loadPolicy, resolvePolicyPath } from './policy.js';
|
|
43
|
+
export type { Policy, PolicyLoader, Verdict } from './policy.js';
|
|
44
|
+
export { INFERRED_TIER, SIDE_EFFECT_TIERS, destructiveNames, gateSideEffect,
|
|
45
|
+
inferredDestructive, isDestructiveLike, isDestructiveName,
|
|
46
|
+
isWriteLike } from './sideeffect.js';
|
|
47
|
+
export type { SideEffect } from './sideeffect.js';
|
|
48
|
+
export { renderPlan } from './plan.js';
|
|
49
|
+
export type { Effect, Plan } from './plan.js';
|
|
35
50
|
export { ErrOffline, OfflineError, guardFetch, isOffline, isOfflineError,
|
|
36
51
|
withOffline } from './netpolicy.js';
|
|
37
52
|
export { HintSet, hintsEnabled, renderHints, active,
|
|
@@ -333,8 +348,24 @@ export interface CLIConfig {
|
|
|
333
348
|
noColor?: boolean;
|
|
334
349
|
hints?: boolean;
|
|
335
350
|
offline?: boolean;
|
|
351
|
+
/** Drop the root `--dry-run` flag; it is then never applied. */
|
|
352
|
+
dryRun?: boolean;
|
|
336
353
|
};
|
|
337
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Resolves a named root `--policy <name>`; see {@link defaultPolicyLoader}
|
|
357
|
+
* for the `$XDG_CONFIG_HOME/<name>/policies/<policy>.yaml` loader. Unset
|
|
358
|
+
* wires none: only the reserved `kit-default` policy resolves.
|
|
359
|
+
*/
|
|
360
|
+
policy?: PolicyLoader;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* The terminal the `--confirm` prompt asks on. Defaults to the
|
|
364
|
+
* controlling terminal (`/dev/tty`); with none, an unset `--confirm`
|
|
365
|
+
* resolves to `no`.
|
|
366
|
+
*/
|
|
367
|
+
promptSource?: PromptSource;
|
|
368
|
+
|
|
338
369
|
/** Command groups for partitioned help (e.g. COMMANDS vs MANAGEMENT). */
|
|
339
370
|
groups?: Array<{
|
|
340
371
|
id: string; // e.g. "management"
|
|
@@ -813,6 +844,14 @@ export function createCLI(cfg: CLIConfig): CLIResult {
|
|
|
813
844
|
program.hook('preAction', (thisCmd) => stamp(thisCmd));
|
|
814
845
|
}
|
|
815
846
|
|
|
847
|
+
// Delegation gates: --dry-run, --confirm, --max-ops, --policy and the
|
|
848
|
+
// hooks enforcing them on every runnable leaf.
|
|
849
|
+
installDelegation(program, {
|
|
850
|
+
policy: cfg.policy,
|
|
851
|
+
promptSource: cfg.promptSource,
|
|
852
|
+
disableDryRun: cfg.disable?.dryRun === true,
|
|
853
|
+
});
|
|
854
|
+
|
|
816
855
|
// Stackable verbosity count flag (-VV = 2). The shorthand comes from the
|
|
817
856
|
// parity contract's verbosity block; commander takes the option spec as a
|
|
818
857
|
// runtime string, so it need not be a literal.
|
|
@@ -12,6 +12,7 @@ import { Command } from 'commander';
|
|
|
12
12
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
13
13
|
|
|
14
14
|
import { AliasStore, bridgeAliases, findCommand } from './alias';
|
|
15
|
+
import { createCLI } from './cli';
|
|
15
16
|
import { bindArgs, bindFlag, completeRequest, completionCommand } from './completion';
|
|
16
17
|
|
|
17
18
|
import {
|
|
@@ -184,11 +185,11 @@ function walk(cmd: Command, fn: (c: Command) => void): void {
|
|
|
184
185
|
for (const c of cmd.commands) walk(c, fn);
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
/** A kit root as the Go runner builds it
|
|
188
|
+
/** A kit root as the Go runner builds it (createCLI: persistent root flags included). */
|
|
188
189
|
function buildRoot(t: Tree): Command {
|
|
189
190
|
strictKeys(t, ['program', 'about', 'commands', 'aliases', 'flag_enums',
|
|
190
191
|
'flag_completers', 'arg_completers'], t.program);
|
|
191
|
-
const program =
|
|
192
|
+
const { program } = createCLI({ name: t.program, version: '1.0.0', description: t.about });
|
|
192
193
|
for (const c of t.commands) program.addCommand(buildCommand(c));
|
|
193
194
|
const store = new AliasStore('');
|
|
194
195
|
for (const [name, target] of Object.entries(t.aliases)) store.set(name, target);
|
package/src/completion.test.ts
CHANGED
|
@@ -192,6 +192,18 @@ describe('bindFlag / bindArgs', () => {
|
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
+
describe('root flags below the root', () => {
|
|
196
|
+
it('a subcommand inherits persistent root flags but not the local version flag', async () => {
|
|
197
|
+
const { program } = createCLI({ name: 'tool', version: '1.0.0', description: 'd' });
|
|
198
|
+
program.command('deploy').description('Deploy');
|
|
199
|
+
const sub = (await request(program, ['deploy', '--'], true)).out.split('\n');
|
|
200
|
+
expect(sub).toContain('--quiet');
|
|
201
|
+
expect(sub).not.toContain('--version');
|
|
202
|
+
const root = (await request(program, ['--ver'], true)).out.split('\n');
|
|
203
|
+
expect(root).toContain('--version');
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
195
207
|
describe('__complete requests', () => {
|
|
196
208
|
afterEach(() => {
|
|
197
209
|
vi.restoreAllMocks();
|
package/src/completion.ts
CHANGED
|
@@ -461,8 +461,9 @@ function toFlag(o: Option, owner: Command, root: Command, inherited: boolean): F
|
|
|
461
461
|
/**
|
|
462
462
|
* The flags of the last command of `chain`, as commander accepts them:
|
|
463
463
|
* ancestors' options (unless an ancestor has positional options), then
|
|
464
|
-
* its own plus its help option
|
|
465
|
-
* own, only help
|
|
464
|
+
* its own plus its help option (a root's version flag stays local to it).
|
|
465
|
+
* A root-alias shim takes no flags of its own, only help, plus the
|
|
466
|
+
* root's persistent flags like any child.
|
|
466
467
|
*/
|
|
467
468
|
function flagsOf(root: Command, chain: Command[]): Flag[] {
|
|
468
469
|
const cmd = chain[chain.length - 1]!;
|
|
@@ -470,7 +471,11 @@ function flagsOf(root: Command, chain: Command[]): Flag[] {
|
|
|
470
471
|
for (let i = chain.length - 2; i >= 0; i--) {
|
|
471
472
|
const anc = chain[i]!;
|
|
472
473
|
if (internals(anc)._enablePositionalOptions) break;
|
|
473
|
-
|
|
474
|
+
// cobra's version flag is local to the root: never inherited.
|
|
475
|
+
for (const o of anc.options) {
|
|
476
|
+
if (internals(anc)._versionOptionName === o.attributeName()) continue;
|
|
477
|
+
out.push(toFlag(o, anc, root, true));
|
|
478
|
+
}
|
|
474
479
|
}
|
|
475
480
|
if (isShim(root, cmd)) {
|
|
476
481
|
out.push({
|