harnesstap 1.1.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 +33 -16
- 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 -54362
- 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 +25 -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,1886 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerProfileParityCommands
|
|
3
|
+
} from "./chunk-YTC2EG64.js";
|
|
4
|
+
import "./chunk-WMSQAFK5.js";
|
|
5
|
+
import {
|
|
6
|
+
mapProfileUseDelegationOptions,
|
|
7
|
+
renderProjectUseHuman
|
|
8
|
+
} from "./chunk-IHWAOIAU.js";
|
|
9
|
+
import "./chunk-SN4BXX3B.js";
|
|
10
|
+
import {
|
|
11
|
+
countMaterialPluginResources,
|
|
12
|
+
createPluginFromSource,
|
|
13
|
+
handlePluginInstallCommand,
|
|
14
|
+
handlePluginListCommand,
|
|
15
|
+
handlePluginPublishCommand,
|
|
16
|
+
handlePluginShowCommand,
|
|
17
|
+
runPluginCreateFromSourceWizard
|
|
18
|
+
} from "./chunk-EMTBGOR3.js";
|
|
19
|
+
import {
|
|
20
|
+
resolvePluginMutationTarget
|
|
21
|
+
} from "./chunk-QIVE2YFJ.js";
|
|
22
|
+
import "./chunk-MK3Q37ZN.js";
|
|
23
|
+
import "./chunk-PMQ55GDB.js";
|
|
24
|
+
import "./chunk-QKXD3EUF.js";
|
|
25
|
+
import {
|
|
26
|
+
applyProfileStashCommand,
|
|
27
|
+
buildProjectProfileChoices,
|
|
28
|
+
detectGlobalProfileStatus,
|
|
29
|
+
executeProjectUse,
|
|
30
|
+
listProfileStashEntries,
|
|
31
|
+
maybeSyncActiveProfileBeforeSwitch,
|
|
32
|
+
popProfileStashCommand,
|
|
33
|
+
printApplyDryRun,
|
|
34
|
+
printApplyPayload,
|
|
35
|
+
promptMaterializationConflict,
|
|
36
|
+
resolveApplyConflictPolicy,
|
|
37
|
+
resolveExpectedPluginName,
|
|
38
|
+
resolveUserPath,
|
|
39
|
+
stashProfileCommand
|
|
40
|
+
} from "./chunk-AOUDSNRK.js";
|
|
41
|
+
import "./chunk-V4IXIM3C.js";
|
|
42
|
+
import "./chunk-UYRK2H24.js";
|
|
43
|
+
import "./chunk-VZQG2JDV.js";
|
|
44
|
+
import "./chunk-DJ6FN6EW.js";
|
|
45
|
+
import "./chunk-KRI4R7EM.js";
|
|
46
|
+
import {
|
|
47
|
+
resolveSkillPackageCheckout
|
|
48
|
+
} from "./chunk-YSXRBUR4.js";
|
|
49
|
+
import "./chunk-6P5IO4BX.js";
|
|
50
|
+
import "./chunk-BNDJJAEI.js";
|
|
51
|
+
import "./chunk-S2E4SSQV.js";
|
|
52
|
+
import "./chunk-XGTTOO4R.js";
|
|
53
|
+
import {
|
|
54
|
+
parseCommaSeparatedList
|
|
55
|
+
} from "./chunk-37E5M4JX.js";
|
|
56
|
+
import "./chunk-JQOKQKQT.js";
|
|
57
|
+
import "./chunk-3FIWOI3H.js";
|
|
58
|
+
import {
|
|
59
|
+
renderCliError
|
|
60
|
+
} from "./chunk-37LQQWMF.js";
|
|
61
|
+
import {
|
|
62
|
+
PinnedPluginInstallConsentError,
|
|
63
|
+
ProfileReservedNameError,
|
|
64
|
+
createProfileCommand,
|
|
65
|
+
deleteProfileCommand,
|
|
66
|
+
getActiveProfileName,
|
|
67
|
+
listProfilePluginsCommand,
|
|
68
|
+
showProfileCommand,
|
|
69
|
+
tagProfileCommand,
|
|
70
|
+
useProfileCommand,
|
|
71
|
+
useProfileCommandUnlocked,
|
|
72
|
+
withProfileApplyLock
|
|
73
|
+
} from "./chunk-WNLFNCOH.js";
|
|
74
|
+
import "./chunk-E5QXNU3K.js";
|
|
75
|
+
import {
|
|
76
|
+
isPromptCancellationError,
|
|
77
|
+
promptForChoice,
|
|
78
|
+
promptForConfirmation,
|
|
79
|
+
promptForSearchableChoice,
|
|
80
|
+
shouldUseWizard
|
|
81
|
+
} from "./chunk-NAGAJ5UM.js";
|
|
82
|
+
import {
|
|
83
|
+
initializeSchema
|
|
84
|
+
} from "./chunk-N3WIJXXM.js";
|
|
85
|
+
import {
|
|
86
|
+
PROFILE_PLUGIN_TAG,
|
|
87
|
+
isEmptyBuiltinProfile,
|
|
88
|
+
isProfilePlugin,
|
|
89
|
+
listProfilePlugins
|
|
90
|
+
} from "./chunk-TNJPTUE4.js";
|
|
91
|
+
import "./chunk-KDUQMINL.js";
|
|
92
|
+
import {
|
|
93
|
+
previewPluginFromProject
|
|
94
|
+
} from "./chunk-2NE3QYMP.js";
|
|
95
|
+
import {
|
|
96
|
+
findProjectConfig,
|
|
97
|
+
getProfileEntry
|
|
98
|
+
} from "./chunk-MSGAGV7B.js";
|
|
99
|
+
import {
|
|
100
|
+
formatPluginLabel
|
|
101
|
+
} from "./chunk-I6XFZLTJ.js";
|
|
102
|
+
import "./chunk-W7HQ5X3S.js";
|
|
103
|
+
import "./chunk-JRFUTIEH.js";
|
|
104
|
+
import {
|
|
105
|
+
assertSupportedHarnessTargets
|
|
106
|
+
} from "./chunk-PFUK3HJ4.js";
|
|
107
|
+
import {
|
|
108
|
+
persistMergedProjectScan,
|
|
109
|
+
persistScanResults,
|
|
110
|
+
scanHomeDefaults
|
|
111
|
+
} from "./chunk-WRX7CB2M.js";
|
|
112
|
+
import "./chunk-E4WRTRMH.js";
|
|
113
|
+
import "./chunk-MZQRSERO.js";
|
|
114
|
+
import "./chunk-DEJLP7QJ.js";
|
|
115
|
+
import {
|
|
116
|
+
addPluginAttachment,
|
|
117
|
+
addResourceToPlugin,
|
|
118
|
+
createPlugin,
|
|
119
|
+
deletePlugin,
|
|
120
|
+
diskCaptureHarnessScope,
|
|
121
|
+
formatPluginRef,
|
|
122
|
+
getPlugin,
|
|
123
|
+
getPluginByName,
|
|
124
|
+
getResource,
|
|
125
|
+
listAttachedPluginRefs,
|
|
126
|
+
listPlugins,
|
|
127
|
+
listResources,
|
|
128
|
+
resolveHomeRoot,
|
|
129
|
+
resolvePluginSelector
|
|
130
|
+
} from "./chunk-TKBMHZTS.js";
|
|
131
|
+
import "./chunk-TXXDMDPN.js";
|
|
132
|
+
import "./chunk-C2IWSFF5.js";
|
|
133
|
+
import "./chunk-NPO2IG6G.js";
|
|
134
|
+
import {
|
|
135
|
+
configureCommandGroup
|
|
136
|
+
} from "./chunk-5TXI6BI2.js";
|
|
137
|
+
import {
|
|
138
|
+
parseOutputFormat,
|
|
139
|
+
printJson
|
|
140
|
+
} from "./chunk-TQ2NA4Z4.js";
|
|
141
|
+
import {
|
|
142
|
+
ON_CONFLICT_APPLY_HELP,
|
|
143
|
+
ON_CONFLICT_PLUGIN_IMPORT_HELP,
|
|
144
|
+
collectRepeatedOption,
|
|
145
|
+
fail,
|
|
146
|
+
failCaught,
|
|
147
|
+
formatCommand,
|
|
148
|
+
formatHintCommand,
|
|
149
|
+
missingRequiredArg,
|
|
150
|
+
parseOnConflict,
|
|
151
|
+
toPluginImportOnConflict
|
|
152
|
+
} from "./chunk-NFYPBTKO.js";
|
|
153
|
+
import {
|
|
154
|
+
formatCount,
|
|
155
|
+
ui
|
|
156
|
+
} from "./chunk-ABXUKHAU.js";
|
|
157
|
+
import "./chunk-2P2EOYEW.js";
|
|
158
|
+
import "./chunk-VQVUJYYY.js";
|
|
159
|
+
import {
|
|
160
|
+
CLI_ERRORS,
|
|
161
|
+
CLI_HINTS,
|
|
162
|
+
SWITCH_CHANGES_FLAG_HELP,
|
|
163
|
+
dryRunStashLine,
|
|
164
|
+
getDb,
|
|
165
|
+
getHarnesstapDir
|
|
166
|
+
} from "./chunk-KLR2DURP.js";
|
|
167
|
+
|
|
168
|
+
// src/cli/commands/profile.ts
|
|
169
|
+
import { Option } from "commander";
|
|
170
|
+
|
|
171
|
+
// src/services/profile-enable-prompt.ts
|
|
172
|
+
function shouldPromptProfileEnable(input) {
|
|
173
|
+
if (input.yes || input.format === "json") {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
if (process.argv.includes("--no-interactive") || process.env.HARNESSTAP_NO_INTERACTIVE === "1") {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const ciValue = process.env.CI?.trim().toLowerCase();
|
|
180
|
+
const ciEnabled = Boolean(
|
|
181
|
+
ciValue && ciValue !== "0" && ciValue !== "false" && ciValue !== "no"
|
|
182
|
+
);
|
|
183
|
+
if (ciEnabled) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
return Boolean(
|
|
187
|
+
process.env.HARNESSTAP_FORCE_WIZARD === "1" || process.stdin.isTTY && process.stdout.isTTY
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
async function maybePromptProfileEnable(input) {
|
|
191
|
+
const format = input.format ?? "human";
|
|
192
|
+
if (format !== "human") {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const status = await detectGlobalProfileStatus({ harness: input.harness });
|
|
196
|
+
if (status.active_profile === input.profileName && !status.has_drift) {
|
|
197
|
+
ui.success(
|
|
198
|
+
`Profile ${ui.theme.accent(input.profileName)} is already active and in sync globally.`
|
|
199
|
+
);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (!shouldPromptProfileEnable({ yes: input.yes, format })) {
|
|
203
|
+
if (status.active_profile === input.profileName) {
|
|
204
|
+
ui.hint(`Run harnesstap profile use ${input.profileName} to apply globally.`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
ui.hint(
|
|
208
|
+
`Switch to it with harnesstap profile use ${input.profileName} or ht ${input.profileName}`
|
|
209
|
+
);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const message = status.active_profile === input.profileName ? `Apply profile ${input.profileName} to your global harness files now?` : `Enable profile ${input.profileName} globally and set it as active?`;
|
|
213
|
+
const confirmed = await promptForConfirmation({
|
|
214
|
+
message,
|
|
215
|
+
default: true
|
|
216
|
+
});
|
|
217
|
+
if (!confirmed) {
|
|
218
|
+
ui.hint(
|
|
219
|
+
`Switch later with harnesstap profile use ${input.profileName} or ht ${input.profileName}`
|
|
220
|
+
);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (status.active_profile && status.active_profile !== input.profileName) {
|
|
224
|
+
const sync = await maybeSyncActiveProfileBeforeSwitch({
|
|
225
|
+
targetProfileName: input.profileName,
|
|
226
|
+
harness: input.harness,
|
|
227
|
+
yes: input.yes,
|
|
228
|
+
format
|
|
229
|
+
});
|
|
230
|
+
if (sync === "abort") {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const conflictPolicy = resolveApplyConflictPolicy({
|
|
235
|
+
onConflict: input.onConflictUse
|
|
236
|
+
});
|
|
237
|
+
const applied = await useProfileCommand(input.profileName, {
|
|
238
|
+
harness: input.harness,
|
|
239
|
+
pull: input.pull,
|
|
240
|
+
account: input.account,
|
|
241
|
+
baseUrl: input.baseUrl,
|
|
242
|
+
conflictPolicy,
|
|
243
|
+
...conflictPolicy === "prompt" ? { conflictResolver: promptMaterializationConflict } : {}
|
|
244
|
+
});
|
|
245
|
+
if (applied.cancelled) {
|
|
246
|
+
ui.warn("Profile apply cancelled.");
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
printApplyPayload(applied);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/services/profile-delete-prompt.ts
|
|
253
|
+
async function maybePromptProfilePluginDelete(input) {
|
|
254
|
+
if (input.deletePluginFlag) {
|
|
255
|
+
if (!deletePlugin(input.pluginId)) {
|
|
256
|
+
throw new Error(`Failed to delete plugin ${input.pluginName}`);
|
|
257
|
+
}
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
const format = input.format ?? "human";
|
|
261
|
+
if (format !== "human") {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
if (!shouldPromptProfileEnable({ yes: input.yes, format })) {
|
|
265
|
+
ui.hint(
|
|
266
|
+
`Plugin ${ui.theme.accent(input.pluginName)} was kept. Delete with harnesstap plugin delete ${input.pluginName}`
|
|
267
|
+
);
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
const confirmed = await promptForConfirmation({
|
|
271
|
+
message: `Also delete plugin ${input.pluginName}?`,
|
|
272
|
+
default: false
|
|
273
|
+
});
|
|
274
|
+
if (!confirmed) {
|
|
275
|
+
ui.hint(
|
|
276
|
+
`Plugin ${ui.theme.accent(input.pluginName)} was kept. Delete with harnesstap plugin delete ${input.pluginName}`
|
|
277
|
+
);
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
if (!deletePlugin(input.pluginId)) {
|
|
281
|
+
throw new Error(`Failed to delete plugin ${input.pluginName}`);
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/services/profile-switch.ts
|
|
287
|
+
var PROFILE_SWITCH_CANCEL_DISABLED_MESSAGE = "Cancel is disabled while an apply step is running";
|
|
288
|
+
var PROFILE_SWITCH_SIGINT_HINT = "Ctrl-C cancels before apply starts; it is ignored while files are being written.";
|
|
289
|
+
function isSigintCancelAllowed(events) {
|
|
290
|
+
return !events.some(
|
|
291
|
+
(event) => event.step === "apply_home" && event.status === "started"
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
function cliArgvRequestsJson(argv) {
|
|
295
|
+
const formatIndex = argv.findIndex((arg) => arg === "--format" || arg === "-f");
|
|
296
|
+
if (formatIndex >= 0) {
|
|
297
|
+
return (argv[formatIndex + 1] ?? "").toLowerCase() === "json";
|
|
298
|
+
}
|
|
299
|
+
return argv.some(
|
|
300
|
+
(arg) => arg === "--format=json" || arg === "-f=json"
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
function installProfileSwitchSigint(events) {
|
|
304
|
+
let cancelled = false;
|
|
305
|
+
const onSigint = () => {
|
|
306
|
+
if (!isSigintCancelAllowed(events)) {
|
|
307
|
+
process.stderr.write(`${PROFILE_SWITCH_CANCEL_DISABLED_MESSAGE}
|
|
308
|
+
`);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
cancelled = true;
|
|
312
|
+
};
|
|
313
|
+
process.on("SIGINT", onSigint);
|
|
314
|
+
if (!cliArgvRequestsJson(process.argv)) {
|
|
315
|
+
ui.hint(PROFILE_SWITCH_SIGINT_HINT);
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
isCancelled: () => cancelled,
|
|
319
|
+
uninstall: () => {
|
|
320
|
+
process.off("SIGINT", onSigint);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
var SwitchRestoreFailedError = class extends Error {
|
|
325
|
+
targetProfile;
|
|
326
|
+
previousProfile;
|
|
327
|
+
applyError;
|
|
328
|
+
restoreError;
|
|
329
|
+
constructor(input) {
|
|
330
|
+
super(
|
|
331
|
+
`Failed to switch to profile "${input.targetProfile}" and could not restore "${input.previousProfile}".`
|
|
332
|
+
);
|
|
333
|
+
this.name = "SwitchRestoreFailed";
|
|
334
|
+
this.targetProfile = input.targetProfile;
|
|
335
|
+
this.previousProfile = input.previousProfile;
|
|
336
|
+
this.applyError = input.applyError;
|
|
337
|
+
this.restoreError = input.restoreError;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
function formatError(error) {
|
|
341
|
+
return error instanceof Error ? error.message : String(error);
|
|
342
|
+
}
|
|
343
|
+
function emitStep(events, onStep, event) {
|
|
344
|
+
events.push(event);
|
|
345
|
+
onStep?.(event);
|
|
346
|
+
}
|
|
347
|
+
function checkCancellation(options, events, previousProfile, step) {
|
|
348
|
+
if (!options.isCancelled?.()) {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
emitStep(events, options.onStep, {
|
|
352
|
+
step,
|
|
353
|
+
status: "cancelled"
|
|
354
|
+
});
|
|
355
|
+
return {
|
|
356
|
+
ok: false,
|
|
357
|
+
cancelled: true,
|
|
358
|
+
previous_profile: previousProfile,
|
|
359
|
+
events
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
async function switchProfile(selector, options) {
|
|
363
|
+
const events = [];
|
|
364
|
+
const ownsSigint = options.isCancelled === void 0;
|
|
365
|
+
const sigint = ownsSigint ? installProfileSwitchSigint(events) : null;
|
|
366
|
+
const resolvedOptions = ownsSigint ? { ...options, isCancelled: () => sigint?.isCancelled() === true } : options;
|
|
367
|
+
try {
|
|
368
|
+
return await withProfileApplyLock(async () => {
|
|
369
|
+
const previousProfile = getActiveProfileName() ?? null;
|
|
370
|
+
const useProfile = resolvedOptions.useProfile ?? useProfileCommandUnlocked;
|
|
371
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
372
|
+
step: "validate_baseline",
|
|
373
|
+
status: "started"
|
|
374
|
+
});
|
|
375
|
+
const cancelledBeforeBaseline = checkCancellation(
|
|
376
|
+
resolvedOptions,
|
|
377
|
+
events,
|
|
378
|
+
previousProfile,
|
|
379
|
+
"validate_baseline"
|
|
380
|
+
);
|
|
381
|
+
if (cancelledBeforeBaseline) {
|
|
382
|
+
return cancelledBeforeBaseline;
|
|
383
|
+
}
|
|
384
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
385
|
+
step: "validate_baseline",
|
|
386
|
+
status: "completed"
|
|
387
|
+
});
|
|
388
|
+
const cancelledBeforeApply = checkCancellation(
|
|
389
|
+
resolvedOptions,
|
|
390
|
+
events,
|
|
391
|
+
previousProfile,
|
|
392
|
+
"apply_home"
|
|
393
|
+
);
|
|
394
|
+
if (cancelledBeforeApply) {
|
|
395
|
+
return cancelledBeforeApply;
|
|
396
|
+
}
|
|
397
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
398
|
+
step: "apply_home",
|
|
399
|
+
status: "started",
|
|
400
|
+
profile_name: selector
|
|
401
|
+
});
|
|
402
|
+
try {
|
|
403
|
+
const apply = await useProfile(selector, resolvedOptions.apply);
|
|
404
|
+
if (apply.cancelled) {
|
|
405
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
406
|
+
step: "apply_home",
|
|
407
|
+
status: "cancelled",
|
|
408
|
+
profile_name: selector
|
|
409
|
+
});
|
|
410
|
+
return {
|
|
411
|
+
ok: false,
|
|
412
|
+
cancelled: true,
|
|
413
|
+
previous_profile: previousProfile,
|
|
414
|
+
events
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
418
|
+
step: "apply_home",
|
|
419
|
+
status: "completed",
|
|
420
|
+
profile_name: selector
|
|
421
|
+
});
|
|
422
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
423
|
+
step: "complete",
|
|
424
|
+
status: "completed",
|
|
425
|
+
profile_name: selector
|
|
426
|
+
});
|
|
427
|
+
return {
|
|
428
|
+
ok: true,
|
|
429
|
+
cancelled: false,
|
|
430
|
+
previous_profile: previousProfile,
|
|
431
|
+
apply,
|
|
432
|
+
events
|
|
433
|
+
};
|
|
434
|
+
} catch (error) {
|
|
435
|
+
const applyError = formatError(error);
|
|
436
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
437
|
+
step: "apply_home",
|
|
438
|
+
status: "failed",
|
|
439
|
+
profile_name: selector,
|
|
440
|
+
error: applyError
|
|
441
|
+
});
|
|
442
|
+
if (!previousProfile || previousProfile === selector) {
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
const cancelledBeforeRestore = checkCancellation(
|
|
446
|
+
resolvedOptions,
|
|
447
|
+
events,
|
|
448
|
+
previousProfile,
|
|
449
|
+
"restore_previous"
|
|
450
|
+
);
|
|
451
|
+
if (cancelledBeforeRestore) {
|
|
452
|
+
return cancelledBeforeRestore;
|
|
453
|
+
}
|
|
454
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
455
|
+
step: "restore_previous",
|
|
456
|
+
status: "started",
|
|
457
|
+
profile_name: previousProfile
|
|
458
|
+
});
|
|
459
|
+
try {
|
|
460
|
+
const restored = await useProfile(previousProfile, resolvedOptions.apply);
|
|
461
|
+
if (restored.cancelled) {
|
|
462
|
+
throw new Error("Restore apply was cancelled.");
|
|
463
|
+
}
|
|
464
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
465
|
+
step: "restore_previous",
|
|
466
|
+
status: "completed",
|
|
467
|
+
profile_name: previousProfile
|
|
468
|
+
});
|
|
469
|
+
return {
|
|
470
|
+
ok: false,
|
|
471
|
+
cancelled: false,
|
|
472
|
+
previous_profile: previousProfile,
|
|
473
|
+
apply_error: applyError,
|
|
474
|
+
restored,
|
|
475
|
+
events
|
|
476
|
+
};
|
|
477
|
+
} catch (restoreError) {
|
|
478
|
+
const restoreMessage = formatError(restoreError);
|
|
479
|
+
emitStep(events, resolvedOptions.onStep, {
|
|
480
|
+
step: "restore_previous",
|
|
481
|
+
status: "failed",
|
|
482
|
+
profile_name: previousProfile,
|
|
483
|
+
error: restoreMessage
|
|
484
|
+
});
|
|
485
|
+
throw new SwitchRestoreFailedError({
|
|
486
|
+
targetProfile: selector,
|
|
487
|
+
previousProfile,
|
|
488
|
+
applyError,
|
|
489
|
+
restoreError: restoreMessage
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
} finally {
|
|
495
|
+
sigint?.uninstall();
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// src/services/profile-use-resolve.ts
|
|
500
|
+
var PROJECT_PREFIX = "project:";
|
|
501
|
+
var GLOBAL_PREFIX = "global:";
|
|
502
|
+
function encodeProjectChoice(profileKey) {
|
|
503
|
+
return `${PROJECT_PREFIX}${profileKey}`;
|
|
504
|
+
}
|
|
505
|
+
function encodeGlobalChoice(pluginName) {
|
|
506
|
+
return `${GLOBAL_PREFIX}${pluginName}`;
|
|
507
|
+
}
|
|
508
|
+
function decodeProfileUseChoice(value) {
|
|
509
|
+
if (value.startsWith(PROJECT_PREFIX)) {
|
|
510
|
+
return { kind: "project", profileKey: value.slice(PROJECT_PREFIX.length) };
|
|
511
|
+
}
|
|
512
|
+
if (value.startsWith(GLOBAL_PREFIX)) {
|
|
513
|
+
return { kind: "global", pluginName: value.slice(GLOBAL_PREFIX.length) };
|
|
514
|
+
}
|
|
515
|
+
throw new Error(`Invalid profile selection: ${value}`);
|
|
516
|
+
}
|
|
517
|
+
function collectProjectPluginNames(config) {
|
|
518
|
+
const names = /* @__PURE__ */ new Set();
|
|
519
|
+
for (const entry of config.profiles) {
|
|
520
|
+
try {
|
|
521
|
+
names.add(resolveExpectedPluginName(config, entry));
|
|
522
|
+
} catch {
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return names;
|
|
526
|
+
}
|
|
527
|
+
function buildGlobalProfileChoices(config) {
|
|
528
|
+
const coveredPluginNames = config ? collectProjectPluginNames(config) : /* @__PURE__ */ new Set();
|
|
529
|
+
return listProfilePlugins().filter((plugin) => !coveredPluginNames.has(plugin.name)).map((plugin) => ({
|
|
530
|
+
name: `${plugin.name}${getActiveProfileName() === plugin.name ? " (active)" : ""}`,
|
|
531
|
+
value: encodeGlobalChoice(plugin.name)
|
|
532
|
+
}));
|
|
533
|
+
}
|
|
534
|
+
function buildCombinedProfileUseChoices(config) {
|
|
535
|
+
const choices = [];
|
|
536
|
+
if (config && config.profiles.length > 0) {
|
|
537
|
+
for (const entry of config.profiles) {
|
|
538
|
+
choices.push({
|
|
539
|
+
name: `[project] ${formatProjectProfileLabel(config, entry)}`,
|
|
540
|
+
value: encodeProjectChoice(entry.name)
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
choices.push(...buildGlobalProfileChoices(config));
|
|
545
|
+
return choices;
|
|
546
|
+
}
|
|
547
|
+
function formatProjectProfileLabel(config, entry) {
|
|
548
|
+
const choice = buildProjectProfileChoices(config).find(
|
|
549
|
+
(candidate) => candidate.value === entry.name
|
|
550
|
+
);
|
|
551
|
+
return choice?.name ?? entry.name;
|
|
552
|
+
}
|
|
553
|
+
function resolveDefaultProfileUseChoice(config, choices) {
|
|
554
|
+
if (config?.default_profile) {
|
|
555
|
+
const projectChoice = encodeProjectChoice(config.default_profile);
|
|
556
|
+
if (choices.some((choice) => choice.value === projectChoice)) {
|
|
557
|
+
return projectChoice;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
const active = getActiveProfileName();
|
|
561
|
+
if (active) {
|
|
562
|
+
const globalChoice = encodeGlobalChoice(active);
|
|
563
|
+
if (choices.some((choice) => choice.value === globalChoice)) {
|
|
564
|
+
return globalChoice;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return choices[0]?.value;
|
|
568
|
+
}
|
|
569
|
+
async function promptForProfileUseSelection(config) {
|
|
570
|
+
const choices = buildCombinedProfileUseChoices(config);
|
|
571
|
+
if (choices.length === 0) {
|
|
572
|
+
throw new Error("No profiles available. Create one with `ht profile create <name>`.");
|
|
573
|
+
}
|
|
574
|
+
const message = config ? "Which profile should be applied globally?" : "Which profile plugin should be applied globally?";
|
|
575
|
+
const defaultChoice = resolveDefaultProfileUseChoice(config, choices);
|
|
576
|
+
const value = choices.length >= 8 ? await promptForSearchableChoice({ message, choices, default: defaultChoice }) : await promptForChoice({ message, choices, default: defaultChoice });
|
|
577
|
+
return decodeProfileUseChoice(value);
|
|
578
|
+
}
|
|
579
|
+
async function resolveProfileUseSelection(input) {
|
|
580
|
+
if (input.name) {
|
|
581
|
+
return { kind: "global", pluginName: input.name };
|
|
582
|
+
}
|
|
583
|
+
const projectPath = resolveUserPath(input.project ?? process.cwd());
|
|
584
|
+
const config = findProjectConfig(projectPath);
|
|
585
|
+
if (input.profile) {
|
|
586
|
+
if (!config) {
|
|
587
|
+
throw new Error(
|
|
588
|
+
"No project config found. Omit --profile to switch a local profile plugin by name."
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
getProfileEntry(config, input.profile);
|
|
592
|
+
return { kind: "project", profileKey: input.profile };
|
|
593
|
+
}
|
|
594
|
+
const interactive = shouldUseWizard({
|
|
595
|
+
interactive: input.interactive,
|
|
596
|
+
noInteractive: input.noInteractive,
|
|
597
|
+
format: input.format,
|
|
598
|
+
missingRequiredArgs: true
|
|
599
|
+
});
|
|
600
|
+
if (interactive) {
|
|
601
|
+
return promptForProfileUseSelection(config);
|
|
602
|
+
}
|
|
603
|
+
throw new Error("Pass a profile name.");
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// src/cli/handlers/profile-create.ts
|
|
607
|
+
import inquirer from "inquirer";
|
|
608
|
+
|
|
609
|
+
// src/services/profile-from-home.ts
|
|
610
|
+
var ProfilePluginExistsError = class extends Error {
|
|
611
|
+
constructor(name) {
|
|
612
|
+
super(`Plugin already exists: ${name}`);
|
|
613
|
+
this.name = "ProfilePluginExistsError";
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
function resourceNamespace(resource) {
|
|
617
|
+
return resource.namespace ?? "";
|
|
618
|
+
}
|
|
619
|
+
function resourceKey(resource) {
|
|
620
|
+
return `${resource.type}:${resource.name}:${resourceNamespace(resource)}`;
|
|
621
|
+
}
|
|
622
|
+
function createNewProfilePlugin(input) {
|
|
623
|
+
try {
|
|
624
|
+
return createPlugin({
|
|
625
|
+
name: input.name,
|
|
626
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
627
|
+
tags: [PROFILE_PLUGIN_TAG]
|
|
628
|
+
});
|
|
629
|
+
} catch (error) {
|
|
630
|
+
if (getPluginByName(input.name)) {
|
|
631
|
+
throw new ProfilePluginExistsError(input.name);
|
|
632
|
+
}
|
|
633
|
+
throw error;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
async function previewProfileFromHome(input) {
|
|
637
|
+
const homeRoot = input?.homeRoot ?? resolveHomeRoot();
|
|
638
|
+
const results = await scanHomeDefaults(input?.platform, homeRoot);
|
|
639
|
+
const scannedResources = results.flatMap((result) => result.resources);
|
|
640
|
+
const existingByKey = new Map(
|
|
641
|
+
listResources().map((resource) => [resourceKey(resource), resource])
|
|
642
|
+
);
|
|
643
|
+
const conflicts = [];
|
|
644
|
+
const conflictKeys = /* @__PURE__ */ new Set();
|
|
645
|
+
for (const scanned of scannedResources) {
|
|
646
|
+
const key = resourceKey(scanned);
|
|
647
|
+
const existing = existingByKey.get(key);
|
|
648
|
+
if (!existing || existing.content === scanned.content || conflictKeys.has(key)) {
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
conflictKeys.add(key);
|
|
652
|
+
conflicts.push({
|
|
653
|
+
type: scanned.type,
|
|
654
|
+
name: scanned.name,
|
|
655
|
+
namespace: resourceNamespace(scanned) || null
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
const preview = {
|
|
659
|
+
totalImports: scannedResources.length,
|
|
660
|
+
platformIds: results.map((result) => result.platformId),
|
|
661
|
+
conflicts
|
|
662
|
+
};
|
|
663
|
+
if (scannedResources.length === 0) {
|
|
664
|
+
preview.warning = "No supported home resources found";
|
|
665
|
+
}
|
|
666
|
+
return preview;
|
|
667
|
+
}
|
|
668
|
+
async function createProfileFromHome(input) {
|
|
669
|
+
if (isEmptyBuiltinProfile(input.name)) {
|
|
670
|
+
throw new ProfileReservedNameError(input.name);
|
|
671
|
+
}
|
|
672
|
+
if (getPluginByName(input.name)) {
|
|
673
|
+
throw new ProfilePluginExistsError(input.name);
|
|
674
|
+
}
|
|
675
|
+
const homeRoot = input.homeRoot ?? resolveHomeRoot();
|
|
676
|
+
const scanResults = await scanHomeDefaults(input.platform, homeRoot);
|
|
677
|
+
const persisted = persistScanResults(scanResults, {
|
|
678
|
+
conflictPolicy: input.conflictPolicy,
|
|
679
|
+
originRef: homeRoot
|
|
680
|
+
});
|
|
681
|
+
const plugin = createNewProfilePlugin({
|
|
682
|
+
name: input.name,
|
|
683
|
+
...input.description !== void 0 ? { description: input.description } : {}
|
|
684
|
+
});
|
|
685
|
+
for (const resource of persisted.resolved) {
|
|
686
|
+
addResourceToPlugin(plugin.id, resource.id, diskCaptureHarnessScope(resource));
|
|
687
|
+
}
|
|
688
|
+
return {
|
|
689
|
+
plugin,
|
|
690
|
+
imported_count: persisted.resolved.length,
|
|
691
|
+
resources: persisted.resolved
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// src/services/profile-create.ts
|
|
696
|
+
function assertProfileNameAvailable(name) {
|
|
697
|
+
if (isEmptyBuiltinProfile(name)) {
|
|
698
|
+
throw new ProfileReservedNameError(name);
|
|
699
|
+
}
|
|
700
|
+
if (getPluginByName(name)) {
|
|
701
|
+
throw new ProfilePluginExistsError(name);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
function createNewProfilePlugin2(input) {
|
|
705
|
+
try {
|
|
706
|
+
return createPlugin({
|
|
707
|
+
name: input.name,
|
|
708
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
709
|
+
tags: [PROFILE_PLUGIN_TAG]
|
|
710
|
+
});
|
|
711
|
+
} catch (error) {
|
|
712
|
+
if (getPluginByName(input.name)) {
|
|
713
|
+
throw new ProfilePluginExistsError(input.name);
|
|
714
|
+
}
|
|
715
|
+
throw error;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
function resolveComposeSelections(input) {
|
|
719
|
+
const pluginIds = [...new Set(input.pluginIds ?? [])];
|
|
720
|
+
const resourceIds = [...new Set(input.resourceIds ?? [])];
|
|
721
|
+
if (pluginIds.length + resourceIds.length === 0) {
|
|
722
|
+
throw new Error("A composed profile requires at least one plugin or resource selection");
|
|
723
|
+
}
|
|
724
|
+
const pluginsById = new Map(listPlugins().map((plugin) => [plugin.id, plugin]));
|
|
725
|
+
const resourcesById = new Map(
|
|
726
|
+
listResources().map((resource) => [resource.id, resource])
|
|
727
|
+
);
|
|
728
|
+
const plugins = pluginIds.map((id) => {
|
|
729
|
+
const plugin = pluginsById.get(id);
|
|
730
|
+
if (!plugin) {
|
|
731
|
+
throw new Error(`Plugin not found: ${id}`);
|
|
732
|
+
}
|
|
733
|
+
return plugin;
|
|
734
|
+
});
|
|
735
|
+
for (const id of resourceIds) {
|
|
736
|
+
if (!resourcesById.has(id)) {
|
|
737
|
+
throw new Error(`Resource not found: ${id}`);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return { plugins, resourceIds, resourcesById };
|
|
741
|
+
}
|
|
742
|
+
function assertProjectPath(projectPath) {
|
|
743
|
+
if (projectPath.trim().length === 0) {
|
|
744
|
+
throw new Error("projectPath is required for project profile creation");
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
function unreachableSource(source) {
|
|
748
|
+
throw new Error(`Unsupported profile create source: ${String(source)}`);
|
|
749
|
+
}
|
|
750
|
+
async function previewProfileCreate(input) {
|
|
751
|
+
switch (input.source) {
|
|
752
|
+
case "compose": {
|
|
753
|
+
assertProfileNameAvailable(input.name);
|
|
754
|
+
const selections = resolveComposeSelections(input);
|
|
755
|
+
return {
|
|
756
|
+
source: input.source,
|
|
757
|
+
name: input.name,
|
|
758
|
+
totalImports: selections.plugins.length + selections.resourceIds.length,
|
|
759
|
+
conflicts: [],
|
|
760
|
+
warnings: []
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
case "home": {
|
|
764
|
+
const preview = await previewProfileFromHome({
|
|
765
|
+
...input.platform ? { platform: input.platform } : {}
|
|
766
|
+
});
|
|
767
|
+
return {
|
|
768
|
+
source: input.source,
|
|
769
|
+
name: input.name,
|
|
770
|
+
totalImports: preview.totalImports,
|
|
771
|
+
conflicts: preview.conflicts,
|
|
772
|
+
warnings: preview.warning ? [preview.warning] : []
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
case "project": {
|
|
776
|
+
assertProjectPath(input.projectPath);
|
|
777
|
+
const preview = await previewPluginFromProject({
|
|
778
|
+
name: input.name,
|
|
779
|
+
projectRoot: input.projectPath,
|
|
780
|
+
...input.platform ? { platform: input.platform } : {}
|
|
781
|
+
});
|
|
782
|
+
return {
|
|
783
|
+
source: input.source,
|
|
784
|
+
name: input.name,
|
|
785
|
+
totalImports: preview.totalImports,
|
|
786
|
+
conflicts: preview.conflicts,
|
|
787
|
+
warnings: []
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
default:
|
|
791
|
+
return unreachableSource(input);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
async function commitProfileCreate(input) {
|
|
795
|
+
switch (input.source) {
|
|
796
|
+
case "compose": {
|
|
797
|
+
assertProfileNameAvailable(input.name);
|
|
798
|
+
const selections = resolveComposeSelections(input);
|
|
799
|
+
const plugin = createNewProfilePlugin2({
|
|
800
|
+
name: input.name,
|
|
801
|
+
...input.description !== void 0 ? { description: input.description } : {}
|
|
802
|
+
});
|
|
803
|
+
for (const dependency of selections.plugins) {
|
|
804
|
+
await addPluginAttachment({
|
|
805
|
+
plugin,
|
|
806
|
+
selector: dependency.name,
|
|
807
|
+
type: "plugin"
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
for (const resourceId of selections.resourceIds) {
|
|
811
|
+
const resource = selections.resourcesById.get(resourceId);
|
|
812
|
+
if (resource?.type === "plugin") {
|
|
813
|
+
await addPluginAttachment({
|
|
814
|
+
plugin,
|
|
815
|
+
selector: formatPluginRef(resource),
|
|
816
|
+
type: "plugin"
|
|
817
|
+
});
|
|
818
|
+
} else {
|
|
819
|
+
addResourceToPlugin(plugin.id, resourceId);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return {
|
|
823
|
+
profile: {
|
|
824
|
+
name: plugin.name,
|
|
825
|
+
id: plugin.id,
|
|
826
|
+
version: plugin.version
|
|
827
|
+
},
|
|
828
|
+
imported_count: selections.plugins.length + selections.resourceIds.length,
|
|
829
|
+
used: false
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
case "home": {
|
|
833
|
+
assertProfileNameAvailable(input.name);
|
|
834
|
+
const result = await createProfileFromHome({
|
|
835
|
+
name: input.name,
|
|
836
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
837
|
+
conflictPolicy: input.conflictPolicy,
|
|
838
|
+
...input.platform ? { platform: input.platform } : {}
|
|
839
|
+
});
|
|
840
|
+
return {
|
|
841
|
+
profile: {
|
|
842
|
+
name: result.plugin.name,
|
|
843
|
+
id: result.plugin.id,
|
|
844
|
+
version: result.plugin.version
|
|
845
|
+
},
|
|
846
|
+
imported_count: result.imported_count,
|
|
847
|
+
used: false
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
case "project": {
|
|
851
|
+
assertProjectPath(input.projectPath);
|
|
852
|
+
assertProfileNameAvailable(input.name);
|
|
853
|
+
const persisted = await persistMergedProjectScan(
|
|
854
|
+
input.projectPath,
|
|
855
|
+
input.platform,
|
|
856
|
+
{
|
|
857
|
+
conflictPolicy: input.conflictPolicy,
|
|
858
|
+
originRef: input.projectPath,
|
|
859
|
+
namespace: input.name
|
|
860
|
+
}
|
|
861
|
+
);
|
|
862
|
+
const plugin = createNewProfilePlugin2({
|
|
863
|
+
name: input.name,
|
|
864
|
+
...input.description !== void 0 ? { description: input.description } : { description: `Inferred from ${input.projectPath}` }
|
|
865
|
+
});
|
|
866
|
+
for (const resource of persisted.resources) {
|
|
867
|
+
addResourceToPlugin(plugin.id, resource.id);
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
profile: {
|
|
871
|
+
name: plugin.name,
|
|
872
|
+
id: plugin.id,
|
|
873
|
+
version: plugin.version
|
|
874
|
+
},
|
|
875
|
+
imported_count: persisted.resources.length,
|
|
876
|
+
used: false
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
default:
|
|
880
|
+
return unreachableSource(input);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// src/cli/handlers/profile-create.ts
|
|
885
|
+
function parsePluginSourceConflictPolicy(value) {
|
|
886
|
+
return toPluginImportOnConflict(parseOnConflict(value, { allowMerge: true }));
|
|
887
|
+
}
|
|
888
|
+
var SINGLE_SOURCE_MESSAGE = "Pass only one of --from, --compose, --from-home, or --from-project.";
|
|
889
|
+
var PREVIEW_SOURCE_MESSAGE = "--preview applies to --compose, --from-home, and --from-project. Skill-package create uses --dry-run.";
|
|
890
|
+
var PREVIEW_USE_MESSAGE = "Do not combine --preview with --use or --dry-run.";
|
|
891
|
+
var COMPOSE_SELECTION_FLAGS_MESSAGE = "--plugins and --resources are only valid with --compose.";
|
|
892
|
+
var COMPOSE_ON_CONFLICT_MESSAGE = "--on-conflict is only valid with --from, --from-home, or --from-project.";
|
|
893
|
+
function flattenSelectors(value) {
|
|
894
|
+
const parts = Array.isArray(value) ? value : value ? [value] : [];
|
|
895
|
+
return parts.flatMap(
|
|
896
|
+
(entry) => entry.split(",").map((item) => item.trim()).filter(Boolean)
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
function selectedCreateSources(opts) {
|
|
900
|
+
const sources = [];
|
|
901
|
+
if (opts.from) sources.push("from");
|
|
902
|
+
if (opts.compose) sources.push("compose");
|
|
903
|
+
if (opts.fromHome) sources.push("from-home");
|
|
904
|
+
if (opts.fromProject !== void 0) sources.push("from-project");
|
|
905
|
+
return sources;
|
|
906
|
+
}
|
|
907
|
+
function isLibraryCreateSource(opts) {
|
|
908
|
+
return Boolean(opts.compose || opts.fromHome || opts.fromProject !== void 0);
|
|
909
|
+
}
|
|
910
|
+
function assertCreateSourceFlags(opts) {
|
|
911
|
+
if (selectedCreateSources(opts).length > 1) {
|
|
912
|
+
throw new Error(SINGLE_SOURCE_MESSAGE);
|
|
913
|
+
}
|
|
914
|
+
const pluginSelectors = flattenSelectors(opts.plugins);
|
|
915
|
+
const resourceSelectors = flattenSelectors(opts.resources);
|
|
916
|
+
if (!opts.compose && (pluginSelectors.length > 0 || resourceSelectors.length > 0)) {
|
|
917
|
+
throw new Error(COMPOSE_SELECTION_FLAGS_MESSAGE);
|
|
918
|
+
}
|
|
919
|
+
if (opts.compose && opts.onConflict !== void 0) {
|
|
920
|
+
throw new Error(COMPOSE_ON_CONFLICT_MESSAGE);
|
|
921
|
+
}
|
|
922
|
+
if (opts.preview && (opts.use || opts.dryRun)) {
|
|
923
|
+
throw new Error(PREVIEW_USE_MESSAGE);
|
|
924
|
+
}
|
|
925
|
+
if (opts.preview && !isLibraryCreateSource(opts)) {
|
|
926
|
+
throw new Error(PREVIEW_SOURCE_MESSAGE);
|
|
927
|
+
}
|
|
928
|
+
if ((opts.fromHome || opts.fromProject !== void 0) && opts.onConflict) {
|
|
929
|
+
parseHomeProjectConflictPolicy(opts.onConflict);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
function resolvePluginId(selector) {
|
|
933
|
+
const plugin = getPlugin(selector);
|
|
934
|
+
if (!plugin) {
|
|
935
|
+
throw new Error(`Plugin not found: ${selector}`);
|
|
936
|
+
}
|
|
937
|
+
return plugin.id;
|
|
938
|
+
}
|
|
939
|
+
function resolveResourceId(selector) {
|
|
940
|
+
const resource = getResource(selector);
|
|
941
|
+
if (!resource) {
|
|
942
|
+
throw new Error(`Resource not found: ${selector}`);
|
|
943
|
+
}
|
|
944
|
+
return resource.id;
|
|
945
|
+
}
|
|
946
|
+
function parseHomeProjectConflictPolicy(value) {
|
|
947
|
+
if (!value) return "skip";
|
|
948
|
+
const parsed = parseOnConflict(value);
|
|
949
|
+
if (parsed === "skip") return "skip";
|
|
950
|
+
if (parsed === "replace") return "overwrite";
|
|
951
|
+
throw new Error(`Invalid --on-conflict value: ${value}. Use skip or replace.`);
|
|
952
|
+
}
|
|
953
|
+
async function resolveComposeIds(opts, format) {
|
|
954
|
+
const pluginSelectors = flattenSelectors(opts.plugins);
|
|
955
|
+
const resourceSelectors = flattenSelectors(opts.resources);
|
|
956
|
+
if (pluginSelectors.length > 0 || resourceSelectors.length > 0) {
|
|
957
|
+
return {
|
|
958
|
+
pluginIds: pluginSelectors.map(resolvePluginId),
|
|
959
|
+
resourceIds: resourceSelectors.map(resolveResourceId)
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
const shouldPrompt = shouldUseWizard({
|
|
963
|
+
noInteractive: opts.noInteractive ?? opts.yes ?? opts.interactive === false,
|
|
964
|
+
interactive: opts.interactive,
|
|
965
|
+
format,
|
|
966
|
+
missingRequiredArgs: true
|
|
967
|
+
});
|
|
968
|
+
if (!shouldPrompt) {
|
|
969
|
+
throw new Error(
|
|
970
|
+
"A composed profile requires at least one plugin or resource selection"
|
|
971
|
+
);
|
|
972
|
+
}
|
|
973
|
+
return promptComposeSelections();
|
|
974
|
+
}
|
|
975
|
+
async function promptComposeSelections() {
|
|
976
|
+
const answers = await inquirer.prompt([
|
|
977
|
+
{
|
|
978
|
+
type: "checkbox",
|
|
979
|
+
name: "pluginIds",
|
|
980
|
+
message: "Plugins to attach",
|
|
981
|
+
choices: listPlugins().map((plugin) => ({
|
|
982
|
+
name: plugin.name,
|
|
983
|
+
value: plugin.id
|
|
984
|
+
}))
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
type: "checkbox",
|
|
988
|
+
name: "resourceIds",
|
|
989
|
+
message: "Resources to add",
|
|
990
|
+
choices: listResources().map((resource) => ({
|
|
991
|
+
name: `${resource.type}: ${resource.name}`,
|
|
992
|
+
value: resource.id
|
|
993
|
+
}))
|
|
994
|
+
}
|
|
995
|
+
]);
|
|
996
|
+
return {
|
|
997
|
+
pluginIds: answers.pluginIds ?? [],
|
|
998
|
+
resourceIds: answers.resourceIds ?? []
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
function conflictLabel(conflict, index) {
|
|
1002
|
+
if (typeof conflict !== "object" || conflict === null) {
|
|
1003
|
+
return String(conflict);
|
|
1004
|
+
}
|
|
1005
|
+
const row = conflict;
|
|
1006
|
+
if (typeof row.name === "string") {
|
|
1007
|
+
const type = typeof row.type === "string" ? `${row.type}: ` : "";
|
|
1008
|
+
return `${type}${row.name}`;
|
|
1009
|
+
}
|
|
1010
|
+
if (typeof row.existingResource === "object" && row.existingResource !== null) {
|
|
1011
|
+
const resource = row.existingResource;
|
|
1012
|
+
if (typeof resource.name === "string") {
|
|
1013
|
+
const type = typeof resource.type === "string" ? `${resource.type}: ` : "";
|
|
1014
|
+
return `${type}${resource.name}`;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return `Conflict ${index + 1}`;
|
|
1018
|
+
}
|
|
1019
|
+
function sourcePhrase(source) {
|
|
1020
|
+
switch (source) {
|
|
1021
|
+
case "compose":
|
|
1022
|
+
return "compose";
|
|
1023
|
+
case "home":
|
|
1024
|
+
return "home";
|
|
1025
|
+
case "project":
|
|
1026
|
+
return "project";
|
|
1027
|
+
default: {
|
|
1028
|
+
const exhaustive = source;
|
|
1029
|
+
throw new Error(`Unsupported profile create source: ${String(exhaustive)}`);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function printHumanPreview(preview) {
|
|
1034
|
+
ui.success(`Would create profile ${ui.theme.accent(preview.name)} from ${sourcePhrase(preview.source)}`);
|
|
1035
|
+
ui.kvBlock([
|
|
1036
|
+
{ key: "Imports", value: String(preview.totalImports) },
|
|
1037
|
+
{ key: "Conflicts", value: String(preview.conflicts.length) },
|
|
1038
|
+
{ key: "Warnings", value: String(preview.warnings.length) }
|
|
1039
|
+
]);
|
|
1040
|
+
preview.conflicts.forEach((conflict, index) => {
|
|
1041
|
+
ui.info(conflictLabel(conflict, index));
|
|
1042
|
+
});
|
|
1043
|
+
for (const warning of preview.warnings) {
|
|
1044
|
+
ui.warn(warning);
|
|
1045
|
+
}
|
|
1046
|
+
ui.hint(
|
|
1047
|
+
"Re-run without --preview to create. Use --on-conflict replace to replace library copies."
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
async function buildLibraryCreateInput(name, opts, format) {
|
|
1051
|
+
if (opts.compose) {
|
|
1052
|
+
const selections = await resolveComposeIds(opts, format);
|
|
1053
|
+
return {
|
|
1054
|
+
source: "compose",
|
|
1055
|
+
name,
|
|
1056
|
+
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
1057
|
+
pluginIds: selections.pluginIds,
|
|
1058
|
+
resourceIds: selections.resourceIds
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
if (opts.fromHome) {
|
|
1062
|
+
return {
|
|
1063
|
+
source: "home",
|
|
1064
|
+
name,
|
|
1065
|
+
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
1066
|
+
conflictPolicy: parseHomeProjectConflictPolicy(opts.onConflict)
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
if (opts.fromProject !== void 0) {
|
|
1070
|
+
return {
|
|
1071
|
+
source: "project",
|
|
1072
|
+
name,
|
|
1073
|
+
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
1074
|
+
projectPath: opts.fromProject,
|
|
1075
|
+
conflictPolicy: parseHomeProjectConflictPolicy(opts.onConflict)
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
throw new Error(SINGLE_SOURCE_MESSAGE);
|
|
1079
|
+
}
|
|
1080
|
+
async function handleLibraryProfileCreate(name, opts, format) {
|
|
1081
|
+
const input = await buildLibraryCreateInput(name, opts, format);
|
|
1082
|
+
if (opts.preview) {
|
|
1083
|
+
const preview = await previewProfileCreate(input);
|
|
1084
|
+
if (format === "json") {
|
|
1085
|
+
printJson(preview);
|
|
1086
|
+
} else {
|
|
1087
|
+
printHumanPreview(preview);
|
|
1088
|
+
}
|
|
1089
|
+
return "preview";
|
|
1090
|
+
}
|
|
1091
|
+
const result = await commitProfileCreate(input);
|
|
1092
|
+
if (format === "json") {
|
|
1093
|
+
if (!opts.use) {
|
|
1094
|
+
printJson(result);
|
|
1095
|
+
}
|
|
1096
|
+
return "committed";
|
|
1097
|
+
}
|
|
1098
|
+
ui.success(
|
|
1099
|
+
`Created profile ${ui.theme.accent(result.profile.name)} ${ui.icons.bullet} ${formatCount(result.imported_count, "imported", "imported")}`
|
|
1100
|
+
);
|
|
1101
|
+
return "committed";
|
|
1102
|
+
}
|
|
1103
|
+
async function handleProfileCreateCommand(name, opts) {
|
|
1104
|
+
const format = parseOutputFormat(opts.format);
|
|
1105
|
+
const db = getDb();
|
|
1106
|
+
initializeSchema(db);
|
|
1107
|
+
const version = opts.version ?? "1.0.0";
|
|
1108
|
+
assertCreateSourceFlags(opts);
|
|
1109
|
+
if (isLibraryCreateSource(opts)) {
|
|
1110
|
+
const libraryResult = await handleLibraryProfileCreate(name, opts, format);
|
|
1111
|
+
if (libraryResult === "preview") {
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
if (format === "json" && !opts.use) {
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
} else if (opts.from) {
|
|
1118
|
+
const harnesstapDir = getHarnesstapDir();
|
|
1119
|
+
const homeRoot = resolveHomeRoot();
|
|
1120
|
+
const skillNames = parseCommaSeparatedList(opts.skill);
|
|
1121
|
+
const excludeCategories = [
|
|
1122
|
+
...opts.excludeCategory ?? []
|
|
1123
|
+
].flatMap((entry) => entry.split(",").map((part) => part.trim()).filter(Boolean));
|
|
1124
|
+
const onConflictFlag = parsePluginSourceConflictPolicy(opts.onConflict);
|
|
1125
|
+
const harnesses = parseCommaSeparatedList(opts.harness);
|
|
1126
|
+
if (harnesses) {
|
|
1127
|
+
assertSupportedHarnessTargets(harnesses);
|
|
1128
|
+
}
|
|
1129
|
+
const resolvedPackage = resolveSkillPackageCheckout(opts.from, harnesstapDir);
|
|
1130
|
+
const shouldPrompt = shouldUseWizard({
|
|
1131
|
+
noInteractive: opts.yes,
|
|
1132
|
+
interactive: opts.interactive,
|
|
1133
|
+
format,
|
|
1134
|
+
missingRequiredArgs: !opts.all && (!skillNames || skillNames.length === 0)
|
|
1135
|
+
});
|
|
1136
|
+
const wizard = await runPluginCreateFromSourceWizard({
|
|
1137
|
+
pluginName: name,
|
|
1138
|
+
pluginVersion: version,
|
|
1139
|
+
discovered: resolvedPackage.discovered,
|
|
1140
|
+
skillNames,
|
|
1141
|
+
all: opts.all,
|
|
1142
|
+
excludeCategories: excludeCategories.length > 0 ? excludeCategories : void 0,
|
|
1143
|
+
onConflict: onConflictFlag,
|
|
1144
|
+
shouldPrompt
|
|
1145
|
+
});
|
|
1146
|
+
if (wizard.cancelled) {
|
|
1147
|
+
ui.info("Operation cancelled.");
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
const result = await createPluginFromSource({
|
|
1151
|
+
name,
|
|
1152
|
+
source: opts.from,
|
|
1153
|
+
version,
|
|
1154
|
+
description: opts.description,
|
|
1155
|
+
tags: [PROFILE_PLUGIN_TAG],
|
|
1156
|
+
skillNames: wizard.skillNames,
|
|
1157
|
+
all: wizard.all,
|
|
1158
|
+
excludeCategories: excludeCategories.length > 0 ? excludeCategories : void 0,
|
|
1159
|
+
onConflict: onConflictFlag ?? wizard.onConflict,
|
|
1160
|
+
dryRun: opts.dryRun,
|
|
1161
|
+
homeRoot,
|
|
1162
|
+
harnesstapDir
|
|
1163
|
+
});
|
|
1164
|
+
if (!isProfilePlugin(result.plugin)) {
|
|
1165
|
+
tagProfileCommand(result.plugin.name);
|
|
1166
|
+
}
|
|
1167
|
+
if (opts.dryRun && !opts.use) {
|
|
1168
|
+
if (format === "json") {
|
|
1169
|
+
printJson({
|
|
1170
|
+
plugin: result.plugin,
|
|
1171
|
+
created: true,
|
|
1172
|
+
promoted: true,
|
|
1173
|
+
namespace: result.namespace,
|
|
1174
|
+
attached_skills: result.attachedSkills
|
|
1175
|
+
});
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
ui.success(
|
|
1179
|
+
`Dry run ${ui.icons.hint} would create profile ${ui.theme.accent(result.plugin.name)} with ${formatCount(result.attachedSkills.length, "skill")} from ${result.namespace}`
|
|
1180
|
+
);
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
if (format !== "json") {
|
|
1184
|
+
ui.success(
|
|
1185
|
+
`Created profile ${ui.theme.accent(result.plugin.name)} ${ui.icons.bullet} ${formatCount(result.attachedSkills.length, "skill")} attached from ${result.namespace}`
|
|
1186
|
+
);
|
|
1187
|
+
} else if (!opts.use) {
|
|
1188
|
+
printJson({
|
|
1189
|
+
plugin: result.plugin,
|
|
1190
|
+
created: true,
|
|
1191
|
+
promoted: true,
|
|
1192
|
+
namespace: result.namespace,
|
|
1193
|
+
attached_skills: result.attachedSkills
|
|
1194
|
+
});
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
} else {
|
|
1198
|
+
const result = createProfileCommand({
|
|
1199
|
+
name,
|
|
1200
|
+
description: opts.description,
|
|
1201
|
+
version
|
|
1202
|
+
});
|
|
1203
|
+
if (format === "json" && !opts.use) {
|
|
1204
|
+
printJson(result);
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
if (result.created) {
|
|
1208
|
+
ui.success(`Created profile ${ui.theme.accent(result.plugin.name)}`);
|
|
1209
|
+
} else if (result.promoted) {
|
|
1210
|
+
ui.success(`Tagged plugin ${ui.theme.accent(result.plugin.name)} as profile`);
|
|
1211
|
+
} else {
|
|
1212
|
+
ui.info(`Profile ${ui.theme.accent(result.plugin.name)} already exists`);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
if (opts.use) {
|
|
1216
|
+
const conflictPolicy = resolveApplyConflictPolicy({
|
|
1217
|
+
onConflict: opts.onConflictUse
|
|
1218
|
+
});
|
|
1219
|
+
try {
|
|
1220
|
+
if (!opts.dryRun) {
|
|
1221
|
+
const sync = await maybeSyncActiveProfileBeforeSwitch({
|
|
1222
|
+
targetProfileName: name,
|
|
1223
|
+
harness: opts.harness,
|
|
1224
|
+
yes: opts.yes,
|
|
1225
|
+
format
|
|
1226
|
+
});
|
|
1227
|
+
if (sync === "abort") {
|
|
1228
|
+
process.exitCode = 1;
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
const applied = await useProfileCommand(name, {
|
|
1233
|
+
dryRun: opts.dryRun,
|
|
1234
|
+
harness: opts.harness,
|
|
1235
|
+
pull: opts.pull,
|
|
1236
|
+
account: opts.account,
|
|
1237
|
+
baseUrl: opts.baseUrl,
|
|
1238
|
+
conflictPolicy,
|
|
1239
|
+
...conflictPolicy === "prompt" ? { conflictResolver: promptMaterializationConflict } : {}
|
|
1240
|
+
});
|
|
1241
|
+
if (format === "json") {
|
|
1242
|
+
printJson({ apply: applied });
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
if (applied.cancelled) {
|
|
1246
|
+
process.exitCode = 1;
|
|
1247
|
+
ui.warn("Profile apply cancelled.");
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
printApplyPayload(applied);
|
|
1251
|
+
return;
|
|
1252
|
+
} catch (err) {
|
|
1253
|
+
process.exitCode = 1;
|
|
1254
|
+
ui.danger(err instanceof Error ? err.message : String(err));
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
if (format === "json") {
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
try {
|
|
1262
|
+
await maybePromptProfileEnable({
|
|
1263
|
+
profileName: name,
|
|
1264
|
+
format: opts.format,
|
|
1265
|
+
yes: opts.yes,
|
|
1266
|
+
harness: opts.harness,
|
|
1267
|
+
pull: opts.pull,
|
|
1268
|
+
account: opts.account,
|
|
1269
|
+
baseUrl: opts.baseUrl,
|
|
1270
|
+
onConflictUse: opts.onConflictUse
|
|
1271
|
+
});
|
|
1272
|
+
} catch (err) {
|
|
1273
|
+
if (isPromptCancellationError(err)) {
|
|
1274
|
+
ui.info("Operation cancelled.");
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
throw err;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
function registerProfileCreateSourceOptions(command) {
|
|
1281
|
+
return command.option("--compose", "Create by attaching library plugins and resources").option(
|
|
1282
|
+
"--plugins <selectors>",
|
|
1283
|
+
"Compose: plugin names or ids (comma-separated, repeatable)",
|
|
1284
|
+
collectRepeatedOption,
|
|
1285
|
+
[]
|
|
1286
|
+
).option(
|
|
1287
|
+
"--resources <selectors>",
|
|
1288
|
+
"Compose: resource names or ids (comma-separated, repeatable)",
|
|
1289
|
+
collectRepeatedOption,
|
|
1290
|
+
[]
|
|
1291
|
+
).option("--from-home", "Import from global home harness files").option("--from-project <path>", "Import from a project path").option("--preview", "Print create preview without writing").option("--no-interactive", "Don't open the compose picker");
|
|
1292
|
+
}
|
|
1293
|
+
function registerProfileCreateCommand(profileCmd) {
|
|
1294
|
+
const createCmd = profileCmd.command("create").argument("<name>", "Profile plugin name").option("-d, --description <text>", "Profile description").option("--version <semver>", "Plugin version when creating from a source", "1.0.0").option(
|
|
1295
|
+
"--from <source>",
|
|
1296
|
+
"Skill package source (owner/repo, git URL, or local path)"
|
|
1297
|
+
).option("--skill <names>", "Comma-separated skills to attach when using --from").option("--all", "Attach all discovered skills when using --from").option(
|
|
1298
|
+
"--exclude-category <names>",
|
|
1299
|
+
"Exclude skill categories when using --from (repeatable or comma-separated)",
|
|
1300
|
+
collectRepeatedOption,
|
|
1301
|
+
[]
|
|
1302
|
+
).option(
|
|
1303
|
+
"--on-conflict <policy>",
|
|
1304
|
+
`${ON_CONFLICT_PLUGIN_IMPORT_HELP} (default: cancel). merge is plugin import only.`
|
|
1305
|
+
).option("--use", "Apply globally and set as the active profile").option("--dry-run", "Preview profile apply when used with --use").option("--harness <slugs>", "Harness targets for --use").option(
|
|
1306
|
+
"--on-conflict-use <policy>",
|
|
1307
|
+
ON_CONFLICT_APPLY_HELP
|
|
1308
|
+
).option("--account <name>", "Cloud account for dependency pulls during --use").option("--base-url <url>", "Cloud base URL for dependency pulls during --use").option("--no-pull", "Do not auto-pull missing published dependencies during --use").option("--format <mode>", "Output format: human or json", "human").option("--interactive", "Prompt for skill selection when using --from").option("-y, --yes", "Skip prompts when using --from");
|
|
1309
|
+
registerProfileCreateSourceOptions(createCmd).description("Create a profile plugin, promote an existing plugin, or import from a skill package").action(async (name, opts) => {
|
|
1310
|
+
try {
|
|
1311
|
+
await handleProfileCreateCommand(name, opts);
|
|
1312
|
+
} catch (err) {
|
|
1313
|
+
process.exitCode = 1;
|
|
1314
|
+
if (isPromptCancellationError(err)) {
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
ui.danger(err instanceof Error ? err.message : String(err));
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// src/cli/commands/profile.ts
|
|
1323
|
+
async function handleProfilePullCommand(selector, opts) {
|
|
1324
|
+
const installed = await handlePluginInstallCommand(selector, opts);
|
|
1325
|
+
if (!installed || process.exitCode) {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
const installedPlugin = getPlugin(installed.pluginName);
|
|
1329
|
+
if (!installedPlugin || isProfilePlugin(installedPlugin)) {
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
ui.warn(
|
|
1333
|
+
`Installed plugin ${ui.theme.accent(installed.pluginName)} is not tagged as a profile.`
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1336
|
+
function warnProfilePublishValidation(plugin) {
|
|
1337
|
+
const refs = listAttachedPluginRefs(plugin.id);
|
|
1338
|
+
const materialCount = countMaterialPluginResources(plugin.id);
|
|
1339
|
+
if (refs.length === 0 && materialCount === 0) {
|
|
1340
|
+
ui.warn(
|
|
1341
|
+
`Profile ${ui.theme.accent(plugin.name)} has no plugin references and no material resources.`
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
const unresolvedLocalRefs = [];
|
|
1345
|
+
for (const ref of refs) {
|
|
1346
|
+
const local = resolvePluginSelector(
|
|
1347
|
+
ref.version_constraint ? `${ref.dependency_name}@${ref.version_constraint}` : ref.dependency_name
|
|
1348
|
+
);
|
|
1349
|
+
if (!local) {
|
|
1350
|
+
continue;
|
|
1351
|
+
}
|
|
1352
|
+
if (!local.org_slug || !local.catalog_slug) {
|
|
1353
|
+
unresolvedLocalRefs.push(ref.dependency_name);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
if (unresolvedLocalRefs.length > 0) {
|
|
1357
|
+
ui.warn(
|
|
1358
|
+
`Profile ${ui.theme.accent(plugin.name)} references unpublished local plugins: ${unresolvedLocalRefs.join(", ")}`
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
async function handleProfilePublishCommand(pluginName, opts) {
|
|
1363
|
+
const db = getDb();
|
|
1364
|
+
initializeSchema(db);
|
|
1365
|
+
const plugin = getPlugin(pluginName);
|
|
1366
|
+
if (!plugin) {
|
|
1367
|
+
process.exitCode = 1;
|
|
1368
|
+
fail(`Plugin not found: ${pluginName}`);
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
if (!isProfilePlugin(plugin)) {
|
|
1372
|
+
ui.warn(`Plugin "${plugin.name}" is not tagged as a profile.`);
|
|
1373
|
+
}
|
|
1374
|
+
warnProfilePublishValidation(plugin);
|
|
1375
|
+
await handlePluginPublishCommand(pluginName, void 0, { ...opts, kind: "profile" });
|
|
1376
|
+
}
|
|
1377
|
+
function registerProfileCommands(root) {
|
|
1378
|
+
const profileCmd = configureCommandGroup(
|
|
1379
|
+
root.command("profile").alias("p").description("Manage profile plugins and global profile switching")
|
|
1380
|
+
);
|
|
1381
|
+
profileCmd.command("list").alias("ls").option("-s, --search <query>", "Filter by name, description, or tags").option("--remote", "Include remote catalog profile plugins").addOption(new Option("--local-only", "List only local profile plugins").hideHelp()).option("--remote-only", "List only remote catalog profile plugins").option("--account <name>", "Cloud account to use for remote listing").option("--base-url <url>", "HarnessTap Cloud base URL").option("--no-interactive", "Disable interactive wizards").option("--interactive", "Enable interactive wizards").option("--format <mode>", "Output format: human or json", "human").description("List local profile plugins (pass --remote to include the catalog)").action(async (opts) => {
|
|
1382
|
+
const db = getDb();
|
|
1383
|
+
initializeSchema(db);
|
|
1384
|
+
try {
|
|
1385
|
+
await handlePluginListCommand({
|
|
1386
|
+
profileMode: true,
|
|
1387
|
+
localPluginsProvider: listProfilePluginsCommand,
|
|
1388
|
+
tag: PROFILE_PLUGIN_TAG,
|
|
1389
|
+
search: opts.search,
|
|
1390
|
+
remote: opts.remote,
|
|
1391
|
+
localOnly: opts.localOnly,
|
|
1392
|
+
remoteOnly: opts.remoteOnly,
|
|
1393
|
+
format: parseOutputFormat(opts.format),
|
|
1394
|
+
account: opts.account,
|
|
1395
|
+
baseUrl: opts.baseUrl,
|
|
1396
|
+
noInteractive: opts.noInteractive,
|
|
1397
|
+
interactive: opts.interactive
|
|
1398
|
+
});
|
|
1399
|
+
} catch (error) {
|
|
1400
|
+
if (isPromptCancellationError(error)) {
|
|
1401
|
+
process.exitCode = 1;
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1404
|
+
process.exitCode = 1;
|
|
1405
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
profileCmd.command("show").argument("[name]", "Profile plugin name or selector").option("--format <mode>", "Output format: human or json", "human").option("--show-id", "Show IDs in list-oriented human tables").option("--interactive", "Prompt instead of relying on explicit flags").description("Show profile plugin details, resources, and dependencies").action(async (name, opts) => {
|
|
1409
|
+
const db = getDb();
|
|
1410
|
+
initializeSchema(db);
|
|
1411
|
+
const resolvedName = name ?? await resolvePluginMutationTarget({
|
|
1412
|
+
pluginName: name,
|
|
1413
|
+
profileMode: true,
|
|
1414
|
+
interactive: opts.interactive,
|
|
1415
|
+
noInteractive: opts.noInteractive,
|
|
1416
|
+
format: opts.format,
|
|
1417
|
+
message: "Which profile do you want to show?"
|
|
1418
|
+
});
|
|
1419
|
+
if (!resolvedName) {
|
|
1420
|
+
process.exitCode = 1;
|
|
1421
|
+
renderCliError(missingRequiredArg("name", "profile show"));
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
const payload = showProfileCommand(resolvedName);
|
|
1425
|
+
handlePluginShowCommand(formatPluginLabel(payload.profile), opts, {
|
|
1426
|
+
active: payload.active
|
|
1427
|
+
});
|
|
1428
|
+
});
|
|
1429
|
+
profileCmd.command("status").option("--harness <slugs>", "Comma-separated harness slugs (defaults to global harness preference)").option("--depth <mode>", "Status scan depth: fast or full", "full").option("--project <path>", "Project directory for project drift checks").option("--check", "Exit with code 1 when global state is out of sync with the active profile").option("--format <mode>", "Output format: human or json", "human").description("Show the active profile and whether global harness files are in sync").action(async (opts) => {
|
|
1430
|
+
const db = getDb();
|
|
1431
|
+
initializeSchema(db);
|
|
1432
|
+
const format = parseOutputFormat(opts.format);
|
|
1433
|
+
const depth = opts.depth === "fast" ? "fast" : "full";
|
|
1434
|
+
try {
|
|
1435
|
+
const status = await detectGlobalProfileStatus({
|
|
1436
|
+
harness: opts.harness,
|
|
1437
|
+
depth,
|
|
1438
|
+
projectPath: opts.project
|
|
1439
|
+
});
|
|
1440
|
+
if (format === "json") {
|
|
1441
|
+
printJson(status);
|
|
1442
|
+
} else if (!status.active_profile) {
|
|
1443
|
+
ui.info("No active profile set.");
|
|
1444
|
+
} else if (status.warning) {
|
|
1445
|
+
ui.warn(status.warning);
|
|
1446
|
+
} else if (!status.applied) {
|
|
1447
|
+
ui.warn(
|
|
1448
|
+
`Active profile ${ui.theme.accent(status.active_profile)} has not been applied globally yet.`
|
|
1449
|
+
);
|
|
1450
|
+
ui.hint(
|
|
1451
|
+
`Run ${formatHintCommand(["profile", "use", status.active_profile])} to materialize home harness files.`
|
|
1452
|
+
);
|
|
1453
|
+
} else if (!status.has_drift) {
|
|
1454
|
+
ui.success(`Global harness files are in sync with profile ${ui.theme.accent(status.active_profile)}.`);
|
|
1455
|
+
} else {
|
|
1456
|
+
ui.warn(
|
|
1457
|
+
`Global harness files are out of sync with profile ${ui.theme.accent(status.active_profile)}.`
|
|
1458
|
+
);
|
|
1459
|
+
if (!status.stack_in_sync) {
|
|
1460
|
+
ui.dim("Profile stack changed since the last global apply.");
|
|
1461
|
+
}
|
|
1462
|
+
if (status.changes.length > 0) {
|
|
1463
|
+
ui.dim(
|
|
1464
|
+
`${formatCount(status.changes.length, "file")} ${status.changes.length === 1 ? "differs" : "differ"} on disk.`
|
|
1465
|
+
);
|
|
1466
|
+
}
|
|
1467
|
+
ui.hint(
|
|
1468
|
+
`Run ${formatHintCommand(["profile", "use", status.active_profile])} to refresh global harness files.`
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
const collisionCount = status.host_managed?.cursor?.collisions.length ?? 0;
|
|
1472
|
+
if (format !== "json" && collisionCount > 0) {
|
|
1473
|
+
ui.warn(
|
|
1474
|
+
`${formatCount(collisionCount, "Cursor host-managed skill name collision")} with user or profile skills.`
|
|
1475
|
+
);
|
|
1476
|
+
ui.hint(
|
|
1477
|
+
"Cursor built-ins live under ~/.cursor/skills-cursor/ (read-only inventory). User skills belong in ~/.cursor/skills/."
|
|
1478
|
+
);
|
|
1479
|
+
}
|
|
1480
|
+
if (opts.check && status.has_drift) {
|
|
1481
|
+
process.exitCode = 1;
|
|
1482
|
+
}
|
|
1483
|
+
} catch (err) {
|
|
1484
|
+
process.exitCode = 1;
|
|
1485
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
profileCmd.command("use").argument("[name]", "Profile plugin name or selector").option("--profile <name>", "Profile key from apm.yml").option("--project <path>", "Project directory for apm.yml discovery", ".").option("--dry-run", "Show what would be written or removed").option(
|
|
1489
|
+
"--harness <slugs>",
|
|
1490
|
+
"Comma-separated harness slugs (defaults to global harness preference)"
|
|
1491
|
+
).option(
|
|
1492
|
+
"--on-conflict <policy>",
|
|
1493
|
+
ON_CONFLICT_APPLY_HELP
|
|
1494
|
+
).option(
|
|
1495
|
+
"--force-remove",
|
|
1496
|
+
"Also remove user-modified managed files and unmanaged files in the planned removal set"
|
|
1497
|
+
).option("--account <name>", "Cloud account name for dependency pulls").option("--base-url <url>", "Cloud base URL for dependency pulls").option("--no-pull", "Do not auto-pull missing published plugin dependencies").option("--force", "Apply even when the profile is already active and in sync").option("--no-interactive", "Disable interactive prompts").option("--interactive", "Enable interactive prompts").option("-y, --yes", "Install pinned marketplace plugins without a prompt").option("--format <mode>", "Output format: human or json", "human").option(
|
|
1498
|
+
"--changes <action>",
|
|
1499
|
+
SWITCH_CHANGES_FLAG_HELP
|
|
1500
|
+
).description("Switch the active profile and apply globally to harness home paths").action(async (name, opts) => {
|
|
1501
|
+
const db = getDb();
|
|
1502
|
+
initializeSchema(db);
|
|
1503
|
+
const format = parseOutputFormat(opts.format);
|
|
1504
|
+
if (!name) {
|
|
1505
|
+
try {
|
|
1506
|
+
const selection = await resolveProfileUseSelection({
|
|
1507
|
+
name,
|
|
1508
|
+
profile: opts.profile,
|
|
1509
|
+
project: opts.project,
|
|
1510
|
+
interactive: opts.interactive,
|
|
1511
|
+
noInteractive: opts.noInteractive,
|
|
1512
|
+
format: opts.format
|
|
1513
|
+
});
|
|
1514
|
+
if (!selection) {
|
|
1515
|
+
fail(CLI_ERRORS.missingProfileName, { hint: CLI_HINTS.profileUseExample });
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
if (selection.kind === "project") {
|
|
1519
|
+
const result = await executeProjectUse(
|
|
1520
|
+
mapProfileUseDelegationOptions({ ...opts, profile: selection.profileKey })
|
|
1521
|
+
);
|
|
1522
|
+
if (format === "json") {
|
|
1523
|
+
printJson(result);
|
|
1524
|
+
return;
|
|
1525
|
+
}
|
|
1526
|
+
renderProjectUseHuman(result);
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
name = selection.pluginName;
|
|
1530
|
+
} catch (err) {
|
|
1531
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1532
|
+
fail(message, {
|
|
1533
|
+
hint: message === CLI_ERRORS.missingProfileName ? CLI_HINTS.profileUseExample : void 0
|
|
1534
|
+
});
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
const conflictPolicy = resolveApplyConflictPolicy({
|
|
1539
|
+
onConflict: opts.onConflict,
|
|
1540
|
+
noInteractive: opts.noInteractive ?? format === "json"
|
|
1541
|
+
});
|
|
1542
|
+
try {
|
|
1543
|
+
if (!opts.dryRun) {
|
|
1544
|
+
const sync = await maybeSyncActiveProfileBeforeSwitch({
|
|
1545
|
+
targetProfileName: name,
|
|
1546
|
+
harness: opts.harness,
|
|
1547
|
+
format,
|
|
1548
|
+
changes: opts.changes,
|
|
1549
|
+
noInteractive: opts.noInteractive
|
|
1550
|
+
});
|
|
1551
|
+
if (sync === "abort") {
|
|
1552
|
+
process.exitCode = 1;
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
const payload = await useProfileCommand(name, {
|
|
1557
|
+
dryRun: opts.dryRun,
|
|
1558
|
+
harness: opts.harness,
|
|
1559
|
+
pull: opts.pull,
|
|
1560
|
+
account: opts.account,
|
|
1561
|
+
baseUrl: opts.baseUrl,
|
|
1562
|
+
conflictPolicy,
|
|
1563
|
+
forceRemove: opts.forceRemove,
|
|
1564
|
+
yes: Boolean(opts.yes),
|
|
1565
|
+
interactive: opts.noInteractive === true ? false : opts.interactive,
|
|
1566
|
+
...conflictPolicy === "prompt" ? { conflictResolver: promptMaterializationConflict } : {}
|
|
1567
|
+
});
|
|
1568
|
+
if (format === "json") {
|
|
1569
|
+
printJson(payload);
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
if (payload.cancelled) {
|
|
1573
|
+
process.exitCode = 1;
|
|
1574
|
+
ui.warn("Profile apply cancelled.");
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
if (payload.default_environment_name) {
|
|
1578
|
+
ui.info(`Default environment: ${payload.default_environment_name}`);
|
|
1579
|
+
}
|
|
1580
|
+
if ((payload.pulled_plugins?.length ?? 0) > 0) {
|
|
1581
|
+
ui.info(
|
|
1582
|
+
`Pulled ${payload.pulled_plugins?.length ?? 0} missing plugin dependencies:`
|
|
1583
|
+
);
|
|
1584
|
+
for (const pulled of payload.pulled_plugins ?? []) {
|
|
1585
|
+
console.log(` - ${pulled.plugin_name} (${pulled.source})`);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
printApplyPayload(payload);
|
|
1589
|
+
} catch (err) {
|
|
1590
|
+
process.exitCode = 1;
|
|
1591
|
+
if (err instanceof PinnedPluginInstallConsentError) {
|
|
1592
|
+
fail(err.message, { hint: err.hint });
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
failCaught(err);
|
|
1596
|
+
}
|
|
1597
|
+
});
|
|
1598
|
+
const stashCmd = profileCmd.command("stash").option("--dry-run", "Show what would be cleared without writing").option(
|
|
1599
|
+
"--harness <slugs>",
|
|
1600
|
+
"Comma-separated harness slugs (defaults to global harness preference)"
|
|
1601
|
+
).option(
|
|
1602
|
+
"--on-conflict <policy>",
|
|
1603
|
+
ON_CONFLICT_APPLY_HELP
|
|
1604
|
+
).option("--format <mode>", "Output format: human or json", "human").description("Stash untracked on-disk resources for the active profile (like git stash -u)").action(async (opts) => {
|
|
1605
|
+
const db = getDb();
|
|
1606
|
+
initializeSchema(db);
|
|
1607
|
+
const format = parseOutputFormat(opts.format);
|
|
1608
|
+
const conflictPolicy = resolveApplyConflictPolicy({
|
|
1609
|
+
onConflict: opts.onConflict,
|
|
1610
|
+
noInteractive: opts.noInteractive ?? format === "json"
|
|
1611
|
+
});
|
|
1612
|
+
try {
|
|
1613
|
+
const result = await stashProfileCommand({
|
|
1614
|
+
dryRun: opts.dryRun,
|
|
1615
|
+
harness: opts.harness,
|
|
1616
|
+
conflictPolicy,
|
|
1617
|
+
pull: false,
|
|
1618
|
+
...conflictPolicy === "prompt" ? { conflictResolver: promptMaterializationConflict } : {}
|
|
1619
|
+
});
|
|
1620
|
+
if (format === "json") {
|
|
1621
|
+
printJson(result);
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
const stashCount = result.entry.contents.resources.length;
|
|
1625
|
+
if (result.cleared.dry_run) {
|
|
1626
|
+
console.log(dryRunStashLine(stashCount, result.entry.profile_name));
|
|
1627
|
+
printApplyDryRun({
|
|
1628
|
+
wouldWrite: [],
|
|
1629
|
+
wouldRemove: result.cleared.removed_files ?? [],
|
|
1630
|
+
wouldKeep: [],
|
|
1631
|
+
unchanged: 0,
|
|
1632
|
+
header: false
|
|
1633
|
+
});
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
ui.success(
|
|
1637
|
+
`Stashed ${formatCount(stashCount, "untracked resource")} for profile ${ui.theme.accent(result.entry.profile_name)}.`
|
|
1638
|
+
);
|
|
1639
|
+
if ((result.cleared.removed_files?.length ?? 0) > 0) {
|
|
1640
|
+
ui.dim(`Removed ${formatCount(result.cleared.removed_files?.length ?? 0, "managed file")}.`);
|
|
1641
|
+
}
|
|
1642
|
+
ui.hint(`Restore with ${formatCommand(["profile", "stash", "pop"])}.`);
|
|
1643
|
+
} catch (err) {
|
|
1644
|
+
process.exitCode = 1;
|
|
1645
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
1646
|
+
}
|
|
1647
|
+
});
|
|
1648
|
+
stashCmd.command("list").alias("ls").option("--format <mode>", "Output format: human or json", "human").description("List stashed profiles").action((opts) => {
|
|
1649
|
+
const db = getDb();
|
|
1650
|
+
initializeSchema(db);
|
|
1651
|
+
const format = parseOutputFormat(opts.format);
|
|
1652
|
+
const entries = listProfileStashEntries();
|
|
1653
|
+
if (format === "json") {
|
|
1654
|
+
printJson({ entries });
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1657
|
+
if (entries.length === 0) {
|
|
1658
|
+
ui.info("No stashed profiles.");
|
|
1659
|
+
return;
|
|
1660
|
+
}
|
|
1661
|
+
for (const [index, entry] of entries.entries()) {
|
|
1662
|
+
ui.info(
|
|
1663
|
+
`stash@{${index}}: ${ui.theme.accent(entry.profile_name)} (${entry.id})`
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
});
|
|
1667
|
+
stashCmd.command("pop").option("--dry-run", "Show what would be restored without writing").option(
|
|
1668
|
+
"--harness <slugs>",
|
|
1669
|
+
"Comma-separated harness slugs (defaults to global harness preference)"
|
|
1670
|
+
).option(
|
|
1671
|
+
"--on-conflict <policy>",
|
|
1672
|
+
ON_CONFLICT_APPLY_HELP
|
|
1673
|
+
).option("--account <name>", "Cloud account name for dependency pulls").option("--base-url <url>", "Cloud base URL for dependency pulls").option("--no-pull", "Do not auto-pull missing published plugin dependencies").option("--format <mode>", "Output format: human or json", "human").description("Restore the most recent stashed profile and remove it from the stash").action(async (opts) => {
|
|
1674
|
+
const db = getDb();
|
|
1675
|
+
initializeSchema(db);
|
|
1676
|
+
const format = parseOutputFormat(opts.format);
|
|
1677
|
+
const conflictPolicy = resolveApplyConflictPolicy({
|
|
1678
|
+
onConflict: opts.onConflict,
|
|
1679
|
+
noInteractive: opts.noInteractive ?? format === "json"
|
|
1680
|
+
});
|
|
1681
|
+
try {
|
|
1682
|
+
const result = await popProfileStashCommand({
|
|
1683
|
+
dryRun: opts.dryRun,
|
|
1684
|
+
harness: opts.harness,
|
|
1685
|
+
pull: opts.pull,
|
|
1686
|
+
account: opts.account,
|
|
1687
|
+
baseUrl: opts.baseUrl,
|
|
1688
|
+
conflictPolicy,
|
|
1689
|
+
...conflictPolicy === "prompt" ? { conflictResolver: promptMaterializationConflict } : {}
|
|
1690
|
+
});
|
|
1691
|
+
if (format === "json") {
|
|
1692
|
+
printJson(result);
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1695
|
+
if (result.restored.cancelled) {
|
|
1696
|
+
process.exitCode = 1;
|
|
1697
|
+
ui.warn("Profile restore cancelled.");
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
const dryPrefix = result.restored.dry_run ? `${ui.theme.muted("[dry run] ")} ` : "";
|
|
1701
|
+
ui.success(
|
|
1702
|
+
`${dryPrefix}Restored stashed profile ${ui.theme.accent(result.entry.profile_name)}.`
|
|
1703
|
+
);
|
|
1704
|
+
} catch (err) {
|
|
1705
|
+
process.exitCode = 1;
|
|
1706
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
1707
|
+
}
|
|
1708
|
+
});
|
|
1709
|
+
stashCmd.command("apply").option("--dry-run", "Show what would be restored without writing").option(
|
|
1710
|
+
"--harness <slugs>",
|
|
1711
|
+
"Comma-separated harness slugs (defaults to global harness preference)"
|
|
1712
|
+
).option(
|
|
1713
|
+
"--on-conflict <policy>",
|
|
1714
|
+
ON_CONFLICT_APPLY_HELP
|
|
1715
|
+
).option("--account <name>", "Cloud account name for dependency pulls").option("--base-url <url>", "Cloud base URL for dependency pulls").option("--no-pull", "Do not auto-pull missing published plugin dependencies").option("--format <mode>", "Output format: human or json", "human").description("Restore the most recent stashed profile without removing it from the stash").action(async (opts) => {
|
|
1716
|
+
const db = getDb();
|
|
1717
|
+
initializeSchema(db);
|
|
1718
|
+
const format = parseOutputFormat(opts.format);
|
|
1719
|
+
const conflictPolicy = resolveApplyConflictPolicy({
|
|
1720
|
+
onConflict: opts.onConflict,
|
|
1721
|
+
noInteractive: opts.noInteractive ?? format === "json"
|
|
1722
|
+
});
|
|
1723
|
+
try {
|
|
1724
|
+
const result = await applyProfileStashCommand({
|
|
1725
|
+
dryRun: opts.dryRun,
|
|
1726
|
+
harness: opts.harness,
|
|
1727
|
+
pull: opts.pull,
|
|
1728
|
+
account: opts.account,
|
|
1729
|
+
baseUrl: opts.baseUrl,
|
|
1730
|
+
conflictPolicy,
|
|
1731
|
+
...conflictPolicy === "prompt" ? { conflictResolver: promptMaterializationConflict } : {}
|
|
1732
|
+
});
|
|
1733
|
+
if (format === "json") {
|
|
1734
|
+
printJson(result);
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
if (result.restored.cancelled) {
|
|
1738
|
+
process.exitCode = 1;
|
|
1739
|
+
ui.warn("Profile restore cancelled.");
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
if (result.restored.dry_run) {
|
|
1743
|
+
printApplyDryRun({
|
|
1744
|
+
wouldWrite: result.restored.restored_files,
|
|
1745
|
+
wouldRemove: [],
|
|
1746
|
+
wouldKeep: [],
|
|
1747
|
+
unchanged: 0
|
|
1748
|
+
});
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
ui.success(
|
|
1752
|
+
`Applied stashed profile ${ui.theme.accent(result.entry.profile_name)}.`
|
|
1753
|
+
);
|
|
1754
|
+
} catch (err) {
|
|
1755
|
+
process.exitCode = 1;
|
|
1756
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
1757
|
+
}
|
|
1758
|
+
});
|
|
1759
|
+
profileCmd.command("switch").argument("<name>", "Profile plugin name or selector").option("--dry-run", "Show what would be written or removed").option(
|
|
1760
|
+
"--harness <slugs>",
|
|
1761
|
+
"Comma-separated harness slugs (defaults to global harness preference)"
|
|
1762
|
+
).option(
|
|
1763
|
+
"--on-conflict <policy>",
|
|
1764
|
+
ON_CONFLICT_APPLY_HELP
|
|
1765
|
+
).option(
|
|
1766
|
+
"--force-remove",
|
|
1767
|
+
"Also remove user-modified managed files and unmanaged files in the planned removal set"
|
|
1768
|
+
).option("--account <name>", "Cloud account name for dependency pulls").option("--base-url <url>", "Cloud base URL for dependency pulls").option("--no-pull", "Do not auto-pull missing published plugin dependencies").option("--no-interactive", "Disable interactive prompts").option("--interactive", "Enable interactive prompts").option("--format <mode>", "Output format: human or json", "human").option(
|
|
1769
|
+
"--changes <action>",
|
|
1770
|
+
SWITCH_CHANGES_FLAG_HELP
|
|
1771
|
+
).description("Switch the active profile and restore the previous one on failure").action(async (name, opts) => {
|
|
1772
|
+
const db = getDb();
|
|
1773
|
+
initializeSchema(db);
|
|
1774
|
+
const format = parseOutputFormat(opts.format);
|
|
1775
|
+
const conflictPolicy = resolveApplyConflictPolicy({
|
|
1776
|
+
onConflict: opts.onConflict,
|
|
1777
|
+
noInteractive: opts.noInteractive ?? format === "json"
|
|
1778
|
+
});
|
|
1779
|
+
try {
|
|
1780
|
+
if (!opts.dryRun) {
|
|
1781
|
+
const sync = await maybeSyncActiveProfileBeforeSwitch({
|
|
1782
|
+
targetProfileName: name,
|
|
1783
|
+
harness: opts.harness,
|
|
1784
|
+
format,
|
|
1785
|
+
changes: opts.changes,
|
|
1786
|
+
noInteractive: opts.noInteractive
|
|
1787
|
+
});
|
|
1788
|
+
if (sync === "abort") {
|
|
1789
|
+
process.exitCode = 1;
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
const result = await switchProfile(name, {
|
|
1794
|
+
apply: {
|
|
1795
|
+
dryRun: opts.dryRun,
|
|
1796
|
+
harness: opts.harness,
|
|
1797
|
+
pull: opts.pull,
|
|
1798
|
+
account: opts.account,
|
|
1799
|
+
baseUrl: opts.baseUrl,
|
|
1800
|
+
conflictPolicy,
|
|
1801
|
+
forceRemove: opts.forceRemove,
|
|
1802
|
+
...conflictPolicy === "prompt" ? { conflictResolver: promptMaterializationConflict } : {}
|
|
1803
|
+
}
|
|
1804
|
+
});
|
|
1805
|
+
if (format === "json") {
|
|
1806
|
+
printJson(result);
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
if (result.cancelled) {
|
|
1810
|
+
process.exitCode = 1;
|
|
1811
|
+
ui.warn("Profile switch cancelled.");
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1814
|
+
if (!result.ok) {
|
|
1815
|
+
process.exitCode = 1;
|
|
1816
|
+
fail(`Failed to switch to profile ${ui.theme.accent(name)}: ${result.apply_error}`);
|
|
1817
|
+
ui.info(
|
|
1818
|
+
`Restored previous profile ${ui.theme.accent(result.restored.profile_name)}.`
|
|
1819
|
+
);
|
|
1820
|
+
return;
|
|
1821
|
+
}
|
|
1822
|
+
if (result.apply.default_environment_name && !result.apply.dry_run) {
|
|
1823
|
+
ui.info(`Default environment: ${result.apply.default_environment_name}`);
|
|
1824
|
+
}
|
|
1825
|
+
printApplyPayload(result.apply);
|
|
1826
|
+
} catch (err) {
|
|
1827
|
+
process.exitCode = 1;
|
|
1828
|
+
if (err instanceof SwitchRestoreFailedError) {
|
|
1829
|
+
fail(err.message);
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
1833
|
+
}
|
|
1834
|
+
});
|
|
1835
|
+
registerProfileCreateCommand(profileCmd);
|
|
1836
|
+
profileCmd.command("delete").argument("<name>", "Profile plugin name or selector").option("--plugin", "Also delete the underlying plugin without prompting").option("-y, --yes", "Skip the interactive plugin delete prompt").option("--format <mode>", "Output format: human or json", "human").description("Demote a profile plugin and optionally delete the underlying plugin").action(async (name, opts) => {
|
|
1837
|
+
const db = getDb();
|
|
1838
|
+
initializeSchema(db);
|
|
1839
|
+
const format = parseOutputFormat(opts.format);
|
|
1840
|
+
try {
|
|
1841
|
+
const demoted = deleteProfileCommand(name);
|
|
1842
|
+
let pluginDeleted = false;
|
|
1843
|
+
if (opts.plugin || format === "human") {
|
|
1844
|
+
pluginDeleted = await maybePromptProfilePluginDelete({
|
|
1845
|
+
pluginName: demoted.plugin_name,
|
|
1846
|
+
pluginId: demoted.plugin_id,
|
|
1847
|
+
format: opts.format,
|
|
1848
|
+
yes: opts.yes,
|
|
1849
|
+
deletePluginFlag: opts.plugin
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
if (format === "json") {
|
|
1853
|
+
printJson({
|
|
1854
|
+
...demoted,
|
|
1855
|
+
plugin_deleted: pluginDeleted
|
|
1856
|
+
});
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
ui.success(`Demoted profile ${ui.theme.accent(demoted.plugin_name)}`);
|
|
1860
|
+
if (demoted.was_active) {
|
|
1861
|
+
ui.info("Cleared active profile pointer.");
|
|
1862
|
+
}
|
|
1863
|
+
if (pluginDeleted) {
|
|
1864
|
+
ui.success(`Deleted plugin ${ui.theme.accent(demoted.plugin_name)}`);
|
|
1865
|
+
}
|
|
1866
|
+
} catch (err) {
|
|
1867
|
+
process.exitCode = 1;
|
|
1868
|
+
if (isPromptCancellationError(err)) {
|
|
1869
|
+
ui.info("Operation cancelled.");
|
|
1870
|
+
return;
|
|
1871
|
+
}
|
|
1872
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
1873
|
+
}
|
|
1874
|
+
});
|
|
1875
|
+
profileCmd.command("pull").argument("<selector>", "Catalog profile selector").option("--as <name>", "Install as local plugin name").option("--org <slug>", "Organization slug helper for short selectors").option("--catalog <slug>", "Catalog slug helper for short selectors").option("--version <version>", "Plugin version helper for short selectors").option("--account <name>", "Cloud account name").option("--base-url <url>", "Cloud base URL").option("--format <mode>", "Output format: human or json", "human").description("Pull a profile plugin from catalog").action(async (selector, opts) => {
|
|
1876
|
+
await handleProfilePullCommand(selector, opts);
|
|
1877
|
+
});
|
|
1878
|
+
profileCmd.command("publish").argument("<name>", "Profile plugin name").option("--org <slug>", "Organization slug").option("--catalog <slug>", "Catalog slug").option("--account <name>", "Cloud account name").option("--format <mode>", "Output format: human or json", "human").description("Publish a profile plugin with validation warnings").action(async (name, opts) => {
|
|
1879
|
+
await handleProfilePublishCommand(name, opts);
|
|
1880
|
+
});
|
|
1881
|
+
registerProfileParityCommands(profileCmd);
|
|
1882
|
+
}
|
|
1883
|
+
export {
|
|
1884
|
+
registerProfileCommands
|
|
1885
|
+
};
|
|
1886
|
+
//# sourceMappingURL=profile-4JQ6LECP.js.map
|