harnesstap 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -15
- package/dist/apply-QSS4242W.js +67 -0
- package/dist/apply-QSS4242W.js.map +1 -0
- package/dist/approve-CNYQY6DC.js +181 -0
- package/dist/approve-CNYQY6DC.js.map +1 -0
- package/dist/audit-V4SUV7KA.js +434 -0
- package/dist/audit-V4SUV7KA.js.map +1 -0
- package/dist/auth-63FOHIQ3.js +220 -0
- package/dist/auth-63FOHIQ3.js.map +1 -0
- package/dist/bin.js +166 -0
- package/dist/bin.js.map +1 -0
- package/dist/chunk-2H7UOFLK.js +11 -0
- package/dist/chunk-2H7UOFLK.js.map +1 -0
- package/dist/chunk-2NE3QYMP.js +103 -0
- package/dist/chunk-2NE3QYMP.js.map +1 -0
- package/dist/chunk-2P2EOYEW.js +1140 -0
- package/dist/chunk-2P2EOYEW.js.map +1 -0
- package/dist/chunk-37E5M4JX.js +34 -0
- package/dist/chunk-37E5M4JX.js.map +1 -0
- package/dist/chunk-37LQQWMF.js +496 -0
- package/dist/chunk-37LQQWMF.js.map +1 -0
- package/dist/chunk-3FIWOI3H.js +98 -0
- package/dist/chunk-3FIWOI3H.js.map +1 -0
- package/dist/chunk-3PGC6OA3.js +540 -0
- package/dist/chunk-3PGC6OA3.js.map +1 -0
- package/dist/chunk-4IHKBIY3.js +118 -0
- package/dist/chunk-4IHKBIY3.js.map +1 -0
- package/dist/chunk-4ZUBRLSP.js +17 -0
- package/dist/chunk-4ZUBRLSP.js.map +1 -0
- package/dist/chunk-5F3LNDZG.js +9 -0
- package/dist/chunk-5F3LNDZG.js.map +1 -0
- package/dist/chunk-5TXI6BI2.js +1359 -0
- package/dist/chunk-5TXI6BI2.js.map +1 -0
- package/dist/chunk-6P5IO4BX.js +235 -0
- package/dist/chunk-6P5IO4BX.js.map +1 -0
- package/dist/chunk-ABXUKHAU.js +571 -0
- package/dist/chunk-ABXUKHAU.js.map +1 -0
- package/dist/chunk-AOUDSNRK.js +1357 -0
- package/dist/chunk-AOUDSNRK.js.map +1 -0
- package/dist/chunk-BNDJJAEI.js +311 -0
- package/dist/chunk-BNDJJAEI.js.map +1 -0
- package/dist/chunk-C2IWSFF5.js +818 -0
- package/dist/chunk-C2IWSFF5.js.map +1 -0
- package/dist/chunk-CHQGE2HF.js +283 -0
- package/dist/chunk-CHQGE2HF.js.map +1 -0
- package/dist/chunk-DEJLP7QJ.js +681 -0
- package/dist/chunk-DEJLP7QJ.js.map +1 -0
- package/dist/chunk-DJ6FN6EW.js +532 -0
- package/dist/chunk-DJ6FN6EW.js.map +1 -0
- package/dist/chunk-E4WRTRMH.js +1173 -0
- package/dist/chunk-E4WRTRMH.js.map +1 -0
- package/dist/chunk-E5QXNU3K.js +238 -0
- package/dist/chunk-E5QXNU3K.js.map +1 -0
- package/dist/chunk-EMTBGOR3.js +2959 -0
- package/dist/chunk-EMTBGOR3.js.map +1 -0
- package/dist/chunk-FFWYIGQ4.js +18 -0
- package/dist/chunk-FFWYIGQ4.js.map +1 -0
- package/dist/chunk-I6XFZLTJ.js +9 -0
- package/dist/chunk-I6XFZLTJ.js.map +1 -0
- package/dist/chunk-IHWAOIAU.js +172 -0
- package/dist/chunk-IHWAOIAU.js.map +1 -0
- package/dist/chunk-IHZUYG66.js +583 -0
- package/dist/chunk-IHZUYG66.js.map +1 -0
- package/dist/chunk-JQOKQKQT.js +158 -0
- package/dist/chunk-JQOKQKQT.js.map +1 -0
- package/dist/chunk-JRFUTIEH.js +426 -0
- package/dist/chunk-JRFUTIEH.js.map +1 -0
- package/dist/chunk-KCBI6JQC.js +115 -0
- package/dist/chunk-KCBI6JQC.js.map +1 -0
- package/dist/chunk-KDUQMINL.js +60 -0
- package/dist/chunk-KDUQMINL.js.map +1 -0
- package/dist/chunk-KLR2DURP.js +656 -0
- package/dist/chunk-KLR2DURP.js.map +1 -0
- package/dist/chunk-KRI4R7EM.js +25 -0
- package/dist/chunk-KRI4R7EM.js.map +1 -0
- package/dist/chunk-LYQMK6SV.js +87 -0
- package/dist/chunk-LYQMK6SV.js.map +1 -0
- package/dist/chunk-MK3Q37ZN.js +183 -0
- package/dist/chunk-MK3Q37ZN.js.map +1 -0
- package/dist/chunk-MSGAGV7B.js +346 -0
- package/dist/chunk-MSGAGV7B.js.map +1 -0
- package/dist/chunk-MZQRSERO.js +430 -0
- package/dist/chunk-MZQRSERO.js.map +1 -0
- package/dist/chunk-N3WIJXXM.js +691 -0
- package/dist/chunk-N3WIJXXM.js.map +1 -0
- package/dist/chunk-NAGAJ5UM.js +145 -0
- package/dist/chunk-NAGAJ5UM.js.map +1 -0
- package/dist/chunk-NFYPBTKO.js +302 -0
- package/dist/chunk-NFYPBTKO.js.map +1 -0
- package/dist/chunk-NPO2IG6G.js +491 -0
- package/dist/chunk-NPO2IG6G.js.map +1 -0
- package/dist/chunk-OS6NUIBJ.js +38 -0
- package/dist/chunk-OS6NUIBJ.js.map +1 -0
- package/dist/chunk-PFUK3HJ4.js +296 -0
- package/dist/chunk-PFUK3HJ4.js.map +1 -0
- package/dist/chunk-PMQ55GDB.js +115 -0
- package/dist/chunk-PMQ55GDB.js.map +1 -0
- package/dist/chunk-QIVE2YFJ.js +514 -0
- package/dist/chunk-QIVE2YFJ.js.map +1 -0
- package/dist/chunk-QKXD3EUF.js +691 -0
- package/dist/chunk-QKXD3EUF.js.map +1 -0
- package/dist/chunk-RNQYUWF6.js +32 -0
- package/dist/chunk-RNQYUWF6.js.map +1 -0
- package/dist/chunk-S2E4SSQV.js +41 -0
- package/dist/chunk-S2E4SSQV.js.map +1 -0
- package/dist/chunk-SN4BXX3B.js +186 -0
- package/dist/chunk-SN4BXX3B.js.map +1 -0
- package/dist/chunk-SNVAMWB7.js +40 -0
- package/dist/chunk-SNVAMWB7.js.map +1 -0
- package/dist/chunk-T5VRREN4.js +696 -0
- package/dist/chunk-T5VRREN4.js.map +1 -0
- package/dist/chunk-TKBMHZTS.js +10945 -0
- package/dist/chunk-TKBMHZTS.js.map +1 -0
- package/dist/chunk-TNJPTUE4.js +35 -0
- package/dist/chunk-TNJPTUE4.js.map +1 -0
- package/dist/chunk-TQ2NA4Z4.js +24 -0
- package/dist/chunk-TQ2NA4Z4.js.map +1 -0
- package/dist/chunk-TXXDMDPN.js +998 -0
- package/dist/chunk-TXXDMDPN.js.map +1 -0
- package/dist/chunk-UWXUBU7V.js +184 -0
- package/dist/chunk-UWXUBU7V.js.map +1 -0
- package/dist/chunk-UYRK2H24.js +141 -0
- package/dist/chunk-UYRK2H24.js.map +1 -0
- package/dist/chunk-V4IXIM3C.js +806 -0
- package/dist/chunk-V4IXIM3C.js.map +1 -0
- package/dist/chunk-VFHVXXP4.js +6438 -0
- package/dist/chunk-VFHVXXP4.js.map +1 -0
- package/dist/chunk-VQVUJYYY.js +244 -0
- package/dist/chunk-VQVUJYYY.js.map +1 -0
- package/dist/chunk-VZQG2JDV.js +9 -0
- package/dist/chunk-VZQG2JDV.js.map +1 -0
- package/dist/chunk-W7HQ5X3S.js +610 -0
- package/dist/chunk-W7HQ5X3S.js.map +1 -0
- package/dist/chunk-WMSQAFK5.js +65 -0
- package/dist/chunk-WMSQAFK5.js.map +1 -0
- package/dist/chunk-WMYTBJPB.js +364 -0
- package/dist/chunk-WMYTBJPB.js.map +1 -0
- package/dist/chunk-WNLFNCOH.js +7795 -0
- package/dist/chunk-WNLFNCOH.js.map +1 -0
- package/dist/chunk-WRX7CB2M.js +6448 -0
- package/dist/chunk-WRX7CB2M.js.map +1 -0
- package/dist/chunk-XGTTOO4R.js +84 -0
- package/dist/chunk-XGTTOO4R.js.map +1 -0
- package/dist/chunk-YSXRBUR4.js +682 -0
- package/dist/chunk-YSXRBUR4.js.map +1 -0
- package/dist/chunk-YTC2EG64.js +1759 -0
- package/dist/chunk-YTC2EG64.js.map +1 -0
- package/dist/compile-J3UGQSS3.js +161 -0
- package/dist/compile-J3UGQSS3.js.map +1 -0
- package/dist/config-5BPSZND3.js +438 -0
- package/dist/config-5BPSZND3.js.map +1 -0
- package/dist/doctor-BVFKLJVO.js +111 -0
- package/dist/doctor-BVFKLJVO.js.map +1 -0
- package/dist/environment-3RI5H32O.js +2745 -0
- package/dist/environment-3RI5H32O.js.map +1 -0
- package/dist/github-YFJQVH5K.js +114 -0
- package/dist/github-YFJQVH5K.js.map +1 -0
- package/dist/harness-ECGHPEKA.js +746 -0
- package/dist/harness-ECGHPEKA.js.map +1 -0
- package/dist/help-ELPNPPEM.js +2079 -0
- package/dist/help-ELPNPPEM.js.map +1 -0
- package/dist/help-UL5XLY3I.js +1892 -0
- package/dist/help-UL5XLY3I.js.map +1 -0
- package/dist/index.d.ts +164 -1
- package/dist/index.js +50 -59246
- package/dist/index.js.map +1 -1
- package/dist/init-UJQTDHW7.js +873 -0
- package/dist/init-UJQTDHW7.js.map +1 -0
- package/dist/lock-XUMJ63NZ.js +455 -0
- package/dist/lock-XUMJ63NZ.js.map +1 -0
- package/dist/marketplace-ZUMOLVXE.js +495 -0
- package/dist/marketplace-ZUMOLVXE.js.map +1 -0
- package/dist/mcp-RZA5O2ND.js +202 -0
- package/dist/mcp-RZA5O2ND.js.map +1 -0
- package/dist/migrate-CYQI2FH6.js +1043 -0
- package/dist/migrate-CYQI2FH6.js.map +1 -0
- package/dist/open-AWOAWLKO.js +32 -0
- package/dist/open-AWOAWLKO.js.map +1 -0
- package/dist/pack-2QD5ZUIO.js +99 -0
- package/dist/pack-2QD5ZUIO.js.map +1 -0
- package/dist/plugin-GQSSSFX4.js +64 -0
- package/dist/plugin-GQSSSFX4.js.map +1 -0
- package/dist/plugin-from-project-SIQUFYIO.js +16 -0
- package/dist/plugin-from-project-SIQUFYIO.js.map +1 -0
- package/dist/policy-CT4JRCJI.js +105 -0
- package/dist/policy-CT4JRCJI.js.map +1 -0
- package/dist/profile-4JQ6LECP.js +1886 -0
- package/dist/profile-4JQ6LECP.js.map +1 -0
- package/dist/project-JG7QWXRG.js +1392 -0
- package/dist/project-JG7QWXRG.js.map +1 -0
- package/dist/resource-QRMR6CSD.js +555 -0
- package/dist/resource-QRMR6CSD.js.map +1 -0
- package/dist/version-LZ5POOXY.js +17 -0
- package/dist/version-LZ5POOXY.js.map +1 -0
- package/package.json +21 -14
- package/schemas/ap-package.v1.json +36 -0
- package/schemas/fixtures/catalog-missing-schema.ap.json +13 -0
- package/schemas/fixtures/confidence.ap.json +13 -0
- package/schemas/fixtures/context7.ap.json +13 -0
- package/schemas/fixtures/minimal-with-schema.ap.json +13 -0
- package/schemas/fixtures/superpowers.ap.json +13 -0
- package/schemas/fixtures/third-party-skills.ap.json +13 -0
|
@@ -0,0 +1,2959 @@
|
|
|
1
|
+
import {
|
|
2
|
+
filterLocalBrowseRows,
|
|
3
|
+
formatLocalPluginListName,
|
|
4
|
+
formatPluginOriginDisplay,
|
|
5
|
+
listNavigablePluginListBrowseRows,
|
|
6
|
+
renderGroupedPluginListBrowseViewport,
|
|
7
|
+
toRemoteBrowseRows
|
|
8
|
+
} from "./chunk-QIVE2YFJ.js";
|
|
9
|
+
import {
|
|
10
|
+
isPluginPackageDirectory,
|
|
11
|
+
isZipBundlePath,
|
|
12
|
+
looksLikeFilesystemPath
|
|
13
|
+
} from "./chunk-MK3Q37ZN.js";
|
|
14
|
+
import {
|
|
15
|
+
promptMaterializationConflict,
|
|
16
|
+
resolveApplyConflictPolicy
|
|
17
|
+
} from "./chunk-AOUDSNRK.js";
|
|
18
|
+
import {
|
|
19
|
+
computeShowViewportBounds,
|
|
20
|
+
createPromptScreen,
|
|
21
|
+
renderScrollableShowContent
|
|
22
|
+
} from "./chunk-DJ6FN6EW.js";
|
|
23
|
+
import {
|
|
24
|
+
DEFAULT_EXCLUDED_SKILL_CATEGORIES,
|
|
25
|
+
createRemoteCatalogListPrompt,
|
|
26
|
+
defaultInteractiveSkillNames,
|
|
27
|
+
importSkillPackage,
|
|
28
|
+
installSkillsToGlobal,
|
|
29
|
+
installSkillsToProject,
|
|
30
|
+
resolveSelectedSkills,
|
|
31
|
+
resolveSkillPackageCheckout,
|
|
32
|
+
useDebouncedRemoteSearch
|
|
33
|
+
} from "./chunk-YSXRBUR4.js";
|
|
34
|
+
import {
|
|
35
|
+
catalogPluginKey,
|
|
36
|
+
formatCatalogSelectionLabel,
|
|
37
|
+
renderCatalogListChunk
|
|
38
|
+
} from "./chunk-6P5IO4BX.js";
|
|
39
|
+
import {
|
|
40
|
+
useTerminalSize
|
|
41
|
+
} from "./chunk-S2E4SSQV.js";
|
|
42
|
+
import {
|
|
43
|
+
VIEWPORT_CHROME_LINES,
|
|
44
|
+
computeRemoteListFetchLimit
|
|
45
|
+
} from "./chunk-XGTTOO4R.js";
|
|
46
|
+
import {
|
|
47
|
+
promptForSearchableMultiSelect
|
|
48
|
+
} from "./chunk-JQOKQKQT.js";
|
|
49
|
+
import {
|
|
50
|
+
buildHelpLine,
|
|
51
|
+
clampActiveIndex,
|
|
52
|
+
handleNavigationKeypress,
|
|
53
|
+
interactivePromptTheme,
|
|
54
|
+
isEscapeKey,
|
|
55
|
+
isLetterKey,
|
|
56
|
+
isSearchCharacter
|
|
57
|
+
} from "./chunk-3FIWOI3H.js";
|
|
58
|
+
import {
|
|
59
|
+
applyToGlobal,
|
|
60
|
+
collectPluginPinsForPrepare,
|
|
61
|
+
getActiveProfileName,
|
|
62
|
+
installPluginFromCatalog,
|
|
63
|
+
preparePluginPinsForApply,
|
|
64
|
+
resolveEnvironmentCascadeForApply
|
|
65
|
+
} from "./chunk-WNLFNCOH.js";
|
|
66
|
+
import {
|
|
67
|
+
isPromptCancellationError,
|
|
68
|
+
promptForChoice,
|
|
69
|
+
promptForConfirmation,
|
|
70
|
+
shouldUseWizard
|
|
71
|
+
} from "./chunk-NAGAJ5UM.js";
|
|
72
|
+
import {
|
|
73
|
+
initializeSchema
|
|
74
|
+
} from "./chunk-N3WIJXXM.js";
|
|
75
|
+
import {
|
|
76
|
+
isProfilePlugin
|
|
77
|
+
} from "./chunk-TNJPTUE4.js";
|
|
78
|
+
import {
|
|
79
|
+
resolveScanGlobalHarnessTargets
|
|
80
|
+
} from "./chunk-PFUK3HJ4.js";
|
|
81
|
+
import {
|
|
82
|
+
getImportedSnapshot,
|
|
83
|
+
recordImportedSnapshotInstall
|
|
84
|
+
} from "./chunk-WRX7CB2M.js";
|
|
85
|
+
import {
|
|
86
|
+
PluginProvenanceError,
|
|
87
|
+
PluginVersionError,
|
|
88
|
+
RESOURCE_TYPES,
|
|
89
|
+
addPluginAttachment,
|
|
90
|
+
assertAuthored,
|
|
91
|
+
assertPluginsCleanForShare,
|
|
92
|
+
buildApPackageFiles,
|
|
93
|
+
createPlugin,
|
|
94
|
+
cutPluginVersion,
|
|
95
|
+
deletePlugin,
|
|
96
|
+
downloadCatalogPackage,
|
|
97
|
+
envelopeFromFiles,
|
|
98
|
+
formatPluginVersionLabel,
|
|
99
|
+
formatPublishedPluginSelector,
|
|
100
|
+
getEnvironment,
|
|
101
|
+
getPlugin,
|
|
102
|
+
getPluginByCatalogVersion,
|
|
103
|
+
getPluginById,
|
|
104
|
+
getPluginByName,
|
|
105
|
+
getPluginByPublishedIdentity,
|
|
106
|
+
getPluginResources,
|
|
107
|
+
importApPackageFiles,
|
|
108
|
+
isApEnvelopePath,
|
|
109
|
+
listAttachedPluginPins,
|
|
110
|
+
listCatalogPluginsPage,
|
|
111
|
+
listDependencies,
|
|
112
|
+
listLatestPublishedPluginsBySlug,
|
|
113
|
+
listPluginDependencies,
|
|
114
|
+
listPlugins,
|
|
115
|
+
listPluginsInScope,
|
|
116
|
+
mergePluginsById,
|
|
117
|
+
rankCatalogSearchResults,
|
|
118
|
+
resolveClaudeEnabledPluginRef,
|
|
119
|
+
resolveComposition,
|
|
120
|
+
resolveHomeRoot,
|
|
121
|
+
resolvePluginSelector,
|
|
122
|
+
satisfiesConstraint,
|
|
123
|
+
substituteResourcesForApply,
|
|
124
|
+
updatePluginPublishedIdentity
|
|
125
|
+
} from "./chunk-TKBMHZTS.js";
|
|
126
|
+
import {
|
|
127
|
+
trackPluginUsed
|
|
128
|
+
} from "./chunk-NPO2IG6G.js";
|
|
129
|
+
import {
|
|
130
|
+
parseOutputFormat,
|
|
131
|
+
printJson
|
|
132
|
+
} from "./chunk-TQ2NA4Z4.js";
|
|
133
|
+
import {
|
|
134
|
+
fail,
|
|
135
|
+
formatCommand
|
|
136
|
+
} from "./chunk-NFYPBTKO.js";
|
|
137
|
+
import {
|
|
138
|
+
formatCount,
|
|
139
|
+
formatRelativeTimeWithAbsolute,
|
|
140
|
+
renderPanel,
|
|
141
|
+
renderSubheader,
|
|
142
|
+
renderTable,
|
|
143
|
+
shortenId,
|
|
144
|
+
theme,
|
|
145
|
+
ui
|
|
146
|
+
} from "./chunk-ABXUKHAU.js";
|
|
147
|
+
import {
|
|
148
|
+
createPersistingCloudClient,
|
|
149
|
+
ensureRegisteredPublishCatalog,
|
|
150
|
+
formatCanonicalPublishedSelector,
|
|
151
|
+
formatCanonicalPublishedSelectorWithVersion,
|
|
152
|
+
formatCatalogScopeLabel,
|
|
153
|
+
formatPublishCatalogSelector,
|
|
154
|
+
formatPublishedSelector,
|
|
155
|
+
getCloudAccount,
|
|
156
|
+
isPublicCatalogEnabled,
|
|
157
|
+
loadRegisteredCatalogs,
|
|
158
|
+
parsePluginSelector,
|
|
159
|
+
parsePublishCatalogSelector,
|
|
160
|
+
publishCatalogKey,
|
|
161
|
+
registerPublishCatalog,
|
|
162
|
+
resolveCatalogScope,
|
|
163
|
+
resolveRemotePluginSelector,
|
|
164
|
+
resolvedRemotePluginFromCatalog,
|
|
165
|
+
unregisterPublishCatalog
|
|
166
|
+
} from "./chunk-2P2EOYEW.js";
|
|
167
|
+
import {
|
|
168
|
+
CLI_ERRORS,
|
|
169
|
+
CLI_HINTS,
|
|
170
|
+
fetchWithTimeout,
|
|
171
|
+
formatCatalogRequestError,
|
|
172
|
+
getDb
|
|
173
|
+
} from "./chunk-KLR2DURP.js";
|
|
174
|
+
|
|
175
|
+
// src/services/plugin-source.ts
|
|
176
|
+
import { mkdtempSync, writeFileSync } from "fs";
|
|
177
|
+
import { tmpdir } from "os";
|
|
178
|
+
import { join } from "path";
|
|
179
|
+
var URL_PATTERN = /^https?:\/\//i;
|
|
180
|
+
function isPluginUrl(source) {
|
|
181
|
+
return URL_PATTERN.test(source);
|
|
182
|
+
}
|
|
183
|
+
function isPluginExportFilePath(source) {
|
|
184
|
+
if (isApEnvelopePath(source)) return true;
|
|
185
|
+
if (source.endsWith("/plugin.json") || source.endsWith("\\plugin.json")) return true;
|
|
186
|
+
if (isZipBundlePath(source)) return true;
|
|
187
|
+
return looksLikeFilesystemPath(source) && isPluginPackageDirectory(source);
|
|
188
|
+
}
|
|
189
|
+
function writePluginExportToTempFile(body) {
|
|
190
|
+
const dir = mkdtempSync(join(tmpdir(), "harnesstap-plugin-export-"));
|
|
191
|
+
const filePath = join(dir, "remote.ap.json");
|
|
192
|
+
writeFileSync(filePath, body, "utf-8");
|
|
193
|
+
return filePath;
|
|
194
|
+
}
|
|
195
|
+
async function fetchPluginExportToTempFile(url) {
|
|
196
|
+
const response = await fetchWithTimeout(url, { timeoutMs: 6e4 });
|
|
197
|
+
if (!response.ok) {
|
|
198
|
+
throw new Error(`Failed to fetch plugin export (${response.status}): ${url}`);
|
|
199
|
+
}
|
|
200
|
+
const body = await response.text();
|
|
201
|
+
return writePluginExportToTempFile(body);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/services/plugin-bare-name-resolve.ts
|
|
205
|
+
var PluginResolveError = class extends Error {
|
|
206
|
+
hints;
|
|
207
|
+
constructor(message, hints = []) {
|
|
208
|
+
super(message);
|
|
209
|
+
this.name = "PluginResolveError";
|
|
210
|
+
this.hints = hints;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
var PluginAmbiguityError = class extends PluginResolveError {
|
|
214
|
+
candidates;
|
|
215
|
+
constructor(selector, candidates) {
|
|
216
|
+
const lines = candidates.map(
|
|
217
|
+
(plugin) => formatCatalogSelector(plugin, plugin.latestVersion ?? void 0)
|
|
218
|
+
);
|
|
219
|
+
super(
|
|
220
|
+
`Ambiguous plugin name: ${selector}
|
|
221
|
+
${lines.map((line) => ` ${line}`).join("\n")}`,
|
|
222
|
+
["Use a fully qualified selector: org/catalog/slug@version"]
|
|
223
|
+
);
|
|
224
|
+
this.candidates = candidates;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
function isBareInstallSelector(selector) {
|
|
228
|
+
if (isPluginUrl(selector) || isPluginExportFilePath(selector)) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return !selector.includes("/");
|
|
232
|
+
}
|
|
233
|
+
async function resolveInstallSelector(selector, options = {}) {
|
|
234
|
+
if (isBareInstallSelector(selector)) {
|
|
235
|
+
const hasRemoteHelpers = Boolean(
|
|
236
|
+
options.org || options.catalog || options.version
|
|
237
|
+
);
|
|
238
|
+
if (hasRemoteHelpers || !isPublicCatalogEnabled()) {
|
|
239
|
+
return resolveRemotePluginSelector(selector, {
|
|
240
|
+
org: options.org,
|
|
241
|
+
catalog: options.catalog,
|
|
242
|
+
version: options.version
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return resolveBareNameFromCatalog(selector, options);
|
|
246
|
+
}
|
|
247
|
+
return resolveRemotePluginSelector(selector, {
|
|
248
|
+
org: options.org,
|
|
249
|
+
catalog: options.catalog,
|
|
250
|
+
version: options.version
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function exactCatalogMatches(plugins, searchName) {
|
|
254
|
+
const normalized = searchName.trim().toLowerCase();
|
|
255
|
+
return plugins.filter(
|
|
256
|
+
(plugin) => plugin.slug.toLowerCase() === normalized || plugin.name.toLowerCase() === normalized
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
function dedupeCatalogPluginsByIdentity(plugins) {
|
|
260
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
261
|
+
for (const plugin of plugins) {
|
|
262
|
+
byKey.set(catalogPluginKey(plugin), plugin);
|
|
263
|
+
}
|
|
264
|
+
return [...byKey.values()];
|
|
265
|
+
}
|
|
266
|
+
function formatCatalogSelector(plugin, version) {
|
|
267
|
+
const base = `${plugin.orgSlug}/${plugin.catalogSlug}/${plugin.slug}`;
|
|
268
|
+
const resolvedVersion = version ?? plugin.latestVersion ?? void 0;
|
|
269
|
+
return resolvedVersion ? `${base}@${resolvedVersion}` : base;
|
|
270
|
+
}
|
|
271
|
+
function formatCatalogPluginChoiceLabel(plugin) {
|
|
272
|
+
const selector = formatCatalogSelector(plugin, plugin.latestVersion ?? void 0);
|
|
273
|
+
const summary = plugin.summary?.trim() || plugin.name;
|
|
274
|
+
return `${selector}: ${summary}`;
|
|
275
|
+
}
|
|
276
|
+
async function promptCatalogPluginAmbiguity(selector, candidates) {
|
|
277
|
+
const selectedKey = await promptForChoice({
|
|
278
|
+
message: `Multiple catalog plugins match "${selector}". Which one?`,
|
|
279
|
+
choices: candidates.map((plugin) => ({
|
|
280
|
+
name: formatCatalogPluginChoiceLabel(plugin),
|
|
281
|
+
value: catalogPluginKey(plugin)
|
|
282
|
+
}))
|
|
283
|
+
});
|
|
284
|
+
const match = candidates.find((plugin) => catalogPluginKey(plugin) === selectedKey);
|
|
285
|
+
if (!match) {
|
|
286
|
+
throw new PluginResolveError(`Plugin not found: ${selector}`);
|
|
287
|
+
}
|
|
288
|
+
return match;
|
|
289
|
+
}
|
|
290
|
+
async function pickCatalogPluginMatch(selector, matches, options) {
|
|
291
|
+
const unique = dedupeCatalogPluginsByIdentity(matches);
|
|
292
|
+
if (unique.length === 1) {
|
|
293
|
+
const only = unique[0];
|
|
294
|
+
if (!only) {
|
|
295
|
+
throw new PluginResolveError(`Plugin not found: ${selector}`);
|
|
296
|
+
}
|
|
297
|
+
return only;
|
|
298
|
+
}
|
|
299
|
+
if (options.promptAmbiguity) {
|
|
300
|
+
return options.promptAmbiguity({ selector, candidates: unique });
|
|
301
|
+
}
|
|
302
|
+
const canPrompt = shouldUseWizard({
|
|
303
|
+
interactive: options.interactive ?? true,
|
|
304
|
+
noInteractive: options.noInteractive,
|
|
305
|
+
format: options.format ?? "human",
|
|
306
|
+
missingRequiredArgs: false
|
|
307
|
+
});
|
|
308
|
+
if (!canPrompt) {
|
|
309
|
+
throw new PluginAmbiguityError(selector, unique);
|
|
310
|
+
}
|
|
311
|
+
return promptCatalogPluginAmbiguity(selector, unique);
|
|
312
|
+
}
|
|
313
|
+
async function resolveBareNameFromCatalog(selector, options = {}) {
|
|
314
|
+
if (!isPublicCatalogEnabled()) {
|
|
315
|
+
throw new PluginResolveError(
|
|
316
|
+
`Plugin not found: ${selector}`,
|
|
317
|
+
[
|
|
318
|
+
"Enable catalog.publicCatalog in ~/.harnesstap/config.jsonc",
|
|
319
|
+
"Or use a published selector: org/catalog/slug"
|
|
320
|
+
]
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
const parsed = parsePluginSelector(selector);
|
|
324
|
+
if (parsed.scope !== "local") {
|
|
325
|
+
throw new PluginResolveError(`Plugin not found: ${selector}`);
|
|
326
|
+
}
|
|
327
|
+
const catalogResults = await listPluginsInScope(
|
|
328
|
+
{ q: parsed.name, limit: 100, sort: "name" },
|
|
329
|
+
{ account: options.account, baseUrl: options.baseUrl }
|
|
330
|
+
);
|
|
331
|
+
const matches = exactCatalogMatches(catalogResults, parsed.name);
|
|
332
|
+
if (matches.length === 0) {
|
|
333
|
+
throw new PluginResolveError(`Plugin not found: ${selector}`, [
|
|
334
|
+
"ht plugin list --search <query> --remote-only",
|
|
335
|
+
"ht plugin pull org/catalog/slug",
|
|
336
|
+
"ht plugin list"
|
|
337
|
+
]);
|
|
338
|
+
}
|
|
339
|
+
const match = await pickCatalogPluginMatch(selector, matches, options);
|
|
340
|
+
return resolveRemotePluginSelector(
|
|
341
|
+
formatCatalogSelector(match, parsed.version ?? match.latestVersion ?? void 0),
|
|
342
|
+
{}
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/cli/handlers/plugin-install.ts
|
|
347
|
+
async function handlePluginInstallCommand(selector, opts) {
|
|
348
|
+
const db = getDb();
|
|
349
|
+
initializeSchema(db);
|
|
350
|
+
let parsed;
|
|
351
|
+
try {
|
|
352
|
+
parsed = await resolveInstallSelector(selector, {
|
|
353
|
+
org: opts.org,
|
|
354
|
+
catalog: opts.catalog,
|
|
355
|
+
version: opts.version,
|
|
356
|
+
account: opts.account,
|
|
357
|
+
baseUrl: opts.baseUrl,
|
|
358
|
+
interactive: opts.interactive,
|
|
359
|
+
noInteractive: opts.noInteractive,
|
|
360
|
+
format: parseOutputFormat(opts.format)
|
|
361
|
+
});
|
|
362
|
+
} catch (err) {
|
|
363
|
+
process.exitCode = 1;
|
|
364
|
+
if (err instanceof PluginResolveError || err instanceof PluginAmbiguityError) {
|
|
365
|
+
ui.danger(err.message, { hints: err.hints });
|
|
366
|
+
return void 0;
|
|
367
|
+
}
|
|
368
|
+
ui.danger(err instanceof Error ? err.message : String(err));
|
|
369
|
+
return void 0;
|
|
370
|
+
}
|
|
371
|
+
try {
|
|
372
|
+
const installed = await installPluginFromCatalog(parsed, {
|
|
373
|
+
as: opts.as,
|
|
374
|
+
account: opts.account,
|
|
375
|
+
baseUrl: opts.baseUrl
|
|
376
|
+
});
|
|
377
|
+
if (parseOutputFormat(opts.format) === "json") {
|
|
378
|
+
printJson({
|
|
379
|
+
plugin_name: installed.pluginName,
|
|
380
|
+
org_slug: parsed.org_slug,
|
|
381
|
+
catalog_slug: parsed.catalog_slug,
|
|
382
|
+
plugin_slug: parsed.plugin_slug,
|
|
383
|
+
version: installed.version
|
|
384
|
+
});
|
|
385
|
+
return { pluginName: installed.pluginName, pluginId: installed.pluginId };
|
|
386
|
+
}
|
|
387
|
+
const sourceLabel = formatPublishedSelector({
|
|
388
|
+
org: parsed.org_slug,
|
|
389
|
+
catalog: parsed.catalog_slug,
|
|
390
|
+
name: parsed.plugin_slug
|
|
391
|
+
});
|
|
392
|
+
ui.success(`Installed plugin ${installed.pluginName} from ${sourceLabel}`);
|
|
393
|
+
return { pluginName: installed.pluginName, pluginId: installed.pluginId };
|
|
394
|
+
} catch (err) {
|
|
395
|
+
process.exitCode = 1;
|
|
396
|
+
ui.danger(err instanceof Error ? err.message : String(err));
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// src/services/plugin-publish-targets.ts
|
|
402
|
+
function listPluginPublishTargets(pluginId) {
|
|
403
|
+
const db = getDb();
|
|
404
|
+
const rows = db.prepare(
|
|
405
|
+
`SELECT org_slug, catalog_slug
|
|
406
|
+
FROM plugin_publish_targets
|
|
407
|
+
WHERE plugin_id = ?
|
|
408
|
+
ORDER BY org_slug, catalog_slug`
|
|
409
|
+
).all(pluginId);
|
|
410
|
+
return rows.map((row) => ({
|
|
411
|
+
org: row.org_slug,
|
|
412
|
+
catalog: row.catalog_slug
|
|
413
|
+
}));
|
|
414
|
+
}
|
|
415
|
+
function setPluginPublishTargets(pluginId, targets) {
|
|
416
|
+
const db = getDb();
|
|
417
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
418
|
+
const uniqueTargets = /* @__PURE__ */ new Map();
|
|
419
|
+
for (const target of targets) {
|
|
420
|
+
uniqueTargets.set(publishCatalogKey(target), {
|
|
421
|
+
org: target.org,
|
|
422
|
+
catalog: target.catalog
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
db.transaction(() => {
|
|
426
|
+
db.prepare("DELETE FROM plugin_publish_targets WHERE plugin_id = ?").run(pluginId);
|
|
427
|
+
const insert = db.prepare(
|
|
428
|
+
`INSERT INTO plugin_publish_targets (plugin_id, org_slug, catalog_slug, created_at)
|
|
429
|
+
VALUES (?, ?, ?, ?)`
|
|
430
|
+
);
|
|
431
|
+
for (const target of uniqueTargets.values()) {
|
|
432
|
+
insert.run(pluginId, target.org, target.catalog, now);
|
|
433
|
+
}
|
|
434
|
+
})();
|
|
435
|
+
}
|
|
436
|
+
function clearPluginPublishTargets(pluginId) {
|
|
437
|
+
const db = getDb();
|
|
438
|
+
db.prepare("DELETE FROM plugin_publish_targets WHERE plugin_id = ?").run(pluginId);
|
|
439
|
+
}
|
|
440
|
+
function removePluginPublishTarget(pluginId, target) {
|
|
441
|
+
const db = getDb();
|
|
442
|
+
const result = db.prepare(
|
|
443
|
+
`DELETE FROM plugin_publish_targets
|
|
444
|
+
WHERE plugin_id = ? AND org_slug = ? AND catalog_slug = ?`
|
|
445
|
+
).run(pluginId, target.org, target.catalog);
|
|
446
|
+
return result.changes > 0;
|
|
447
|
+
}
|
|
448
|
+
function resolvePublishTargets(pluginId) {
|
|
449
|
+
const registered = loadRegisteredCatalogs();
|
|
450
|
+
const allowList = listPluginPublishTargets(pluginId);
|
|
451
|
+
if (allowList.length === 0) {
|
|
452
|
+
return registered;
|
|
453
|
+
}
|
|
454
|
+
const registeredByKey = new Map(
|
|
455
|
+
registered.map((entry) => [publishCatalogKey(entry), entry])
|
|
456
|
+
);
|
|
457
|
+
const effective = [];
|
|
458
|
+
for (const target of allowList) {
|
|
459
|
+
const registeredEntry = registeredByKey.get(publishCatalogKey(target));
|
|
460
|
+
if (registeredEntry) {
|
|
461
|
+
effective.push(registeredEntry);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return effective;
|
|
465
|
+
}
|
|
466
|
+
function buildPluginCatalogBindingsView(plugin) {
|
|
467
|
+
const registered = loadRegisteredCatalogs();
|
|
468
|
+
const allowList = listPluginPublishTargets(plugin.id);
|
|
469
|
+
const effective = resolvePublishTargets(plugin.id);
|
|
470
|
+
return {
|
|
471
|
+
plugin: plugin.name,
|
|
472
|
+
mode: allowList.length === 0 ? "all_registered" : "explicit",
|
|
473
|
+
registered,
|
|
474
|
+
effective,
|
|
475
|
+
allowList
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function assertResolvablePublishTargets(pluginId) {
|
|
479
|
+
const registered = loadRegisteredCatalogs();
|
|
480
|
+
if (registered.length === 0) {
|
|
481
|
+
throw new Error(
|
|
482
|
+
"No publish catalogs registered. Run `ht plugin catalog register org/catalog` first."
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
const effective = resolvePublishTargets(pluginId);
|
|
486
|
+
if (effective.length === 0) {
|
|
487
|
+
throw new Error(
|
|
488
|
+
"No effective publish catalogs for this plugin. Update bindings with `ht plugin catalog bindings <plugin>`."
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
const allowList = listPluginPublishTargets(pluginId);
|
|
492
|
+
const registeredKeys = new Set(registered.map((entry) => publishCatalogKey(entry)));
|
|
493
|
+
const missing = allowList.filter((entry) => !registeredKeys.has(publishCatalogKey(entry)));
|
|
494
|
+
if (missing.length > 0) {
|
|
495
|
+
const labels = missing.map((entry) => `${entry.org}/${entry.catalog}`).join(", ");
|
|
496
|
+
console.warn(`Warning: skipping unregistered publish catalogs: ${labels}`);
|
|
497
|
+
}
|
|
498
|
+
return effective;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// src/services/wizards/plugin-catalog-bindings.ts
|
|
502
|
+
function groupRegisteredCatalogs(catalogs) {
|
|
503
|
+
return [...catalogs].sort((left, right) => {
|
|
504
|
+
const orgCompare = left.org.localeCompare(right.org);
|
|
505
|
+
if (orgCompare !== 0) {
|
|
506
|
+
return orgCompare;
|
|
507
|
+
}
|
|
508
|
+
return left.catalog.localeCompare(right.catalog);
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
function formatCatalogChoiceName(catalog) {
|
|
512
|
+
return `${catalog.org} / ${catalog.catalog}`;
|
|
513
|
+
}
|
|
514
|
+
async function promptForInteractivePluginCatalogBindings(input) {
|
|
515
|
+
const registered = groupRegisteredCatalogs(loadRegisteredCatalogs());
|
|
516
|
+
if (registered.length === 0) {
|
|
517
|
+
throw new Error(
|
|
518
|
+
"No publish catalogs registered. Run `ht plugin catalog register org/catalog` first."
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
const allowList = listPluginPublishTargets(input.plugin.id);
|
|
522
|
+
const registeredKeys = new Set(registered.map((entry) => publishCatalogKey(entry)));
|
|
523
|
+
const effectiveAllowList = allowList.filter(
|
|
524
|
+
(entry) => registeredKeys.has(publishCatalogKey(entry))
|
|
525
|
+
);
|
|
526
|
+
const allRegistered = allowList.length === 0;
|
|
527
|
+
const selectedKeys = new Set(
|
|
528
|
+
(allRegistered ? registered : effectiveAllowList).map(
|
|
529
|
+
(entry) => publishCatalogKey(entry)
|
|
530
|
+
)
|
|
531
|
+
);
|
|
532
|
+
const choices = registered.map((catalog) => ({
|
|
533
|
+
name: formatCatalogChoiceName(catalog),
|
|
534
|
+
value: publishCatalogKey(catalog),
|
|
535
|
+
short: formatPublishCatalogSelector(catalog)
|
|
536
|
+
}));
|
|
537
|
+
const header = allRegistered ? `Publishing to: all registered (${registered.length} catalogs)` : `Publishing to: ${effectiveAllowList.length} of ${registered.length} registered catalogs`;
|
|
538
|
+
ui.info(header);
|
|
539
|
+
const selected = await promptForSearchableMultiSelect({
|
|
540
|
+
message: `Publish catalogs for plugin ${input.plugin.name}`,
|
|
541
|
+
choices,
|
|
542
|
+
default: [...selectedKeys]
|
|
543
|
+
});
|
|
544
|
+
const selectedSet = new Set(selected);
|
|
545
|
+
if (selectedSet.size === registered.length) {
|
|
546
|
+
clearPluginPublishTargets(input.plugin.id);
|
|
547
|
+
ui.success(`Plugin ${ui.theme.accent(input.plugin.name)} will publish to all registered catalogs.`);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (selectedSet.size === 0) {
|
|
551
|
+
throw new Error("Select at least one publish catalog.");
|
|
552
|
+
}
|
|
553
|
+
const targets = registered.filter((catalog) => selectedSet.has(publishCatalogKey(catalog)));
|
|
554
|
+
setPluginPublishTargets(input.plugin.id, targets);
|
|
555
|
+
ui.success(
|
|
556
|
+
`Plugin ${ui.theme.accent(input.plugin.name)} publish targets: ${targets.map((target) => formatPublishCatalogSelector(target)).join(", ")}`
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// src/services/plugin-catalog-bindings.ts
|
|
561
|
+
function sortPluginsForPicker(plugins) {
|
|
562
|
+
return [...plugins].sort((left, right) => {
|
|
563
|
+
const leftProfile = isProfilePlugin(left) ? 0 : 1;
|
|
564
|
+
const rightProfile = isProfilePlugin(right) ? 0 : 1;
|
|
565
|
+
if (leftProfile !== rightProfile) {
|
|
566
|
+
return leftProfile - rightProfile;
|
|
567
|
+
}
|
|
568
|
+
return left.name.localeCompare(right.name);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
async function handlePluginCatalogRegisterCommand(selector, opts) {
|
|
572
|
+
const parsed = parsePublishCatalogSelector(selector);
|
|
573
|
+
const withAccount = opts.account?.trim() ? { ...parsed, account: opts.account.trim() } : parsed;
|
|
574
|
+
const { catalog, created } = registerPublishCatalog(formatPublishCatalogSelector(withAccount));
|
|
575
|
+
if (opts.format === "json") {
|
|
576
|
+
console.log(JSON.stringify({ catalog, created }, null, 2));
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (created) {
|
|
580
|
+
ui.success(`Registered publish catalog ${ui.theme.accent(formatPublishCatalogSelector(catalog))}`);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
ui.info(`Publish catalog ${ui.theme.accent(formatPublishCatalogSelector(catalog))} is already registered.`);
|
|
584
|
+
}
|
|
585
|
+
async function handlePluginCatalogUnregisterCommand(selector, opts) {
|
|
586
|
+
const parsed = parsePublishCatalogSelector(selector);
|
|
587
|
+
unregisterPublishCatalog(formatPublishCatalogSelector(parsed));
|
|
588
|
+
if (opts.format === "json") {
|
|
589
|
+
console.log(JSON.stringify({ removed: parsed }, null, 2));
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
ui.success(`Unregistered publish catalog ${ui.theme.accent(formatPublishCatalogSelector(parsed))}`);
|
|
593
|
+
}
|
|
594
|
+
async function handlePluginCatalogRegisteredCommand(opts) {
|
|
595
|
+
const registered = loadRegisteredCatalogs();
|
|
596
|
+
if (opts.format === "json") {
|
|
597
|
+
console.log(JSON.stringify({ registered }, null, 2));
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (registered.length === 0) {
|
|
601
|
+
ui.dim("No publish catalogs registered.");
|
|
602
|
+
ui.hint("Register one: ht plugin catalog register org/catalog");
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
for (const catalog of registered) {
|
|
606
|
+
console.log(formatPublishCatalogSelector(catalog));
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function renderBindingsView(view) {
|
|
610
|
+
if (view.mode === "all_registered") {
|
|
611
|
+
ui.info(`Plugin ${ui.theme.accent(view.plugin)} publishes to all registered catalogs (${view.effective.length}).`);
|
|
612
|
+
} else {
|
|
613
|
+
ui.info(
|
|
614
|
+
`Plugin ${ui.theme.accent(view.plugin)} publishes to ${view.effective.length} of ${view.registered.length} registered catalogs.`
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
if (view.effective.length === 0) {
|
|
618
|
+
ui.dim("No effective publish catalogs.");
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
for (const catalog of view.effective) {
|
|
622
|
+
console.log(` ${formatPublishCatalogSelector(catalog)}`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
async function applyBindingMutations(pluginName, opts) {
|
|
626
|
+
const plugin = getPlugin(pluginName);
|
|
627
|
+
if (!plugin) {
|
|
628
|
+
throw new Error(`Plugin not found: ${pluginName}`);
|
|
629
|
+
}
|
|
630
|
+
if (opts.clear) {
|
|
631
|
+
clearPluginPublishTargets(plugin.id);
|
|
632
|
+
if (opts.format === "json") {
|
|
633
|
+
console.log(JSON.stringify(buildPluginCatalogBindingsView(plugin), null, 2));
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
ui.success(`Plugin ${ui.theme.accent(plugin.name)} will publish to all registered catalogs.`);
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
if (opts.add && opts.add.length > 0) {
|
|
640
|
+
const targets = [];
|
|
641
|
+
for (const selector of opts.add) {
|
|
642
|
+
const { catalog, created } = ensureRegisteredPublishCatalog(selector, {
|
|
643
|
+
account: opts.account
|
|
644
|
+
});
|
|
645
|
+
if (created && opts.format !== "json") {
|
|
646
|
+
ui.info(`Registered publish catalog ${formatPublishCatalogSelector(catalog)}`);
|
|
647
|
+
}
|
|
648
|
+
targets.push(catalog);
|
|
649
|
+
}
|
|
650
|
+
setPluginPublishTargets(plugin.id, targets);
|
|
651
|
+
if (opts.format === "json") {
|
|
652
|
+
console.log(JSON.stringify(buildPluginCatalogBindingsView(plugin), null, 2));
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
ui.success(
|
|
656
|
+
`Plugin ${ui.theme.accent(plugin.name)} publish targets: ${targets.map((target) => formatPublishCatalogSelector(target)).join(", ")}`
|
|
657
|
+
);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (opts.remove && opts.remove.length > 0) {
|
|
661
|
+
for (const selector of opts.remove) {
|
|
662
|
+
const parsed = parsePublishCatalogSelector(selector);
|
|
663
|
+
removePluginPublishTarget(plugin.id, parsed);
|
|
664
|
+
}
|
|
665
|
+
if (listPluginPublishTargets(plugin.id).length === 0) {
|
|
666
|
+
clearPluginPublishTargets(plugin.id);
|
|
667
|
+
}
|
|
668
|
+
if (opts.format === "json") {
|
|
669
|
+
console.log(JSON.stringify(buildPluginCatalogBindingsView(plugin), null, 2));
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
renderBindingsView(buildPluginCatalogBindingsView(plugin));
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
const view = buildPluginCatalogBindingsView(plugin);
|
|
676
|
+
if (opts.format === "json") {
|
|
677
|
+
console.log(JSON.stringify(view, null, 2));
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
renderBindingsView(view);
|
|
681
|
+
}
|
|
682
|
+
async function handlePluginCatalogBindingsCommand(pluginName, opts) {
|
|
683
|
+
const format = opts.format ?? "human";
|
|
684
|
+
const hasMutation = Boolean(
|
|
685
|
+
opts.clear || opts.add && opts.add.length > 0 || opts.remove && opts.remove.length > 0
|
|
686
|
+
);
|
|
687
|
+
if (hasMutation && !pluginName) {
|
|
688
|
+
throw new Error("Plugin name is required when using --add, --remove, or --clear.");
|
|
689
|
+
}
|
|
690
|
+
const mutationFlags = [
|
|
691
|
+
opts.clear ? "--clear" : void 0,
|
|
692
|
+
opts.add && opts.add.length > 0 ? "--add" : void 0,
|
|
693
|
+
opts.remove && opts.remove.length > 0 ? "--remove" : void 0
|
|
694
|
+
].filter((flag) => Boolean(flag));
|
|
695
|
+
if (mutationFlags.length > 1) {
|
|
696
|
+
throw new Error(
|
|
697
|
+
`Use only one of ${mutationFlags.join(", ")} per invocation.`
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
if (pluginName && hasMutation) {
|
|
701
|
+
await applyBindingMutations(pluginName, opts);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
if (pluginName) {
|
|
705
|
+
const canPrompt2 = shouldUseWizard({
|
|
706
|
+
interactive: opts.interactive,
|
|
707
|
+
noInteractive: opts.noInteractive,
|
|
708
|
+
format,
|
|
709
|
+
missingRequiredArgs: false
|
|
710
|
+
});
|
|
711
|
+
if (canPrompt2) {
|
|
712
|
+
const plugin2 = getPlugin(pluginName);
|
|
713
|
+
if (!plugin2) {
|
|
714
|
+
throw new Error(`Plugin not found: ${pluginName}`);
|
|
715
|
+
}
|
|
716
|
+
await promptForInteractivePluginCatalogBindings({ plugin: plugin2 });
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
await applyBindingMutations(pluginName, { ...opts, format });
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
const canPrompt = shouldUseWizard({
|
|
723
|
+
interactive: opts.interactive,
|
|
724
|
+
noInteractive: opts.noInteractive,
|
|
725
|
+
format,
|
|
726
|
+
missingRequiredArgs: true
|
|
727
|
+
});
|
|
728
|
+
if (!canPrompt) {
|
|
729
|
+
throw new Error(
|
|
730
|
+
"Plugin name is required in non-interactive mode. Pass a plugin name or use an interactive terminal."
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
const plugins = sortPluginsForPicker(listPlugins());
|
|
734
|
+
if (plugins.length === 0) {
|
|
735
|
+
throw new Error("No local plugins found. Create one with `ht plugin from-project` or `ht init`.");
|
|
736
|
+
}
|
|
737
|
+
const selectedName = await promptForChoice({
|
|
738
|
+
message: "Select plugin to configure publish catalogs",
|
|
739
|
+
choices: plugins.map((plugin2) => ({
|
|
740
|
+
name: `${plugin2.name}@${plugin2.version}`,
|
|
741
|
+
value: plugin2.name
|
|
742
|
+
}))
|
|
743
|
+
});
|
|
744
|
+
const plugin = getPlugin(selectedName);
|
|
745
|
+
if (!plugin) {
|
|
746
|
+
throw new Error(`Plugin not found: ${selectedName}`);
|
|
747
|
+
}
|
|
748
|
+
await promptForInteractivePluginCatalogBindings({ plugin });
|
|
749
|
+
}
|
|
750
|
+
function resolvePublishTargetsForPlugin(pluginId) {
|
|
751
|
+
return assertResolvablePublishTargets(pluginId);
|
|
752
|
+
}
|
|
753
|
+
function resolveOneOffPublishTarget(input) {
|
|
754
|
+
if (input.catalogSelector) {
|
|
755
|
+
const parsed = parsePublishCatalogSelector(input.catalogSelector);
|
|
756
|
+
return [
|
|
757
|
+
input.account?.trim() ? { ...parsed, account: input.account.trim() } : parsed
|
|
758
|
+
];
|
|
759
|
+
}
|
|
760
|
+
if (input.org?.trim()) {
|
|
761
|
+
return [
|
|
762
|
+
{
|
|
763
|
+
org: input.org.trim().toLowerCase(),
|
|
764
|
+
catalog: (input.catalog?.trim() || "default").toLowerCase(),
|
|
765
|
+
...input.account?.trim() ? { account: input.account.trim() } : {}
|
|
766
|
+
}
|
|
767
|
+
];
|
|
768
|
+
}
|
|
769
|
+
return [];
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// src/services/plugin-publish.ts
|
|
773
|
+
async function createCloudClientForTarget(target, accountOverride) {
|
|
774
|
+
const accountName = accountOverride ?? target.account;
|
|
775
|
+
const created = await createPersistingCloudClient(accountName);
|
|
776
|
+
return created?.client;
|
|
777
|
+
}
|
|
778
|
+
async function publishPluginToCatalogs(plugin, targets, opts) {
|
|
779
|
+
assertPluginsCleanForShare([plugin]);
|
|
780
|
+
const apPackage = envelopeFromFiles(buildApPackageFiles(plugin.id));
|
|
781
|
+
const results = [];
|
|
782
|
+
let firstSuccess;
|
|
783
|
+
for (const target of targets) {
|
|
784
|
+
const label = formatPublishCatalogSelector(target);
|
|
785
|
+
try {
|
|
786
|
+
const client = await createCloudClientForTarget(target, opts?.account);
|
|
787
|
+
if (!client) {
|
|
788
|
+
results.push({
|
|
789
|
+
target,
|
|
790
|
+
ok: false,
|
|
791
|
+
error: `No cloud account configured for ${label}. Use \`auth login\` or pass --account.`
|
|
792
|
+
});
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
const resp = await client.publishPackage(
|
|
796
|
+
{
|
|
797
|
+
plugin_name: plugin.name,
|
|
798
|
+
org_slug: target.org,
|
|
799
|
+
catalog_slug: target.catalog
|
|
800
|
+
},
|
|
801
|
+
apPackage
|
|
802
|
+
);
|
|
803
|
+
const version = typeof resp.version === "string" ? resp.version : void 0;
|
|
804
|
+
results.push({ target, ok: true, version });
|
|
805
|
+
if (!firstSuccess) {
|
|
806
|
+
firstSuccess = {
|
|
807
|
+
org_slug: target.org,
|
|
808
|
+
catalog_slug: target.catalog,
|
|
809
|
+
version
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
} catch (error) {
|
|
813
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
814
|
+
results.push({ target, ok: false, error: message });
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (firstSuccess && targets.length === 1) {
|
|
818
|
+
updatePluginPublishedIdentity(plugin.id, firstSuccess);
|
|
819
|
+
}
|
|
820
|
+
return results;
|
|
821
|
+
}
|
|
822
|
+
function renderPublishResults(pluginName, results) {
|
|
823
|
+
for (const result of results) {
|
|
824
|
+
const label = formatPublishedSelector({
|
|
825
|
+
org: result.target.org,
|
|
826
|
+
catalog: result.target.catalog,
|
|
827
|
+
name: pluginName
|
|
828
|
+
});
|
|
829
|
+
if (result.ok) {
|
|
830
|
+
const versionSuffix = result.version ? `@${result.version}` : "";
|
|
831
|
+
ui.success(`Published ${pluginName} to ${label}${versionSuffix}`);
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
const errorMsg = result.error ?? "Publish failed";
|
|
835
|
+
if (errorMsg.includes("409")) {
|
|
836
|
+
ui.danger(
|
|
837
|
+
`Failed ${label}: plugin slug "${pluginName}" already exists in that catalog.`
|
|
838
|
+
);
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
ui.danger(`Failed ${label}: ${errorMsg}`);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
async function planPluginPublish(plugin, targets, opts) {
|
|
845
|
+
const plans = [];
|
|
846
|
+
for (const target of targets) {
|
|
847
|
+
const label = formatPublishCatalogSelector(target);
|
|
848
|
+
const accountName = opts?.account ?? target.account;
|
|
849
|
+
const accountInfo = await getCloudAccount(accountName);
|
|
850
|
+
if (!accountInfo.account?.cloudBaseUrl) {
|
|
851
|
+
plans.push({
|
|
852
|
+
target,
|
|
853
|
+
account: accountName,
|
|
854
|
+
ok: false,
|
|
855
|
+
error: `No cloud account configured for ${label}`
|
|
856
|
+
});
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
859
|
+
try {
|
|
860
|
+
const client = await createCloudClientForTarget(target, opts?.account);
|
|
861
|
+
if (!client) {
|
|
862
|
+
plans.push({
|
|
863
|
+
target,
|
|
864
|
+
account: accountName,
|
|
865
|
+
ok: false,
|
|
866
|
+
error: `No cloud account configured for ${label}`
|
|
867
|
+
});
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
const { nextVersion } = await client.planPluginPublishVersion({
|
|
871
|
+
plugin_name: plugin.name,
|
|
872
|
+
org_slug: target.org,
|
|
873
|
+
catalog_slug: target.catalog
|
|
874
|
+
});
|
|
875
|
+
plans.push({
|
|
876
|
+
target,
|
|
877
|
+
account: accountInfo.accountName ?? accountName,
|
|
878
|
+
nextVersion,
|
|
879
|
+
ok: true
|
|
880
|
+
});
|
|
881
|
+
} catch (error) {
|
|
882
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
883
|
+
plans.push({
|
|
884
|
+
target,
|
|
885
|
+
account: accountInfo.accountName ?? accountName,
|
|
886
|
+
ok: false,
|
|
887
|
+
error: message
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
return plans;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// src/cli/handlers/plugin-publish.ts
|
|
895
|
+
function publishVersionRequiredMessage(pluginName, reason, kind) {
|
|
896
|
+
if (kind === "profile") {
|
|
897
|
+
return `${reason} Cut a version first, then publish. For example: ${formatCommand(["plugin", "cut", pluginName, "--version", "1.1.0"])}`;
|
|
898
|
+
}
|
|
899
|
+
return `${reason} Pass --version <semver> to cut a new plugin version before publishing (e.g. \`${formatCommand(["plugin", "publish", pluginName, "--version", "1.1.0"])}\`).`;
|
|
900
|
+
}
|
|
901
|
+
async function handlePluginPublishCommand(pluginName, catalogSelector, opts) {
|
|
902
|
+
const db = getDb();
|
|
903
|
+
initializeSchema(db);
|
|
904
|
+
let plugin = getPlugin(pluginName);
|
|
905
|
+
if (!plugin) {
|
|
906
|
+
process.exitCode = 1;
|
|
907
|
+
ui.danger(`Plugin not found: ${pluginName}`);
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
try {
|
|
911
|
+
assertAuthored(plugin.id, "publish");
|
|
912
|
+
if (opts.version) {
|
|
913
|
+
plugin = cutPluginVersion({ pluginId: plugin.id, newVersion: opts.version });
|
|
914
|
+
} else if (plugin.dirty) {
|
|
915
|
+
throw new PluginVersionError(
|
|
916
|
+
"dirty_plugins",
|
|
917
|
+
publishVersionRequiredMessage(
|
|
918
|
+
plugin.name,
|
|
919
|
+
`Plugin ${plugin.name}@${plugin.version} has unpublished edits.`,
|
|
920
|
+
opts.kind ?? "plugin"
|
|
921
|
+
),
|
|
922
|
+
{ dirtyPlugins: [{ name: plugin.name, version: plugin.version }] }
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
assertPluginsCleanForShare([plugin]);
|
|
926
|
+
const oneOffTargets = resolveOneOffPublishTarget({
|
|
927
|
+
catalogSelector,
|
|
928
|
+
org: opts.org,
|
|
929
|
+
catalog: opts.catalog,
|
|
930
|
+
account: opts.account
|
|
931
|
+
});
|
|
932
|
+
const targets = oneOffTargets.length > 0 ? oneOffTargets : resolvePublishTargetsForPlugin(plugin.id);
|
|
933
|
+
const results = await publishPluginToCatalogs(plugin, targets, {
|
|
934
|
+
account: opts.account
|
|
935
|
+
});
|
|
936
|
+
const format = parseOutputFormat(opts.format);
|
|
937
|
+
if (format === "json") {
|
|
938
|
+
printJson({
|
|
939
|
+
plugin: plugin.name,
|
|
940
|
+
results: results.map((result) => ({
|
|
941
|
+
org: result.target.org,
|
|
942
|
+
catalog: result.target.catalog,
|
|
943
|
+
account: result.target.account,
|
|
944
|
+
ok: result.ok,
|
|
945
|
+
version: result.version,
|
|
946
|
+
error: result.error
|
|
947
|
+
}))
|
|
948
|
+
});
|
|
949
|
+
} else {
|
|
950
|
+
renderPublishResults(plugin.name, results);
|
|
951
|
+
}
|
|
952
|
+
if (results.some((result) => !result.ok)) {
|
|
953
|
+
process.exitCode = 1;
|
|
954
|
+
}
|
|
955
|
+
} catch (err) {
|
|
956
|
+
process.exitCode = 1;
|
|
957
|
+
if (err instanceof PluginProvenanceError) {
|
|
958
|
+
ui.danger(err.message, { hints: err.hints });
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
if (err instanceof PluginVersionError) {
|
|
962
|
+
ui.danger(err.message);
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
ui.danger(err instanceof Error ? err.message : String(err));
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
async function handlePluginPublishPlanCommand(pluginName, opts) {
|
|
969
|
+
const db = getDb();
|
|
970
|
+
initializeSchema(db);
|
|
971
|
+
const plugin = getPlugin(pluginName);
|
|
972
|
+
if (!plugin) {
|
|
973
|
+
process.exitCode = 1;
|
|
974
|
+
ui.danger(`Plugin not found: ${pluginName}`);
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
try {
|
|
978
|
+
assertAuthored(plugin.id, "publish");
|
|
979
|
+
const targets = resolvePublishTargetsForPlugin(plugin.id);
|
|
980
|
+
const plans = await planPluginPublish(plugin, targets, { account: opts.account });
|
|
981
|
+
const format = parseOutputFormat(opts.format);
|
|
982
|
+
if (format === "json") {
|
|
983
|
+
printJson({ plugin: plugin.name, plans });
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
for (const plan of plans) {
|
|
987
|
+
const label = formatPublishedSelector({
|
|
988
|
+
org: plan.target.org,
|
|
989
|
+
catalog: plan.target.catalog,
|
|
990
|
+
name: plugin.name
|
|
991
|
+
});
|
|
992
|
+
if (plan.ok) {
|
|
993
|
+
const accountLabel = plan.account ? ` (account: ${plan.account})` : "";
|
|
994
|
+
const versionLabel = plan.nextVersion ? ` \u2192 ${plan.nextVersion}` : "";
|
|
995
|
+
console.log(`${label}${accountLabel}${versionLabel}`);
|
|
996
|
+
} else {
|
|
997
|
+
ui.danger(`${label}: ${plan.error ?? "unavailable"}`);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
if (plans.some((plan) => !plan.ok)) {
|
|
1001
|
+
process.exitCode = 1;
|
|
1002
|
+
}
|
|
1003
|
+
} catch (err) {
|
|
1004
|
+
process.exitCode = 1;
|
|
1005
|
+
if (err instanceof PluginProvenanceError) {
|
|
1006
|
+
ui.danger(err.message, { hints: err.hints });
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
ui.danger(err instanceof Error ? err.message : String(err));
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
function countMaterialPluginResources(pluginId) {
|
|
1013
|
+
return getPluginResources(pluginId).filter(
|
|
1014
|
+
(resource) => resource.type !== "plugin"
|
|
1015
|
+
).length;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// src/services/plugin-show-render.ts
|
|
1019
|
+
function summarizeResourceTypes(resources) {
|
|
1020
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1021
|
+
for (const resource of resources) {
|
|
1022
|
+
counts.set(resource.type, (counts.get(resource.type) ?? 0) + 1);
|
|
1023
|
+
}
|
|
1024
|
+
const summary = RESOURCE_TYPES.filter(
|
|
1025
|
+
(type) => (counts.get(type) ?? 0) > 0
|
|
1026
|
+
).map((type) => formatCount(counts.get(type) ?? 0, type));
|
|
1027
|
+
return summary.join(", ");
|
|
1028
|
+
}
|
|
1029
|
+
function formatPluginLabel(plugin) {
|
|
1030
|
+
return `${plugin.name}@${formatPluginVersionLabel(plugin.version, plugin.dirty)}`;
|
|
1031
|
+
}
|
|
1032
|
+
function formatDependencyConstraint(versionConstraint) {
|
|
1033
|
+
return versionConstraint.trim() || "*";
|
|
1034
|
+
}
|
|
1035
|
+
function formatOriginLabel(origin, originLocator) {
|
|
1036
|
+
return formatPluginOriginDisplay(origin || "authored", originLocator);
|
|
1037
|
+
}
|
|
1038
|
+
function makeIdColumn(showId, width = 12) {
|
|
1039
|
+
return showId ? [{
|
|
1040
|
+
key: "id",
|
|
1041
|
+
header: "ID",
|
|
1042
|
+
width,
|
|
1043
|
+
transform: (value) => shortenId(String(value))
|
|
1044
|
+
}] : [];
|
|
1045
|
+
}
|
|
1046
|
+
function makeResourceTypeColumn(width = 14) {
|
|
1047
|
+
return {
|
|
1048
|
+
key: "type",
|
|
1049
|
+
header: "TYPE",
|
|
1050
|
+
width,
|
|
1051
|
+
style: (value) => theme.resourceType(value)
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
function resolveConfiguredPlugin(selector, plugin) {
|
|
1055
|
+
if (/^[0-9A-Z]{26}$/.test(selector)) {
|
|
1056
|
+
return getPluginById(selector);
|
|
1057
|
+
}
|
|
1058
|
+
const atIdx = selector.lastIndexOf("@");
|
|
1059
|
+
if (atIdx > 0) {
|
|
1060
|
+
return resolvePluginSelector(selector);
|
|
1061
|
+
}
|
|
1062
|
+
return resolvePluginSelector(`${plugin.name}@${plugin.version}`);
|
|
1063
|
+
}
|
|
1064
|
+
function renderPluginShow(plugin, selector, opts) {
|
|
1065
|
+
const allResources = getPluginResources(plugin.id);
|
|
1066
|
+
const resources = allResources.filter(
|
|
1067
|
+
(resource) => resource.type !== "plugin"
|
|
1068
|
+
);
|
|
1069
|
+
const dependencies = listDependencies(plugin.id);
|
|
1070
|
+
const configuredPlugin = resolveConfiguredPlugin(selector, plugin);
|
|
1071
|
+
const configuredPluginDefaultEnvironment = configuredPlugin?.default_environment_id ? getEnvironment(configuredPlugin.default_environment_id) : void 0;
|
|
1072
|
+
const pluginLabel = opts?.pluginLabel ?? formatPluginLabel(plugin);
|
|
1073
|
+
const sections = [
|
|
1074
|
+
renderPanel({
|
|
1075
|
+
title: ["PLUGIN", pluginLabel],
|
|
1076
|
+
rows: [
|
|
1077
|
+
["Description", plugin.description || ": "],
|
|
1078
|
+
["Tags", plugin.tags.length > 0 ? plugin.tags.join(", ") : ": "],
|
|
1079
|
+
["Origin", formatOriginLabel(plugin.origin, plugin.origin_locator)],
|
|
1080
|
+
...opts?.profileExtras ? [["Active", opts.profileExtras.active ? "yes" : "no"]] : [],
|
|
1081
|
+
["Resources", `${resources.length} (${summarizeResourceTypes(resources) || "none"})`],
|
|
1082
|
+
[
|
|
1083
|
+
"Dependencies",
|
|
1084
|
+
dependencies.length === 0 ? "(none)" : `${dependencies.length}`
|
|
1085
|
+
],
|
|
1086
|
+
...configuredPlugin ? [[
|
|
1087
|
+
"Default environment",
|
|
1088
|
+
configuredPluginDefaultEnvironment?.name ?? configuredPlugin.default_environment_id ?? ": "
|
|
1089
|
+
]] : [],
|
|
1090
|
+
["Updated", formatRelativeTimeWithAbsolute(plugin.updated_at)]
|
|
1091
|
+
]
|
|
1092
|
+
}),
|
|
1093
|
+
renderSubheader("RESOURCES"),
|
|
1094
|
+
renderTable({
|
|
1095
|
+
columns: [
|
|
1096
|
+
...makeIdColumn(Boolean(opts?.showId)),
|
|
1097
|
+
makeResourceTypeColumn(),
|
|
1098
|
+
{ key: "name", header: "NAME", width: 26 }
|
|
1099
|
+
],
|
|
1100
|
+
rows: resources,
|
|
1101
|
+
empty: "No resources in this plugin."
|
|
1102
|
+
})
|
|
1103
|
+
];
|
|
1104
|
+
if (dependencies.length > 0) {
|
|
1105
|
+
sections.push(
|
|
1106
|
+
renderSubheader("DEPENDENCIES"),
|
|
1107
|
+
renderTable({
|
|
1108
|
+
columns: [
|
|
1109
|
+
{ key: "name", header: "NAME", width: 22 },
|
|
1110
|
+
{ key: "constraint", header: "CONSTRAINT", width: 12 },
|
|
1111
|
+
{ key: "source", header: "SOURCE", width: 14 }
|
|
1112
|
+
],
|
|
1113
|
+
rows: dependencies.map((dependency) => ({
|
|
1114
|
+
name: dependency.name,
|
|
1115
|
+
constraint: formatDependencyConstraint(dependency.version_constraint),
|
|
1116
|
+
source: dependency.source_kind
|
|
1117
|
+
}))
|
|
1118
|
+
})
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
return sections.join("\n");
|
|
1122
|
+
}
|
|
1123
|
+
function renderPluginShowForPlugin(plugin, opts) {
|
|
1124
|
+
return renderPluginShow(plugin, `${plugin.name}@${plugin.version}`, opts);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// src/cli/handlers/plugin-show-command.ts
|
|
1128
|
+
function handlePluginShowCommand(name, opts, profileExtras) {
|
|
1129
|
+
const db = getDb();
|
|
1130
|
+
initializeSchema(db);
|
|
1131
|
+
const format = parseOutputFormat(opts.format);
|
|
1132
|
+
const plugin = getPlugin(name);
|
|
1133
|
+
if (!plugin) {
|
|
1134
|
+
fail(CLI_ERRORS.pluginNotFound(name), { hint: CLI_HINTS.pluginList });
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
trackPluginUsed({
|
|
1138
|
+
pluginSlug: plugin.name
|
|
1139
|
+
});
|
|
1140
|
+
const allResources = getPluginResources(plugin.id);
|
|
1141
|
+
const resources = allResources.filter(
|
|
1142
|
+
(resource) => resource.type !== "plugin"
|
|
1143
|
+
);
|
|
1144
|
+
const pluginPins = listAttachedPluginPins(plugin.id);
|
|
1145
|
+
const pluginPinRows = pluginPins.map((pin, index) => ({
|
|
1146
|
+
plugin_id: plugin.id,
|
|
1147
|
+
ref: pin.ref,
|
|
1148
|
+
version_constraint: pin.version_constraint,
|
|
1149
|
+
order: index,
|
|
1150
|
+
embed_on_export: pin.embed_on_export
|
|
1151
|
+
}));
|
|
1152
|
+
const dependencies = listPluginDependencies(plugin.id);
|
|
1153
|
+
const configuredPlugin = (() => {
|
|
1154
|
+
if (/^[0-9A-Z]{26}$/.test(name)) {
|
|
1155
|
+
return getPluginById(name);
|
|
1156
|
+
}
|
|
1157
|
+
const atIdx = name.lastIndexOf("@");
|
|
1158
|
+
if (atIdx > 0) {
|
|
1159
|
+
return resolvePluginSelector(name);
|
|
1160
|
+
}
|
|
1161
|
+
return resolvePluginSelector(`${plugin.name}@${plugin.version}`);
|
|
1162
|
+
})();
|
|
1163
|
+
const configuredPluginDefaultEnvironment = configuredPlugin?.default_environment_id ? getEnvironment(configuredPlugin.default_environment_id) : void 0;
|
|
1164
|
+
if (format === "json") {
|
|
1165
|
+
printJson({
|
|
1166
|
+
id: plugin.id,
|
|
1167
|
+
name: plugin.name,
|
|
1168
|
+
version: plugin.version,
|
|
1169
|
+
dirty: plugin.dirty,
|
|
1170
|
+
description: plugin.description,
|
|
1171
|
+
tags: plugin.tags,
|
|
1172
|
+
...plugin.claude ? { claude: plugin.claude } : {},
|
|
1173
|
+
created_at: plugin.created_at,
|
|
1174
|
+
updated_at: plugin.updated_at,
|
|
1175
|
+
resources,
|
|
1176
|
+
plugin_pins: pluginPinRows,
|
|
1177
|
+
dependencies,
|
|
1178
|
+
...configuredPlugin ? {
|
|
1179
|
+
configured_plugin: {
|
|
1180
|
+
id: configuredPlugin.id,
|
|
1181
|
+
name: configuredPlugin.name,
|
|
1182
|
+
version: configuredPlugin.version,
|
|
1183
|
+
default_environment: configuredPluginDefaultEnvironment?.name ?? configuredPlugin.default_environment_id ?? null
|
|
1184
|
+
}
|
|
1185
|
+
} : {},
|
|
1186
|
+
...profileExtras ? { active: profileExtras.active } : {}
|
|
1187
|
+
});
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
console.log(renderPluginShow(plugin, name, {
|
|
1191
|
+
showId: opts.showId,
|
|
1192
|
+
profileExtras
|
|
1193
|
+
}));
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// src/services/plugin-apply-source.ts
|
|
1197
|
+
function resolveLocalPlugin(selector) {
|
|
1198
|
+
const direct = resolvePluginSelector(selector);
|
|
1199
|
+
if (direct) {
|
|
1200
|
+
return direct;
|
|
1201
|
+
}
|
|
1202
|
+
try {
|
|
1203
|
+
const parsed = parsePluginSelector(selector);
|
|
1204
|
+
if (parsed.scope !== "published") {
|
|
1205
|
+
return void 0;
|
|
1206
|
+
}
|
|
1207
|
+
if (parsed.version) {
|
|
1208
|
+
const byPublishedIdentity = getPluginByPublishedIdentity({
|
|
1209
|
+
name: parsed.name,
|
|
1210
|
+
version: parsed.version,
|
|
1211
|
+
org: parsed.org,
|
|
1212
|
+
catalog: parsed.catalog
|
|
1213
|
+
});
|
|
1214
|
+
if (byPublishedIdentity) {
|
|
1215
|
+
return byPublishedIdentity;
|
|
1216
|
+
}
|
|
1217
|
+
return getPluginByCatalogVersion(parsed.org, parsed.catalog, parsed.version);
|
|
1218
|
+
}
|
|
1219
|
+
return getPluginByName(parsed.name);
|
|
1220
|
+
} catch {
|
|
1221
|
+
return void 0;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
function isPublishedSelector(selector) {
|
|
1225
|
+
try {
|
|
1226
|
+
return parsePluginSelector(selector).scope === "published";
|
|
1227
|
+
} catch {
|
|
1228
|
+
return false;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
function isBarePluginName(selector) {
|
|
1232
|
+
if (isPluginUrl(selector) || isPluginExportFilePath(selector)) {
|
|
1233
|
+
return false;
|
|
1234
|
+
}
|
|
1235
|
+
return !selector.includes("/");
|
|
1236
|
+
}
|
|
1237
|
+
function filterPluginsByVersionConstraint(plugins, versionConstraint) {
|
|
1238
|
+
if (!versionConstraint) {
|
|
1239
|
+
return plugins;
|
|
1240
|
+
}
|
|
1241
|
+
return plugins.filter((plugin) => satisfiesConstraint(versionConstraint, plugin.version));
|
|
1242
|
+
}
|
|
1243
|
+
function getUnpublishedLocalByName(name) {
|
|
1244
|
+
const plugin = resolvePluginSelector(name);
|
|
1245
|
+
if (!plugin) {
|
|
1246
|
+
return void 0;
|
|
1247
|
+
}
|
|
1248
|
+
if (plugin.org_slug || plugin.catalog_slug) {
|
|
1249
|
+
return void 0;
|
|
1250
|
+
}
|
|
1251
|
+
return plugin;
|
|
1252
|
+
}
|
|
1253
|
+
function formatLocalPublishedAmbiguity(selector, plugins) {
|
|
1254
|
+
const lines = plugins.map((plugin) => formatPublishedPluginSelector(plugin));
|
|
1255
|
+
return `Ambiguous plugin name: ${selector}
|
|
1256
|
+
${lines.map((line) => ` ${line}`).join("\n")}`;
|
|
1257
|
+
}
|
|
1258
|
+
async function promptLocalPublishedAmbiguity(selector, plugins) {
|
|
1259
|
+
const selected = await promptForChoice({
|
|
1260
|
+
message: `Multiple installed plugins match "${selector}". Which one?`,
|
|
1261
|
+
choices: plugins.map((plugin) => ({
|
|
1262
|
+
name: formatPublishedPluginSelector(plugin),
|
|
1263
|
+
value: plugin.id
|
|
1264
|
+
}))
|
|
1265
|
+
});
|
|
1266
|
+
const match = plugins.find((plugin) => plugin.id === selected);
|
|
1267
|
+
if (!match) {
|
|
1268
|
+
throw new PluginResolveError(`Plugin not found: ${selector}`);
|
|
1269
|
+
}
|
|
1270
|
+
return match;
|
|
1271
|
+
}
|
|
1272
|
+
async function pickLocalPublishedPlugin(selector, plugins, options) {
|
|
1273
|
+
if (plugins.length === 1) {
|
|
1274
|
+
const only = plugins[0];
|
|
1275
|
+
if (!only) {
|
|
1276
|
+
throw new PluginResolveError(`Plugin not found: ${selector}`);
|
|
1277
|
+
}
|
|
1278
|
+
return only;
|
|
1279
|
+
}
|
|
1280
|
+
const canPrompt = shouldUseWizard({
|
|
1281
|
+
interactive: options.interactive ?? true,
|
|
1282
|
+
noInteractive: options.noInteractive,
|
|
1283
|
+
format: options.format ?? "human",
|
|
1284
|
+
missingRequiredArgs: false
|
|
1285
|
+
});
|
|
1286
|
+
if (!canPrompt) {
|
|
1287
|
+
throw new PluginResolveError(formatLocalPublishedAmbiguity(selector, plugins), [
|
|
1288
|
+
"Use a fully qualified selector: org/catalog/slug@version"
|
|
1289
|
+
]);
|
|
1290
|
+
}
|
|
1291
|
+
return promptLocalPublishedAmbiguity(selector, plugins);
|
|
1292
|
+
}
|
|
1293
|
+
async function resolveBareApplyPluginSource(selector, options) {
|
|
1294
|
+
const parsed = parsePluginSelector(selector);
|
|
1295
|
+
if (parsed.scope !== "local") {
|
|
1296
|
+
throw new PluginResolveError(`Plugin not found: ${selector}`);
|
|
1297
|
+
}
|
|
1298
|
+
const publishedLocals = filterPluginsByVersionConstraint(
|
|
1299
|
+
listLatestPublishedPluginsBySlug(parsed.name),
|
|
1300
|
+
parsed.version
|
|
1301
|
+
);
|
|
1302
|
+
if (publishedLocals.length > 0) {
|
|
1303
|
+
const plugin = await pickLocalPublishedPlugin(selector, publishedLocals, options);
|
|
1304
|
+
return { kind: "local", pluginId: plugin.id };
|
|
1305
|
+
}
|
|
1306
|
+
const unpublishedLocal = getUnpublishedLocalByName(parsed.name);
|
|
1307
|
+
if (unpublishedLocal) {
|
|
1308
|
+
return { kind: "local", pluginId: unpublishedLocal.id };
|
|
1309
|
+
}
|
|
1310
|
+
const remote = await resolveBareNameFromCatalog(selector, {
|
|
1311
|
+
account: options.account,
|
|
1312
|
+
baseUrl: options.baseUrl,
|
|
1313
|
+
interactive: options.interactive,
|
|
1314
|
+
noInteractive: options.noInteractive,
|
|
1315
|
+
format: options.format,
|
|
1316
|
+
promptAmbiguity: options.promptAmbiguity
|
|
1317
|
+
});
|
|
1318
|
+
const installed = await installPluginFromCatalog(remote, {
|
|
1319
|
+
account: options.account,
|
|
1320
|
+
baseUrl: options.baseUrl,
|
|
1321
|
+
onFetched: options.onFetched
|
|
1322
|
+
});
|
|
1323
|
+
options.onFetched?.(installed.sourceLabel);
|
|
1324
|
+
return { kind: "local", pluginId: installed.pluginId };
|
|
1325
|
+
}
|
|
1326
|
+
async function resolveApplyPluginSource(selector, options = {}) {
|
|
1327
|
+
if (isPluginUrl(selector)) {
|
|
1328
|
+
const path = await fetchPluginExportToTempFile(selector);
|
|
1329
|
+
return { kind: "plugin-export", path };
|
|
1330
|
+
}
|
|
1331
|
+
if (isPluginExportFilePath(selector)) {
|
|
1332
|
+
return { kind: "plugin-export", path: selector };
|
|
1333
|
+
}
|
|
1334
|
+
const localPlugin = resolveLocalPlugin(selector);
|
|
1335
|
+
if (localPlugin && !isBarePluginName(selector)) {
|
|
1336
|
+
return { kind: "local", pluginId: localPlugin.id };
|
|
1337
|
+
}
|
|
1338
|
+
if (isBarePluginName(selector)) {
|
|
1339
|
+
return resolveBareApplyPluginSource(selector, options);
|
|
1340
|
+
}
|
|
1341
|
+
if (!isPublishedSelector(selector)) {
|
|
1342
|
+
throw new PluginResolveError(`Plugin not found: ${selector}`, [
|
|
1343
|
+
"ht plugin list --search <query> --remote-only",
|
|
1344
|
+
"ht plugin pull org/catalog/name",
|
|
1345
|
+
"ht plugin list"
|
|
1346
|
+
]);
|
|
1347
|
+
}
|
|
1348
|
+
const parsed = resolveRemotePluginSelector(selector, {});
|
|
1349
|
+
const installed = await installPluginFromCatalog(parsed, {
|
|
1350
|
+
account: options.account,
|
|
1351
|
+
baseUrl: options.baseUrl,
|
|
1352
|
+
onFetched: options.onFetched
|
|
1353
|
+
});
|
|
1354
|
+
options.onFetched?.(installed.sourceLabel);
|
|
1355
|
+
return { kind: "local", pluginId: installed.pluginId };
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
// src/services/plugin-search-apply.ts
|
|
1359
|
+
import { resolve } from "path";
|
|
1360
|
+
function catalogSearchSelectors(selections) {
|
|
1361
|
+
if (selections.length === 0) {
|
|
1362
|
+
throw new Error("No plugins selected.");
|
|
1363
|
+
}
|
|
1364
|
+
return selections.map((selection) => selection.selector);
|
|
1365
|
+
}
|
|
1366
|
+
async function promptCatalogSearchApplyScope() {
|
|
1367
|
+
return promptForChoice({
|
|
1368
|
+
message: "Where should selected plugins be applied?",
|
|
1369
|
+
choices: [
|
|
1370
|
+
{ name: "This project (current directory)", value: "project" },
|
|
1371
|
+
{ name: "Global (user home: ~/.claude, ~/.codex, ...)", value: "global" }
|
|
1372
|
+
],
|
|
1373
|
+
default: "project"
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
async function resolveRootPluginsForSearchApply(selectors, options) {
|
|
1377
|
+
const resolvedSources = await Promise.all(
|
|
1378
|
+
selectors.map((selector) => resolveApplyPluginSource(selector, options))
|
|
1379
|
+
);
|
|
1380
|
+
const rootPluginIds = [];
|
|
1381
|
+
const rootSelectors = [];
|
|
1382
|
+
for (const source of resolvedSources) {
|
|
1383
|
+
if (source.kind === "plugin-export") {
|
|
1384
|
+
throw new Error("Plugin export paths cannot be applied from catalog search.");
|
|
1385
|
+
}
|
|
1386
|
+
const plugin = getPluginById(source.pluginId);
|
|
1387
|
+
if (!plugin) {
|
|
1388
|
+
throw new Error(`Plugin not found: ${source.pluginId}`);
|
|
1389
|
+
}
|
|
1390
|
+
rootPluginIds.push(plugin.id);
|
|
1391
|
+
rootSelectors.push(`${plugin.name}@${plugin.version}`);
|
|
1392
|
+
}
|
|
1393
|
+
return { rootPluginIds, rootSelectors };
|
|
1394
|
+
}
|
|
1395
|
+
async function applyPluginsGlobally(selectors, options) {
|
|
1396
|
+
const homeRoot = resolveHomeRoot();
|
|
1397
|
+
const sourceOptions = {
|
|
1398
|
+
account: options.account,
|
|
1399
|
+
baseUrl: options.baseUrl,
|
|
1400
|
+
onFetched: options.onFetched
|
|
1401
|
+
};
|
|
1402
|
+
const { rootPluginIds, rootSelectors } = await resolveRootPluginsForSearchApply(
|
|
1403
|
+
selectors,
|
|
1404
|
+
sourceOptions
|
|
1405
|
+
);
|
|
1406
|
+
const rootPluginPins = collectPluginPinsForPrepare(rootPluginIds);
|
|
1407
|
+
await preparePluginPinsForApply({
|
|
1408
|
+
pins: rootPluginPins,
|
|
1409
|
+
baseResources: [],
|
|
1410
|
+
projectRoot: homeRoot,
|
|
1411
|
+
claudeConfig: mergePluginsById(rootPluginIds).claude,
|
|
1412
|
+
scope: "user",
|
|
1413
|
+
skipSync: rootPluginPins.length === 0
|
|
1414
|
+
});
|
|
1415
|
+
let resolution = resolveComposition({ rootSelectors });
|
|
1416
|
+
const configuredPluginIds = resolution.selected.filter((plugin) => !(plugin.depth === 0 && resolution.root.ephemeral)).map((plugin) => plugin.pluginId);
|
|
1417
|
+
const rootPinRefs = new Set(rootPluginPins.map((pin) => pin.ref));
|
|
1418
|
+
const additionalPins = collectPluginPinsForPrepare(configuredPluginIds).filter(
|
|
1419
|
+
(pin) => !rootPinRefs.has(pin.ref)
|
|
1420
|
+
);
|
|
1421
|
+
if (additionalPins.length > 0) {
|
|
1422
|
+
const additionalPrepare = await preparePluginPinsForApply({
|
|
1423
|
+
pins: additionalPins,
|
|
1424
|
+
baseResources: resolution.resources,
|
|
1425
|
+
projectRoot: homeRoot,
|
|
1426
|
+
claudeConfig: mergePluginsById(
|
|
1427
|
+
[...resolution.selected].sort((a, b) => b.depth - a.depth || b.declarationIndex - a.declarationIndex).map((plugin) => plugin.pluginId)
|
|
1428
|
+
).claude,
|
|
1429
|
+
scope: "user",
|
|
1430
|
+
skipSync: false
|
|
1431
|
+
});
|
|
1432
|
+
if (additionalPrepare.installs.some(
|
|
1433
|
+
(install) => install.status !== "already_installed"
|
|
1434
|
+
)) {
|
|
1435
|
+
resolution = resolveComposition({ rootSelectors });
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
const harnesses = resolveScanGlobalHarnessTargets(options.harness, homeRoot);
|
|
1439
|
+
const resolvedEnvironment = resolveEnvironmentCascadeForApply({
|
|
1440
|
+
configuredPluginIds
|
|
1441
|
+
});
|
|
1442
|
+
const mergedClaude = mergePluginsById(
|
|
1443
|
+
[...resolution.selected].sort((a, b) => b.depth - a.depth || b.declarationIndex - a.declarationIndex).map((plugin) => plugin.pluginId)
|
|
1444
|
+
).claude;
|
|
1445
|
+
const homeRootForClaude = resolveHomeRoot();
|
|
1446
|
+
const resolvedClaude = mergedClaude?.plugins && mergedClaude.plugins.length > 0 ? {
|
|
1447
|
+
...mergedClaude,
|
|
1448
|
+
plugins: mergedClaude.plugins.map((plugin) => ({
|
|
1449
|
+
...plugin,
|
|
1450
|
+
id: resolveClaudeEnabledPluginRef(plugin.id, homeRootForClaude)
|
|
1451
|
+
}))
|
|
1452
|
+
} : mergedClaude;
|
|
1453
|
+
const applyResources = substituteResourcesForApply(
|
|
1454
|
+
resolution.resources,
|
|
1455
|
+
resolvedEnvironment.vars
|
|
1456
|
+
).resources;
|
|
1457
|
+
const applied = await applyToGlobal(applyResources, harnesses, homeRoot, {
|
|
1458
|
+
conflictPolicy: options.conflictPolicy,
|
|
1459
|
+
conflictResolver: options.conflictResolver,
|
|
1460
|
+
resolvedEnvironment,
|
|
1461
|
+
claudeConfig: resolvedClaude
|
|
1462
|
+
});
|
|
1463
|
+
if (applied.cancelled) {
|
|
1464
|
+
return { cancelled: true };
|
|
1465
|
+
}
|
|
1466
|
+
ui.success(
|
|
1467
|
+
`Applied ${selectors.join(" + ")} globally (${formatCount(applied.writtenFiles.length, "file")})`
|
|
1468
|
+
);
|
|
1469
|
+
return { cancelled: false };
|
|
1470
|
+
}
|
|
1471
|
+
function resolveCatalogSearchProjectRoot(cwd = process.cwd()) {
|
|
1472
|
+
return resolve(cwd);
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
// src/services/catalog-plugin-manage.ts
|
|
1476
|
+
function isCatalogPluginManageable(plugin) {
|
|
1477
|
+
return plugin.manageable === true && typeof plugin.pluginId === "string" && typeof plugin.orgId === "string";
|
|
1478
|
+
}
|
|
1479
|
+
function findLocalPluginForCatalogEntry(plugin) {
|
|
1480
|
+
const matches = listPlugins().filter(
|
|
1481
|
+
(local) => local.org_slug === plugin.orgSlug && local.catalog_slug === plugin.catalogSlug && (local.name === plugin.slug || local.name === plugin.name)
|
|
1482
|
+
);
|
|
1483
|
+
if (matches.length === 0) {
|
|
1484
|
+
return void 0;
|
|
1485
|
+
}
|
|
1486
|
+
return [...matches].sort(
|
|
1487
|
+
(left, right) => Date.parse(right.updated_at) - Date.parse(left.updated_at)
|
|
1488
|
+
)[0];
|
|
1489
|
+
}
|
|
1490
|
+
async function createAuthenticatedCloudClient(opts) {
|
|
1491
|
+
const created = await createPersistingCloudClient(opts?.account);
|
|
1492
|
+
if (!created) {
|
|
1493
|
+
throw new Error("Not authenticated. Run `ht auth login` first.");
|
|
1494
|
+
}
|
|
1495
|
+
return created.client;
|
|
1496
|
+
}
|
|
1497
|
+
function formatCatalogPluginManageLabel(plugin) {
|
|
1498
|
+
return formatCatalogSelectionLabel(plugin);
|
|
1499
|
+
}
|
|
1500
|
+
async function deleteCatalogPlugin(plugin, opts) {
|
|
1501
|
+
if (!isCatalogPluginManageable(plugin)) {
|
|
1502
|
+
throw new Error(
|
|
1503
|
+
`Catalog plugin is not manageable: ${formatCatalogPluginManageLabel(plugin)}`
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
const client = await createAuthenticatedCloudClient(opts);
|
|
1507
|
+
await client.deletePublishedPlugin({
|
|
1508
|
+
orgId: plugin.orgId,
|
|
1509
|
+
pluginId: plugin.pluginId
|
|
1510
|
+
});
|
|
1511
|
+
ui.success(
|
|
1512
|
+
`Deleted catalog plugin ${ui.theme.accent(formatCatalogPluginManageLabel(plugin))}`
|
|
1513
|
+
);
|
|
1514
|
+
ui.dim("Any local install of this plugin was not removed.");
|
|
1515
|
+
}
|
|
1516
|
+
async function editCatalogPluginComposition(plugin, selection, opts) {
|
|
1517
|
+
if (!isCatalogPluginManageable(plugin)) {
|
|
1518
|
+
throw new Error(
|
|
1519
|
+
`Catalog plugin is not manageable: ${formatCatalogPluginManageLabel(plugin)}`
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
let localPlugin = findLocalPluginForCatalogEntry(plugin);
|
|
1523
|
+
if (!localPlugin) {
|
|
1524
|
+
const parsed = resolvedRemotePluginFromCatalog({
|
|
1525
|
+
org: selection.orgSlug,
|
|
1526
|
+
catalog: selection.catalogSlug,
|
|
1527
|
+
name: selection.slug,
|
|
1528
|
+
version: selection.version
|
|
1529
|
+
});
|
|
1530
|
+
const installed = await installPluginFromCatalog(parsed, {
|
|
1531
|
+
account: opts.account,
|
|
1532
|
+
baseUrl: opts.baseUrl
|
|
1533
|
+
});
|
|
1534
|
+
localPlugin = getPlugin(installed.pluginName);
|
|
1535
|
+
if (!localPlugin) {
|
|
1536
|
+
throw new Error(`Failed to load installed plugin: ${installed.pluginName}`);
|
|
1537
|
+
}
|
|
1538
|
+
ui.info(`Installed ${ui.theme.accent(installed.sourceLabel)} for editing`);
|
|
1539
|
+
}
|
|
1540
|
+
await opts.onEditLocal(localPlugin.name);
|
|
1541
|
+
const catalogSelector = formatCanonicalPublishedSelector({
|
|
1542
|
+
org: selection.orgSlug,
|
|
1543
|
+
catalog: selection.catalogSlug,
|
|
1544
|
+
name: selection.slug
|
|
1545
|
+
});
|
|
1546
|
+
const shouldPublish = await promptForConfirmation({
|
|
1547
|
+
message: `Publish changes to ${catalogSelector}?`,
|
|
1548
|
+
default: false
|
|
1549
|
+
});
|
|
1550
|
+
if (!shouldPublish) {
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
await opts.onPublish(localPlugin.name, catalogSelector, {
|
|
1554
|
+
account: opts.account
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// src/services/catalog-list-stream.ts
|
|
1559
|
+
var visibilityRank = { organization: 3, shared: 2, public: 1 };
|
|
1560
|
+
function catalogPluginKey2(plugin) {
|
|
1561
|
+
return `${plugin.orgSlug}/${plugin.catalogSlug}/${plugin.slug}`;
|
|
1562
|
+
}
|
|
1563
|
+
function dedupePagePlugins(plugins, seen) {
|
|
1564
|
+
const result = [];
|
|
1565
|
+
for (const plugin of plugins) {
|
|
1566
|
+
const key = catalogPluginKey2(plugin);
|
|
1567
|
+
const existing = seen.get(key);
|
|
1568
|
+
if (!existing) {
|
|
1569
|
+
seen.set(key, plugin);
|
|
1570
|
+
result.push(plugin);
|
|
1571
|
+
continue;
|
|
1572
|
+
}
|
|
1573
|
+
if (visibilityRank[plugin.visibility] > visibilityRank[existing.visibility]) {
|
|
1574
|
+
seen.set(key, plugin);
|
|
1575
|
+
result.push(plugin);
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
return result;
|
|
1579
|
+
}
|
|
1580
|
+
async function* streamCatalogPlugins(sources, opts = {}) {
|
|
1581
|
+
const deadlineMs = opts.deadlineMs ?? 3e4;
|
|
1582
|
+
const deadline = Date.now() + deadlineMs;
|
|
1583
|
+
const pageSize = opts.q?.trim() ? 25 : 50;
|
|
1584
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1585
|
+
const queue = [];
|
|
1586
|
+
let pendingSources = sources.length;
|
|
1587
|
+
let timedOut = false;
|
|
1588
|
+
let notify = null;
|
|
1589
|
+
function enqueue(item) {
|
|
1590
|
+
queue.push(item);
|
|
1591
|
+
notify?.();
|
|
1592
|
+
notify = null;
|
|
1593
|
+
}
|
|
1594
|
+
function sourceFinished() {
|
|
1595
|
+
pendingSources -= 1;
|
|
1596
|
+
notify?.();
|
|
1597
|
+
notify = null;
|
|
1598
|
+
}
|
|
1599
|
+
function isPastDeadline() {
|
|
1600
|
+
if (Date.now() >= deadline) {
|
|
1601
|
+
timedOut = true;
|
|
1602
|
+
return true;
|
|
1603
|
+
}
|
|
1604
|
+
return false;
|
|
1605
|
+
}
|
|
1606
|
+
async function fetchSource(source) {
|
|
1607
|
+
let cursor = null;
|
|
1608
|
+
let pageIndex = 0;
|
|
1609
|
+
try {
|
|
1610
|
+
while (!isPastDeadline()) {
|
|
1611
|
+
const result = await listCatalogPluginsPage(
|
|
1612
|
+
{
|
|
1613
|
+
q: opts.q,
|
|
1614
|
+
tag: opts.tag,
|
|
1615
|
+
sort: opts.sort,
|
|
1616
|
+
orgs: source.orgs,
|
|
1617
|
+
selectors: source.selectors,
|
|
1618
|
+
catalog: source.catalog,
|
|
1619
|
+
limit: pageSize,
|
|
1620
|
+
cursor
|
|
1621
|
+
},
|
|
1622
|
+
{
|
|
1623
|
+
...source.account ? { account: source.account } : {},
|
|
1624
|
+
...opts.baseUrl ? { baseUrl: opts.baseUrl } : {}
|
|
1625
|
+
}
|
|
1626
|
+
);
|
|
1627
|
+
const plugins = dedupePagePlugins(result.plugins, seen);
|
|
1628
|
+
const exhausted = result.nextCursor === null;
|
|
1629
|
+
enqueue({
|
|
1630
|
+
type: "chunk",
|
|
1631
|
+
chunk: {
|
|
1632
|
+
sourceLabel: source.label,
|
|
1633
|
+
plugins,
|
|
1634
|
+
pageIndex,
|
|
1635
|
+
exhausted
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
if (exhausted) break;
|
|
1639
|
+
cursor = result.nextCursor;
|
|
1640
|
+
pageIndex += 1;
|
|
1641
|
+
}
|
|
1642
|
+
} catch (error) {
|
|
1643
|
+
const message = formatCatalogRequestError(error);
|
|
1644
|
+
enqueue({ type: "error", sourceLabel: source.label, message });
|
|
1645
|
+
} finally {
|
|
1646
|
+
sourceFinished();
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
for (const source of sources) {
|
|
1650
|
+
void fetchSource(source);
|
|
1651
|
+
}
|
|
1652
|
+
while (pendingSources > 0 || queue.length > 0) {
|
|
1653
|
+
if (queue.length > 0) {
|
|
1654
|
+
const item = queue.shift();
|
|
1655
|
+
if (item === void 0) {
|
|
1656
|
+
continue;
|
|
1657
|
+
}
|
|
1658
|
+
switch (item.type) {
|
|
1659
|
+
case "chunk":
|
|
1660
|
+
yield { type: "chunk", chunk: item.chunk };
|
|
1661
|
+
break;
|
|
1662
|
+
case "error":
|
|
1663
|
+
yield { type: "error", sourceLabel: item.sourceLabel, message: item.message };
|
|
1664
|
+
break;
|
|
1665
|
+
default: {
|
|
1666
|
+
const _exhaustive = item;
|
|
1667
|
+
throw new Error(`Unhandled queue item: ${String(_exhaustive)}`);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
continue;
|
|
1671
|
+
}
|
|
1672
|
+
if (pendingSources === 0) break;
|
|
1673
|
+
await new Promise((resolve3) => {
|
|
1674
|
+
notify = resolve3;
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
yield { type: "done", timedOut };
|
|
1678
|
+
}
|
|
1679
|
+
async function listCatalogPluginsFromSources(sources, opts) {
|
|
1680
|
+
const limit = opts.limit ?? (opts.q?.trim() ? 25 : 50);
|
|
1681
|
+
const collected = [];
|
|
1682
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1683
|
+
let timedOut = false;
|
|
1684
|
+
for await (const event of streamCatalogPlugins(sources, opts)) {
|
|
1685
|
+
switch (event.type) {
|
|
1686
|
+
case "chunk": {
|
|
1687
|
+
for (const plugin of event.chunk.plugins) {
|
|
1688
|
+
const key = catalogPluginKey2(plugin);
|
|
1689
|
+
if (seen.has(key)) {
|
|
1690
|
+
continue;
|
|
1691
|
+
}
|
|
1692
|
+
seen.add(key);
|
|
1693
|
+
collected.push(plugin);
|
|
1694
|
+
if (collected.length >= limit) {
|
|
1695
|
+
return { plugins: collected, timedOut };
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
break;
|
|
1699
|
+
}
|
|
1700
|
+
case "error":
|
|
1701
|
+
break;
|
|
1702
|
+
case "done":
|
|
1703
|
+
timedOut = event.timedOut;
|
|
1704
|
+
break;
|
|
1705
|
+
default: {
|
|
1706
|
+
const neverEvent = event;
|
|
1707
|
+
throw new Error(`Unhandled catalog stream event: ${String(neverEvent)}`);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
return { plugins: collected, timedOut };
|
|
1712
|
+
}
|
|
1713
|
+
function buildCatalogListSources(input) {
|
|
1714
|
+
const scopeOrgs = new Set(input.scope.orgs.map((o) => o.toLowerCase()));
|
|
1715
|
+
const sources = [
|
|
1716
|
+
{
|
|
1717
|
+
label: input.scope.defaultOrgSlug,
|
|
1718
|
+
kind: "scope",
|
|
1719
|
+
orgs: [...input.scope.orgs],
|
|
1720
|
+
selectors: [...input.scope.selectors]
|
|
1721
|
+
}
|
|
1722
|
+
];
|
|
1723
|
+
const seenRegistered = /* @__PURE__ */ new Set();
|
|
1724
|
+
for (const entry of input.registered) {
|
|
1725
|
+
const key = publishCatalogKey(entry);
|
|
1726
|
+
if (seenRegistered.has(key)) continue;
|
|
1727
|
+
seenRegistered.add(key);
|
|
1728
|
+
if (scopeOrgs.has(entry.org.toLowerCase())) continue;
|
|
1729
|
+
sources.push({
|
|
1730
|
+
label: `${entry.org}/${entry.catalog}`,
|
|
1731
|
+
kind: "registered",
|
|
1732
|
+
orgs: [entry.org],
|
|
1733
|
+
catalog: entry.catalog,
|
|
1734
|
+
...entry.account ? { account: entry.account } : {}
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
return sources;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// src/services/catalog-plugin-preview.ts
|
|
1741
|
+
import { ulid } from "ulid";
|
|
1742
|
+
async function renderCatalogPluginPreviewShow(catalogPlugin, opts = {}) {
|
|
1743
|
+
const downloaded = await downloadCatalogPackage({
|
|
1744
|
+
orgSlug: catalogPlugin.orgSlug,
|
|
1745
|
+
catalogSlug: catalogPlugin.catalogSlug,
|
|
1746
|
+
pluginSlug: catalogPlugin.slug,
|
|
1747
|
+
version: catalogPlugin.latestVersion ?? "latest",
|
|
1748
|
+
account: opts.account,
|
|
1749
|
+
baseUrl: opts.baseUrl
|
|
1750
|
+
});
|
|
1751
|
+
const previewPluginName = `__hd-preview-${ulid().toLowerCase()}__`;
|
|
1752
|
+
const imported = importApPackageFiles(downloaded.files, {
|
|
1753
|
+
as: previewPluginName,
|
|
1754
|
+
origin: "catalog"
|
|
1755
|
+
});
|
|
1756
|
+
try {
|
|
1757
|
+
const pluginLabel = formatCanonicalPublishedSelectorWithVersion({
|
|
1758
|
+
org: catalogPlugin.orgSlug,
|
|
1759
|
+
catalog: catalogPlugin.catalogSlug,
|
|
1760
|
+
name: catalogPlugin.slug,
|
|
1761
|
+
version: downloaded.version
|
|
1762
|
+
});
|
|
1763
|
+
return renderPluginShow(imported, pluginLabel, {
|
|
1764
|
+
showId: opts.showId,
|
|
1765
|
+
pluginLabel
|
|
1766
|
+
});
|
|
1767
|
+
} finally {
|
|
1768
|
+
deletePlugin(imported.id);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
// src/services/wizards/interactive-catalog-search.ts
|
|
1773
|
+
var promptForInteractiveCatalogSearch = (config, context) => createRemoteCatalogListPrompt(
|
|
1774
|
+
{ ...config, mode: { kind: "apply" } },
|
|
1775
|
+
context
|
|
1776
|
+
);
|
|
1777
|
+
async function runInteractiveCatalogSearch(input) {
|
|
1778
|
+
return promptForInteractiveCatalogSearch(input);
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
// src/services/wizards/interactive-plugin-list-browse.ts
|
|
1782
|
+
import {
|
|
1783
|
+
createPrompt,
|
|
1784
|
+
ExitPromptError,
|
|
1785
|
+
isBackspaceKey,
|
|
1786
|
+
isDownKey,
|
|
1787
|
+
isEnterKey,
|
|
1788
|
+
isUpKey,
|
|
1789
|
+
makeTheme,
|
|
1790
|
+
useEffect,
|
|
1791
|
+
useKeypress,
|
|
1792
|
+
usePrefix,
|
|
1793
|
+
useRef,
|
|
1794
|
+
useState
|
|
1795
|
+
} from "@inquirer/core";
|
|
1796
|
+
function toBrowseSelection(plugin) {
|
|
1797
|
+
return {
|
|
1798
|
+
orgSlug: plugin.orgSlug,
|
|
1799
|
+
catalogSlug: plugin.catalogSlug,
|
|
1800
|
+
slug: plugin.slug,
|
|
1801
|
+
version: plugin.latestVersion,
|
|
1802
|
+
selector: formatCanonicalPublishedSelectorWithVersion({
|
|
1803
|
+
org: plugin.orgSlug,
|
|
1804
|
+
catalog: plugin.catalogSlug,
|
|
1805
|
+
name: plugin.slug,
|
|
1806
|
+
version: plugin.latestVersion ?? void 0
|
|
1807
|
+
})
|
|
1808
|
+
};
|
|
1809
|
+
}
|
|
1810
|
+
function finishBrowseAction(done, action, plugin) {
|
|
1811
|
+
done({ action, selection: toBrowseSelection(plugin) });
|
|
1812
|
+
}
|
|
1813
|
+
function isManageableRemoteRow(row) {
|
|
1814
|
+
return row?.section === "remote" && isCatalogPluginManageable(row.catalogPlugin);
|
|
1815
|
+
}
|
|
1816
|
+
function finishRemoteManageAction(done, action, plugin) {
|
|
1817
|
+
done({
|
|
1818
|
+
action,
|
|
1819
|
+
selection: toBrowseSelection(plugin),
|
|
1820
|
+
catalogPlugin: plugin
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
function formatPendingDeletePrompt(row) {
|
|
1824
|
+
if (row.section === "local") {
|
|
1825
|
+
return `Delete plugin "${row.plugin.name}"? [y/N]`;
|
|
1826
|
+
}
|
|
1827
|
+
return `Delete catalog plugin "${formatCatalogPluginManageLabel(row.catalogPlugin)}"? [y/N] (local install is kept)`;
|
|
1828
|
+
}
|
|
1829
|
+
function buildBrowseHelpLine(activeRow) {
|
|
1830
|
+
if (activeRow?.section === "remote" && isCatalogPluginManageable(activeRow.catalogPlugin)) {
|
|
1831
|
+
return buildHelpLine([
|
|
1832
|
+
["\u2191\u2193", "select"],
|
|
1833
|
+
["type", "search"],
|
|
1834
|
+
["\u232B", "erase"],
|
|
1835
|
+
["\u23CE", "show"],
|
|
1836
|
+
["ctrl+e", "edit catalog"],
|
|
1837
|
+
["ctrl+x", "delete catalog"],
|
|
1838
|
+
["esc", "cancel"]
|
|
1839
|
+
]);
|
|
1840
|
+
}
|
|
1841
|
+
if (activeRow?.section === "local") {
|
|
1842
|
+
return buildHelpLine([
|
|
1843
|
+
["\u2191\u2193", "select"],
|
|
1844
|
+
["type", "search"],
|
|
1845
|
+
["\u232B", "erase"],
|
|
1846
|
+
["\u23CE", "show"],
|
|
1847
|
+
["ctrl+e", "edit local"],
|
|
1848
|
+
["ctrl+x", "delete local"],
|
|
1849
|
+
["esc", "cancel"]
|
|
1850
|
+
]);
|
|
1851
|
+
}
|
|
1852
|
+
return buildHelpLine([
|
|
1853
|
+
["\u2191\u2193", "select"],
|
|
1854
|
+
["type", "search"],
|
|
1855
|
+
["\u232B", "erase"],
|
|
1856
|
+
["\u23CE", "show"],
|
|
1857
|
+
["esc", "cancel"]
|
|
1858
|
+
]);
|
|
1859
|
+
}
|
|
1860
|
+
function isConfirmYes(key) {
|
|
1861
|
+
return isLetterKey(key, "y") || isLetterKey(key, "Y");
|
|
1862
|
+
}
|
|
1863
|
+
function isConfirmNo(key) {
|
|
1864
|
+
return isLetterKey(key, "n") || isLetterKey(key, "N") || isEscapeKey(key);
|
|
1865
|
+
}
|
|
1866
|
+
var promptForInteractivePluginListBrowse = createPrompt((config, done) => {
|
|
1867
|
+
const promptTheme = makeTheme(interactivePromptTheme, {});
|
|
1868
|
+
const prefix = usePrefix({ status: "idle", theme: promptTheme });
|
|
1869
|
+
const [query, setQuery] = useState("");
|
|
1870
|
+
const [active, setActive] = useState(0);
|
|
1871
|
+
const [view, setView] = useState("browse");
|
|
1872
|
+
const [showingRow, setShowingRow] = useState(null);
|
|
1873
|
+
const [showScrollOffset, setShowScrollOffset] = useState(0);
|
|
1874
|
+
const [remoteShowContent, setRemoteShowContent] = useState(null);
|
|
1875
|
+
const [remoteShowLoading, setRemoteShowLoading] = useState(false);
|
|
1876
|
+
const [remoteShowError, setRemoteShowError] = useState(null);
|
|
1877
|
+
const [pendingDeleteRow, setPendingDeleteRow] = useState(null);
|
|
1878
|
+
const [pendingExitMessage, setPendingExitMessage] = useState(null);
|
|
1879
|
+
const promptScreenRef = useRef(null);
|
|
1880
|
+
if (promptScreenRef.current === null) {
|
|
1881
|
+
promptScreenRef.current = createPromptScreen();
|
|
1882
|
+
promptScreenRef.current.enter();
|
|
1883
|
+
}
|
|
1884
|
+
const { width: terminalWidth, height: terminalRows } = useTerminalSize();
|
|
1885
|
+
useEffect(() => {
|
|
1886
|
+
return () => promptScreenRef.current?.exit();
|
|
1887
|
+
}, []);
|
|
1888
|
+
useEffect(() => {
|
|
1889
|
+
if (view !== "show" || showingRow?.section !== "remote") {
|
|
1890
|
+
setRemoteShowContent(null);
|
|
1891
|
+
setRemoteShowLoading(false);
|
|
1892
|
+
setRemoteShowError(null);
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
const plugin = showingRow.catalogPlugin;
|
|
1896
|
+
if (!config.fetchRemotePluginShow) {
|
|
1897
|
+
setRemoteShowContent(null);
|
|
1898
|
+
setRemoteShowLoading(false);
|
|
1899
|
+
setRemoteShowError(null);
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
let cancelled = false;
|
|
1903
|
+
setRemoteShowContent(null);
|
|
1904
|
+
setRemoteShowLoading(true);
|
|
1905
|
+
setRemoteShowError(null);
|
|
1906
|
+
void config.fetchRemotePluginShow(plugin).then(
|
|
1907
|
+
(content) => {
|
|
1908
|
+
if (cancelled) {
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
setRemoteShowContent(content);
|
|
1912
|
+
setRemoteShowLoading(false);
|
|
1913
|
+
},
|
|
1914
|
+
(error2) => {
|
|
1915
|
+
if (cancelled) {
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
setRemoteShowError(error2 instanceof Error ? error2.message : String(error2));
|
|
1919
|
+
setRemoteShowLoading(false);
|
|
1920
|
+
}
|
|
1921
|
+
);
|
|
1922
|
+
return () => {
|
|
1923
|
+
cancelled = true;
|
|
1924
|
+
};
|
|
1925
|
+
}, [view, showingRow]);
|
|
1926
|
+
const localRows = filterLocalBrowseRows(config.localPlugins, query);
|
|
1927
|
+
const { items: remotePlugins, loading, error, scheduleSearch } = useDebouncedRemoteSearch({
|
|
1928
|
+
limitFor: (nextQuery) => computeRemoteListFetchLimit(terminalRows, VIEWPORT_CHROME_LINES.pluginListBrowse, {
|
|
1929
|
+
search: Boolean(nextQuery.trim())
|
|
1930
|
+
}),
|
|
1931
|
+
searchFn: (nextQuery, limit) => config.listRemotePlugins({ q: nextQuery, limit })
|
|
1932
|
+
});
|
|
1933
|
+
const remoteRows = toRemoteBrowseRows(remotePlugins);
|
|
1934
|
+
const navigable = listNavigablePluginListBrowseRows(localRows, remoteRows);
|
|
1935
|
+
const clampedActive = clampActiveIndex(active, navigable.length);
|
|
1936
|
+
const activeRow = navigable[clampedActive];
|
|
1937
|
+
const activeProfileName = config.profileMode ? getActiveProfileName() : null;
|
|
1938
|
+
const styledMessage = promptTheme.style.message(config.message, "idle");
|
|
1939
|
+
function openShowView(row) {
|
|
1940
|
+
setShowScrollOffset(0);
|
|
1941
|
+
setShowingRow(row);
|
|
1942
|
+
setView("show");
|
|
1943
|
+
}
|
|
1944
|
+
function localPluginShowOptions() {
|
|
1945
|
+
return {
|
|
1946
|
+
showId: config.showId,
|
|
1947
|
+
profileExtras: config.profileMode && activeProfileName && showingRow?.section === "local" ? { active: activeProfileName === showingRow.plugin.name } : void 0
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
function renderRemoteShowContent() {
|
|
1951
|
+
const sections = [
|
|
1952
|
+
remoteShowLoading ? theme.muted("Loading plugin details...") : "",
|
|
1953
|
+
remoteShowError && !remoteShowContent ? theme.danger(remoteShowError) : "",
|
|
1954
|
+
remoteShowContent ?? ""
|
|
1955
|
+
].filter((section) => section.length > 0);
|
|
1956
|
+
return sections.join("\n");
|
|
1957
|
+
}
|
|
1958
|
+
useKeypress((key) => {
|
|
1959
|
+
if (view === "confirm-delete") {
|
|
1960
|
+
if (isConfirmYes(key) && pendingDeleteRow) {
|
|
1961
|
+
if (pendingDeleteRow.section === "local") {
|
|
1962
|
+
done({ action: "delete", name: pendingDeleteRow.plugin.name });
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
finishRemoteManageAction(done, "delete-remote", pendingDeleteRow.catalogPlugin);
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1968
|
+
if (isConfirmNo(key)) {
|
|
1969
|
+
setPendingDeleteRow(null);
|
|
1970
|
+
setView(showingRow ? "show" : "browse");
|
|
1971
|
+
}
|
|
1972
|
+
return;
|
|
1973
|
+
}
|
|
1974
|
+
if (view === "show" && showingRow) {
|
|
1975
|
+
if (isEscapeKey(key)) {
|
|
1976
|
+
setView("browse");
|
|
1977
|
+
setShowingRow(null);
|
|
1978
|
+
setShowScrollOffset(0);
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
if (showingRow.section === "remote") {
|
|
1982
|
+
const displayPlugin = showingRow.catalogPlugin;
|
|
1983
|
+
if (isLetterKey(key, "i")) {
|
|
1984
|
+
finishBrowseAction(done, "install", displayPlugin);
|
|
1985
|
+
return;
|
|
1986
|
+
}
|
|
1987
|
+
if (isLetterKey(key, "a")) {
|
|
1988
|
+
finishBrowseAction(done, "apply", displayPlugin);
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
if (isCatalogPluginManageable(displayPlugin) && isLetterKey(key, "e")) {
|
|
1992
|
+
finishRemoteManageAction(done, "edit-remote", displayPlugin);
|
|
1993
|
+
return;
|
|
1994
|
+
}
|
|
1995
|
+
if (isCatalogPluginManageable(displayPlugin) && isLetterKey(key, "d")) {
|
|
1996
|
+
setPendingDeleteRow(showingRow);
|
|
1997
|
+
setView("confirm-delete");
|
|
1998
|
+
return;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
if (showingRow.section === "local") {
|
|
2002
|
+
if (isLetterKey(key, "e")) {
|
|
2003
|
+
done({ action: "edit", name: showingRow.plugin.name });
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
2006
|
+
if (isLetterKey(key, "d")) {
|
|
2007
|
+
setPendingDeleteRow(showingRow);
|
|
2008
|
+
setView("confirm-delete");
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
const showContent = showingRow.section === "local" ? renderPluginShowForPlugin(showingRow.plugin, localPluginShowOptions()) : renderRemoteShowContent();
|
|
2013
|
+
const { maxScroll } = computeShowViewportBounds(
|
|
2014
|
+
showContent.split("\n").length,
|
|
2015
|
+
showScrollOffset,
|
|
2016
|
+
terminalRows
|
|
2017
|
+
);
|
|
2018
|
+
if (handleNavigationKeypress({
|
|
2019
|
+
clampedActive: showScrollOffset,
|
|
2020
|
+
length: maxScroll + 1,
|
|
2021
|
+
setActive: setShowScrollOffset,
|
|
2022
|
+
key
|
|
2023
|
+
})) {
|
|
2024
|
+
return;
|
|
2025
|
+
}
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
if (isEscapeKey(key)) {
|
|
2029
|
+
setPendingExitMessage("Plugin list cancelled.");
|
|
2030
|
+
return;
|
|
2031
|
+
}
|
|
2032
|
+
if (isEnterKey(key)) {
|
|
2033
|
+
if (!activeRow) {
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
openShowView(activeRow);
|
|
2037
|
+
return;
|
|
2038
|
+
}
|
|
2039
|
+
if (activeRow?.section === "local") {
|
|
2040
|
+
if (key.ctrl && key.name === "e") {
|
|
2041
|
+
done({ action: "edit", name: activeRow.plugin.name });
|
|
2042
|
+
return;
|
|
2043
|
+
}
|
|
2044
|
+
if (key.ctrl && key.name === "x") {
|
|
2045
|
+
setPendingDeleteRow(activeRow);
|
|
2046
|
+
setView("confirm-delete");
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
if (isManageableRemoteRow(activeRow)) {
|
|
2051
|
+
if (key.ctrl && key.name === "e") {
|
|
2052
|
+
finishRemoteManageAction(done, "edit-remote", activeRow.catalogPlugin);
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
if (key.ctrl && key.name === "x") {
|
|
2056
|
+
setPendingDeleteRow(activeRow);
|
|
2057
|
+
setView("confirm-delete");
|
|
2058
|
+
return;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
if (navigable.length > 0 && (isUpKey(key) || isDownKey(key))) {
|
|
2062
|
+
const direction = isUpKey(key) ? -1 : 1;
|
|
2063
|
+
setActive(clampActiveIndex(clampedActive + direction, navigable.length));
|
|
2064
|
+
return;
|
|
2065
|
+
}
|
|
2066
|
+
if (isBackspaceKey(key)) {
|
|
2067
|
+
const nextQuery = query.slice(0, -1);
|
|
2068
|
+
setQuery(nextQuery);
|
|
2069
|
+
setActive(0);
|
|
2070
|
+
scheduleSearch(nextQuery);
|
|
2071
|
+
return;
|
|
2072
|
+
}
|
|
2073
|
+
if (isSearchCharacter(key)) {
|
|
2074
|
+
const nextQuery = query + key.sequence;
|
|
2075
|
+
setQuery(nextQuery);
|
|
2076
|
+
setActive(0);
|
|
2077
|
+
scheduleSearch(nextQuery);
|
|
2078
|
+
}
|
|
2079
|
+
});
|
|
2080
|
+
if (pendingExitMessage) {
|
|
2081
|
+
throw new ExitPromptError(pendingExitMessage);
|
|
2082
|
+
}
|
|
2083
|
+
if (view === "show" && showingRow?.section === "local") {
|
|
2084
|
+
const showContent = renderPluginShowForPlugin(showingRow.plugin, localPluginShowOptions());
|
|
2085
|
+
const helpLine2 = buildHelpLine([
|
|
2086
|
+
["\u2191\u2193", "scroll"],
|
|
2087
|
+
["e", "edit"],
|
|
2088
|
+
["d", "delete"],
|
|
2089
|
+
["esc", "back"]
|
|
2090
|
+
]);
|
|
2091
|
+
return [
|
|
2092
|
+
renderScrollableShowContent(
|
|
2093
|
+
showContent,
|
|
2094
|
+
showScrollOffset,
|
|
2095
|
+
terminalRows,
|
|
2096
|
+
terminalWidth
|
|
2097
|
+
),
|
|
2098
|
+
"",
|
|
2099
|
+
helpLine2
|
|
2100
|
+
].join("\n");
|
|
2101
|
+
}
|
|
2102
|
+
if (view === "show" && showingRow?.section === "remote") {
|
|
2103
|
+
const displayPlugin = showingRow.catalogPlugin;
|
|
2104
|
+
const showContent = renderRemoteShowContent();
|
|
2105
|
+
const remoteHelp = [
|
|
2106
|
+
["\u2191\u2193", "scroll"],
|
|
2107
|
+
["i", "install"],
|
|
2108
|
+
["a", "apply"]
|
|
2109
|
+
];
|
|
2110
|
+
if (isCatalogPluginManageable(displayPlugin)) {
|
|
2111
|
+
remoteHelp.push(["e", "edit"], ["d", "delete"]);
|
|
2112
|
+
}
|
|
2113
|
+
remoteHelp.push(["esc", "back"]);
|
|
2114
|
+
const helpLine2 = buildHelpLine(remoteHelp);
|
|
2115
|
+
return [
|
|
2116
|
+
renderScrollableShowContent(
|
|
2117
|
+
showContent,
|
|
2118
|
+
showScrollOffset,
|
|
2119
|
+
terminalRows,
|
|
2120
|
+
terminalWidth
|
|
2121
|
+
),
|
|
2122
|
+
"",
|
|
2123
|
+
helpLine2
|
|
2124
|
+
].join("\n");
|
|
2125
|
+
}
|
|
2126
|
+
const helpLine = buildBrowseHelpLine(activeRow);
|
|
2127
|
+
const tableSection = error ? theme.danger(error) : loading && navigable.length === 0 ? theme.muted("Loading plugins...") : renderGroupedPluginListBrowseViewport({
|
|
2128
|
+
activeIndex: clampedActive,
|
|
2129
|
+
navigable,
|
|
2130
|
+
terminalRows,
|
|
2131
|
+
maxWidth: terminalWidth,
|
|
2132
|
+
showId: config.showId,
|
|
2133
|
+
profileMode: config.profileMode,
|
|
2134
|
+
activeProfileName,
|
|
2135
|
+
scopeLabel: config.scopeLabel,
|
|
2136
|
+
localPlugins: config.localPlugins
|
|
2137
|
+
});
|
|
2138
|
+
if (view === "confirm-delete" && pendingDeleteRow) {
|
|
2139
|
+
return [
|
|
2140
|
+
`${prefix} ${styledMessage}`,
|
|
2141
|
+
`${theme.label("Search:")} ${query ? theme.entity(query) : theme.muted("(type to filter)")}`,
|
|
2142
|
+
"",
|
|
2143
|
+
tableSection,
|
|
2144
|
+
"",
|
|
2145
|
+
helpLine,
|
|
2146
|
+
"",
|
|
2147
|
+
theme.danger(formatPendingDeletePrompt(pendingDeleteRow))
|
|
2148
|
+
].join("\n");
|
|
2149
|
+
}
|
|
2150
|
+
return [
|
|
2151
|
+
`${prefix} ${styledMessage}`,
|
|
2152
|
+
`${theme.label("Search:")} ${query ? theme.entity(query) : theme.muted("(type to filter)")}`,
|
|
2153
|
+
"",
|
|
2154
|
+
tableSection,
|
|
2155
|
+
"",
|
|
2156
|
+
helpLine
|
|
2157
|
+
].join("\n");
|
|
2158
|
+
});
|
|
2159
|
+
async function runInteractivePluginListBrowse(input) {
|
|
2160
|
+
return promptForInteractivePluginListBrowse(input);
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
// src/services/plugin-list.ts
|
|
2164
|
+
var interactiveDeps = null;
|
|
2165
|
+
function configurePluginListInteractiveDeps(deps) {
|
|
2166
|
+
interactiveDeps = deps;
|
|
2167
|
+
}
|
|
2168
|
+
function makeIdColumn2(showId, width = 12) {
|
|
2169
|
+
return showId ? [{
|
|
2170
|
+
key: "id",
|
|
2171
|
+
header: "ID",
|
|
2172
|
+
width,
|
|
2173
|
+
transform: (value) => ui.format.shortenId(String(value))
|
|
2174
|
+
}] : [];
|
|
2175
|
+
}
|
|
2176
|
+
function filterLocalPlugins(plugins, search) {
|
|
2177
|
+
const normalizedSearch = search?.trim().toLowerCase();
|
|
2178
|
+
if (!normalizedSearch) {
|
|
2179
|
+
return plugins;
|
|
2180
|
+
}
|
|
2181
|
+
return plugins.filter((plugin) => {
|
|
2182
|
+
const haystack = [
|
|
2183
|
+
plugin.name,
|
|
2184
|
+
plugin.description,
|
|
2185
|
+
...plugin.tags
|
|
2186
|
+
].join(" ").toLowerCase();
|
|
2187
|
+
return haystack.includes(normalizedSearch);
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
function formatOriginCell(origin) {
|
|
2191
|
+
if (origin === "upstream" || origin === "catalog") {
|
|
2192
|
+
return ui.theme.muted(origin);
|
|
2193
|
+
}
|
|
2194
|
+
return origin || "authored";
|
|
2195
|
+
}
|
|
2196
|
+
function renderLocalPluginListTable(plugins, opts) {
|
|
2197
|
+
return ui.table.render({
|
|
2198
|
+
columns: [
|
|
2199
|
+
...makeIdColumn2(opts.showId),
|
|
2200
|
+
{ key: "name", header: "NAME", width: 26 },
|
|
2201
|
+
{
|
|
2202
|
+
key: "origin",
|
|
2203
|
+
header: "ORIGIN",
|
|
2204
|
+
width: 12,
|
|
2205
|
+
style: (value) => formatOriginCell(String(value))
|
|
2206
|
+
},
|
|
2207
|
+
{ key: "version", header: "VERSION", width: 12 },
|
|
2208
|
+
{
|
|
2209
|
+
key: "description",
|
|
2210
|
+
header: "DESCRIPTION",
|
|
2211
|
+
width: 44,
|
|
2212
|
+
truncate: true,
|
|
2213
|
+
transform: (value) => value || ": "
|
|
2214
|
+
}
|
|
2215
|
+
],
|
|
2216
|
+
rows: plugins.map((plugin) => ({
|
|
2217
|
+
...opts.showId ? { id: plugin.id } : {},
|
|
2218
|
+
name: formatLocalPluginListName(plugin, { static: true }),
|
|
2219
|
+
origin: formatPluginOriginDisplay(plugin.origin || "authored", plugin.origin_locator),
|
|
2220
|
+
version: formatPluginVersionLabel(plugin.version, plugin.dirty),
|
|
2221
|
+
description: plugin.description ?? ""
|
|
2222
|
+
})),
|
|
2223
|
+
summary: `${formatCount(plugins.length, "plugin")} ${ui.icons.bullet} run \`${formatCommand("plugin show <name>")}\` for details`,
|
|
2224
|
+
empty: "No plugins found."
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
function resolveLocalPlugins(opts) {
|
|
2228
|
+
const plugins = opts.localPluginsProvider?.() ?? listPlugins();
|
|
2229
|
+
return filterLocalPlugins(plugins, opts.search);
|
|
2230
|
+
}
|
|
2231
|
+
function renderProfileLocalPluginListTable(plugins) {
|
|
2232
|
+
const activeProfile = getActiveProfileName();
|
|
2233
|
+
return ui.table.render({
|
|
2234
|
+
columns: [
|
|
2235
|
+
{ key: "name", header: "NAME", width: 24 },
|
|
2236
|
+
{ key: "version", header: "VERSION", width: 12 },
|
|
2237
|
+
{ key: "active", header: "ACTIVE", width: 8 },
|
|
2238
|
+
{
|
|
2239
|
+
key: "description",
|
|
2240
|
+
header: "DESCRIPTION",
|
|
2241
|
+
width: 50,
|
|
2242
|
+
truncate: true,
|
|
2243
|
+
transform: (value) => value || ": "
|
|
2244
|
+
}
|
|
2245
|
+
],
|
|
2246
|
+
rows: plugins.map((plugin) => ({
|
|
2247
|
+
name: formatLocalPluginListName(plugin, { static: true }),
|
|
2248
|
+
version: formatPluginVersionLabel(plugin.version, plugin.dirty),
|
|
2249
|
+
active: activeProfile === plugin.name ? "yes" : "",
|
|
2250
|
+
description: plugin.description ?? ""
|
|
2251
|
+
})),
|
|
2252
|
+
empty: "No profile plugins found."
|
|
2253
|
+
});
|
|
2254
|
+
}
|
|
2255
|
+
function renderLocalPluginListSection(plugins, opts) {
|
|
2256
|
+
if (opts.profileMode) {
|
|
2257
|
+
return renderProfileLocalPluginListTable(plugins);
|
|
2258
|
+
}
|
|
2259
|
+
return renderLocalPluginListTable(plugins, { showId: Boolean(opts.showId) });
|
|
2260
|
+
}
|
|
2261
|
+
function pluginListIncludesRemote(opts) {
|
|
2262
|
+
return Boolean(opts.remote || opts.remoteOnly);
|
|
2263
|
+
}
|
|
2264
|
+
function shouldUseInteractivePluginListBrowse(opts) {
|
|
2265
|
+
if (opts.remoteOnly) {
|
|
2266
|
+
return false;
|
|
2267
|
+
}
|
|
2268
|
+
if ((opts.format ?? "human") !== "human") {
|
|
2269
|
+
return false;
|
|
2270
|
+
}
|
|
2271
|
+
if (!shouldUseWizard({
|
|
2272
|
+
interactive: opts.interactive ?? true,
|
|
2273
|
+
noInteractive: opts.noInteractive,
|
|
2274
|
+
format: opts.format ?? "human",
|
|
2275
|
+
missingRequiredArgs: false
|
|
2276
|
+
})) {
|
|
2277
|
+
return false;
|
|
2278
|
+
}
|
|
2279
|
+
if (opts.installOnSelect) {
|
|
2280
|
+
return true;
|
|
2281
|
+
}
|
|
2282
|
+
return !opts.search?.trim();
|
|
2283
|
+
}
|
|
2284
|
+
async function listRemotePluginsForBrowse(opts, input) {
|
|
2285
|
+
const scope = resolveCatalogScope({ baseUrl: opts.baseUrl });
|
|
2286
|
+
const registered = loadRegisteredCatalogs();
|
|
2287
|
+
const sources = buildCatalogListSources({ scope, registered });
|
|
2288
|
+
const { plugins } = await listCatalogPluginsFromSources(sources, {
|
|
2289
|
+
q: input.q,
|
|
2290
|
+
tag: opts.tag,
|
|
2291
|
+
baseUrl: opts.baseUrl,
|
|
2292
|
+
limit: input.limit
|
|
2293
|
+
});
|
|
2294
|
+
return input.q.trim() ? rankCatalogSearchResults(plugins, input.q) : plugins;
|
|
2295
|
+
}
|
|
2296
|
+
async function runInteractivePluginListBrowse2(opts) {
|
|
2297
|
+
const localPlugins = resolveLocalPlugins(opts);
|
|
2298
|
+
const scope = resolveCatalogScope({ baseUrl: opts.baseUrl });
|
|
2299
|
+
if (!interactiveDeps) {
|
|
2300
|
+
throw new Error("Interactive plugin list is not configured");
|
|
2301
|
+
}
|
|
2302
|
+
try {
|
|
2303
|
+
while (true) {
|
|
2304
|
+
const result = await runInteractivePluginListBrowse({
|
|
2305
|
+
message: opts.profileMode ? "Select a profile plugin" : "Select a plugin",
|
|
2306
|
+
scopeLabel: formatCatalogScopeLabel(scope),
|
|
2307
|
+
localPlugins,
|
|
2308
|
+
profileMode: opts.profileMode,
|
|
2309
|
+
showId: Boolean(opts.showId),
|
|
2310
|
+
listRemotePlugins: pluginListIncludesRemote(opts) ? ({ q, limit }) => listRemotePluginsForBrowse(opts, { q, limit }) : async () => [],
|
|
2311
|
+
fetchRemotePluginShow: (plugin) => renderCatalogPluginPreviewShow(plugin, {
|
|
2312
|
+
account: opts.account,
|
|
2313
|
+
baseUrl: opts.baseUrl,
|
|
2314
|
+
showId: Boolean(opts.showId)
|
|
2315
|
+
})
|
|
2316
|
+
});
|
|
2317
|
+
switch (result.action) {
|
|
2318
|
+
case "install":
|
|
2319
|
+
await interactiveDeps.onInstall(result.selection.selector, {
|
|
2320
|
+
...opts.installContext,
|
|
2321
|
+
account: opts.account ?? opts.installContext?.account,
|
|
2322
|
+
baseUrl: opts.baseUrl ?? opts.installContext?.baseUrl,
|
|
2323
|
+
format: opts.format ?? opts.installContext?.format,
|
|
2324
|
+
noInteractive: opts.noInteractive ?? opts.installContext?.noInteractive,
|
|
2325
|
+
interactive: opts.interactive ?? opts.installContext?.interactive,
|
|
2326
|
+
version: opts.installContext?.version
|
|
2327
|
+
});
|
|
2328
|
+
return;
|
|
2329
|
+
case "apply": {
|
|
2330
|
+
const selectors = [result.selection.selector];
|
|
2331
|
+
const applyScope = await promptCatalogSearchApplyScope();
|
|
2332
|
+
const onFetched = (sourceLabel) => {
|
|
2333
|
+
ui.info(`Fetched ${sourceLabel} from catalog`);
|
|
2334
|
+
};
|
|
2335
|
+
if (applyScope === "project") {
|
|
2336
|
+
await interactiveDeps.applyToProject(selectors, {
|
|
2337
|
+
account: opts.account,
|
|
2338
|
+
baseUrl: opts.baseUrl,
|
|
2339
|
+
format: opts.format,
|
|
2340
|
+
noInteractive: opts.noInteractive
|
|
2341
|
+
});
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
const conflictPolicy = resolveApplyConflictPolicy({
|
|
2345
|
+
noInteractive: opts.noInteractive
|
|
2346
|
+
});
|
|
2347
|
+
const conflictResolver = conflictPolicy === "prompt" ? promptMaterializationConflict : void 0;
|
|
2348
|
+
const applied = await applyPluginsGlobally(selectors, {
|
|
2349
|
+
account: opts.account,
|
|
2350
|
+
baseUrl: opts.baseUrl,
|
|
2351
|
+
conflictPolicy,
|
|
2352
|
+
conflictResolver,
|
|
2353
|
+
onFetched
|
|
2354
|
+
});
|
|
2355
|
+
if (applied.cancelled) {
|
|
2356
|
+
process.exitCode = 1;
|
|
2357
|
+
ui.danger("Apply cancelled due to file conflicts");
|
|
2358
|
+
}
|
|
2359
|
+
return;
|
|
2360
|
+
}
|
|
2361
|
+
case "edit":
|
|
2362
|
+
await interactiveDeps.onEdit(result.name, { format: opts.format });
|
|
2363
|
+
localPlugins.splice(0, localPlugins.length, ...resolveLocalPlugins(opts));
|
|
2364
|
+
continue;
|
|
2365
|
+
case "delete":
|
|
2366
|
+
await interactiveDeps.onDelete(result.name, { format: opts.format });
|
|
2367
|
+
localPlugins.splice(0, localPlugins.length, ...resolveLocalPlugins(opts));
|
|
2368
|
+
continue;
|
|
2369
|
+
case "edit-remote":
|
|
2370
|
+
await interactiveDeps.onEditRemote(result.catalogPlugin, result.selection, {
|
|
2371
|
+
account: opts.account,
|
|
2372
|
+
baseUrl: opts.baseUrl,
|
|
2373
|
+
format: opts.format
|
|
2374
|
+
});
|
|
2375
|
+
localPlugins.splice(0, localPlugins.length, ...resolveLocalPlugins(opts));
|
|
2376
|
+
continue;
|
|
2377
|
+
case "delete-remote":
|
|
2378
|
+
await interactiveDeps.onDeleteRemote(result.catalogPlugin, {
|
|
2379
|
+
account: opts.account,
|
|
2380
|
+
baseUrl: opts.baseUrl,
|
|
2381
|
+
format: opts.format
|
|
2382
|
+
});
|
|
2383
|
+
continue;
|
|
2384
|
+
default: {
|
|
2385
|
+
const _exhaustive = result;
|
|
2386
|
+
throw _exhaustive;
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
} catch (error) {
|
|
2391
|
+
if (isPromptCancellationError(error)) {
|
|
2392
|
+
process.exitCode = 1;
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
2395
|
+
throw error;
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
function shouldUseInteractiveRemoteSearch(opts) {
|
|
2399
|
+
return shouldUseWizard({
|
|
2400
|
+
interactive: opts.interactive ?? true,
|
|
2401
|
+
noInteractive: opts.noInteractive,
|
|
2402
|
+
format: opts.format ?? "human",
|
|
2403
|
+
missingRequiredArgs: false
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2406
|
+
async function runInteractiveRemotePluginSearch(opts) {
|
|
2407
|
+
const query = opts.search?.trim();
|
|
2408
|
+
if (!query) {
|
|
2409
|
+
return;
|
|
2410
|
+
}
|
|
2411
|
+
const catalogOptions = { account: opts.account, baseUrl: opts.baseUrl };
|
|
2412
|
+
const scope = resolveCatalogScope({ baseUrl: opts.baseUrl });
|
|
2413
|
+
const result = await runInteractiveCatalogSearch({
|
|
2414
|
+
message: "Search catalog plugins to apply",
|
|
2415
|
+
scopeLabel: formatCatalogScopeLabel(scope),
|
|
2416
|
+
initialQuery: query,
|
|
2417
|
+
listPlugins: ({ q, limit }) => listPluginsInScope(
|
|
2418
|
+
{ q, tag: opts.tag, limit, sort: "updated" },
|
|
2419
|
+
catalogOptions
|
|
2420
|
+
)
|
|
2421
|
+
});
|
|
2422
|
+
if (result.selections.length === 0) {
|
|
2423
|
+
return;
|
|
2424
|
+
}
|
|
2425
|
+
const selectors = catalogSearchSelectors(result.selections);
|
|
2426
|
+
const applyScope = await promptCatalogSearchApplyScope();
|
|
2427
|
+
const onFetched = (sourceLabel) => {
|
|
2428
|
+
ui.info(`Fetched ${sourceLabel} from catalog`);
|
|
2429
|
+
};
|
|
2430
|
+
if (applyScope === "project") {
|
|
2431
|
+
if (!interactiveDeps) {
|
|
2432
|
+
throw new Error("Interactive project apply is not configured");
|
|
2433
|
+
}
|
|
2434
|
+
await interactiveDeps.applyToProject(selectors, {
|
|
2435
|
+
account: opts.account,
|
|
2436
|
+
baseUrl: opts.baseUrl,
|
|
2437
|
+
format: opts.format,
|
|
2438
|
+
noInteractive: opts.noInteractive
|
|
2439
|
+
});
|
|
2440
|
+
return;
|
|
2441
|
+
}
|
|
2442
|
+
const conflictPolicy = resolveApplyConflictPolicy({
|
|
2443
|
+
noInteractive: opts.noInteractive
|
|
2444
|
+
});
|
|
2445
|
+
const conflictResolver = conflictPolicy === "prompt" ? promptMaterializationConflict : void 0;
|
|
2446
|
+
const applied = await applyPluginsGlobally(selectors, {
|
|
2447
|
+
account: opts.account,
|
|
2448
|
+
baseUrl: opts.baseUrl,
|
|
2449
|
+
conflictPolicy,
|
|
2450
|
+
conflictResolver,
|
|
2451
|
+
onFetched
|
|
2452
|
+
});
|
|
2453
|
+
if (applied.cancelled) {
|
|
2454
|
+
process.exitCode = 1;
|
|
2455
|
+
ui.danger("Apply cancelled due to file conflicts");
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
async function collectRemotePlugins(opts) {
|
|
2459
|
+
const scope = resolveCatalogScope({ baseUrl: opts.baseUrl });
|
|
2460
|
+
const registered = loadRegisteredCatalogs();
|
|
2461
|
+
const sources = buildCatalogListSources({ scope, registered });
|
|
2462
|
+
const sourceStats = new Map(
|
|
2463
|
+
sources.map((source) => [source.label, { label: source.label, pluginCount: 0, error: null }])
|
|
2464
|
+
);
|
|
2465
|
+
const remote = [];
|
|
2466
|
+
let timedOut = false;
|
|
2467
|
+
for await (const event of streamCatalogPlugins(sources, {
|
|
2468
|
+
q: opts.search,
|
|
2469
|
+
tag: opts.tag,
|
|
2470
|
+
baseUrl: opts.baseUrl
|
|
2471
|
+
})) {
|
|
2472
|
+
switch (event.type) {
|
|
2473
|
+
case "chunk": {
|
|
2474
|
+
for (const plugin of event.chunk.plugins) {
|
|
2475
|
+
remote.push(plugin);
|
|
2476
|
+
}
|
|
2477
|
+
const stat = sourceStats.get(event.chunk.sourceLabel);
|
|
2478
|
+
if (stat) {
|
|
2479
|
+
stat.pluginCount += event.chunk.plugins.length;
|
|
2480
|
+
}
|
|
2481
|
+
break;
|
|
2482
|
+
}
|
|
2483
|
+
case "error": {
|
|
2484
|
+
const stat = sourceStats.get(event.sourceLabel);
|
|
2485
|
+
if (stat) {
|
|
2486
|
+
stat.error = event.message;
|
|
2487
|
+
} else {
|
|
2488
|
+
sourceStats.set(event.sourceLabel, {
|
|
2489
|
+
label: event.sourceLabel,
|
|
2490
|
+
pluginCount: 0,
|
|
2491
|
+
error: event.message
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
break;
|
|
2495
|
+
}
|
|
2496
|
+
case "done":
|
|
2497
|
+
timedOut = event.timedOut;
|
|
2498
|
+
break;
|
|
2499
|
+
default: {
|
|
2500
|
+
const neverEvent = event;
|
|
2501
|
+
throw new Error(`Unhandled catalog stream event: ${String(neverEvent)}`);
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
const orderedRemote = opts.search?.trim() ? rankCatalogSearchResults(remote, opts.search) : remote;
|
|
2506
|
+
return {
|
|
2507
|
+
remote: orderedRemote,
|
|
2508
|
+
sourceStats: [...sourceStats.values()],
|
|
2509
|
+
timedOut
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
function printListSummaryFooter(localCount, remoteCount, sourceCount, includeLocal, includeRemote) {
|
|
2513
|
+
if (!includeRemote) {
|
|
2514
|
+
return;
|
|
2515
|
+
}
|
|
2516
|
+
const parts = [];
|
|
2517
|
+
if (includeLocal) {
|
|
2518
|
+
parts.push(`${localCount} local`);
|
|
2519
|
+
}
|
|
2520
|
+
parts.push(
|
|
2521
|
+
`${formatCount(remoteCount, "remote plugin")} across ${formatCount(sourceCount, "source")}`
|
|
2522
|
+
);
|
|
2523
|
+
console.log("");
|
|
2524
|
+
ui.dim(parts.join(" \xB7 "));
|
|
2525
|
+
}
|
|
2526
|
+
async function handlePluginListCommand(opts) {
|
|
2527
|
+
const format = opts.format ?? parseOutputFormat(void 0);
|
|
2528
|
+
const includeLocal = !opts.remoteOnly;
|
|
2529
|
+
const includeRemote = pluginListIncludesRemote(opts);
|
|
2530
|
+
if (shouldUseInteractivePluginListBrowse({ ...opts, format })) {
|
|
2531
|
+
await runInteractivePluginListBrowse2({ ...opts, format });
|
|
2532
|
+
return;
|
|
2533
|
+
}
|
|
2534
|
+
if (includeRemote && !includeLocal && opts.search?.trim() && shouldUseInteractiveRemoteSearch(opts)) {
|
|
2535
|
+
await runInteractiveRemotePluginSearch(opts);
|
|
2536
|
+
return;
|
|
2537
|
+
}
|
|
2538
|
+
const localPlugins = includeLocal ? resolveLocalPlugins(opts) : [];
|
|
2539
|
+
const activeProfile = opts.profileMode ? getActiveProfileName() : null;
|
|
2540
|
+
if (format === "json") {
|
|
2541
|
+
if (opts.profileMode && includeLocal && !includeRemote) {
|
|
2542
|
+
printJson({
|
|
2543
|
+
profiles: localPlugins.map((profile) => ({
|
|
2544
|
+
...profile,
|
|
2545
|
+
active: activeProfile === profile.name
|
|
2546
|
+
}))
|
|
2547
|
+
});
|
|
2548
|
+
return;
|
|
2549
|
+
}
|
|
2550
|
+
if (includeLocal && !includeRemote) {
|
|
2551
|
+
printJson(localPlugins);
|
|
2552
|
+
return;
|
|
2553
|
+
}
|
|
2554
|
+
if (opts.remoteOnly) {
|
|
2555
|
+
const { remote: remote2 } = await collectRemotePlugins(opts);
|
|
2556
|
+
printJson(remote2);
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
if (!includeRemote) {
|
|
2560
|
+
printJson(localPlugins);
|
|
2561
|
+
return;
|
|
2562
|
+
}
|
|
2563
|
+
const { remote, sourceStats, timedOut } = await collectRemotePlugins(opts);
|
|
2564
|
+
if (opts.profileMode) {
|
|
2565
|
+
printJson({
|
|
2566
|
+
profiles: localPlugins.map((profile) => ({
|
|
2567
|
+
...profile,
|
|
2568
|
+
active: activeProfile === profile.name
|
|
2569
|
+
})),
|
|
2570
|
+
remote,
|
|
2571
|
+
sources: sourceStats.map((source) => ({
|
|
2572
|
+
label: source.label,
|
|
2573
|
+
pluginCount: source.pluginCount,
|
|
2574
|
+
error: source.error
|
|
2575
|
+
})),
|
|
2576
|
+
timedOut
|
|
2577
|
+
});
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2580
|
+
printJson({
|
|
2581
|
+
local: localPlugins,
|
|
2582
|
+
remote,
|
|
2583
|
+
sources: sourceStats.map((source) => ({
|
|
2584
|
+
label: source.label,
|
|
2585
|
+
pluginCount: source.pluginCount,
|
|
2586
|
+
error: source.error
|
|
2587
|
+
})),
|
|
2588
|
+
timedOut
|
|
2589
|
+
});
|
|
2590
|
+
return;
|
|
2591
|
+
}
|
|
2592
|
+
let remoteCount = 0;
|
|
2593
|
+
let sourceCount = 0;
|
|
2594
|
+
if (includeLocal) {
|
|
2595
|
+
ui.header(
|
|
2596
|
+
opts.profileMode ? `Local profiles (${localPlugins.length})` : `Local plugins (${localPlugins.length})`
|
|
2597
|
+
);
|
|
2598
|
+
console.log(renderLocalPluginListSection(localPlugins, opts));
|
|
2599
|
+
if (includeRemote) {
|
|
2600
|
+
console.log("");
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
if (includeRemote) {
|
|
2604
|
+
const scope = resolveCatalogScope({ baseUrl: opts.baseUrl });
|
|
2605
|
+
const registered = loadRegisteredCatalogs();
|
|
2606
|
+
const sources = buildCatalogListSources({ scope, registered });
|
|
2607
|
+
sourceCount = sources.length;
|
|
2608
|
+
let timedOut = false;
|
|
2609
|
+
for await (const event of streamCatalogPlugins(sources, {
|
|
2610
|
+
q: opts.search,
|
|
2611
|
+
tag: opts.tag,
|
|
2612
|
+
baseUrl: opts.baseUrl
|
|
2613
|
+
})) {
|
|
2614
|
+
switch (event.type) {
|
|
2615
|
+
case "chunk": {
|
|
2616
|
+
const rendered = renderCatalogListChunk(event.chunk);
|
|
2617
|
+
if (rendered) {
|
|
2618
|
+
console.log(rendered);
|
|
2619
|
+
console.log("");
|
|
2620
|
+
}
|
|
2621
|
+
remoteCount += event.chunk.plugins.length;
|
|
2622
|
+
break;
|
|
2623
|
+
}
|
|
2624
|
+
case "error":
|
|
2625
|
+
ui.warn(`${event.sourceLabel}: ${event.message}`);
|
|
2626
|
+
break;
|
|
2627
|
+
case "done":
|
|
2628
|
+
timedOut = event.timedOut;
|
|
2629
|
+
break;
|
|
2630
|
+
default: {
|
|
2631
|
+
const neverEvent = event;
|
|
2632
|
+
throw new Error(`Unhandled catalog stream event: ${String(neverEvent)}`);
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
if (timedOut) {
|
|
2637
|
+
ui.warn("Remote listing stopped after 30s (partial results shown)");
|
|
2638
|
+
}
|
|
2639
|
+
if (opts.remoteOnly && opts.search?.trim() && remoteCount === 0) {
|
|
2640
|
+
ui.dim("No remote results.");
|
|
2641
|
+
}
|
|
2642
|
+
printListSummaryFooter(localPlugins.length, remoteCount, sourceCount, includeLocal, includeRemote);
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
// src/services/plugin-from-source.ts
|
|
2647
|
+
import { resolve as resolve2 } from "path";
|
|
2648
|
+
function skillAttachmentKey(name, namespace) {
|
|
2649
|
+
return `skill:${name}@${namespace}`;
|
|
2650
|
+
}
|
|
2651
|
+
function pluginHasSkillAttachment(pluginId, name, namespace) {
|
|
2652
|
+
const resources = getPluginResources(pluginId);
|
|
2653
|
+
return resources.some(
|
|
2654
|
+
(resource) => resource.type === "skill" && resource.name === name && resource.namespace === namespace
|
|
2655
|
+
);
|
|
2656
|
+
}
|
|
2657
|
+
function updateSnapshotInstalledSkillNames(snapshotId, installedSkillNames) {
|
|
2658
|
+
const snapshot = getImportedSnapshot(snapshotId);
|
|
2659
|
+
if (!snapshot) return;
|
|
2660
|
+
const db = getDb();
|
|
2661
|
+
const metadata = {
|
|
2662
|
+
...snapshot.metadata,
|
|
2663
|
+
installed_skill_names: installedSkillNames
|
|
2664
|
+
};
|
|
2665
|
+
db.prepare("UPDATE imported_snapshots SET metadata = ? WHERE id = ?").run(
|
|
2666
|
+
JSON.stringify(metadata),
|
|
2667
|
+
snapshotId
|
|
2668
|
+
);
|
|
2669
|
+
}
|
|
2670
|
+
function resolveHarnessTargets(harnesses, homeRoot) {
|
|
2671
|
+
if (harnesses && harnesses.length > 0) {
|
|
2672
|
+
return harnesses;
|
|
2673
|
+
}
|
|
2674
|
+
return resolveScanGlobalHarnessTargets(void 0, homeRoot);
|
|
2675
|
+
}
|
|
2676
|
+
async function attachSkillsToPlugin(plugin, namespace, skillNames) {
|
|
2677
|
+
const attached = [];
|
|
2678
|
+
for (const skillName of skillNames) {
|
|
2679
|
+
if (pluginHasSkillAttachment(plugin.id, skillName, namespace)) {
|
|
2680
|
+
continue;
|
|
2681
|
+
}
|
|
2682
|
+
await addPluginAttachment({
|
|
2683
|
+
plugin,
|
|
2684
|
+
selector: skillAttachmentKey(skillName, namespace),
|
|
2685
|
+
type: "skill"
|
|
2686
|
+
});
|
|
2687
|
+
attached.push(skillName);
|
|
2688
|
+
}
|
|
2689
|
+
return attached;
|
|
2690
|
+
}
|
|
2691
|
+
function resolvePluginForConflict(input) {
|
|
2692
|
+
const existing = getPluginByName(input.name, input.version);
|
|
2693
|
+
if (!existing) {
|
|
2694
|
+
const plugin = createPlugin({
|
|
2695
|
+
name: input.name,
|
|
2696
|
+
version: input.version,
|
|
2697
|
+
description: input.description,
|
|
2698
|
+
tags: input.tags
|
|
2699
|
+
});
|
|
2700
|
+
return { plugin, conflictPolicy: "create" };
|
|
2701
|
+
}
|
|
2702
|
+
switch (input.onConflict) {
|
|
2703
|
+
case "merge":
|
|
2704
|
+
return { plugin: existing, conflictPolicy: "merge" };
|
|
2705
|
+
case "overwrite": {
|
|
2706
|
+
const preservedDescription = input.description !== void 0 && input.description !== "" ? input.description : existing.description;
|
|
2707
|
+
deletePlugin(existing.id);
|
|
2708
|
+
const plugin = createPlugin({
|
|
2709
|
+
name: input.name,
|
|
2710
|
+
version: input.version,
|
|
2711
|
+
description: preservedDescription,
|
|
2712
|
+
tags: input.tags ?? existing.tags
|
|
2713
|
+
});
|
|
2714
|
+
return { plugin, conflictPolicy: "overwrite" };
|
|
2715
|
+
}
|
|
2716
|
+
default:
|
|
2717
|
+
throw new Error(
|
|
2718
|
+
`A plugin named "${input.name}" already exists. Use --on-conflict replace to replace it.`
|
|
2719
|
+
);
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
async function createPluginFromSource(options) {
|
|
2723
|
+
const version = options.version ?? "1.0.0";
|
|
2724
|
+
const onConflict = options.onConflict ?? "cancel";
|
|
2725
|
+
const method = options.method ?? "symlink";
|
|
2726
|
+
const resolved = resolveSkillPackageCheckout(
|
|
2727
|
+
options.source,
|
|
2728
|
+
options.harnesstapDir
|
|
2729
|
+
);
|
|
2730
|
+
const skillsToAttach = resolveSelectedSkills(resolved.discovered, {
|
|
2731
|
+
skillNames: options.skillNames,
|
|
2732
|
+
all: options.all,
|
|
2733
|
+
excludeCategories: options.excludeCategories
|
|
2734
|
+
});
|
|
2735
|
+
const attachedSkillNames = skillsToAttach.map((skill) => skill.name);
|
|
2736
|
+
const importedSkills = resolved.discovered.map((skill) => skill.name);
|
|
2737
|
+
if (options.dryRun) {
|
|
2738
|
+
const existing = getPluginByName(options.name, version);
|
|
2739
|
+
const conflictPolicy2 = existing ? onConflict === "cancel" ? "cancel" : onConflict : "create";
|
|
2740
|
+
if (existing && onConflict === "cancel") {
|
|
2741
|
+
throw new Error(
|
|
2742
|
+
`A plugin named "${options.name}" already exists. Use --on-conflict replace to replace it.`
|
|
2743
|
+
);
|
|
2744
|
+
}
|
|
2745
|
+
return {
|
|
2746
|
+
plugin: existing ?? {
|
|
2747
|
+
id: "dry-run",
|
|
2748
|
+
name: options.name,
|
|
2749
|
+
version,
|
|
2750
|
+
org_slug: "",
|
|
2751
|
+
catalog_slug: "",
|
|
2752
|
+
origin: "authored",
|
|
2753
|
+
description: options.description ?? "",
|
|
2754
|
+
tags: options.tags ?? [],
|
|
2755
|
+
dirty: false,
|
|
2756
|
+
created_at: "",
|
|
2757
|
+
updated_at: ""
|
|
2758
|
+
},
|
|
2759
|
+
namespace: resolved.namespace,
|
|
2760
|
+
importedSkills,
|
|
2761
|
+
attachedSkills: attachedSkillNames,
|
|
2762
|
+
installedSkills: options.install ? attachedSkillNames : [],
|
|
2763
|
+
conflictPolicy: conflictPolicy2,
|
|
2764
|
+
snapshotId: ""
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
const { plugin, conflictPolicy } = resolvePluginForConflict({
|
|
2768
|
+
name: options.name,
|
|
2769
|
+
version,
|
|
2770
|
+
description: options.description,
|
|
2771
|
+
tags: options.tags,
|
|
2772
|
+
onConflict
|
|
2773
|
+
});
|
|
2774
|
+
const importResult = await importSkillPackage({
|
|
2775
|
+
rootPath: resolved.checkoutRoot,
|
|
2776
|
+
sourceLabel: resolved.namespace,
|
|
2777
|
+
gitUrl: resolved.gitUrl,
|
|
2778
|
+
gitSha: resolved.gitSha
|
|
2779
|
+
});
|
|
2780
|
+
const attachedSkills = await attachSkillsToPlugin(
|
|
2781
|
+
plugin,
|
|
2782
|
+
resolved.namespace,
|
|
2783
|
+
attachedSkillNames
|
|
2784
|
+
);
|
|
2785
|
+
let installedSkills = [];
|
|
2786
|
+
if (options.install) {
|
|
2787
|
+
if (!options.scope) {
|
|
2788
|
+
throw new Error("Scope required when --install is set. Pass --global or --project.");
|
|
2789
|
+
}
|
|
2790
|
+
const harnesses = resolveHarnessTargets(options.harnesses, options.homeRoot);
|
|
2791
|
+
if (options.scope === "global") {
|
|
2792
|
+
const installResult = await installSkillsToGlobal({
|
|
2793
|
+
checkoutRoot: resolved.checkoutRoot,
|
|
2794
|
+
skills: skillsToAttach,
|
|
2795
|
+
harnesses,
|
|
2796
|
+
homeRoot: options.homeRoot,
|
|
2797
|
+
method
|
|
2798
|
+
});
|
|
2799
|
+
installedSkills = installResult.installed;
|
|
2800
|
+
recordImportedSnapshotInstall({
|
|
2801
|
+
snapshot_id: importResult.snapshot.id,
|
|
2802
|
+
platform_id: "hub",
|
|
2803
|
+
files: installResult.files
|
|
2804
|
+
});
|
|
2805
|
+
} else {
|
|
2806
|
+
const projectRoot = resolve2(options.projectRoot ?? ".");
|
|
2807
|
+
const installResult = await installSkillsToProject({
|
|
2808
|
+
checkoutRoot: resolved.checkoutRoot,
|
|
2809
|
+
skills: skillsToAttach,
|
|
2810
|
+
harnesses,
|
|
2811
|
+
projectRoot,
|
|
2812
|
+
method
|
|
2813
|
+
});
|
|
2814
|
+
installedSkills = installResult.installed;
|
|
2815
|
+
recordImportedSnapshotInstall({
|
|
2816
|
+
snapshot_id: importResult.snapshot.id,
|
|
2817
|
+
platform_id: "project",
|
|
2818
|
+
files: installResult.files
|
|
2819
|
+
});
|
|
2820
|
+
}
|
|
2821
|
+
updateSnapshotInstalledSkillNames(importResult.snapshot.id, installedSkills);
|
|
2822
|
+
}
|
|
2823
|
+
const finalized = getPlugin(plugin.name);
|
|
2824
|
+
if (!finalized) {
|
|
2825
|
+
throw new Error(`Failed to resolve plugin after create: ${options.name}`);
|
|
2826
|
+
}
|
|
2827
|
+
return {
|
|
2828
|
+
plugin: finalized,
|
|
2829
|
+
namespace: resolved.namespace,
|
|
2830
|
+
importedSkills,
|
|
2831
|
+
attachedSkills,
|
|
2832
|
+
installedSkills,
|
|
2833
|
+
conflictPolicy,
|
|
2834
|
+
snapshotId: importResult.snapshot.id
|
|
2835
|
+
};
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
// src/services/wizards/plugin-create-from-source.ts
|
|
2839
|
+
function buildSkillChoices(discovered) {
|
|
2840
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
2841
|
+
for (const skill of discovered) {
|
|
2842
|
+
const category = skill.category || "general";
|
|
2843
|
+
const group = byCategory.get(category) ?? [];
|
|
2844
|
+
group.push(skill);
|
|
2845
|
+
byCategory.set(category, group);
|
|
2846
|
+
}
|
|
2847
|
+
const categories = [...byCategory.keys()].sort((a, b) => a.localeCompare(b));
|
|
2848
|
+
const choices = [];
|
|
2849
|
+
for (const category of categories) {
|
|
2850
|
+
const skills = byCategory.get(category) ?? [];
|
|
2851
|
+
for (const skill of skills.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2852
|
+
const description = skill.description.trim() || void 0;
|
|
2853
|
+
choices.push({
|
|
2854
|
+
name: `[${category}] ${skill.name}`,
|
|
2855
|
+
value: skill.name,
|
|
2856
|
+
description
|
|
2857
|
+
});
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
return choices;
|
|
2861
|
+
}
|
|
2862
|
+
async function runPluginCreateFromSourceWizard(input) {
|
|
2863
|
+
const excludeCategories = input.excludeCategories ?? [...DEFAULT_EXCLUDED_SKILL_CATEGORIES];
|
|
2864
|
+
let skillNames = input.skillNames;
|
|
2865
|
+
let all = input.all;
|
|
2866
|
+
if (!all && (!skillNames || skillNames.length === 0)) {
|
|
2867
|
+
if (!input.shouldPrompt) {
|
|
2868
|
+
throw new Error("No skills selected. Pass --skill <names>, --all, or use the wizard.");
|
|
2869
|
+
}
|
|
2870
|
+
const selected = await promptForSearchableMultiSelect({
|
|
2871
|
+
message: "Which skills should this plugin include?",
|
|
2872
|
+
choices: buildSkillChoices(input.discovered),
|
|
2873
|
+
default: defaultInteractiveSkillNames(input.discovered, excludeCategories),
|
|
2874
|
+
pageSize: 12,
|
|
2875
|
+
loop: false
|
|
2876
|
+
});
|
|
2877
|
+
if (selected.length === 0) {
|
|
2878
|
+
throw new Error("No skills selected.");
|
|
2879
|
+
}
|
|
2880
|
+
if (selected.length === input.discovered.length) {
|
|
2881
|
+
all = true;
|
|
2882
|
+
skillNames = void 0;
|
|
2883
|
+
} else {
|
|
2884
|
+
skillNames = selected;
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
const existing = getPluginByName(input.pluginName, input.pluginVersion);
|
|
2888
|
+
if (!existing) {
|
|
2889
|
+
return {
|
|
2890
|
+
skillNames,
|
|
2891
|
+
all,
|
|
2892
|
+
onConflict: "cancel",
|
|
2893
|
+
cancelled: false
|
|
2894
|
+
};
|
|
2895
|
+
}
|
|
2896
|
+
if (input.onConflict && input.onConflict !== "cancel") {
|
|
2897
|
+
return {
|
|
2898
|
+
skillNames,
|
|
2899
|
+
all,
|
|
2900
|
+
onConflict: input.onConflict,
|
|
2901
|
+
cancelled: false
|
|
2902
|
+
};
|
|
2903
|
+
}
|
|
2904
|
+
if (!input.shouldPrompt) {
|
|
2905
|
+
return {
|
|
2906
|
+
skillNames,
|
|
2907
|
+
all,
|
|
2908
|
+
onConflict: "cancel",
|
|
2909
|
+
cancelled: false
|
|
2910
|
+
};
|
|
2911
|
+
}
|
|
2912
|
+
const action = await promptForChoice({
|
|
2913
|
+
message: `Plugin "${input.pluginName}@${input.pluginVersion}" already exists. How do you want to proceed?`,
|
|
2914
|
+
choices: [
|
|
2915
|
+
{ name: "Merge new skills into existing plugin", value: "merge" },
|
|
2916
|
+
{ name: "Replace plugin (replace attachments from this import)", value: "overwrite" },
|
|
2917
|
+
{ name: "Cancel", value: "cancel" }
|
|
2918
|
+
],
|
|
2919
|
+
default: "merge"
|
|
2920
|
+
});
|
|
2921
|
+
if (action === "cancel") {
|
|
2922
|
+
return {
|
|
2923
|
+
skillNames,
|
|
2924
|
+
all,
|
|
2925
|
+
onConflict: "cancel",
|
|
2926
|
+
cancelled: true
|
|
2927
|
+
};
|
|
2928
|
+
}
|
|
2929
|
+
return {
|
|
2930
|
+
skillNames,
|
|
2931
|
+
all,
|
|
2932
|
+
onConflict: action,
|
|
2933
|
+
cancelled: false
|
|
2934
|
+
};
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
export {
|
|
2938
|
+
isPluginUrl,
|
|
2939
|
+
PluginResolveError,
|
|
2940
|
+
PluginAmbiguityError,
|
|
2941
|
+
handlePluginInstallCommand,
|
|
2942
|
+
handlePluginCatalogRegisterCommand,
|
|
2943
|
+
handlePluginCatalogUnregisterCommand,
|
|
2944
|
+
handlePluginCatalogRegisteredCommand,
|
|
2945
|
+
handlePluginCatalogBindingsCommand,
|
|
2946
|
+
handlePluginPublishCommand,
|
|
2947
|
+
handlePluginPublishPlanCommand,
|
|
2948
|
+
countMaterialPluginResources,
|
|
2949
|
+
handlePluginShowCommand,
|
|
2950
|
+
resolveApplyPluginSource,
|
|
2951
|
+
resolveCatalogSearchProjectRoot,
|
|
2952
|
+
deleteCatalogPlugin,
|
|
2953
|
+
editCatalogPluginComposition,
|
|
2954
|
+
configurePluginListInteractiveDeps,
|
|
2955
|
+
handlePluginListCommand,
|
|
2956
|
+
createPluginFromSource,
|
|
2957
|
+
runPluginCreateFromSourceWizard
|
|
2958
|
+
};
|
|
2959
|
+
//# sourceMappingURL=chunk-EMTBGOR3.js.map
|