@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.11
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 +275 -0
- package/LICENSE +1 -1
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +55 -259
- package/dist/aim-DZHwwiIc.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/aim.js +13 -414
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +2 -73
- package/dist/alias.js +27 -207
- package/dist/api-DAexsu2H.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/api.js +10 -164
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/auth.js +6 -40
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4FMALWYB.js +669 -0
- package/dist/chunk-4GPCWBBA.js +143 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-65VPWMPV.js +1134 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-BXJ2J27B.js +219 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-CXBZTONY.js +65 -0
- package/dist/chunk-EE4M2UOF.js +818 -0
- package/dist/chunk-GFRAYYRD.js +817 -0
- package/dist/chunk-IVQHLI56.js +1890 -0
- package/dist/chunk-IZ6Q4SE3.js +178 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-K7E34Q3A.js +1445 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MFVUENZR.js +1549 -0
- package/dist/chunk-ML7D5DWY.js +263 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RYKLVOVK.js +309 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T6OZMPPV.js +68 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-VGOA5Y7S.js +251 -0
- package/dist/chunk-VWGP4NVJ.js +513 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-RSRk1M36.d.ts +707 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +125 -945
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +3 -0
- package/dist/completion.js +34 -0
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -97
- package/dist/config.js +8 -78
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/id/index.js +14 -65
- package/dist/index-BKJZClJx.d.ts +1486 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-CGE5yLBj.d.ts +328 -0
- package/dist/index-VLDcI5NF.d.ts +95 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +132 -0
- package/dist/llm-DYuR7_uX.d.ts +1069 -0
- package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
- package/dist/llm-anthropic.d.ts +2 -0
- package/dist/llm-anthropic.js +13 -0
- package/dist/llm-openai-DyFrucmV.d.ts +87 -0
- package/dist/llm-openai.d.ts +2 -0
- package/dist/llm-openai.js +19 -0
- package/dist/llm.d.ts +1 -188
- package/dist/llm.js +101 -356
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +185 -0
- package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +25 -0
- package/dist/output-CjZWmL8s.d.ts +420 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +135 -447
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/progress.js +6 -55
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/routellm.js +13 -255
- package/dist/rpc-D31Lg0Kc.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/rpc.js +4 -98
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/safety.js +6 -43
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/scope.js +20 -377
- package/dist/serve-D8yWMrTc.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +75 -0
- package/dist/sqlstore.js +6 -39
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +26 -599
- package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
- package/dist/toolspec.d.ts +2 -0
- package/dist/toolspec.js +37 -0
- package/dist/tui/index.d.ts +6 -298
- package/dist/tui/index.js +17 -381
- package/dist/upgrade-C3RWGwRi.d.ts +125 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/upgrade.js +6 -114
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/dist/xdg.js +14 -128
- package/package.json +192 -24
- package/src/README.md +15 -0
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.root.conformance.test.ts +166 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +234 -25
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +76 -16
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +298 -0
- package/src/completion.test.ts +268 -145
- package/src/completion.ts +772 -121
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +228 -1
- package/src/config.ts +429 -16
- package/src/delegation.test.ts +299 -0
- package/src/delegation.ts +807 -0
- package/src/gen/crud_pb.ts +7 -7
- package/src/id/README.md +38 -0
- package/src/id/contract.test.ts +1 -1
- package/src/id/index.test.ts +1 -1
- package/src/id/index.ts +3 -2
- package/src/index.test.ts +71 -0
- package/src/index.ts +46 -0
- package/src/llm-anthropic.conformance.test.ts +1135 -0
- package/src/llm-anthropic.test.ts +152 -0
- package/src/llm-anthropic.ts +940 -0
- package/src/llm-choice-hermetic.test.ts +335 -0
- package/src/llm-config.test.ts +232 -0
- package/src/llm-config.ts +106 -0
- package/src/llm-endpoint.ts +254 -0
- package/src/llm-error.ts +17 -0
- package/src/llm-errors.ts +152 -0
- package/src/llm-file.ts +126 -0
- package/src/llm-http.ts +317 -0
- package/src/llm-keys.ts +167 -0
- package/src/llm-media.conformance.test.ts +87 -0
- package/src/llm-media.test.ts +279 -0
- package/src/llm-media.ts +322 -0
- package/src/llm-openai.conformance.test.ts +407 -0
- package/src/llm-openai.test.ts +510 -0
- package/src/llm-openai.ts +708 -0
- package/src/llm-payload.ts +155 -0
- package/src/llm-quote.ts +46 -0
- package/src/llm-routellm.conformance.test.ts +44 -0
- package/src/llm-toolnames.conformance.test.ts +112 -0
- package/src/llm-toolnames.test.ts +132 -0
- package/src/llm-toolnames.ts +298 -0
- package/src/llm-uri.ts +99 -0
- package/src/llm.test.ts +43 -15
- package/src/llm.toolcall.test.ts +175 -0
- package/src/llm.ts +602 -190
- package/src/log.parity.test.ts +105 -0
- package/src/log.test.ts +270 -1
- package/src/log.ts +228 -49
- package/src/mcp/README.md +63 -0
- package/src/mcp/args-separator.test.ts +164 -0
- package/src/mcp/args.test.ts +223 -0
- package/src/mcp/args.ts +160 -0
- package/src/mcp/audit.test.ts +520 -0
- package/src/mcp/audit.ts +70 -0
- package/src/mcp/bridge.test.ts +250 -0
- package/src/mcp/bridge.ts +286 -0
- package/src/mcp/conformance.test.ts +357 -0
- package/src/mcp/dispatch.ts +359 -0
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +176 -0
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +367 -0
- package/src/mcp/mcp.test.ts +707 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +484 -0
- package/src/mcp/modern.ts +788 -0
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +689 -0
- package/src/netpolicy.test.ts +280 -0
- package/src/netpolicy.ts +256 -0
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +459 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/README.md +50 -0
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +64 -3
- package/src/plan.ts +89 -0
- package/src/policy.ts +472 -0
- package/src/published-types.test.ts +133 -0
- package/src/routellm.test.ts +209 -28
- package/src/routellm.toolcall.test.ts +521 -0
- package/src/routellm.ts +213 -177
- package/src/router/README.md +44 -0
- package/src/router/server.test.ts +41 -0
- package/src/router/server.ts +11 -0
- package/src/safety.test.ts +19 -9
- package/src/scope-defaults.json +29 -29
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/sideeffect.ts +105 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +12 -6
- package/src/telemetry/offline.test.ts +64 -0
- package/src/toolspec-internal.ts +279 -0
- package/src/toolspec-manifest.test.ts +167 -0
- package/src/toolspec-manifest.ts +415 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +350 -0
- package/src/toolspec.test.ts +2 -2
- package/src/toolspec.ts +222 -0
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/src/upgrade.test.ts +291 -0
- package/src/upgrade.ts +116 -7
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/csv.test.ts +164 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +277 -0
- package/test/output/smoke-capture.ts +2 -2
- package/test/output/smoke.test.ts +2 -2
- package/test/output/taxonomy-contract.test.ts +148 -0
- package/test/setup-env.ts +16 -0
- package/test/toolspec/fixture.ts +79 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
- package/src/tui/parity.json +0 -74
|
@@ -0,0 +1,1549 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkCXBZTONYjs = require('./chunk-CXBZTONY.js');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunkGFRAYYRDjs = require('./chunk-GFRAYYRD.js');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
var _chunkT6OZMPPVjs = require('./chunk-T6OZMPPV.js');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
var _chunkKVG7YCTSjs = require('./chunk-KVG7YCTS.js');
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
var _chunk4UE5TCMQjs = require('./chunk-4UE5TCMQ.js');
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
var _chunk65VPWMPVjs = require('./chunk-65VPWMPV.js');
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
49
|
+
|
|
50
|
+
// src/cli.ts
|
|
51
|
+
var cli_exports = {};
|
|
52
|
+
_chunkR5U7XKVJjs.__export.call(void 0, cli_exports, {
|
|
53
|
+
Dark: () => Dark,
|
|
54
|
+
Engine: () => Engine,
|
|
55
|
+
ErrOffline: () => _chunkKVG7YCTSjs.ErrOffline,
|
|
56
|
+
HintSet: () => HintSet,
|
|
57
|
+
INFERRED_TIER: () => _chunkCXBZTONYjs.INFERRED_TIER,
|
|
58
|
+
KIT_DEFAULT_NAME: () => KIT_DEFAULT_NAME,
|
|
59
|
+
MaxOpsExceededError: () => MaxOpsExceededError,
|
|
60
|
+
Neon: () => Neon,
|
|
61
|
+
OfflineError: () => _chunkKVG7YCTSjs.OfflineError,
|
|
62
|
+
SIDE_EFFECT_TIERS: () => _chunkCXBZTONYjs.SIDE_EFFECT_TIERS,
|
|
63
|
+
active: () => active,
|
|
64
|
+
applyHelpTheme: () => applyHelpTheme,
|
|
65
|
+
buildTheme: () => buildTheme,
|
|
66
|
+
channel: () => channel,
|
|
67
|
+
controllingTTY: () => controllingTTY,
|
|
68
|
+
createCLI: () => createCLI,
|
|
69
|
+
defaultPolicyLoader: () => defaultPolicyLoader,
|
|
70
|
+
destructiveNames: () => _chunkCXBZTONYjs.destructiveNames,
|
|
71
|
+
destructiveToken: () => destructiveToken,
|
|
72
|
+
dryRunApplied: () => dryRunApplied,
|
|
73
|
+
gateSideEffect: () => _chunkCXBZTONYjs.gateSideEffect,
|
|
74
|
+
getCommandGroup: () => getCommandGroup,
|
|
75
|
+
getStreamDefs: () => getStreamDefs,
|
|
76
|
+
guardFetch: () => _chunkKVG7YCTSjs.guardFetch,
|
|
77
|
+
hintsEnabled: () => hintsEnabled,
|
|
78
|
+
inferredDestructive: () => _chunkCXBZTONYjs.inferredDestructive,
|
|
79
|
+
installConfirmTokenFlag: () => installConfirmTokenFlag,
|
|
80
|
+
isDestructiveLike: () => _chunkCXBZTONYjs.isDestructiveLike,
|
|
81
|
+
isDestructiveName: () => _chunkCXBZTONYjs.isDestructiveName,
|
|
82
|
+
isDryRun: () => isDryRun,
|
|
83
|
+
isOffline: () => _chunkKVG7YCTSjs.isOffline,
|
|
84
|
+
isOfflineError: () => _chunkKVG7YCTSjs.isOfflineError,
|
|
85
|
+
isQuiet: () => isQuiet,
|
|
86
|
+
isWriteLike: () => _chunkCXBZTONYjs.isWriteLike,
|
|
87
|
+
kitDefault: () => kitDefault,
|
|
88
|
+
loadNamedPolicy: () => loadNamedPolicy,
|
|
89
|
+
loadPolicy: () => loadPolicy,
|
|
90
|
+
noPrompt: () => noPrompt,
|
|
91
|
+
registerStream: () => registerStream,
|
|
92
|
+
registerUpgradeHints: () => registerUpgradeHints,
|
|
93
|
+
registerVersionHints: () => registerVersionHints,
|
|
94
|
+
renderHints: () => renderHints,
|
|
95
|
+
renderPlan: () => renderPlan,
|
|
96
|
+
resolveConfirmMode: () => resolveConfirmMode,
|
|
97
|
+
resolveDryRunPolicy: () => resolveDryRunPolicy,
|
|
98
|
+
resolvePolicyPath: () => resolvePolicyPath,
|
|
99
|
+
scriptedPrompt: () => scriptedPrompt,
|
|
100
|
+
setCommandGroup: () => setCommandGroup,
|
|
101
|
+
streamFlagName: () => streamFlagName,
|
|
102
|
+
streamLabel: () => streamLabel,
|
|
103
|
+
streamOutput: () => streamOutput,
|
|
104
|
+
verboseCount: () => verboseCount,
|
|
105
|
+
verbosityFlagSpec: () => verbosityFlagSpec,
|
|
106
|
+
verbosityShorthand: () => verbosityShorthand,
|
|
107
|
+
withOffline: () => _chunkKVG7YCTSjs.withOffline
|
|
108
|
+
});
|
|
109
|
+
var _commander = require('commander');
|
|
110
|
+
|
|
111
|
+
// src/delegation.ts
|
|
112
|
+
var _crypto = require('crypto');
|
|
113
|
+
var _fs = require('fs'); var fs2 = _interopRequireWildcard(_fs); var fs = _interopRequireWildcard(_fs);
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
// src/plan.ts
|
|
117
|
+
var _jsyaml = require('js-yaml'); var yaml = _interopRequireWildcard(_jsyaml); var yaml2 = _interopRequireWildcard(_jsyaml);
|
|
118
|
+
function rfc3339Now() {
|
|
119
|
+
return (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
120
|
+
}
|
|
121
|
+
function toWire(p, commandPath2) {
|
|
122
|
+
const w = { command: p.command || commandPath2 };
|
|
123
|
+
if (p.args && Object.keys(p.args).length > 0) w["args"] = p.args;
|
|
124
|
+
w["effects"] = (_nullishCoalesce(p.effects, () => ( []))).map((e) => {
|
|
125
|
+
const o = { kind: e.kind, target: e.target, reversible: e.reversible };
|
|
126
|
+
if (e.detail) o["detail"] = e.detail;
|
|
127
|
+
return o;
|
|
128
|
+
});
|
|
129
|
+
if (p.prerequisites_checked && p.prerequisites_checked.length > 0) {
|
|
130
|
+
w["prerequisites_checked"] = p.prerequisites_checked;
|
|
131
|
+
}
|
|
132
|
+
if (p.warnings && p.warnings.length > 0) w["warnings"] = p.warnings;
|
|
133
|
+
w["generated_at"] = p.generated_at || rfc3339Now();
|
|
134
|
+
return w;
|
|
135
|
+
}
|
|
136
|
+
function renderPlan(w, format, plan, commandPath2 = "") {
|
|
137
|
+
const wire = toWire(plan, commandPath2);
|
|
138
|
+
if (format === "json") {
|
|
139
|
+
w.write(`${JSON.stringify(wire, null, 2)}
|
|
140
|
+
`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (format === "yaml") {
|
|
144
|
+
w.write(yaml.dump(wire));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
w.write(`COMMAND ${wire["command"]}
|
|
148
|
+
`);
|
|
149
|
+
w.write(`GENERATED ${wire["generated_at"]}
|
|
150
|
+
`);
|
|
151
|
+
for (const warn of _nullishCoalesce(plan.warnings, () => ( []))) w.write(`WARNING ${warn}
|
|
152
|
+
`);
|
|
153
|
+
_chunkGFRAYYRDjs.render.call(void 0, w, _chunkGFRAYYRDjs.TABLE_FORMAT, wire["effects"]);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/policy.ts
|
|
157
|
+
|
|
158
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
159
|
+
|
|
160
|
+
var KIT_DEFAULT_NAME = "kit-default";
|
|
161
|
+
var MaxOpsExceededError = class extends Error {
|
|
162
|
+
constructor() {
|
|
163
|
+
super("policy: max-ops budget exceeded");
|
|
164
|
+
this.name = "MaxOpsExceededError";
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
function emptyPolicy() {
|
|
168
|
+
return { name: "", max_ops: 0, require_confirm: [], permissions: [], callers: [] };
|
|
169
|
+
}
|
|
170
|
+
function kitDefault() {
|
|
171
|
+
return {
|
|
172
|
+
name: KIT_DEFAULT_NAME,
|
|
173
|
+
unannotated: "write",
|
|
174
|
+
allow: { write: [], destructive: [] },
|
|
175
|
+
max_ops: 0,
|
|
176
|
+
require_confirm: [],
|
|
177
|
+
permissions: [],
|
|
178
|
+
callers: [
|
|
179
|
+
{
|
|
180
|
+
allow: { write: ["*"], destructive: ["*"] },
|
|
181
|
+
require_declared_scope: ["destructive"]
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
remedy: "kit's default beyond loopback: writes need an authenticated caller, destructive commands a declared kit/permissions scope; name a --policy to choose otherwise"
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function classOf(tier) {
|
|
188
|
+
switch (tier) {
|
|
189
|
+
case "read":
|
|
190
|
+
case "write":
|
|
191
|
+
case "destructive":
|
|
192
|
+
case "interactive":
|
|
193
|
+
return tier;
|
|
194
|
+
case "write-local":
|
|
195
|
+
case "write-shared":
|
|
196
|
+
return "write";
|
|
197
|
+
case "destructive-local":
|
|
198
|
+
case "destructive-shared":
|
|
199
|
+
return "destructive";
|
|
200
|
+
default:
|
|
201
|
+
return void 0;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function pathMatch(pattern, name) {
|
|
205
|
+
let re = "^";
|
|
206
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
207
|
+
const c = pattern[i];
|
|
208
|
+
if (c === "*") {
|
|
209
|
+
re += "[^/]*";
|
|
210
|
+
} else if (c === "?") {
|
|
211
|
+
re += "[^/]";
|
|
212
|
+
} else if (c === "\\") {
|
|
213
|
+
i++;
|
|
214
|
+
if (i >= pattern.length) return false;
|
|
215
|
+
re += escapeRe(pattern[i]);
|
|
216
|
+
} else if (c === "[") {
|
|
217
|
+
let j = i + 1;
|
|
218
|
+
let cls = "[";
|
|
219
|
+
if (pattern[j] === "^") {
|
|
220
|
+
cls += "^";
|
|
221
|
+
j++;
|
|
222
|
+
}
|
|
223
|
+
let n = 0;
|
|
224
|
+
for (; ; j++) {
|
|
225
|
+
if (j >= pattern.length) return false;
|
|
226
|
+
const d = pattern[j];
|
|
227
|
+
if (d === "]" && n > 0) break;
|
|
228
|
+
n++;
|
|
229
|
+
if (d === "\\") {
|
|
230
|
+
j++;
|
|
231
|
+
if (j >= pattern.length) return false;
|
|
232
|
+
cls += escapeRe(pattern[j]);
|
|
233
|
+
} else if (d === "-" && n > 1 && pattern[j + 1] !== "]") {
|
|
234
|
+
cls += "-";
|
|
235
|
+
} else {
|
|
236
|
+
cls += escapeRe(d);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
re += cls + "]";
|
|
240
|
+
i = j;
|
|
241
|
+
} else {
|
|
242
|
+
re += escapeRe(c);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
return new RegExp(re + "$", "s").test(name);
|
|
247
|
+
} catch (e2) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function escapeRe(c) {
|
|
252
|
+
return c.replace(/[\\^$.*+?()[\]{}|/-]/g, "\\$&");
|
|
253
|
+
}
|
|
254
|
+
function matchAny(patterns, value) {
|
|
255
|
+
for (const p of patterns) {
|
|
256
|
+
if (p === "*") return true;
|
|
257
|
+
if (pathMatch(p, value)) return true;
|
|
258
|
+
if (p.endsWith(":*")) {
|
|
259
|
+
const prefix = p.slice(0, -2);
|
|
260
|
+
if (value === prefix || value.startsWith(prefix + " ")) return true;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
function lookupClass(allow, tier) {
|
|
266
|
+
if (!allow) return void 0;
|
|
267
|
+
if (Object.prototype.hasOwnProperty.call(allow, tier)) return allow[tier];
|
|
268
|
+
const cls = classOf(tier);
|
|
269
|
+
if (cls !== void 0 && cls !== tier && Object.prototype.hasOwnProperty.call(allow, cls)) {
|
|
270
|
+
return allow[cls];
|
|
271
|
+
}
|
|
272
|
+
return void 0;
|
|
273
|
+
}
|
|
274
|
+
var Engine = class {
|
|
275
|
+
/** `maxOpsOverride > 0` takes precedence over the policy's `max_ops`. */
|
|
276
|
+
constructor(policy, maxOpsOverride = 0) {
|
|
277
|
+
this.policy = policy;
|
|
278
|
+
this.ops = 0;
|
|
279
|
+
this.max = maxOpsOverride > 0 ? maxOpsOverride : policy.max_ops;
|
|
280
|
+
}
|
|
281
|
+
maxOps() {
|
|
282
|
+
return this.max;
|
|
283
|
+
}
|
|
284
|
+
opsCount() {
|
|
285
|
+
return this.ops;
|
|
286
|
+
}
|
|
287
|
+
authorize(cmd) {
|
|
288
|
+
const se = _nullishCoalesce(cmd.sideEffect, () => ( this.policy.unannotated));
|
|
289
|
+
if (se === void 0 || se === "") return { allowed: true, requireConfirm: false, reason: "" };
|
|
290
|
+
if (se === "read") return { allowed: true, requireConfirm: false, reason: "" };
|
|
291
|
+
if (classOf(se) === void 0) {
|
|
292
|
+
return {
|
|
293
|
+
allowed: false,
|
|
294
|
+
requireConfirm: false,
|
|
295
|
+
reason: this.refusal(`policy: unknown side-effect ${JSON.stringify(se)} for ${cmd.verb}`)
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
const patterns = lookupClass(this.policy.allow, se);
|
|
299
|
+
if (patterns !== void 0 && !matchAny(patterns, cmd.verb)) {
|
|
300
|
+
return {
|
|
301
|
+
allowed: false,
|
|
302
|
+
requireConfirm: false,
|
|
303
|
+
reason: this.refusal(`policy: ${se} not allowed for ${cmd.verb}`)
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
allowed: true,
|
|
308
|
+
requireConfirm: matchAny(this.policy.require_confirm, cmd.verb),
|
|
309
|
+
reason: ""
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/** Accounts a successful mutating op; throws once the budget is hit. */
|
|
313
|
+
recordOp() {
|
|
314
|
+
this.ops++;
|
|
315
|
+
if (this.max > 0 && this.ops > this.max) throw new MaxOpsExceededError();
|
|
316
|
+
}
|
|
317
|
+
refusal(reason) {
|
|
318
|
+
const r = this.policy.remedy;
|
|
319
|
+
return r ? `${reason} (policy ${this.policy.name}: ${r})` : reason;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var VALID_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
323
|
+
function resolvePolicyPath(tool, name) {
|
|
324
|
+
if (tool === "") throw new Error("policy: tool name required for XDG resolution");
|
|
325
|
+
if (name === "") throw new Error("policy: policy name required");
|
|
326
|
+
if (!VALID_NAME.test(name)) {
|
|
327
|
+
throw new Error(`policy: invalid policy name ${JSON.stringify(name)} (want [A-Za-z0-9_-]{1,64})`);
|
|
328
|
+
}
|
|
329
|
+
return path.join(_chunk4UE5TCMQjs.configDir.call(void 0, tool), "policies", `${name}.yaml`);
|
|
330
|
+
}
|
|
331
|
+
function isRecord(v) {
|
|
332
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
333
|
+
}
|
|
334
|
+
function strList(v, what) {
|
|
335
|
+
if (v === void 0 || v === null) return [];
|
|
336
|
+
if (!Array.isArray(v) || v.some((x) => typeof x !== "string")) {
|
|
337
|
+
throw new Error(`${what}: want a list of strings`);
|
|
338
|
+
}
|
|
339
|
+
return v;
|
|
340
|
+
}
|
|
341
|
+
function allowMap(v, what) {
|
|
342
|
+
if (v === void 0 || v === null) return void 0;
|
|
343
|
+
if (!isRecord(v)) throw new Error(`${what}: want a mapping of class to patterns`);
|
|
344
|
+
const out = {};
|
|
345
|
+
for (const [k, list] of Object.entries(v)) out[k] = strList(list, `${what}.${k}`);
|
|
346
|
+
return out;
|
|
347
|
+
}
|
|
348
|
+
function int(v, what) {
|
|
349
|
+
if (v === void 0 || v === null) return 0;
|
|
350
|
+
if (typeof v !== "number" || !Number.isInteger(v)) throw new Error(`${what}: want an integer`);
|
|
351
|
+
return v;
|
|
352
|
+
}
|
|
353
|
+
function validatePermissionRules(rules) {
|
|
354
|
+
const seen = /* @__PURE__ */ new Set();
|
|
355
|
+
rules.forEach((r, i) => {
|
|
356
|
+
if (!r.name) throw new Error(`permissions[${i}]: name required`);
|
|
357
|
+
if (seen.has(r.name)) throw new Error(`permission rule ${JSON.stringify(r.name)}: duplicate name`);
|
|
358
|
+
seen.add(r.name);
|
|
359
|
+
if (!r.when) throw new Error(`permission rule ${JSON.stringify(r.name)}: 'when' required`);
|
|
360
|
+
for (const [field, value] of [
|
|
361
|
+
["effect", r.effect],
|
|
362
|
+
["otherwise", r.otherwise]
|
|
363
|
+
]) {
|
|
364
|
+
if (value === "" || value === void 0) {
|
|
365
|
+
throw new Error(`permission rule ${JSON.stringify(r.name)}: ${field} required (allow|deny)`);
|
|
366
|
+
}
|
|
367
|
+
if (value !== "allow" && value !== "deny") {
|
|
368
|
+
throw new Error(
|
|
369
|
+
`permission rule ${JSON.stringify(r.name)}: ${field} ${JSON.stringify(value)} invalid (want allow|deny)`
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
function parsePolicy(doc) {
|
|
376
|
+
if (doc === null || doc === void 0) return emptyPolicy();
|
|
377
|
+
if (!isRecord(doc)) throw new Error("want a mapping at the top level");
|
|
378
|
+
const p = emptyPolicy();
|
|
379
|
+
if (doc["name"] !== void 0 && doc["name"] !== null) {
|
|
380
|
+
if (typeof doc["name"] !== "string") throw new Error("name: want a string");
|
|
381
|
+
p.name = doc["name"];
|
|
382
|
+
}
|
|
383
|
+
const allow = allowMap(doc["allow"], "allow");
|
|
384
|
+
if (allow) p.allow = allow;
|
|
385
|
+
p.max_ops = int(doc["max_ops"], "max_ops");
|
|
386
|
+
p.require_confirm = strList(doc["require_confirm"], "require_confirm");
|
|
387
|
+
if (doc["unannotated"] !== void 0 && doc["unannotated"] !== null) {
|
|
388
|
+
if (typeof doc["unannotated"] !== "string") throw new Error("unannotated: want a string");
|
|
389
|
+
p.unannotated = doc["unannotated"];
|
|
390
|
+
}
|
|
391
|
+
const perms = doc["permissions"];
|
|
392
|
+
if (perms !== void 0 && perms !== null) {
|
|
393
|
+
if (!Array.isArray(perms) || perms.some((r) => !isRecord(r))) {
|
|
394
|
+
throw new Error("permissions: want a list of rules");
|
|
395
|
+
}
|
|
396
|
+
p.permissions = perms.map((r) => {
|
|
397
|
+
const rec = r;
|
|
398
|
+
const s = (k) => typeof rec[k] === "string" ? rec[k] : "";
|
|
399
|
+
return { name: s("name"), when: s("when"), effect: s("effect"), otherwise: s("otherwise"), message: s("message") };
|
|
400
|
+
});
|
|
401
|
+
validatePermissionRules(p.permissions);
|
|
402
|
+
}
|
|
403
|
+
const callers = doc["callers"];
|
|
404
|
+
if (callers !== void 0 && callers !== null) {
|
|
405
|
+
if (!Array.isArray(callers) || callers.some((r) => !isRecord(r))) {
|
|
406
|
+
throw new Error("callers: want a list of rules");
|
|
407
|
+
}
|
|
408
|
+
p.callers = callers.map((r, i) => {
|
|
409
|
+
const rec = r;
|
|
410
|
+
const at = `callers[${i}]`;
|
|
411
|
+
const rule = {};
|
|
412
|
+
for (const k of ["principal", "tenant", "scope", "window"]) {
|
|
413
|
+
if (rec[k] !== void 0 && rec[k] !== null) {
|
|
414
|
+
if (typeof rec[k] !== "string") throw new Error(`${at}.${k}: want a string`);
|
|
415
|
+
rule[k] = rec[k];
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const ra = allowMap(rec["allow"], `${at}.allow`);
|
|
419
|
+
if (ra) rule.allow = ra;
|
|
420
|
+
rule.max_ops = int(rec["max_ops"], `${at}.max_ops`);
|
|
421
|
+
rule.require_declared_scope = strList(rec["require_declared_scope"], `${at}.require_declared_scope`);
|
|
422
|
+
return rule;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
validate(p);
|
|
426
|
+
return p;
|
|
427
|
+
}
|
|
428
|
+
function validate(p) {
|
|
429
|
+
const errs = [];
|
|
430
|
+
if (p.unannotated && classOf(p.unannotated) === void 0) {
|
|
431
|
+
errs.push(`unannotated: unknown side-effect class ${JSON.stringify(p.unannotated)}`);
|
|
432
|
+
}
|
|
433
|
+
p.callers.forEach((r, i) => {
|
|
434
|
+
for (const c of Object.keys(_nullishCoalesce(r.allow, () => ( {})))) {
|
|
435
|
+
if (classOf(c) === void 0) errs.push(`callers[${i}]: allow: unknown side-effect class ${JSON.stringify(c)}`);
|
|
436
|
+
}
|
|
437
|
+
for (const c of _nullishCoalesce(r.require_declared_scope, () => ( []))) {
|
|
438
|
+
if (classOf(c) === void 0) {
|
|
439
|
+
errs.push(`callers[${i}]: require_declared_scope: unknown side-effect class ${JSON.stringify(c)}`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if ((_nullishCoalesce(r.max_ops, () => ( 0))) < 0) errs.push(`callers[${i}]: max_ops ${r.max_ops} is negative; 0 means no budget`);
|
|
443
|
+
});
|
|
444
|
+
if (errs.length > 0) throw new Error(errs.join("\n"));
|
|
445
|
+
}
|
|
446
|
+
function loadPolicy(file) {
|
|
447
|
+
let data;
|
|
448
|
+
try {
|
|
449
|
+
data = fs.readFileSync(file, "utf8");
|
|
450
|
+
} catch (e) {
|
|
451
|
+
throw new Error(`policy: load ${file}: ${e.message}`);
|
|
452
|
+
}
|
|
453
|
+
let p;
|
|
454
|
+
try {
|
|
455
|
+
p = parsePolicy(yaml2.load(data));
|
|
456
|
+
} catch (e) {
|
|
457
|
+
throw new Error(`policy: parse ${file}: ${e.message}`);
|
|
458
|
+
}
|
|
459
|
+
if (p.name === "") p.name = path.basename(file).replace(/\.(yaml|yml)$/, "");
|
|
460
|
+
return p;
|
|
461
|
+
}
|
|
462
|
+
function loadNamedPolicy(tool, name) {
|
|
463
|
+
if (name === KIT_DEFAULT_NAME) return kitDefault();
|
|
464
|
+
return loadPolicy(resolvePolicyPath(tool, name));
|
|
465
|
+
}
|
|
466
|
+
function defaultPolicyLoader(tool) {
|
|
467
|
+
return (name) => loadNamedPolicy(tool, name);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/delegation.ts
|
|
471
|
+
var DESTRUCTIVE_TOKEN_ANNOTATION = "kit/destructive-token";
|
|
472
|
+
var DRY_RUN_ANNOTATION = "kit/dry-run";
|
|
473
|
+
var DRY_RUN_RATIONALE_ANNOTATION = "kit/dry-run-rationale";
|
|
474
|
+
var CONFIRM_TOKEN_FLAG = "--confirm-token";
|
|
475
|
+
var SUPERVISOR_COMMAND = "serve";
|
|
476
|
+
var BUILTIN_NAMES = /* @__PURE__ */ new Set(["help", "completion", "__complete", "__completeNoDesc"]);
|
|
477
|
+
var noPrompt = () => null;
|
|
478
|
+
function scriptedPrompt(answers) {
|
|
479
|
+
const queue = [...answers];
|
|
480
|
+
const p = {
|
|
481
|
+
ask() {
|
|
482
|
+
const a = queue.shift();
|
|
483
|
+
return a === void 0 ? null : a.trim().toLowerCase();
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
return () => p;
|
|
487
|
+
}
|
|
488
|
+
var ttyPrompter;
|
|
489
|
+
var controllingTTY = () => {
|
|
490
|
+
if (ttyPrompter !== void 0) return ttyPrompter;
|
|
491
|
+
try {
|
|
492
|
+
const fd = fs2.openSync("/dev/tty", "r+");
|
|
493
|
+
ttyPrompter = {
|
|
494
|
+
ask(question) {
|
|
495
|
+
fs2.writeSync(fd, question);
|
|
496
|
+
const buf = Buffer.alloc(1);
|
|
497
|
+
let line = "";
|
|
498
|
+
for (; ; ) {
|
|
499
|
+
let n = 0;
|
|
500
|
+
try {
|
|
501
|
+
n = fs2.readSync(fd, buf, 0, 1, null);
|
|
502
|
+
} catch (e3) {
|
|
503
|
+
n = 0;
|
|
504
|
+
}
|
|
505
|
+
if (n === 0) return line === "" ? null : line.trim().toLowerCase();
|
|
506
|
+
const ch = buf.toString("utf8");
|
|
507
|
+
if (ch === "\n") return line.trim().toLowerCase();
|
|
508
|
+
line += ch;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
} catch (e4) {
|
|
513
|
+
ttyPrompter = null;
|
|
514
|
+
}
|
|
515
|
+
return ttyPrompter;
|
|
516
|
+
};
|
|
517
|
+
function resolveConfirmMode(src, raw) {
|
|
518
|
+
const v = raw.trim().toLowerCase();
|
|
519
|
+
if (v === "yes" || v === "no" || v === "auto" || v === "prompt") return v;
|
|
520
|
+
return src() !== null ? "prompt" : "no";
|
|
521
|
+
}
|
|
522
|
+
function destructiveToken(commandPath2) {
|
|
523
|
+
return _crypto.createHash.call(void 0, "sha256").update(commandPath2).digest("hex").slice(0, 12);
|
|
524
|
+
}
|
|
525
|
+
function requiresToken(ann) {
|
|
526
|
+
const v = ann[DESTRUCTIVE_TOKEN_ANNOTATION];
|
|
527
|
+
return v === "required" || v === "true";
|
|
528
|
+
}
|
|
529
|
+
function resolveDryRunPolicy(name, ann) {
|
|
530
|
+
switch (ann[DRY_RUN_ANNOTATION]) {
|
|
531
|
+
case "opted-out":
|
|
532
|
+
return "reject-opt-out";
|
|
533
|
+
case "supported":
|
|
534
|
+
return "allow";
|
|
535
|
+
}
|
|
536
|
+
const s = ann[_chunkCXBZTONYjs.SIDE_EFFECT_ANNOTATION];
|
|
537
|
+
if (s === void 0 || s === "") {
|
|
538
|
+
return _chunkCXBZTONYjs.isDestructiveName.call(void 0, name) ? "allow" : "reject-untagged";
|
|
539
|
+
}
|
|
540
|
+
if (_chunkCXBZTONYjs.isWriteLike.call(void 0, s) || _chunkCXBZTONYjs.isDestructiveLike.call(void 0, s)) return "allow";
|
|
541
|
+
if (s === "read") return "noop";
|
|
542
|
+
if (s === "interactive") return "reject-interactive";
|
|
543
|
+
return "reject-malformed";
|
|
544
|
+
}
|
|
545
|
+
function dryRunRefusal(path2, ann, p) {
|
|
546
|
+
let msg;
|
|
547
|
+
let fix;
|
|
548
|
+
switch (p) {
|
|
549
|
+
case "reject-interactive":
|
|
550
|
+
msg = `${JSON.stringify(path2)} does not accept --dry-run: interactive sessions have no batch boundary to scope the preview`;
|
|
551
|
+
fix = "run without --dry-run";
|
|
552
|
+
break;
|
|
553
|
+
case "reject-opt-out":
|
|
554
|
+
msg = `${JSON.stringify(path2)} does not support --dry-run: the command explicitly opted out via cli.OptOutDryRun`;
|
|
555
|
+
if (ann[DRY_RUN_RATIONALE_ANNOTATION]) msg += ` (${ann[DRY_RUN_RATIONALE_ANNOTATION]})`;
|
|
556
|
+
fix = "run without --dry-run; see the command's documentation for the rationale";
|
|
557
|
+
break;
|
|
558
|
+
case "reject-untagged":
|
|
559
|
+
msg = `${JSON.stringify(path2)} cannot apply --dry-run: the command is missing the required kit/side-effect tag`;
|
|
560
|
+
fix = "adopter must declare the tier with the kit/side-effect annotation";
|
|
561
|
+
break;
|
|
562
|
+
case "reject-malformed":
|
|
563
|
+
msg = `${JSON.stringify(path2)} cannot apply --dry-run: the command has a malformed kit/side-effect tag ${JSON.stringify(_nullishCoalesce(ann[_chunkCXBZTONYjs.SIDE_EFFECT_ANNOTATION], () => ( "")))} that names no tier`;
|
|
564
|
+
fix = "adopter must declare one of the kit side-effect tiers";
|
|
565
|
+
break;
|
|
566
|
+
default:
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
569
|
+
return { ..._chunkPOR5L2DGjs.usageError.call(void 0, msg), suggested_fix: fix };
|
|
570
|
+
}
|
|
571
|
+
var states = /* @__PURE__ */ new WeakMap();
|
|
572
|
+
var GATE_FLAGS = [
|
|
573
|
+
{ long: "--confirm", value: true },
|
|
574
|
+
{ long: "--max-ops", value: true },
|
|
575
|
+
{ long: "--policy", value: true },
|
|
576
|
+
{ long: "--dry-run", value: false }
|
|
577
|
+
];
|
|
578
|
+
function annotationsOf(cmd) {
|
|
579
|
+
return _nullishCoalesce(cmd.annotations, () => ( {}));
|
|
580
|
+
}
|
|
581
|
+
function isRunnable(cmd) {
|
|
582
|
+
return cmd._actionHandler != null;
|
|
583
|
+
}
|
|
584
|
+
function isBuiltin(cmd) {
|
|
585
|
+
return BUILTIN_NAMES.has(cmd.name()) || _optionalChain([cmd, 'access', _2 => _2.parent, 'optionalAccess', _3 => _3.name, 'call', _4 => _4()]) === "completion";
|
|
586
|
+
}
|
|
587
|
+
function camel(long) {
|
|
588
|
+
return long.replace(/^--/, "").replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
589
|
+
}
|
|
590
|
+
function commandPath(cmd) {
|
|
591
|
+
const names = [];
|
|
592
|
+
for (let c = cmd; c; c = c.parent) names.unshift(c.name());
|
|
593
|
+
return names.join(" ");
|
|
594
|
+
}
|
|
595
|
+
function verbOf(cmd) {
|
|
596
|
+
const names = [];
|
|
597
|
+
for (let c = cmd; _optionalChain([c, 'optionalAccess', _5 => _5.parent]); c = c.parent) names.unshift(c.name());
|
|
598
|
+
return names.join(" ");
|
|
599
|
+
}
|
|
600
|
+
function rootOf(cmd) {
|
|
601
|
+
let c = cmd;
|
|
602
|
+
while (c.parent) c = c.parent;
|
|
603
|
+
return c;
|
|
604
|
+
}
|
|
605
|
+
function declares(cmd, long) {
|
|
606
|
+
return cmd.options.some((o) => o.long === long);
|
|
607
|
+
}
|
|
608
|
+
function installDelegation(program, opts = {}) {
|
|
609
|
+
if (states.has(program)) return;
|
|
610
|
+
const st = { opts, shadow: /* @__PURE__ */ new Map(), runs: /* @__PURE__ */ new WeakMap() };
|
|
611
|
+
states.set(program, st);
|
|
612
|
+
const hidden = (o) => o.hideHelp();
|
|
613
|
+
if (!opts.disableDryRun) {
|
|
614
|
+
program.addOption(
|
|
615
|
+
hidden(new (0, _commander.Option)("--dry-run", "Preview side effects without applying them (must be supported by the command)."))
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
program.addOption(
|
|
619
|
+
hidden(
|
|
620
|
+
new (0, _commander.Option)(
|
|
621
|
+
"--confirm <mode>",
|
|
622
|
+
"Confirmation policy for destructive commands (auto|yes|no|prompt). Default: prompt on a TTY, no otherwise."
|
|
623
|
+
)
|
|
624
|
+
)
|
|
625
|
+
);
|
|
626
|
+
program.addOption(
|
|
627
|
+
hidden(
|
|
628
|
+
new (0, _commander.Option)("--max-ops <n>", "Cap mutating operations per invocation. 0 = unlimited.").argParser(
|
|
629
|
+
(v) => {
|
|
630
|
+
if (!/^[-+]?\d+$/.test(v)) {
|
|
631
|
+
program.error(`error: option '--max-ops <n>' argument '${v}' is invalid. expected an integer`, {
|
|
632
|
+
exitCode: _chunkPOR5L2DGjs.EXIT_USAGE,
|
|
633
|
+
code: "commander.invalidArgument"
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
return Number.parseInt(v, 10);
|
|
637
|
+
}
|
|
638
|
+
)
|
|
639
|
+
)
|
|
640
|
+
);
|
|
641
|
+
program.addOption(
|
|
642
|
+
hidden(
|
|
643
|
+
new (0, _commander.Option)(
|
|
644
|
+
"--policy <name>",
|
|
645
|
+
"Named delegation policy (loaded from $XDG_CONFIG_HOME/<tool>/policies/<name>.yaml)."
|
|
646
|
+
)
|
|
647
|
+
)
|
|
648
|
+
);
|
|
649
|
+
program.hook("preAction", (_this, action) => {
|
|
650
|
+
if (isBuiltin(action)) return;
|
|
651
|
+
gate(program, st, action);
|
|
652
|
+
});
|
|
653
|
+
program.hook("postAction", (_this, action) => {
|
|
654
|
+
const run = st.runs.get(action);
|
|
655
|
+
if (!run || run.dryRun) return;
|
|
656
|
+
if (run.tier === void 0 || !(_chunkCXBZTONYjs.isWriteLike.call(void 0, run.tier) || _chunkCXBZTONYjs.isDestructiveLike.call(void 0, run.tier))) return;
|
|
657
|
+
try {
|
|
658
|
+
run.engine.recordOp();
|
|
659
|
+
} catch (e) {
|
|
660
|
+
if (e instanceof MaxOpsExceededError) {
|
|
661
|
+
refuse(program, _chunkPOR5L2DGjs.rateLimitedError.call(void 0, `max-ops budget exceeded after running ${commandPath(action)}`));
|
|
662
|
+
}
|
|
663
|
+
throw e;
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
wrapParse(program, st);
|
|
667
|
+
}
|
|
668
|
+
function dryRunApplied(cmd) {
|
|
669
|
+
const st = states.get(rootOf(cmd));
|
|
670
|
+
return _optionalChain([st, 'optionalAccess', _6 => _6.runs, 'access', _7 => _7.get, 'call', _8 => _8(cmd), 'optionalAccess', _9 => _9.dryRun]) === true;
|
|
671
|
+
}
|
|
672
|
+
function isDryRun(cmd) {
|
|
673
|
+
if (dryRunApplied(cmd)) return true;
|
|
674
|
+
const root = rootOf(cmd);
|
|
675
|
+
const st = states.get(root);
|
|
676
|
+
return _optionalChain([st, 'optionalAccess', _10 => _10.shadow, 'access', _11 => _11.get, 'call', _12 => _12("--dry-run")]) === true || root.getOptionValue("dryRun") === true;
|
|
677
|
+
}
|
|
678
|
+
function rootFlag(program, st, long) {
|
|
679
|
+
return st.shadow.has(long) ? st.shadow.get(long) : program.getOptionValue(camel(long));
|
|
680
|
+
}
|
|
681
|
+
function flagValue(program, st, cmd, long) {
|
|
682
|
+
for (let c = cmd; c; c = c.parent) {
|
|
683
|
+
if (c === program) return stringOf(rootFlag(program, st, long));
|
|
684
|
+
if (declares(c, long)) return stringOf(c.getOptionValue(camel(long)));
|
|
685
|
+
}
|
|
686
|
+
return "";
|
|
687
|
+
}
|
|
688
|
+
function stringOf(v) {
|
|
689
|
+
return v === void 0 || v === null ? "" : String(v);
|
|
690
|
+
}
|
|
691
|
+
function flagInt(program, st, cmd, long) {
|
|
692
|
+
const m = /^[-+]?\d+/.exec(flagValue(program, st, cmd, long));
|
|
693
|
+
return m ? Number.parseInt(m[0], 10) : 0;
|
|
694
|
+
}
|
|
695
|
+
function buildEngine(st, name, maxOps) {
|
|
696
|
+
let policy;
|
|
697
|
+
if (name === KIT_DEFAULT_NAME) {
|
|
698
|
+
policy = kitDefault();
|
|
699
|
+
} else if (name !== "") {
|
|
700
|
+
if (!st.opts.policy) {
|
|
701
|
+
throw _chunkPOR5L2DGjs.usageError.call(void 0, "--policy is set but no policy loader is wired (createCLI policy option)");
|
|
702
|
+
}
|
|
703
|
+
try {
|
|
704
|
+
policy = st.opts.policy(name);
|
|
705
|
+
} catch (e) {
|
|
706
|
+
throw _chunkPOR5L2DGjs.usageError.call(void 0, `policy ${JSON.stringify(name)}: ${e.message}`);
|
|
707
|
+
}
|
|
708
|
+
} else {
|
|
709
|
+
policy = emptyPolicy();
|
|
710
|
+
}
|
|
711
|
+
return new Engine(policy, maxOps);
|
|
712
|
+
}
|
|
713
|
+
function startsServices(program, cmd) {
|
|
714
|
+
return cmd.parent === program && cmd.name() === SUPERVISOR_COMMAND;
|
|
715
|
+
}
|
|
716
|
+
function gate(program, st, cmd) {
|
|
717
|
+
const ann = annotationsOf(cmd);
|
|
718
|
+
const tier = _chunkCXBZTONYjs.gateSideEffect.call(void 0, cmd.name(), ann);
|
|
719
|
+
const path2 = commandPath(cmd);
|
|
720
|
+
try {
|
|
721
|
+
const declared = ann[_chunkCXBZTONYjs.SIDE_EFFECT_ANNOTATION];
|
|
722
|
+
if (declared !== void 0 && declared !== "" && !_chunkCXBZTONYjs.isValidSideEffect.call(void 0, declared)) {
|
|
723
|
+
throw {
|
|
724
|
+
..._chunkPOR5L2DGjs.usageError.call(void 0,
|
|
725
|
+
`${JSON.stringify(path2)} has a malformed kit/side-effect tag ${JSON.stringify(declared)} that names no tier`
|
|
726
|
+
),
|
|
727
|
+
suggested_fix: "declare one of the kit side-effect tiers"
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
let dryRun = false;
|
|
731
|
+
if (!st.opts.disableDryRun && rootFlag(program, st, "--dry-run") === true) {
|
|
732
|
+
const p = resolveDryRunPolicy(cmd.name(), ann);
|
|
733
|
+
const refusal = dryRunRefusal(path2, ann, p);
|
|
734
|
+
if (refusal) throw refusal;
|
|
735
|
+
dryRun = p === "allow";
|
|
736
|
+
}
|
|
737
|
+
const policyName = stringOf(rootFlag(program, st, "--policy"));
|
|
738
|
+
const engine = buildEngine(st, policyName, flagInt(program, st, cmd, "--max-ops"));
|
|
739
|
+
st.runs.set(cmd, { engine, dryRun, tier });
|
|
740
|
+
let policyConfirm = false;
|
|
741
|
+
if (!startsServices(program, cmd)) {
|
|
742
|
+
const v = engine.authorize({ verb: verbOf(cmd), sideEffect: tier });
|
|
743
|
+
if (!v.allowed) throw _chunkPOR5L2DGjs.unauthorizedError.call(void 0, v.reason);
|
|
744
|
+
policyConfirm = v.requireConfirm;
|
|
745
|
+
}
|
|
746
|
+
if (dryRun && _chunkCXBZTONYjs.inferredDestructive.call(void 0, cmd.name(), ann) && ann[DRY_RUN_ANNOTATION] === void 0) {
|
|
747
|
+
previewInferred(program, cmd, path2);
|
|
748
|
+
}
|
|
749
|
+
if (!dryRun && (tier !== void 0 && _chunkCXBZTONYjs.isDestructiveLike.call(void 0, tier) || policyConfirm)) {
|
|
750
|
+
gateConfirm(program, st, cmd, _nullishCoalesce(tier, () => ( "")), path2, ann);
|
|
751
|
+
}
|
|
752
|
+
} catch (e) {
|
|
753
|
+
if (isEnvelope(e)) refuse(program, e);
|
|
754
|
+
throw e;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
function previewInferred(program, cmd, path2) {
|
|
758
|
+
const chunks = [];
|
|
759
|
+
renderPlan(
|
|
760
|
+
{ write: (c) => chunks.push(c) },
|
|
761
|
+
activeFormat(program),
|
|
762
|
+
{
|
|
763
|
+
command: path2,
|
|
764
|
+
effects: [{ kind: cmd.name(), target: path2, reversible: false, detail: "inferred destructive-shared; a real run requires --confirm" }],
|
|
765
|
+
warnings: ["kit/side-effect is not declared: the handler was not invoked"]
|
|
766
|
+
},
|
|
767
|
+
path2
|
|
768
|
+
);
|
|
769
|
+
_optionalChain([program, 'access', _13 => _13.configureOutput, 'call', _14 => _14(), 'access', _15 => _15.writeOut, 'optionalCall', _16 => _16(chunks.join(""))]);
|
|
770
|
+
return program._exit(
|
|
771
|
+
0,
|
|
772
|
+
"kit.dryRunPreview",
|
|
773
|
+
"dry-run preview"
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
function isEnvelope(e) {
|
|
777
|
+
return typeof e === "object" && e !== null && "code" in e && "exit_code" in e;
|
|
778
|
+
}
|
|
779
|
+
function gateConfirm(program, st, cmd, tier, path2, ann) {
|
|
780
|
+
const src = _nullishCoalesce(st.opts.promptSource, () => ( controllingTTY));
|
|
781
|
+
const mode = resolveConfirmMode(src, flagValue(program, st, cmd, "--confirm"));
|
|
782
|
+
if (requiresToken(ann)) {
|
|
783
|
+
const expected = destructiveToken(path2);
|
|
784
|
+
const got = stringOf(cmd.getOptionValue("confirmToken"));
|
|
785
|
+
if (got === "") {
|
|
786
|
+
const refusal = _chunkPOR5L2DGjs.unauthorizedError.call(void 0, `destructive command ${path2} requires ${CONFIRM_TOKEN_FLAG}=${expected}`);
|
|
787
|
+
if (isMachineFormat(program)) {
|
|
788
|
+
refusal.suggested_fix = `re-run with ${CONFIRM_TOKEN_FLAG}=${expected} to proceed`;
|
|
789
|
+
} else {
|
|
790
|
+
writeErr(
|
|
791
|
+
program,
|
|
792
|
+
`This is a destructive operation requiring typed confirmation.
|
|
793
|
+
Token: ${expected}
|
|
794
|
+
Re-run with ${CONFIRM_TOKEN_FLAG}=${expected} to proceed.
|
|
795
|
+
`
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
throw refusal;
|
|
799
|
+
}
|
|
800
|
+
if (got !== expected) {
|
|
801
|
+
throw _chunkPOR5L2DGjs.unauthorizedError.call(void 0, `${CONFIRM_TOKEN_FLAG} mismatch for ${path2}; expected ${expected}`);
|
|
802
|
+
}
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
switch (mode) {
|
|
806
|
+
case "yes":
|
|
807
|
+
case "auto":
|
|
808
|
+
return;
|
|
809
|
+
case "no":
|
|
810
|
+
throw _chunkPOR5L2DGjs.withTransience.call(void 0,
|
|
811
|
+
_chunkPOR5L2DGjs.unauthorizedError.call(void 0, `destructive command ${path2} refused: --confirm=no (or non-TTY default)`),
|
|
812
|
+
_chunkPOR5L2DGjs.TRANSIENCE_TRANSIENT
|
|
813
|
+
);
|
|
814
|
+
case "prompt": {
|
|
815
|
+
const answer = _nullishCoalesce(_optionalChain([src, 'call', _17 => _17(), 'optionalAccess', _18 => _18.ask, 'call', _19 => _19(`This is a ${tier} operation (${path2}). Continue? [y/N] `)]), () => ( null));
|
|
816
|
+
if (answer === "y" || answer === "yes") return;
|
|
817
|
+
throw _chunkPOR5L2DGjs.withTransience.call(void 0,
|
|
818
|
+
_chunkPOR5L2DGjs.unauthorizedError.call(void 0, `aborted by user at confirm prompt for ${path2}`),
|
|
819
|
+
_chunkPOR5L2DGjs.TRANSIENCE_TRANSIENT
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function activeFormat(program) {
|
|
825
|
+
return stringOf(program.getOptionValue("format"));
|
|
826
|
+
}
|
|
827
|
+
function isMachineFormat(program) {
|
|
828
|
+
const f = activeFormat(program);
|
|
829
|
+
return f === "json" || f === "yaml";
|
|
830
|
+
}
|
|
831
|
+
function writeErr(program, s) {
|
|
832
|
+
_optionalChain([program, 'access', _20 => _20.configureOutput, 'call', _21 => _21(), 'access', _22 => _22.writeErr, 'optionalCall', _23 => _23(s)]);
|
|
833
|
+
}
|
|
834
|
+
function refuse(program, e) {
|
|
835
|
+
const chunks = [];
|
|
836
|
+
_chunkPOR5L2DGjs.renderError.call(void 0, { write: (c) => chunks.push(c) }, activeFormat(program), e);
|
|
837
|
+
writeErr(program, chunks.join(""));
|
|
838
|
+
return program._exit(
|
|
839
|
+
e.exit_code,
|
|
840
|
+
"kit.delegation",
|
|
841
|
+
e.message
|
|
842
|
+
);
|
|
843
|
+
}
|
|
844
|
+
function walkAll(cmd, visit) {
|
|
845
|
+
visit(cmd);
|
|
846
|
+
for (const c of cmd.commands) walkAll(c, visit);
|
|
847
|
+
}
|
|
848
|
+
function installConfirmTokenFlag(program) {
|
|
849
|
+
walkAll(program, (c) => {
|
|
850
|
+
if (c === program || c.commands.length > 0 || !isRunnable(c) || isBuiltin(c)) return;
|
|
851
|
+
if (!requiresToken(annotationsOf(c)) || declares(c, CONFIRM_TOKEN_FLAG)) return;
|
|
852
|
+
c.option(
|
|
853
|
+
`${CONFIRM_TOKEN_FLAG} <token>`,
|
|
854
|
+
"Typed confirmation token (sha) printed by the command's prompt. Required for kit/destructive-token commands."
|
|
855
|
+
);
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
function findOption(program, cur, tok) {
|
|
859
|
+
const long = tok.startsWith("--") ? tok.split("=")[0] : void 0;
|
|
860
|
+
const match = (o) => long ? o.long === long : o.short === tok;
|
|
861
|
+
return _nullishCoalesce(cur.options.find(match), () => ( program.options.find(match)));
|
|
862
|
+
}
|
|
863
|
+
function scan(program, st, user) {
|
|
864
|
+
const conflicts = /* @__PURE__ */ new Set();
|
|
865
|
+
walkAll(program, (c) => {
|
|
866
|
+
if (c === program) return;
|
|
867
|
+
for (const g of GATE_FLAGS) if (declares(c, g.long)) conflicts.add(g.long);
|
|
868
|
+
});
|
|
869
|
+
if (conflicts.size === 0) return { user, shadowed: [] };
|
|
870
|
+
const nameAt = [];
|
|
871
|
+
let cur = program;
|
|
872
|
+
let resolving = true;
|
|
873
|
+
for (let i = 0; i < user.length && resolving; i++) {
|
|
874
|
+
const tok = user[i];
|
|
875
|
+
if (tok === "--") break;
|
|
876
|
+
if (tok.startsWith("-") && tok !== "-") {
|
|
877
|
+
const opt = findOption(program, cur, tok);
|
|
878
|
+
if (opt && !tok.includes("=") && (opt.required || opt.optional && !(_nullishCoalesce(user[i + 1], () => ( "-"))).startsWith("-"))) i++;
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
const sub = cur.commands.find((c) => c.name() === tok || c.aliases().includes(tok));
|
|
882
|
+
if (sub) {
|
|
883
|
+
cur = sub;
|
|
884
|
+
nameAt.push({ cmd: sub, idx: i });
|
|
885
|
+
} else {
|
|
886
|
+
resolving = false;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
const boundary = /* @__PURE__ */ new Map();
|
|
890
|
+
for (const g of GATE_FLAGS) {
|
|
891
|
+
const owner = nameAt.find((n) => declares(n.cmd, g.long));
|
|
892
|
+
if (owner) boundary.set(g.long, owner.idx);
|
|
893
|
+
}
|
|
894
|
+
if (boundary.size === 0) return { user, shadowed: [] };
|
|
895
|
+
const out = [];
|
|
896
|
+
for (let i = 0; i < user.length; i++) {
|
|
897
|
+
const tok = user[i];
|
|
898
|
+
if (tok === "--") {
|
|
899
|
+
out.push(...user.slice(i));
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
const g = tok.startsWith("--") ? GATE_FLAGS.find((f) => tok === f.long || tok.startsWith(`${f.long}=`)) : void 0;
|
|
903
|
+
const b = g ? boundary.get(g.long) : void 0;
|
|
904
|
+
if (g && b !== void 0 && i < b) {
|
|
905
|
+
if (!g.value) {
|
|
906
|
+
st.shadow.set(g.long, true);
|
|
907
|
+
} else if (tok.includes("=")) {
|
|
908
|
+
st.shadow.set(g.long, tok.slice(tok.indexOf("=") + 1));
|
|
909
|
+
} else {
|
|
910
|
+
st.shadow.set(g.long, _nullishCoalesce(user[i + 1], () => ( "")));
|
|
911
|
+
i++;
|
|
912
|
+
}
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
out.push(tok);
|
|
916
|
+
if (tok.startsWith("-") && tok !== "-" && !tok.includes("=")) {
|
|
917
|
+
let c = program;
|
|
918
|
+
for (const n of nameAt) if (n.idx < i) c = n.cmd;
|
|
919
|
+
const opt = findOption(program, c, tok);
|
|
920
|
+
if (_optionalChain([opt, 'optionalAccess', _24 => _24.required]) && i + 1 < user.length) out.push(user[++i]);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
return { user: out, shadowed: [...boundary.keys()] };
|
|
924
|
+
}
|
|
925
|
+
function wrapParse(program, st) {
|
|
926
|
+
const origParse = program.parse.bind(program);
|
|
927
|
+
const origParseAsync = program.parseAsync.bind(program);
|
|
928
|
+
const prepare = (argv, options, go, after) => {
|
|
929
|
+
installConfirmTokenFlag(program);
|
|
930
|
+
st.shadow.clear();
|
|
931
|
+
let from = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _25 => _25.from]), () => ( "node"));
|
|
932
|
+
let args = argv;
|
|
933
|
+
if (args === void 0) {
|
|
934
|
+
if (process.versions["electron"]) from = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _26 => _26.from]), () => ( "electron"));
|
|
935
|
+
args = process.argv;
|
|
936
|
+
}
|
|
937
|
+
const skip = from === "user" ? 0 : from === "electron" && !process.defaultApp ? 1 : 2;
|
|
938
|
+
const sc = scan(program, st, args.slice(skip));
|
|
939
|
+
if (sc.shadowed.length === 0) return go(argv, options);
|
|
940
|
+
const removed = [];
|
|
941
|
+
for (const long of sc.shadowed) {
|
|
942
|
+
const opts = program.options;
|
|
943
|
+
const i = opts.findIndex((o) => o.long === long);
|
|
944
|
+
if (i >= 0) removed.push(...opts.splice(i, 1));
|
|
945
|
+
}
|
|
946
|
+
const restore = () => {
|
|
947
|
+
program.options.push(...removed);
|
|
948
|
+
};
|
|
949
|
+
let r;
|
|
950
|
+
try {
|
|
951
|
+
r = go([...args.slice(0, skip), ...sc.user], { ...options, from });
|
|
952
|
+
} catch (e) {
|
|
953
|
+
restore();
|
|
954
|
+
throw e;
|
|
955
|
+
}
|
|
956
|
+
return after(r, restore);
|
|
957
|
+
};
|
|
958
|
+
program.parse = ((argv, options) => prepare(
|
|
959
|
+
argv,
|
|
960
|
+
options,
|
|
961
|
+
(a, o) => origParse(a, o),
|
|
962
|
+
(r, restore) => {
|
|
963
|
+
restore();
|
|
964
|
+
return r;
|
|
965
|
+
}
|
|
966
|
+
));
|
|
967
|
+
program.parseAsync = ((argv, options) => prepare(
|
|
968
|
+
argv,
|
|
969
|
+
options,
|
|
970
|
+
(a, o) => origParseAsync(a, o),
|
|
971
|
+
(r, restore) => r.finally(restore)
|
|
972
|
+
));
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// src/hint.ts
|
|
976
|
+
var HintSet = class {
|
|
977
|
+
constructor() {
|
|
978
|
+
this.m = /* @__PURE__ */ new Map();
|
|
979
|
+
}
|
|
980
|
+
/** Add one or more hints for the given command name. */
|
|
981
|
+
register(cmd, ...hints) {
|
|
982
|
+
const existing = _nullishCoalesce(this.m.get(cmd), () => ( []));
|
|
983
|
+
this.m.set(cmd, [...existing, ...hints]);
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Return a copy of the hints registered for cmd.
|
|
987
|
+
* Returns an empty array when none are registered.
|
|
988
|
+
*/
|
|
989
|
+
lookup(cmd) {
|
|
990
|
+
return [..._nullishCoalesce(this.m.get(cmd), () => ( []))];
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
function active(hints) {
|
|
994
|
+
return hints.filter((h) => h.condition === void 0 || h.condition());
|
|
995
|
+
}
|
|
996
|
+
function hintsEnabled(opts) {
|
|
997
|
+
if (opts.noHints) return false;
|
|
998
|
+
if (opts.hintsEnabled === false) return false;
|
|
999
|
+
if (opts.quiet) return false;
|
|
1000
|
+
const env = process.env["HOP_QUIET_HINTS"];
|
|
1001
|
+
if (env === "1" || env === "true" || env === "yes") return false;
|
|
1002
|
+
return true;
|
|
1003
|
+
}
|
|
1004
|
+
function renderHints(w, hints, format, opts, muted) {
|
|
1005
|
+
if (format !== "table") return;
|
|
1006
|
+
if (!hintsEnabled(opts)) return;
|
|
1007
|
+
const isTTY = w.isTTY === true;
|
|
1008
|
+
if (!isTTY) return;
|
|
1009
|
+
const visible = active(hints);
|
|
1010
|
+
if (visible.length === 0) return;
|
|
1011
|
+
const noColor = process.env["NO_COLOR"] !== void 0 || process.argv.includes("--no-color");
|
|
1012
|
+
w.write("\n");
|
|
1013
|
+
for (const h of visible) {
|
|
1014
|
+
const text = `\u2192 ${h.message}`;
|
|
1015
|
+
if (noColor) {
|
|
1016
|
+
w.write(text + "\n");
|
|
1017
|
+
} else {
|
|
1018
|
+
const hex = muted.replace("#", "");
|
|
1019
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
1020
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
1021
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
1022
|
+
w.write(`\x1B[38;2;${r};${g};${b}m${text}\x1B[0m
|
|
1023
|
+
`);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
function registerUpgradeHints(hints, binary, upgraded) {
|
|
1028
|
+
hints.register("upgrade", {
|
|
1029
|
+
message: `Run \`${binary} version\` to verify.`,
|
|
1030
|
+
condition: upgraded
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
function registerVersionHints(hints, binary, updateAvail) {
|
|
1034
|
+
hints.register("version", {
|
|
1035
|
+
message: `Run \`${binary} upgrade\` to get latest.`,
|
|
1036
|
+
condition: updateAvail
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// src/cli.ts
|
|
1041
|
+
var verboseCountMap = /* @__PURE__ */ new WeakMap();
|
|
1042
|
+
var quietMap = /* @__PURE__ */ new WeakMap();
|
|
1043
|
+
function verbosityShorthand(d) {
|
|
1044
|
+
const s = (_nullishCoalesce(_optionalChain([d, 'access', _27 => _27.verbosity, 'optionalAccess', _28 => _28.flag]), () => ( ""))).replace(/^-+/, "");
|
|
1045
|
+
return s.length === 1 ? s : "V";
|
|
1046
|
+
}
|
|
1047
|
+
function verbosityFlagSpec(d) {
|
|
1048
|
+
return `-${verbosityShorthand(d)}, --verbose`;
|
|
1049
|
+
}
|
|
1050
|
+
function verboseCount(cmd) {
|
|
1051
|
+
let c = cmd;
|
|
1052
|
+
while (c) {
|
|
1053
|
+
const v = verboseCountMap.get(c);
|
|
1054
|
+
if (v !== void 0) return v;
|
|
1055
|
+
c = _nullishCoalesce(c.parent, () => ( null));
|
|
1056
|
+
}
|
|
1057
|
+
return 0;
|
|
1058
|
+
}
|
|
1059
|
+
function isQuiet(cmd) {
|
|
1060
|
+
let c = cmd;
|
|
1061
|
+
while (c) {
|
|
1062
|
+
const q = quietMap.get(c);
|
|
1063
|
+
if (q !== void 0) return q;
|
|
1064
|
+
c = _nullishCoalesce(c.parent, () => ( null));
|
|
1065
|
+
}
|
|
1066
|
+
return false;
|
|
1067
|
+
}
|
|
1068
|
+
var streamDefsMap = /* @__PURE__ */ new WeakMap();
|
|
1069
|
+
function streamFlagName(d) {
|
|
1070
|
+
const name = (_nullishCoalesce(_optionalChain([d, 'access', _29 => _29.streams, 'optionalAccess', _30 => _30.flag]), () => ( ""))).replace(/^-+/, "");
|
|
1071
|
+
return name === "" ? "stream" : name;
|
|
1072
|
+
}
|
|
1073
|
+
function streamLabel(d, name) {
|
|
1074
|
+
const format = _optionalChain([d, 'access', _31 => _31.streams, 'optionalAccess', _32 => _32.label_format]) || "[{name}]";
|
|
1075
|
+
return format.split("{name}").join(name) + " ";
|
|
1076
|
+
}
|
|
1077
|
+
function streamOutput(d) {
|
|
1078
|
+
return _optionalChain([d, 'access', _33 => _33.streams, 'optionalAccess', _34 => _34.output]) === "stdout" ? process.stdout : process.stderr;
|
|
1079
|
+
}
|
|
1080
|
+
function registerStream(cmd, name, description) {
|
|
1081
|
+
let defs = streamDefsMap.get(cmd);
|
|
1082
|
+
if (!defs) {
|
|
1083
|
+
defs = [];
|
|
1084
|
+
streamDefsMap.set(cmd, defs);
|
|
1085
|
+
cmd.option(
|
|
1086
|
+
`--${streamFlagName(_chunkT6OZMPPVjs.parity)} <names>`,
|
|
1087
|
+
"Enable diagnostic streams (comma-separated)"
|
|
1088
|
+
);
|
|
1089
|
+
}
|
|
1090
|
+
defs.push({ name, description });
|
|
1091
|
+
}
|
|
1092
|
+
function getStreamDefs(cmd) {
|
|
1093
|
+
return _nullishCoalesce(streamDefsMap.get(cmd), () => ( []));
|
|
1094
|
+
}
|
|
1095
|
+
var noopWriter = { write(_s) {
|
|
1096
|
+
return true;
|
|
1097
|
+
} };
|
|
1098
|
+
function optionKey(flagName) {
|
|
1099
|
+
return flagName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
1100
|
+
}
|
|
1101
|
+
function channel(cmd, name) {
|
|
1102
|
+
const opts = cmd.opts();
|
|
1103
|
+
const raw = opts[optionKey(streamFlagName(_chunkT6OZMPPVjs.parity))];
|
|
1104
|
+
const enabled = typeof raw === "string" ? raw.split(",").map((s) => s.trim()).includes(name) : false;
|
|
1105
|
+
if (!enabled) return noopWriter;
|
|
1106
|
+
const prefix = streamLabel(_chunkT6OZMPPVjs.parity, name);
|
|
1107
|
+
const w = streamOutput(_chunkT6OZMPPVjs.parity);
|
|
1108
|
+
return {
|
|
1109
|
+
write(s) {
|
|
1110
|
+
const lines = s.split("\n");
|
|
1111
|
+
for (const line of lines) {
|
|
1112
|
+
if (line) w.write(`${prefix}${line}
|
|
1113
|
+
`);
|
|
1114
|
+
}
|
|
1115
|
+
return true;
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
var Neon = {
|
|
1120
|
+
command: "#7ED957",
|
|
1121
|
+
// grass green
|
|
1122
|
+
flag: "#FF00FF"
|
|
1123
|
+
// vivid neon pink
|
|
1124
|
+
};
|
|
1125
|
+
var Dark = {
|
|
1126
|
+
command: "#C1FF72",
|
|
1127
|
+
// lime
|
|
1128
|
+
flag: "#FF66C4"
|
|
1129
|
+
// pink
|
|
1130
|
+
};
|
|
1131
|
+
function buildTheme(accent) {
|
|
1132
|
+
const palette = { ...Neon };
|
|
1133
|
+
if (accent) {
|
|
1134
|
+
palette.command = accent;
|
|
1135
|
+
}
|
|
1136
|
+
return {
|
|
1137
|
+
palette,
|
|
1138
|
+
accent: palette.command,
|
|
1139
|
+
secondary: palette.flag,
|
|
1140
|
+
muted: "#858183",
|
|
1141
|
+
// CharmTone Squid
|
|
1142
|
+
error: "#ED4A5E",
|
|
1143
|
+
// CharmTone Cherry
|
|
1144
|
+
success: "#52CF84",
|
|
1145
|
+
// CharmTone Guac
|
|
1146
|
+
title: "#FFFFFF",
|
|
1147
|
+
// fang ColorScheme.Title
|
|
1148
|
+
argument: "#B5E89B",
|
|
1149
|
+
// fang ColorScheme.Argument
|
|
1150
|
+
dimmedArgument: "#8ABF6E"
|
|
1151
|
+
// fang ColorScheme.DimmedArgument
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
var commandGroupMap = /* @__PURE__ */ new WeakMap();
|
|
1155
|
+
function setCommandGroup(cmd, groupId) {
|
|
1156
|
+
commandGroupMap.set(cmd, groupId);
|
|
1157
|
+
}
|
|
1158
|
+
function getCommandGroup(cmd) {
|
|
1159
|
+
return commandGroupMap.get(cmd);
|
|
1160
|
+
}
|
|
1161
|
+
function hexToRgb(hex) {
|
|
1162
|
+
const h = hex.replace("#", "");
|
|
1163
|
+
return [
|
|
1164
|
+
parseInt(h.slice(0, 2), 16),
|
|
1165
|
+
parseInt(h.slice(2, 4), 16),
|
|
1166
|
+
parseInt(h.slice(4, 6), 16)
|
|
1167
|
+
];
|
|
1168
|
+
}
|
|
1169
|
+
function ansi(hex, text) {
|
|
1170
|
+
const [r, g, b] = hexToRgb(hex);
|
|
1171
|
+
return `\x1B[38;2;${r};${g};${b}m${text}\x1B[0m`;
|
|
1172
|
+
}
|
|
1173
|
+
function ansiBold(hex, text) {
|
|
1174
|
+
const [r, g, b] = hexToRgb(hex);
|
|
1175
|
+
return `\x1B[1;38;2;${r};${g};${b}m${text}\x1B[0m`;
|
|
1176
|
+
}
|
|
1177
|
+
function applyHelpTheme(program, theme, noColor, sectionOrder, showAliases, groups) {
|
|
1178
|
+
const isNoColor = () => noColor || process.argv.includes("--no-color") || process.env["NO_COLOR"] !== void 0;
|
|
1179
|
+
program.configureOutput({
|
|
1180
|
+
..._nullishCoalesce(program._outputConfiguration, () => ( {})),
|
|
1181
|
+
getOutHasColors: () => !isNoColor(),
|
|
1182
|
+
getErrHasColors: () => !isNoColor()
|
|
1183
|
+
});
|
|
1184
|
+
program.configureHelp({
|
|
1185
|
+
// --- V14 style hooks: delegate coloring here ---
|
|
1186
|
+
styleTitle(str) {
|
|
1187
|
+
return isNoColor() ? str : ansiBold(theme.title, str);
|
|
1188
|
+
},
|
|
1189
|
+
styleUsage(str) {
|
|
1190
|
+
if (isNoColor()) return str;
|
|
1191
|
+
return str.split(" ").map((word) => {
|
|
1192
|
+
if (word === "[options]" || word === "[--flags]")
|
|
1193
|
+
return ansi(theme.dimmedArgument, word);
|
|
1194
|
+
if (word[0] === "[" || word[0] === "<")
|
|
1195
|
+
return ansi(theme.argument, word);
|
|
1196
|
+
return ansi(theme.accent, word);
|
|
1197
|
+
}).join(" ");
|
|
1198
|
+
},
|
|
1199
|
+
styleCommandText(str) {
|
|
1200
|
+
return isNoColor() ? str : ansi(theme.accent, str);
|
|
1201
|
+
},
|
|
1202
|
+
styleSubcommandText(str) {
|
|
1203
|
+
return isNoColor() ? str : ansi(theme.accent, str);
|
|
1204
|
+
},
|
|
1205
|
+
styleOptionText(str) {
|
|
1206
|
+
return isNoColor() ? str : ansi(theme.secondary, str);
|
|
1207
|
+
},
|
|
1208
|
+
styleArgumentText(str) {
|
|
1209
|
+
return isNoColor() ? str : ansi(theme.argument, str);
|
|
1210
|
+
},
|
|
1211
|
+
styleDescriptionText(str) {
|
|
1212
|
+
return isNoColor() ? str : ansi(theme.muted, str);
|
|
1213
|
+
},
|
|
1214
|
+
// Color each part of option term separately (short, long, arg).
|
|
1215
|
+
styleOptionTerm(str) {
|
|
1216
|
+
if (isNoColor()) return str;
|
|
1217
|
+
return str.split(" ").map((word) => {
|
|
1218
|
+
if (word === ",") return word;
|
|
1219
|
+
if (word.startsWith("<") || word.startsWith("["))
|
|
1220
|
+
return ansi(theme.argument, word);
|
|
1221
|
+
if (word.endsWith(","))
|
|
1222
|
+
return ansi(theme.secondary, word.slice(0, -1)) + ",";
|
|
1223
|
+
return ansi(theme.secondary, word);
|
|
1224
|
+
}).join(" ");
|
|
1225
|
+
},
|
|
1226
|
+
// Color subcommand term parts: name in accent, args dimmed.
|
|
1227
|
+
styleSubcommandTerm(str) {
|
|
1228
|
+
if (isNoColor()) return str;
|
|
1229
|
+
const words = str.split(" ");
|
|
1230
|
+
return words.map((word, i) => {
|
|
1231
|
+
if (i === 0) return ansi(theme.accent, word);
|
|
1232
|
+
if (word.startsWith("<") || word.startsWith("["))
|
|
1233
|
+
return ansi(theme.dimmedArgument, word);
|
|
1234
|
+
return ansi(theme.accent, word);
|
|
1235
|
+
}).join(" ");
|
|
1236
|
+
},
|
|
1237
|
+
// --- Term overrides ---
|
|
1238
|
+
subcommandTerm(cmd) {
|
|
1239
|
+
const args = cmd.registeredArguments.map((a) => a.required ? `<${a.name()}>` : `[${a.name()}]`).join(" ");
|
|
1240
|
+
const hasSubcmds = cmd.commands.length > 0;
|
|
1241
|
+
let term = cmd.name();
|
|
1242
|
+
if (args) term += " " + args;
|
|
1243
|
+
if (hasSubcmds) term += " [command]";
|
|
1244
|
+
else if (cmd.options.length) term += " [--flags]";
|
|
1245
|
+
return term;
|
|
1246
|
+
},
|
|
1247
|
+
// --- Custom formatHelp for group partitioning + section ordering ---
|
|
1248
|
+
formatHelp(cmd, helper) {
|
|
1249
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
1250
|
+
function callFormatItem(term, description) {
|
|
1251
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
1252
|
+
}
|
|
1253
|
+
const output = [];
|
|
1254
|
+
output.push(
|
|
1255
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`
|
|
1256
|
+
);
|
|
1257
|
+
output.push("");
|
|
1258
|
+
const desc = helper.commandDescription(cmd);
|
|
1259
|
+
if (desc) {
|
|
1260
|
+
output.push(helper.styleCommandDescription(desc));
|
|
1261
|
+
output.push("");
|
|
1262
|
+
}
|
|
1263
|
+
const argList = helper.visibleArguments(cmd);
|
|
1264
|
+
if (argList.length > 0) {
|
|
1265
|
+
const title = _nullishCoalesce(_optionalChain([_chunkT6OZMPPVjs.parity, 'access', _35 => _35.help, 'access', _36 => _36.sections, 'optionalAccess', _37 => _37["arguments"], 'optionalAccess', _38 => _38.title]), () => ( "ARGUMENTS"));
|
|
1266
|
+
output.push(helper.styleTitle(`${title}:`));
|
|
1267
|
+
for (const a of argList) {
|
|
1268
|
+
output.push(callFormatItem(
|
|
1269
|
+
helper.styleArgumentTerm(helper.argumentTerm(a)),
|
|
1270
|
+
helper.styleArgumentDescription(helper.argumentDescription(a))
|
|
1271
|
+
));
|
|
1272
|
+
}
|
|
1273
|
+
output.push("");
|
|
1274
|
+
}
|
|
1275
|
+
const helpSections = [];
|
|
1276
|
+
const helpAll = process.argv.includes("--help-all");
|
|
1277
|
+
let helpGroupFilter;
|
|
1278
|
+
for (const arg of process.argv) {
|
|
1279
|
+
const m = arg.match(/^--help-(.+)$/);
|
|
1280
|
+
if (m && m[1] !== "all") {
|
|
1281
|
+
helpGroupFilter = m[1];
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
const groupDefs = /* @__PURE__ */ new Map();
|
|
1286
|
+
for (const g of _nullishCoalesce(groups, () => ( []))) {
|
|
1287
|
+
groupDefs.set(g.id, { title: g.title, hidden: _nullishCoalesce(g.hidden, () => ( false)) });
|
|
1288
|
+
}
|
|
1289
|
+
const allCmds = helper.visibleCommands(cmd).filter((sc) => sc.name() !== "help");
|
|
1290
|
+
const defaultCmds = [];
|
|
1291
|
+
const groupedCmds = /* @__PURE__ */ new Map();
|
|
1292
|
+
for (const sc of allCmds) {
|
|
1293
|
+
const gid = getCommandGroup(sc);
|
|
1294
|
+
if (gid && groupDefs.has(gid)) {
|
|
1295
|
+
let arr = groupedCmds.get(gid);
|
|
1296
|
+
if (!arr) {
|
|
1297
|
+
arr = [];
|
|
1298
|
+
groupedCmds.set(gid, arr);
|
|
1299
|
+
}
|
|
1300
|
+
arr.push(sc);
|
|
1301
|
+
} else {
|
|
1302
|
+
defaultCmds.push(sc);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
const buildCmdItems = (cmds) => {
|
|
1306
|
+
return cmds.map((sc) => {
|
|
1307
|
+
let descr = helper.subcommandDescription(sc);
|
|
1308
|
+
if (showAliases && sc.aliases().length > 0) {
|
|
1309
|
+
descr += ` (aliases: ${sc.aliases().join(", ")})`;
|
|
1310
|
+
}
|
|
1311
|
+
return callFormatItem(
|
|
1312
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(sc)),
|
|
1313
|
+
helper.styleSubcommandDescription(descr)
|
|
1314
|
+
);
|
|
1315
|
+
});
|
|
1316
|
+
};
|
|
1317
|
+
if (defaultCmds.length > 0 && !helpGroupFilter) {
|
|
1318
|
+
helpSections.push({
|
|
1319
|
+
name: "commands",
|
|
1320
|
+
items: buildCmdItems(defaultCmds)
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
for (const [gid, cmds] of groupedCmds) {
|
|
1324
|
+
if (helpGroupFilter && gid !== helpGroupFilter) continue;
|
|
1325
|
+
const def = groupDefs.get(gid);
|
|
1326
|
+
if (!helpGroupFilter && def.hidden && !helpAll) continue;
|
|
1327
|
+
if (cmds.length > 0) {
|
|
1328
|
+
helpSections.push({ name: gid, items: buildCmdItems(cmds) });
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
const opts = helper.visibleOptions(cmd);
|
|
1332
|
+
if (opts.length > 0) {
|
|
1333
|
+
const flagItems = opts.map(
|
|
1334
|
+
(o) => callFormatItem(
|
|
1335
|
+
helper.styleOptionTerm(helper.optionTerm(o)),
|
|
1336
|
+
helper.styleOptionDescription(helper.optionDescription(o))
|
|
1337
|
+
)
|
|
1338
|
+
);
|
|
1339
|
+
helpSections.push({ name: "flags", items: flagItems });
|
|
1340
|
+
}
|
|
1341
|
+
const sectionMap = new Map(helpSections.map((s) => [s.name, s]));
|
|
1342
|
+
const effectiveOrder = sectionOrder && sectionOrder.length > 0 ? sectionOrder : _chunkT6OZMPPVjs.parity.help.section_order;
|
|
1343
|
+
const sectionTitles = _nullishCoalesce(_chunkT6OZMPPVjs.parity.help.sections, () => ( {}));
|
|
1344
|
+
const resolveTitle = (name) => {
|
|
1345
|
+
const gdef = groupDefs.get(name);
|
|
1346
|
+
if (gdef) return gdef.title;
|
|
1347
|
+
return _nullishCoalesce(_optionalChain([sectionTitles, 'access', _39 => _39[name], 'optionalAccess', _40 => _40.title]), () => ( name.charAt(0).toUpperCase() + name.slice(1)));
|
|
1348
|
+
};
|
|
1349
|
+
for (const name of effectiveOrder) {
|
|
1350
|
+
if (name === "flags") continue;
|
|
1351
|
+
const sec = sectionMap.get(name);
|
|
1352
|
+
if (!sec) continue;
|
|
1353
|
+
output.push(helper.styleTitle(`${resolveTitle(name)}:`));
|
|
1354
|
+
output.push(...sec.items);
|
|
1355
|
+
output.push("");
|
|
1356
|
+
}
|
|
1357
|
+
for (const sec of helpSections) {
|
|
1358
|
+
if (sec.name === "flags") continue;
|
|
1359
|
+
if (effectiveOrder.includes(sec.name)) continue;
|
|
1360
|
+
output.push(helper.styleTitle(`${resolveTitle(sec.name)}:`));
|
|
1361
|
+
output.push(...sec.items);
|
|
1362
|
+
output.push("");
|
|
1363
|
+
}
|
|
1364
|
+
const flagsSec = sectionMap.get("flags");
|
|
1365
|
+
if (flagsSec) {
|
|
1366
|
+
output.push(helper.styleTitle(`${resolveTitle("flags")}:`));
|
|
1367
|
+
output.push(...flagsSec.items);
|
|
1368
|
+
output.push("");
|
|
1369
|
+
}
|
|
1370
|
+
const defs = getStreamDefs(cmd);
|
|
1371
|
+
if (defs.length > 0) {
|
|
1372
|
+
const styleTerm = _nullishCoalesce(_optionalChain([helper, 'access', _41 => _41.styleOptionTerm, 'optionalAccess', _42 => _42.bind, 'call', _43 => _43(helper)]), () => ( ((s) => s)));
|
|
1373
|
+
const styleDesc = _nullishCoalesce(_optionalChain([helper, 'access', _44 => _44.styleDescriptionText, 'optionalAccess', _45 => _45.bind, 'call', _46 => _46(helper)]), () => ( ((s) => s)));
|
|
1374
|
+
output.push(helper.styleTitle("STREAMS:"));
|
|
1375
|
+
for (const d of defs) {
|
|
1376
|
+
output.push(callFormatItem(styleTerm(d.name), styleDesc(d.description)));
|
|
1377
|
+
}
|
|
1378
|
+
output.push("");
|
|
1379
|
+
}
|
|
1380
|
+
return output.join("\n") + "\n";
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
function findHelpTarget(root, operands) {
|
|
1385
|
+
let cmd;
|
|
1386
|
+
let scope = root;
|
|
1387
|
+
for (const word of operands) {
|
|
1388
|
+
cmd = scope.commands.find((c) => c.name() === word || c.aliases().includes(word));
|
|
1389
|
+
if (!cmd) return void 0;
|
|
1390
|
+
scope = cmd;
|
|
1391
|
+
}
|
|
1392
|
+
return cmd;
|
|
1393
|
+
}
|
|
1394
|
+
function createCLI(cfg) {
|
|
1395
|
+
const theme = buildTheme(cfg.accent);
|
|
1396
|
+
const desc = _optionalChain([cfg, 'access', _47 => _47.help, 'optionalAccess', _48 => _48.disclaimer]) ? `${cfg.description}
|
|
1397
|
+
|
|
1398
|
+
${cfg.help.disclaimer}` : cfg.description;
|
|
1399
|
+
const normalizedVersion = cfg.version.startsWith("v") ? cfg.version : `v${cfg.version}`;
|
|
1400
|
+
const versionOutput = `${cfg.name} ${normalizedVersion}`;
|
|
1401
|
+
const program = new (0, _commander.Command)(cfg.name).description(desc).version(versionOutput, "-v, --version", `Print ${cfg.name} version and exit`).helpOption("-h, --help", "Display help").addHelpCommand(false).showHelpAfterError(true);
|
|
1402
|
+
if (!_optionalChain([cfg, 'access', _49 => _49.disable, 'optionalAccess', _50 => _50.format])) {
|
|
1403
|
+
_chunkGFRAYYRDjs.registerOutputFlags.call(void 0, program);
|
|
1404
|
+
}
|
|
1405
|
+
if (!_optionalChain([cfg, 'access', _51 => _51.disable, 'optionalAccess', _52 => _52.quiet])) {
|
|
1406
|
+
program.option("--quiet", "Suppress non-essential output", false);
|
|
1407
|
+
}
|
|
1408
|
+
if (!_optionalChain([cfg, 'access', _53 => _53.disable, 'optionalAccess', _54 => _54.noColor])) {
|
|
1409
|
+
program.option("--no-color", "Disable ANSI colour", false);
|
|
1410
|
+
}
|
|
1411
|
+
if (!_optionalChain([cfg, 'access', _55 => _55.disable, 'optionalAccess', _56 => _56.hints])) {
|
|
1412
|
+
program.option("--no-hints", "Suppress next-step hints after command output", false);
|
|
1413
|
+
}
|
|
1414
|
+
if (!_optionalChain([cfg, 'access', _57 => _57.disable, 'optionalAccess', _58 => _58.offline])) {
|
|
1415
|
+
program.option("--offline", "Disable network access", false);
|
|
1416
|
+
_chunkKVG7YCTSjs.install.call(void 0, );
|
|
1417
|
+
const stamp = (thisCmd) => {
|
|
1418
|
+
_chunkKVG7YCTSjs.setProcessOffline.call(void 0, thisCmd.opts()["offline"] === true);
|
|
1419
|
+
};
|
|
1420
|
+
program.hook("preSubcommand", (thisCmd) => stamp(thisCmd));
|
|
1421
|
+
program.hook("preAction", (thisCmd) => stamp(thisCmd));
|
|
1422
|
+
}
|
|
1423
|
+
installDelegation(program, {
|
|
1424
|
+
policy: cfg.policy,
|
|
1425
|
+
promptSource: cfg.promptSource,
|
|
1426
|
+
disableDryRun: _optionalChain([cfg, 'access', _59 => _59.disable, 'optionalAccess', _60 => _60.dryRun]) === true
|
|
1427
|
+
});
|
|
1428
|
+
program.option(
|
|
1429
|
+
verbosityFlagSpec(_chunkT6OZMPPVjs.parity),
|
|
1430
|
+
"Increase verbosity",
|
|
1431
|
+
(_, prev) => prev + 1,
|
|
1432
|
+
0
|
|
1433
|
+
);
|
|
1434
|
+
program.hook("preAction", (thisCmd) => {
|
|
1435
|
+
const opts = thisCmd.opts();
|
|
1436
|
+
const quiet = opts.quiet === true;
|
|
1437
|
+
quietMap.set(thisCmd, quiet);
|
|
1438
|
+
verboseCountMap.set(thisCmd, quiet ? 0 : _nullishCoalesce(opts.verbose, () => ( 0)));
|
|
1439
|
+
});
|
|
1440
|
+
if (_optionalChain([cfg, 'access', _61 => _61.groups, 'optionalAccess', _62 => _62.some, 'call', _63 => _63((g) => g.hidden)])) {
|
|
1441
|
+
program.option("--help-all", "Show all commands including hidden groups");
|
|
1442
|
+
program.on("option:help-all", () => {
|
|
1443
|
+
program.help();
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
for (const g of _nullishCoalesce(cfg.groups, () => ( []))) {
|
|
1447
|
+
program.option(`--help-${g.id}`, `Show ${g.title} commands`);
|
|
1448
|
+
program.on(`option:help-${g.id}`, () => {
|
|
1449
|
+
program.help();
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
if (cfg.groups && cfg.groups.length > 0) {
|
|
1453
|
+
const groupIds = cfg.groups.map((g) => g.id);
|
|
1454
|
+
const helpCmd = program.command("help [operands...]").description("Show help for a command or command group").action((operands) => {
|
|
1455
|
+
if (operands.length === 0) {
|
|
1456
|
+
program.help();
|
|
1457
|
+
}
|
|
1458
|
+
if (operands.length === 1 && operands[0] === "all") {
|
|
1459
|
+
process.argv.push("--help-all");
|
|
1460
|
+
program.help();
|
|
1461
|
+
}
|
|
1462
|
+
const target = findHelpTarget(program, operands);
|
|
1463
|
+
if (target) {
|
|
1464
|
+
target.help();
|
|
1465
|
+
}
|
|
1466
|
+
if (operands.length === 1 && groupIds.includes(operands[0])) {
|
|
1467
|
+
process.argv.push(`--help-${operands[0]}`);
|
|
1468
|
+
program.help();
|
|
1469
|
+
}
|
|
1470
|
+
program.error(
|
|
1471
|
+
`error: unknown help topic '${operands.join(" ")}' for '${program.name()}'`,
|
|
1472
|
+
{ exitCode: _chunkPOR5L2DGjs.EXIT_USAGE, code: "commander.unknownCommand" }
|
|
1473
|
+
);
|
|
1474
|
+
});
|
|
1475
|
+
helpCmd.hideHelp = true;
|
|
1476
|
+
helpCmd._hidden = true;
|
|
1477
|
+
}
|
|
1478
|
+
for (const g of _nullishCoalesce(cfg.globals, () => ( []))) {
|
|
1479
|
+
const flag = g.short ? `-${g.short}, --${g.name} <value>` : `--${g.name} <value>`;
|
|
1480
|
+
program.option(flag, g.usage, _nullishCoalesce(g.default, () => ( "")));
|
|
1481
|
+
}
|
|
1482
|
+
_chunk65VPWMPVjs.installCompletionRequest.call(void 0, program);
|
|
1483
|
+
applyHelpTheme(
|
|
1484
|
+
program,
|
|
1485
|
+
theme,
|
|
1486
|
+
false,
|
|
1487
|
+
_optionalChain([cfg, 'access', _64 => _64.help, 'optionalAccess', _65 => _65.sectionOrder]),
|
|
1488
|
+
_optionalChain([cfg, 'access', _66 => _66.help, 'optionalAccess', _67 => _67.showAliases]),
|
|
1489
|
+
cfg.groups
|
|
1490
|
+
);
|
|
1491
|
+
const existing = _nullishCoalesce(program._outputConfiguration, () => ( {}));
|
|
1492
|
+
program.configureOutput({
|
|
1493
|
+
...existing,
|
|
1494
|
+
outputError(str, write) {
|
|
1495
|
+
const nc = process.argv.includes("--no-color") || process.env["NO_COLOR"] !== void 0;
|
|
1496
|
+
if (nc) {
|
|
1497
|
+
write(str);
|
|
1498
|
+
} else {
|
|
1499
|
+
write(ansi(theme.error, str));
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
return { program, theme };
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
|
|
1507
|
+
|
|
1508
|
+
|
|
1509
|
+
|
|
1510
|
+
|
|
1511
|
+
|
|
1512
|
+
|
|
1513
|
+
|
|
1514
|
+
|
|
1515
|
+
|
|
1516
|
+
|
|
1517
|
+
|
|
1518
|
+
|
|
1519
|
+
|
|
1520
|
+
|
|
1521
|
+
|
|
1522
|
+
|
|
1523
|
+
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
|
|
1527
|
+
|
|
1528
|
+
|
|
1529
|
+
|
|
1530
|
+
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
|
|
1534
|
+
|
|
1535
|
+
|
|
1536
|
+
|
|
1537
|
+
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
exports.renderPlan = renderPlan; exports.KIT_DEFAULT_NAME = KIT_DEFAULT_NAME; exports.MaxOpsExceededError = MaxOpsExceededError; exports.kitDefault = kitDefault; exports.Engine = Engine; exports.resolvePolicyPath = resolvePolicyPath; exports.loadPolicy = loadPolicy; exports.loadNamedPolicy = loadNamedPolicy; exports.defaultPolicyLoader = defaultPolicyLoader; exports.noPrompt = noPrompt; exports.scriptedPrompt = scriptedPrompt; exports.controllingTTY = controllingTTY; exports.resolveConfirmMode = resolveConfirmMode; exports.destructiveToken = destructiveToken; exports.resolveDryRunPolicy = resolveDryRunPolicy; exports.dryRunApplied = dryRunApplied; exports.isDryRun = isDryRun; exports.installConfirmTokenFlag = installConfirmTokenFlag; exports.HintSet = HintSet; exports.active = active; exports.hintsEnabled = hintsEnabled; exports.renderHints = renderHints; exports.registerUpgradeHints = registerUpgradeHints; exports.registerVersionHints = registerVersionHints; exports.verbosityShorthand = verbosityShorthand; exports.verbosityFlagSpec = verbosityFlagSpec; exports.verboseCount = verboseCount; exports.isQuiet = isQuiet; exports.streamFlagName = streamFlagName; exports.streamLabel = streamLabel; exports.streamOutput = streamOutput; exports.registerStream = registerStream; exports.getStreamDefs = getStreamDefs; exports.channel = channel; exports.Neon = Neon; exports.Dark = Dark; exports.buildTheme = buildTheme; exports.setCommandGroup = setCommandGroup; exports.getCommandGroup = getCommandGroup; exports.applyHelpTheme = applyHelpTheme; exports.createCLI = createCLI; exports.cli_exports = cli_exports;
|