@stoneforge/quarry 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +160 -0
- package/dist/api/index.d.ts +8 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +8 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/quarry-api.d.ts +268 -0
- package/dist/api/quarry-api.d.ts.map +1 -0
- package/dist/api/quarry-api.js +3905 -0
- package/dist/api/quarry-api.js.map +1 -0
- package/dist/api/types.d.ts +1359 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +204 -0
- package/dist/api/types.js.map +1 -0
- package/dist/bin/sf.d.ts +3 -0
- package/dist/bin/sf.d.ts.map +1 -0
- package/dist/bin/sf.js +9 -0
- package/dist/bin/sf.js.map +1 -0
- package/dist/cli/commands/admin.d.ts +11 -0
- package/dist/cli/commands/admin.d.ts.map +1 -0
- package/dist/cli/commands/admin.js +465 -0
- package/dist/cli/commands/admin.js.map +1 -0
- package/dist/cli/commands/alias.d.ts +8 -0
- package/dist/cli/commands/alias.d.ts.map +1 -0
- package/dist/cli/commands/alias.js +70 -0
- package/dist/cli/commands/alias.js.map +1 -0
- package/dist/cli/commands/channel.d.ts +13 -0
- package/dist/cli/commands/channel.d.ts.map +1 -0
- package/dist/cli/commands/channel.js +680 -0
- package/dist/cli/commands/channel.js.map +1 -0
- package/dist/cli/commands/completion.d.ts +8 -0
- package/dist/cli/commands/completion.d.ts.map +1 -0
- package/dist/cli/commands/completion.js +87 -0
- package/dist/cli/commands/completion.js.map +1 -0
- package/dist/cli/commands/config.d.ts +12 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +242 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/crud.d.ts +64 -0
- package/dist/cli/commands/crud.d.ts.map +1 -0
- package/dist/cli/commands/crud.js +805 -0
- package/dist/cli/commands/crud.js.map +1 -0
- package/dist/cli/commands/dep.d.ts +16 -0
- package/dist/cli/commands/dep.d.ts.map +1 -0
- package/dist/cli/commands/dep.js +499 -0
- package/dist/cli/commands/dep.js.map +1 -0
- package/dist/cli/commands/document.d.ts +12 -0
- package/dist/cli/commands/document.d.ts.map +1 -0
- package/dist/cli/commands/document.js +1039 -0
- package/dist/cli/commands/document.js.map +1 -0
- package/dist/cli/commands/embeddings.d.ts +12 -0
- package/dist/cli/commands/embeddings.d.ts.map +1 -0
- package/dist/cli/commands/embeddings.js +273 -0
- package/dist/cli/commands/embeddings.js.map +1 -0
- package/dist/cli/commands/entity.d.ts +16 -0
- package/dist/cli/commands/entity.d.ts.map +1 -0
- package/dist/cli/commands/entity.js +522 -0
- package/dist/cli/commands/entity.js.map +1 -0
- package/dist/cli/commands/gc.d.ts +10 -0
- package/dist/cli/commands/gc.d.ts.map +1 -0
- package/dist/cli/commands/gc.js +257 -0
- package/dist/cli/commands/gc.js.map +1 -0
- package/dist/cli/commands/help.d.ts +11 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/help.js +169 -0
- package/dist/cli/commands/help.js.map +1 -0
- package/dist/cli/commands/history.d.ts +9 -0
- package/dist/cli/commands/history.d.ts.map +1 -0
- package/dist/cli/commands/history.js +160 -0
- package/dist/cli/commands/history.js.map +1 -0
- package/dist/cli/commands/identity.d.ts +18 -0
- package/dist/cli/commands/identity.d.ts.map +1 -0
- package/dist/cli/commands/identity.js +698 -0
- package/dist/cli/commands/identity.js.map +1 -0
- package/dist/cli/commands/inbox.d.ts +20 -0
- package/dist/cli/commands/inbox.d.ts.map +1 -0
- package/dist/cli/commands/inbox.js +493 -0
- package/dist/cli/commands/inbox.js.map +1 -0
- package/dist/cli/commands/init.d.ts +20 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +144 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/install.d.ts +9 -0
- package/dist/cli/commands/install.d.ts.map +1 -0
- package/dist/cli/commands/install.js +200 -0
- package/dist/cli/commands/install.js.map +1 -0
- package/dist/cli/commands/library.d.ts +12 -0
- package/dist/cli/commands/library.d.ts.map +1 -0
- package/dist/cli/commands/library.js +665 -0
- package/dist/cli/commands/library.js.map +1 -0
- package/dist/cli/commands/message.d.ts +11 -0
- package/dist/cli/commands/message.d.ts.map +1 -0
- package/dist/cli/commands/message.js +608 -0
- package/dist/cli/commands/message.js.map +1 -0
- package/dist/cli/commands/plan.d.ts +17 -0
- package/dist/cli/commands/plan.d.ts.map +1 -0
- package/dist/cli/commands/plan.js +698 -0
- package/dist/cli/commands/plan.js.map +1 -0
- package/dist/cli/commands/playbook.d.ts +12 -0
- package/dist/cli/commands/playbook.d.ts.map +1 -0
- package/dist/cli/commands/playbook.js +730 -0
- package/dist/cli/commands/playbook.js.map +1 -0
- package/dist/cli/commands/reset.d.ts +12 -0
- package/dist/cli/commands/reset.d.ts.map +1 -0
- package/dist/cli/commands/reset.js +306 -0
- package/dist/cli/commands/reset.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +11 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +106 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/stats.d.ts +8 -0
- package/dist/cli/commands/stats.d.ts.map +1 -0
- package/dist/cli/commands/stats.js +82 -0
- package/dist/cli/commands/stats.js.map +1 -0
- package/dist/cli/commands/sync.d.ts +14 -0
- package/dist/cli/commands/sync.d.ts.map +1 -0
- package/dist/cli/commands/sync.js +370 -0
- package/dist/cli/commands/sync.js.map +1 -0
- package/dist/cli/commands/task.d.ts +25 -0
- package/dist/cli/commands/task.d.ts.map +1 -0
- package/dist/cli/commands/task.js +1153 -0
- package/dist/cli/commands/task.js.map +1 -0
- package/dist/cli/commands/team.d.ts +13 -0
- package/dist/cli/commands/team.d.ts.map +1 -0
- package/dist/cli/commands/team.js +471 -0
- package/dist/cli/commands/team.js.map +1 -0
- package/dist/cli/commands/workflow.d.ts +16 -0
- package/dist/cli/commands/workflow.d.ts.map +1 -0
- package/dist/cli/commands/workflow.js +753 -0
- package/dist/cli/commands/workflow.js.map +1 -0
- package/dist/cli/completion.d.ts +28 -0
- package/dist/cli/completion.d.ts.map +1 -0
- package/dist/cli/completion.js +295 -0
- package/dist/cli/completion.js.map +1 -0
- package/dist/cli/db.d.ts +38 -0
- package/dist/cli/db.d.ts.map +1 -0
- package/dist/cli/db.js +90 -0
- package/dist/cli/db.js.map +1 -0
- package/dist/cli/formatter.d.ts +87 -0
- package/dist/cli/formatter.d.ts.map +1 -0
- package/dist/cli/formatter.js +464 -0
- package/dist/cli/formatter.js.map +1 -0
- package/dist/cli/index.d.ts +33 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +38 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/parser.d.ts +45 -0
- package/dist/cli/parser.d.ts.map +1 -0
- package/dist/cli/parser.js +256 -0
- package/dist/cli/parser.js.map +1 -0
- package/dist/cli/plugin-loader.d.ts +39 -0
- package/dist/cli/plugin-loader.d.ts.map +1 -0
- package/dist/cli/plugin-loader.js +165 -0
- package/dist/cli/plugin-loader.js.map +1 -0
- package/dist/cli/plugin-registry.d.ts +50 -0
- package/dist/cli/plugin-registry.d.ts.map +1 -0
- package/dist/cli/plugin-registry.js +206 -0
- package/dist/cli/plugin-registry.js.map +1 -0
- package/dist/cli/plugin-types.d.ts +106 -0
- package/dist/cli/plugin-types.d.ts.map +1 -0
- package/dist/cli/plugin-types.js +103 -0
- package/dist/cli/plugin-types.js.map +1 -0
- package/dist/cli/runner.d.ts +35 -0
- package/dist/cli/runner.d.ts.map +1 -0
- package/dist/cli/runner.js +340 -0
- package/dist/cli/runner.js.map +1 -0
- package/dist/cli/suggest.d.ts +15 -0
- package/dist/cli/suggest.d.ts.map +1 -0
- package/dist/cli/suggest.js +49 -0
- package/dist/cli/suggest.js.map +1 -0
- package/dist/cli/types.d.ts +138 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +63 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/config/config.d.ts +86 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +348 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/defaults.d.ts +66 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +114 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/duration.d.ts +75 -0
- package/dist/config/duration.d.ts.map +1 -0
- package/dist/config/duration.js +190 -0
- package/dist/config/duration.js.map +1 -0
- package/dist/config/env.d.ts +67 -0
- package/dist/config/env.d.ts.map +1 -0
- package/dist/config/env.js +207 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/file.d.ts +97 -0
- package/dist/config/file.d.ts.map +1 -0
- package/dist/config/file.js +365 -0
- package/dist/config/file.js.map +1 -0
- package/dist/config/index.d.ts +35 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +41 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/merge.d.ts +53 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/merge.js +226 -0
- package/dist/config/merge.js.map +1 -0
- package/dist/config/types.d.ts +257 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +72 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/validation.d.ts +55 -0
- package/dist/config/validation.d.ts.map +1 -0
- package/dist/config/validation.js +251 -0
- package/dist/config/validation.js.map +1 -0
- package/dist/http/index.d.ts +8 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +12 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/sync-handlers.d.ts +162 -0
- package/dist/http/sync-handlers.d.ts.map +1 -0
- package/dist/http/sync-handlers.js +271 -0
- package/dist/http/sync-handlers.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/server/index.d.ts +34 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3329 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/static.d.ts +18 -0
- package/dist/server/static.d.ts.map +1 -0
- package/dist/server/static.js +71 -0
- package/dist/server/static.js.map +1 -0
- package/dist/server/ws/broadcaster.d.ts +8 -0
- package/dist/server/ws/broadcaster.d.ts.map +1 -0
- package/dist/server/ws/broadcaster.js +7 -0
- package/dist/server/ws/broadcaster.js.map +1 -0
- package/dist/server/ws/handler.d.ts +55 -0
- package/dist/server/ws/handler.d.ts.map +1 -0
- package/dist/server/ws/handler.js +160 -0
- package/dist/server/ws/handler.js.map +1 -0
- package/dist/services/blocked-cache.d.ts +297 -0
- package/dist/services/blocked-cache.d.ts.map +1 -0
- package/dist/services/blocked-cache.js +755 -0
- package/dist/services/blocked-cache.js.map +1 -0
- package/dist/services/dependency.d.ts +205 -0
- package/dist/services/dependency.d.ts.map +1 -0
- package/dist/services/dependency.js +566 -0
- package/dist/services/dependency.js.map +1 -0
- package/dist/services/embeddings/fusion.d.ts +33 -0
- package/dist/services/embeddings/fusion.d.ts.map +1 -0
- package/dist/services/embeddings/fusion.js +34 -0
- package/dist/services/embeddings/fusion.js.map +1 -0
- package/dist/services/embeddings/index.d.ts +12 -0
- package/dist/services/embeddings/index.d.ts.map +1 -0
- package/dist/services/embeddings/index.js +10 -0
- package/dist/services/embeddings/index.js.map +1 -0
- package/dist/services/embeddings/local-provider.d.ts +31 -0
- package/dist/services/embeddings/local-provider.d.ts.map +1 -0
- package/dist/services/embeddings/local-provider.js +80 -0
- package/dist/services/embeddings/local-provider.js.map +1 -0
- package/dist/services/embeddings/service.d.ts +76 -0
- package/dist/services/embeddings/service.d.ts.map +1 -0
- package/dist/services/embeddings/service.js +153 -0
- package/dist/services/embeddings/service.js.map +1 -0
- package/dist/services/embeddings/types.d.ts +70 -0
- package/dist/services/embeddings/types.d.ts.map +1 -0
- package/dist/services/embeddings/types.js +8 -0
- package/dist/services/embeddings/types.js.map +1 -0
- package/dist/services/id-length-cache.d.ts +156 -0
- package/dist/services/id-length-cache.d.ts.map +1 -0
- package/dist/services/id-length-cache.js +197 -0
- package/dist/services/id-length-cache.js.map +1 -0
- package/dist/services/inbox.d.ts +147 -0
- package/dist/services/inbox.d.ts.map +1 -0
- package/dist/services/inbox.js +428 -0
- package/dist/services/inbox.js.map +1 -0
- package/dist/services/index.d.ts +10 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +10 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/priority-service.d.ts +145 -0
- package/dist/services/priority-service.d.ts.map +1 -0
- package/dist/services/priority-service.js +272 -0
- package/dist/services/priority-service.js.map +1 -0
- package/dist/services/search-utils.d.ts +47 -0
- package/dist/services/search-utils.d.ts.map +1 -0
- package/dist/services/search-utils.js +83 -0
- package/dist/services/search-utils.js.map +1 -0
- package/dist/sync/hash.d.ts +48 -0
- package/dist/sync/hash.d.ts.map +1 -0
- package/dist/sync/hash.js +136 -0
- package/dist/sync/hash.js.map +1 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +16 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/merge.d.ts +80 -0
- package/dist/sync/merge.d.ts.map +1 -0
- package/dist/sync/merge.js +310 -0
- package/dist/sync/merge.js.map +1 -0
- package/dist/sync/serialization.d.ts +132 -0
- package/dist/sync/serialization.d.ts.map +1 -0
- package/dist/sync/serialization.js +306 -0
- package/dist/sync/serialization.js.map +1 -0
- package/dist/sync/service.d.ts +102 -0
- package/dist/sync/service.d.ts.map +1 -0
- package/dist/sync/service.js +493 -0
- package/dist/sync/service.js.map +1 -0
- package/dist/sync/types.d.ts +275 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +76 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/systems/identity.d.ts +479 -0
- package/dist/systems/identity.d.ts.map +1 -0
- package/dist/systems/identity.js +817 -0
- package/dist/systems/identity.js.map +1 -0
- package/dist/systems/index.d.ts +8 -0
- package/dist/systems/index.d.ts.map +1 -0
- package/dist/systems/index.js +29 -0
- package/dist/systems/index.js.map +1 -0
- package/package.json +121 -0
- package/web/assets/charts-vendor-D1YcbGux.js +55 -0
- package/web/assets/dnd-vendor-DmxE-_ZH.js +5 -0
- package/web/assets/editor-vendor-BxraAWts.js +279 -0
- package/web/assets/index-B77vv208.js +341 -0
- package/web/assets/index-CF_XnVLh.css +1 -0
- package/web/assets/router-vendor-BCKpRBrB.js +41 -0
- package/web/assets/ui-vendor-DUahGnbT.js +45 -0
- package/web/assets/utils-vendor-CfYKiENT.js +813 -0
- package/web/favicon.ico +0 -0
- package/web/index.html +23 -0
- package/web/logo.png +0 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Argument Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses command-line arguments into structured command and options.
|
|
5
|
+
*/
|
|
6
|
+
import { DEFAULT_GLOBAL_OPTIONS } from './types.js';
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Shell Escape Handling
|
|
9
|
+
// ============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Unescapes common shell escape sequences that shells may add.
|
|
12
|
+
*
|
|
13
|
+
* Shells like bash and zsh often escape exclamation marks (!) with backslashes
|
|
14
|
+
* to disable history expansion. When running commands through nested shells or
|
|
15
|
+
* through tools like Claude Code, multiple layers of escaping can occur,
|
|
16
|
+
* resulting in sequences like \\! or even \\\\!
|
|
17
|
+
*
|
|
18
|
+
* This function removes those unnecessary escapes to provide the expected user input.
|
|
19
|
+
*
|
|
20
|
+
* @param value - The string value to unescape
|
|
21
|
+
* @returns The unescaped string
|
|
22
|
+
*/
|
|
23
|
+
export function unescapeShellArtifacts(value) {
|
|
24
|
+
// Unescape any sequence of one or more backslashes followed by exclamation mark
|
|
25
|
+
// to just the exclamation mark. This handles:
|
|
26
|
+
// - \! -> ! (single escape from shell history expansion)
|
|
27
|
+
// - \\! -> ! (double escape from nested shells)
|
|
28
|
+
// - \\\\! -> ! (quadruple escape from multiple layers)
|
|
29
|
+
return value.replace(/\\+!/g, '!');
|
|
30
|
+
}
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// Global Option Definitions
|
|
33
|
+
// ============================================================================
|
|
34
|
+
const GLOBAL_OPTIONS = {
|
|
35
|
+
'--db': { hasValue: true, key: 'db' },
|
|
36
|
+
'--actor': { hasValue: true, key: 'actor' },
|
|
37
|
+
'--from': { hasValue: true, key: 'actor' }, // Alias for --actor
|
|
38
|
+
'--sign-key': { hasValue: true, key: 'signKey' },
|
|
39
|
+
'--sign-key-file': { hasValue: true, key: 'signKeyFile' },
|
|
40
|
+
'--json': { key: 'json' },
|
|
41
|
+
'--quiet': { short: '-q', key: 'quiet' },
|
|
42
|
+
'--verbose': { short: '-v', key: 'verbose' },
|
|
43
|
+
'--help': { short: '-h', key: 'help' },
|
|
44
|
+
'--version': { short: '-V', key: 'version' },
|
|
45
|
+
};
|
|
46
|
+
// Build reverse lookup for short options
|
|
47
|
+
const SHORT_TO_LONG = {};
|
|
48
|
+
for (const [long, def] of Object.entries(GLOBAL_OPTIONS)) {
|
|
49
|
+
if (def.short) {
|
|
50
|
+
SHORT_TO_LONG[def.short] = long;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// ============================================================================
|
|
54
|
+
// Parse Function
|
|
55
|
+
// ============================================================================
|
|
56
|
+
/**
|
|
57
|
+
* Parses command-line arguments
|
|
58
|
+
*
|
|
59
|
+
* @param argv - Raw arguments (typically process.argv.slice(2))
|
|
60
|
+
* @param commandOptions - Optional command-specific option definitions
|
|
61
|
+
* @param parserOptions - Parser options
|
|
62
|
+
* @param parserOptions.strict - If false, unknown options are skipped instead of throwing (default: true)
|
|
63
|
+
* @returns Parsed command line structure
|
|
64
|
+
*/
|
|
65
|
+
export function parseArgs(argv, commandOptions = [], parserOptions = {}) {
|
|
66
|
+
const { strict = true } = parserOptions;
|
|
67
|
+
const command = [];
|
|
68
|
+
const args = [];
|
|
69
|
+
const options = { ...DEFAULT_GLOBAL_OPTIONS };
|
|
70
|
+
const cmdOptions = {};
|
|
71
|
+
// Build command option lookup
|
|
72
|
+
const cmdOptDefs = {};
|
|
73
|
+
for (const opt of commandOptions) {
|
|
74
|
+
cmdOptDefs[`--${opt.name}`] = { hasValue: opt.hasValue, key: opt.name, array: opt.array };
|
|
75
|
+
if (opt.short) {
|
|
76
|
+
cmdOptDefs[`-${opt.short}`] = { hasValue: opt.hasValue, key: opt.name, array: opt.array };
|
|
77
|
+
}
|
|
78
|
+
// Set defaults
|
|
79
|
+
if (opt.defaultValue !== undefined) {
|
|
80
|
+
cmdOptions[opt.name] = opt.defaultValue;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let i = 0;
|
|
84
|
+
let parsingOptions = true;
|
|
85
|
+
while (i < argv.length) {
|
|
86
|
+
const arg = argv[i];
|
|
87
|
+
// -- stops option parsing, remaining args are positional
|
|
88
|
+
if (arg === '--') {
|
|
89
|
+
i++;
|
|
90
|
+
// Add all remaining arguments as positional args
|
|
91
|
+
while (i < argv.length) {
|
|
92
|
+
args.push(unescapeShellArtifacts(argv[i]));
|
|
93
|
+
i++;
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
// Options
|
|
98
|
+
if (parsingOptions && arg.startsWith('-')) {
|
|
99
|
+
// Handle combined short options (e.g., -qv)
|
|
100
|
+
if (arg.length > 2 && arg[1] !== '-' && !arg.includes('=')) {
|
|
101
|
+
// Expand combined short options
|
|
102
|
+
const shorts = arg.slice(1).split('');
|
|
103
|
+
for (const s of shorts) {
|
|
104
|
+
const shortOpt = `-${s}`;
|
|
105
|
+
const longOpt = SHORT_TO_LONG[shortOpt];
|
|
106
|
+
if (longOpt) {
|
|
107
|
+
const def = GLOBAL_OPTIONS[longOpt];
|
|
108
|
+
if (!def.hasValue) {
|
|
109
|
+
options[def.key] = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
i++;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
// Handle --option=value syntax
|
|
117
|
+
let optName = arg;
|
|
118
|
+
let optValue;
|
|
119
|
+
const eqIndex = arg.indexOf('=');
|
|
120
|
+
if (eqIndex !== -1) {
|
|
121
|
+
optName = arg.slice(0, eqIndex);
|
|
122
|
+
optValue = arg.slice(eqIndex + 1);
|
|
123
|
+
}
|
|
124
|
+
// Normalize short to long
|
|
125
|
+
const normalizedOpt = SHORT_TO_LONG[optName] || optName;
|
|
126
|
+
// Check global options
|
|
127
|
+
const globalDef = GLOBAL_OPTIONS[normalizedOpt];
|
|
128
|
+
if (globalDef) {
|
|
129
|
+
if (globalDef.hasValue) {
|
|
130
|
+
const value = optValue ?? argv[++i];
|
|
131
|
+
if (value === undefined || value.startsWith('-')) {
|
|
132
|
+
throw new Error(`Option ${optName} requires a value`);
|
|
133
|
+
}
|
|
134
|
+
options[globalDef.key] = unescapeShellArtifacts(value);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
options[globalDef.key] = true;
|
|
138
|
+
}
|
|
139
|
+
i++;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// Check command-specific options
|
|
143
|
+
const cmdDef = cmdOptDefs[optName];
|
|
144
|
+
if (cmdDef) {
|
|
145
|
+
if (cmdDef.hasValue) {
|
|
146
|
+
const value = optValue ?? argv[++i];
|
|
147
|
+
if (value === undefined || (value.startsWith('-') && value !== '-')) {
|
|
148
|
+
throw new Error(`Option ${optName} requires a value`);
|
|
149
|
+
}
|
|
150
|
+
const unescapedValue = unescapeShellArtifacts(value);
|
|
151
|
+
if (cmdDef.array) {
|
|
152
|
+
// Accumulate values into an array for array options
|
|
153
|
+
const existing = cmdOptions[cmdDef.key];
|
|
154
|
+
if (Array.isArray(existing)) {
|
|
155
|
+
existing.push(unescapedValue);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
cmdOptions[cmdDef.key] = [unescapedValue];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
cmdOptions[cmdDef.key] = unescapedValue;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
cmdOptions[cmdDef.key] = true;
|
|
167
|
+
}
|
|
168
|
+
i++;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
// Unknown option
|
|
172
|
+
if (strict) {
|
|
173
|
+
throw new Error(`Unknown option: ${optName}`);
|
|
174
|
+
}
|
|
175
|
+
// In non-strict mode, skip unknown options (and their values if using = syntax)
|
|
176
|
+
i++;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
// Commands and positional arguments
|
|
180
|
+
// First non-option args are commands/subcommands, subsequent are positional args
|
|
181
|
+
// Once we've started collecting positional args, don't add more to command path
|
|
182
|
+
if ((command.length === 0 || isSubcommand(arg)) && args.length === 0) {
|
|
183
|
+
command.push(arg);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
args.push(unescapeShellArtifacts(arg));
|
|
187
|
+
}
|
|
188
|
+
i++;
|
|
189
|
+
}
|
|
190
|
+
return { command, args, options, commandOptions: cmdOptions };
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Checks if an argument looks like a subcommand (not an ID or path)
|
|
194
|
+
*/
|
|
195
|
+
function isSubcommand(arg) {
|
|
196
|
+
// Element IDs start with 'el-'
|
|
197
|
+
if (arg.startsWith('el-'))
|
|
198
|
+
return false;
|
|
199
|
+
// Paths contain slashes
|
|
200
|
+
if (arg.includes('/'))
|
|
201
|
+
return false;
|
|
202
|
+
// Numbers are not subcommands
|
|
203
|
+
if (/^\d+$/.test(arg))
|
|
204
|
+
return false;
|
|
205
|
+
// Otherwise likely a subcommand
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
// ============================================================================
|
|
209
|
+
// Option Validation
|
|
210
|
+
// ============================================================================
|
|
211
|
+
/**
|
|
212
|
+
* Validates that required options are present
|
|
213
|
+
*/
|
|
214
|
+
export function validateRequiredOptions(commandOptions, definitions) {
|
|
215
|
+
for (const opt of definitions) {
|
|
216
|
+
if (opt.required && commandOptions[opt.name] === undefined) {
|
|
217
|
+
throw new Error(`Required option --${opt.name} is missing`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// ============================================================================
|
|
222
|
+
// Help Text Generation
|
|
223
|
+
// ============================================================================
|
|
224
|
+
/**
|
|
225
|
+
* Generates help text for global options
|
|
226
|
+
*/
|
|
227
|
+
export function getGlobalOptionsHelp() {
|
|
228
|
+
return `Global Options:
|
|
229
|
+
--db <path> Database file path
|
|
230
|
+
--actor <name> Actor name for operations
|
|
231
|
+
--from <name> Alias for --actor
|
|
232
|
+
--sign-key <key> Private key for signing (base64 PKCS8)
|
|
233
|
+
--sign-key-file <path> Path to file containing private key
|
|
234
|
+
--json Output in JSON format
|
|
235
|
+
-q, --quiet Minimal output (IDs only)
|
|
236
|
+
-v, --verbose Enable debug output
|
|
237
|
+
-h, --help Show help
|
|
238
|
+
-V, --version Show version`;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Generates help text for command-specific options
|
|
242
|
+
*/
|
|
243
|
+
export function getCommandOptionsHelp(options) {
|
|
244
|
+
if (options.length === 0)
|
|
245
|
+
return '';
|
|
246
|
+
const lines = ['Command Options:'];
|
|
247
|
+
for (const opt of options) {
|
|
248
|
+
const shortPart = opt.short ? `-${opt.short}, ` : ' ';
|
|
249
|
+
const valuePart = opt.hasValue ? ` <${opt.name}>` : '';
|
|
250
|
+
const requiredPart = opt.required ? ' (required)' : '';
|
|
251
|
+
lines.push(` ${shortPart}--${opt.name}${valuePart}${requiredPart}`);
|
|
252
|
+
lines.push(` ${opt.description}`);
|
|
253
|
+
}
|
|
254
|
+
return lines.join('\n');
|
|
255
|
+
}
|
|
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E;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO;;;;;;;;;;sCAU6B,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAwB;IAC5D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEpC,MAAM,KAAK,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACnC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;QACzD,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,KAAK,CAAC,IAAI,CAAC,KAAK,SAAS,KAAK,GAAG,CAAC,IAAI,GAAG,SAAS,GAAG,YAAY,EAAE,CAAC,CAAC;QACrE,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Plugin Loader
|
|
3
|
+
*
|
|
4
|
+
* Discovers and loads CLI plugins from known packages and user configuration.
|
|
5
|
+
*
|
|
6
|
+
* Discovery strategies:
|
|
7
|
+
* 1. Known packages: Auto-detect first-party packages (e.g., @stoneforge/smithy)
|
|
8
|
+
* 2. Config-based: User-specified packages in .stoneforge/config.yaml plugins.packages
|
|
9
|
+
*/
|
|
10
|
+
import type { PluginsConfig, PluginDiscoveryResult } from './plugin-types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Gets the list of known plugin packages
|
|
13
|
+
*/
|
|
14
|
+
export declare function getKnownPluginPackages(): readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* Options for plugin discovery
|
|
17
|
+
*/
|
|
18
|
+
export interface DiscoverPluginsOptions {
|
|
19
|
+
/** Enable verbose logging */
|
|
20
|
+
verbose?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Discovers and loads all plugins from known packages and config.
|
|
24
|
+
*
|
|
25
|
+
* @param config - Optional user plugin configuration
|
|
26
|
+
* @param options - Discovery options
|
|
27
|
+
* @returns Discovery result with loaded plugins and status
|
|
28
|
+
*/
|
|
29
|
+
export declare function discoverPlugins(config?: PluginsConfig, options?: DiscoverPluginsOptions): Promise<PluginDiscoveryResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Logs warnings for failed plugin loads.
|
|
32
|
+
*
|
|
33
|
+
* @param result - Discovery result
|
|
34
|
+
* @param options - Logging options
|
|
35
|
+
*/
|
|
36
|
+
export declare function logPluginWarnings(result: PluginDiscoveryResult, options?: {
|
|
37
|
+
verbose?: boolean;
|
|
38
|
+
}): void;
|
|
39
|
+
//# sourceMappingURL=plugin-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-loader.d.ts","sourceRoot":"","sources":["../../src/cli/plugin-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAEV,aAAa,EACb,qBAAqB,EAEtB,MAAM,mBAAmB,CAAC;AAa3B;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,SAAS,MAAM,EAAE,CAE1D;AAMD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,MAAM,CAAC,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,qBAAqB,CAAC,CAoChC;AA+FD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,qBAAqB,EAC7B,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC9B,IAAI,CAmBN"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Plugin Loader
|
|
3
|
+
*
|
|
4
|
+
* Discovers and loads CLI plugins from known packages and user configuration.
|
|
5
|
+
*
|
|
6
|
+
* Discovery strategies:
|
|
7
|
+
* 1. Known packages: Auto-detect first-party packages (e.g., @stoneforge/smithy)
|
|
8
|
+
* 2. Config-based: User-specified packages in .stoneforge/config.yaml plugins.packages
|
|
9
|
+
*/
|
|
10
|
+
import { isValidCLIPlugin } from './plugin-types.js';
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Known Plugin Packages
|
|
13
|
+
// ============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* First-party packages that are automatically discovered if installed.
|
|
16
|
+
* These are tried silently - if not installed, they're skipped without warning.
|
|
17
|
+
*/
|
|
18
|
+
const KNOWN_PLUGIN_PACKAGES = ['@stoneforge/smithy'];
|
|
19
|
+
/**
|
|
20
|
+
* Gets the list of known plugin packages
|
|
21
|
+
*/
|
|
22
|
+
export function getKnownPluginPackages() {
|
|
23
|
+
return KNOWN_PLUGIN_PACKAGES;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Discovers and loads all plugins from known packages and config.
|
|
27
|
+
*
|
|
28
|
+
* @param config - Optional user plugin configuration
|
|
29
|
+
* @param options - Discovery options
|
|
30
|
+
* @returns Discovery result with loaded plugins and status
|
|
31
|
+
*/
|
|
32
|
+
export async function discoverPlugins(config, options) {
|
|
33
|
+
const verbose = options?.verbose ?? false;
|
|
34
|
+
// Combine known packages with user-configured packages (deduplicated)
|
|
35
|
+
const allPackages = new Set([
|
|
36
|
+
...KNOWN_PLUGIN_PACKAGES,
|
|
37
|
+
...(config?.packages ?? []),
|
|
38
|
+
]);
|
|
39
|
+
// Load all plugins in parallel
|
|
40
|
+
const loadPromises = Array.from(allPackages).map((pkg) => loadPlugin(pkg, verbose));
|
|
41
|
+
const results = await Promise.all(loadPromises);
|
|
42
|
+
// Categorize results
|
|
43
|
+
const plugins = [];
|
|
44
|
+
const notFoundPackages = [];
|
|
45
|
+
const failedPackages = [];
|
|
46
|
+
for (const result of results) {
|
|
47
|
+
if (result.success && result.plugin) {
|
|
48
|
+
plugins.push(result.plugin);
|
|
49
|
+
}
|
|
50
|
+
else if (result.notFound) {
|
|
51
|
+
notFoundPackages.push(result.packageName);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
failedPackages.push(result.packageName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
plugins,
|
|
59
|
+
results,
|
|
60
|
+
notFoundPackages,
|
|
61
|
+
failedPackages,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Attempts to load a plugin from a package.
|
|
66
|
+
*
|
|
67
|
+
* @param packageName - Package to load
|
|
68
|
+
* @param verbose - Enable verbose logging
|
|
69
|
+
* @returns Load result
|
|
70
|
+
*/
|
|
71
|
+
async function loadPlugin(packageName, verbose) {
|
|
72
|
+
try {
|
|
73
|
+
// Try to import the package
|
|
74
|
+
const module = await import(packageName);
|
|
75
|
+
// Look for cliPlugin export
|
|
76
|
+
const plugin = module.cliPlugin;
|
|
77
|
+
if (!plugin) {
|
|
78
|
+
// Package exists but doesn't export cliPlugin - silent skip
|
|
79
|
+
if (verbose) {
|
|
80
|
+
console.error(`[plugin] ${packageName}: no cliPlugin export found`);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
packageName,
|
|
84
|
+
success: false,
|
|
85
|
+
notFound: true, // Treat as "not a plugin package"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// Validate plugin structure
|
|
89
|
+
if (!isValidCLIPlugin(plugin)) {
|
|
90
|
+
return {
|
|
91
|
+
packageName,
|
|
92
|
+
success: false,
|
|
93
|
+
error: 'Invalid plugin structure',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (verbose) {
|
|
97
|
+
console.error(`[plugin] Loaded ${plugin.name}@${plugin.version}`);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
packageName,
|
|
101
|
+
success: true,
|
|
102
|
+
plugin,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
// Check if it's a "module not found" error
|
|
107
|
+
const isNotFound = isModuleNotFoundError(err, packageName);
|
|
108
|
+
if (isNotFound) {
|
|
109
|
+
return {
|
|
110
|
+
packageName,
|
|
111
|
+
success: false,
|
|
112
|
+
notFound: true,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Actual load error
|
|
116
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
117
|
+
return {
|
|
118
|
+
packageName,
|
|
119
|
+
success: false,
|
|
120
|
+
error: errorMessage,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Checks if an error is a "module not found" error for the given package.
|
|
126
|
+
*/
|
|
127
|
+
function isModuleNotFoundError(err, packageName) {
|
|
128
|
+
if (!(err instanceof Error)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
// Node.js ERR_MODULE_NOT_FOUND
|
|
132
|
+
const errCode = err.code;
|
|
133
|
+
if (errCode === 'ERR_MODULE_NOT_FOUND') {
|
|
134
|
+
// Make sure it's for the specific package, not a transitive dependency
|
|
135
|
+
return err.message.includes(packageName);
|
|
136
|
+
}
|
|
137
|
+
// CommonJS MODULE_NOT_FOUND
|
|
138
|
+
if (errCode === 'MODULE_NOT_FOUND') {
|
|
139
|
+
return err.message.includes(packageName);
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Logs warnings for failed plugin loads.
|
|
145
|
+
*
|
|
146
|
+
* @param result - Discovery result
|
|
147
|
+
* @param options - Logging options
|
|
148
|
+
*/
|
|
149
|
+
export function logPluginWarnings(result, options) {
|
|
150
|
+
const verbose = options?.verbose ?? false;
|
|
151
|
+
// Log warnings for packages that failed to load (not just "not found")
|
|
152
|
+
for (const loadResult of result.results) {
|
|
153
|
+
if (!loadResult.success && !loadResult.notFound && loadResult.error) {
|
|
154
|
+
console.error(`[plugin] Warning: Failed to load ${loadResult.packageName}: ${loadResult.error}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// In verbose mode, also report on successful loads
|
|
158
|
+
if (verbose && result.plugins.length > 0) {
|
|
159
|
+
const pluginList = result.plugins
|
|
160
|
+
.map((p) => `${p.name}@${p.version}`)
|
|
161
|
+
.join(', ');
|
|
162
|
+
console.error(`[plugin] Loaded plugins: ${pluginList}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=plugin-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-loader.js","sourceRoot":"","sources":["../../src/cli/plugin-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,qBAAqB,GAAG,CAAC,oBAAoB,CAAU,CAAC;AAE9D;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAcD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAsB,EACtB,OAAgC;IAEhC,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;IAE1C,sEAAsE;IACtE,MAAM,WAAW,G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
|
1
|
+
/**
|
|
2
|
+
* CLI Plugin Registry
|
|
3
|
+
*
|
|
4
|
+
* Handles registration of plugin commands and aliases with conflict detection.
|
|
5
|
+
* Built-in commands always take precedence over plugin commands.
|
|
6
|
+
*/
|
|
7
|
+
import type { CLIPlugin, PluginRegistrationResult } from './plugin-types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Options for command registration
|
|
10
|
+
*/
|
|
11
|
+
export interface RegisterPluginOptions {
|
|
12
|
+
/** Enable verbose logging */
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Registers all commands and aliases from a single plugin.
|
|
17
|
+
*
|
|
18
|
+
* Built-in commands always take precedence - plugin commands that conflict
|
|
19
|
+
* with existing commands are skipped with a warning.
|
|
20
|
+
*
|
|
21
|
+
* @param plugin - The plugin to register
|
|
22
|
+
* @param options - Registration options
|
|
23
|
+
* @returns Registration result
|
|
24
|
+
*/
|
|
25
|
+
export declare function registerPluginCommands(plugin: CLIPlugin, options?: RegisterPluginOptions): PluginRegistrationResult;
|
|
26
|
+
/**
|
|
27
|
+
* Registers all plugins' commands and aliases.
|
|
28
|
+
*
|
|
29
|
+
* Plugins are registered in order, so earlier plugins take precedence
|
|
30
|
+
* for command names. Built-in commands always take precedence over all plugins.
|
|
31
|
+
*
|
|
32
|
+
* @param plugins - Plugins to register
|
|
33
|
+
* @param options - Registration options
|
|
34
|
+
* @returns Array of registration results
|
|
35
|
+
*/
|
|
36
|
+
export declare function registerAllPlugins(plugins: CLIPlugin[], options?: RegisterPluginOptions): Promise<PluginRegistrationResult[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Logs conflict warnings from registration results.
|
|
39
|
+
*
|
|
40
|
+
* @param results - Registration results to check for conflicts
|
|
41
|
+
*/
|
|
42
|
+
export declare function logConflictWarnings(results: PluginRegistrationResult[]): void;
|
|
43
|
+
/**
|
|
44
|
+
* Gets a summary of registered plugin commands for the help menu.
|
|
45
|
+
*
|
|
46
|
+
* @param results - Registration results
|
|
47
|
+
* @returns Map of plugin name to registered command names
|
|
48
|
+
*/
|
|
49
|
+
export declare function getPluginCommandSummary(results: PluginRegistrationResult[]): Map<string, string[]>;
|
|
50
|
+
//# sourceMappingURL=plugin-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/cli/plugin-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,wBAAwB,EAAoD,MAAM,mBAAmB,CAAC;AAQ/H;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA2CD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,EACjB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,wBAAwB,CA0G1B;AAED;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,SAAS,EAAE,EACpB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAoBrC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,wBAAwB,EAAE,GAAG,IAAI,CAsB7E;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,EAAE,GAClC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAUvB"}
|