harnesstap 1.2.0 → 1.3.1

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.
Files changed (202) hide show
  1. package/README.md +28 -15
  2. package/dist/apply-2GRNKR5H.js +67 -0
  3. package/dist/apply-2GRNKR5H.js.map +1 -0
  4. package/dist/approve-KQNCNH2R.js +181 -0
  5. package/dist/approve-KQNCNH2R.js.map +1 -0
  6. package/dist/audit-SLYOZCMI.js +434 -0
  7. package/dist/audit-SLYOZCMI.js.map +1 -0
  8. package/dist/auth-3IEVICFT.js +220 -0
  9. package/dist/auth-3IEVICFT.js.map +1 -0
  10. package/dist/bin.js +166 -0
  11. package/dist/bin.js.map +1 -0
  12. package/dist/chunk-2EIJYDNI.js +10945 -0
  13. package/dist/chunk-2EIJYDNI.js.map +1 -0
  14. package/dist/chunk-2H7UOFLK.js +11 -0
  15. package/dist/chunk-2H7UOFLK.js.map +1 -0
  16. package/dist/chunk-37E5M4JX.js +34 -0
  17. package/dist/chunk-37E5M4JX.js.map +1 -0
  18. package/dist/chunk-3FIWOI3H.js +98 -0
  19. package/dist/chunk-3FIWOI3H.js.map +1 -0
  20. package/dist/chunk-3IWTJCPA.js +6448 -0
  21. package/dist/chunk-3IWTJCPA.js.map +1 -0
  22. package/dist/chunk-3IZ7SEGT.js +346 -0
  23. package/dist/chunk-3IZ7SEGT.js.map +1 -0
  24. package/dist/chunk-3RBYT7QN.js +540 -0
  25. package/dist/chunk-3RBYT7QN.js.map +1 -0
  26. package/dist/chunk-4KNQZDZC.js +115 -0
  27. package/dist/chunk-4KNQZDZC.js.map +1 -0
  28. package/dist/chunk-5F3LNDZG.js +9 -0
  29. package/dist/chunk-5F3LNDZG.js.map +1 -0
  30. package/dist/chunk-63U7QWNY.js +364 -0
  31. package/dist/chunk-63U7QWNY.js.map +1 -0
  32. package/dist/chunk-6BY4BV5G.js +998 -0
  33. package/dist/chunk-6BY4BV5G.js.map +1 -0
  34. package/dist/chunk-7L2K4N25.js +610 -0
  35. package/dist/chunk-7L2K4N25.js.map +1 -0
  36. package/dist/chunk-7LWH5SWH.js +18 -0
  37. package/dist/chunk-7LWH5SWH.js.map +1 -0
  38. package/dist/chunk-BIBUCC2E.js +696 -0
  39. package/dist/chunk-BIBUCC2E.js.map +1 -0
  40. package/dist/chunk-BSOBXLYI.js +172 -0
  41. package/dist/chunk-BSOBXLYI.js.map +1 -0
  42. package/dist/chunk-C4QBVVEH.js +32 -0
  43. package/dist/chunk-C4QBVVEH.js.map +1 -0
  44. package/dist/chunk-CHQGE2HF.js +283 -0
  45. package/dist/chunk-CHQGE2HF.js.map +1 -0
  46. package/dist/chunk-DV74UZJI.js +87 -0
  47. package/dist/chunk-DV74UZJI.js.map +1 -0
  48. package/dist/chunk-DWVAR4BP.js +656 -0
  49. package/dist/chunk-DWVAR4BP.js.map +1 -0
  50. package/dist/chunk-DXKAKKLP.js +302 -0
  51. package/dist/chunk-DXKAKKLP.js.map +1 -0
  52. package/dist/chunk-EIWXS4RM.js +235 -0
  53. package/dist/chunk-EIWXS4RM.js.map +1 -0
  54. package/dist/chunk-EWBCFAF3.js +681 -0
  55. package/dist/chunk-EWBCFAF3.js.map +1 -0
  56. package/dist/chunk-F2L4VNQK.js +1759 -0
  57. package/dist/chunk-F2L4VNQK.js.map +1 -0
  58. package/dist/chunk-G26HZZDJ.js +1359 -0
  59. package/dist/chunk-G26HZZDJ.js.map +1 -0
  60. package/dist/chunk-GQKKX7OE.js +818 -0
  61. package/dist/chunk-GQKKX7OE.js.map +1 -0
  62. package/dist/chunk-GRJY22U6.js +691 -0
  63. package/dist/chunk-GRJY22U6.js.map +1 -0
  64. package/dist/chunk-H6DVP2SI.js +682 -0
  65. package/dist/chunk-H6DVP2SI.js.map +1 -0
  66. package/dist/chunk-HVVPTCKR.js +1173 -0
  67. package/dist/chunk-HVVPTCKR.js.map +1 -0
  68. package/dist/chunk-I6XFZLTJ.js +9 -0
  69. package/dist/chunk-I6XFZLTJ.js.map +1 -0
  70. package/dist/chunk-IBOABSIA.js +17 -0
  71. package/dist/chunk-IBOABSIA.js.map +1 -0
  72. package/dist/chunk-IK524ZDW.js +691 -0
  73. package/dist/chunk-IK524ZDW.js.map +1 -0
  74. package/dist/chunk-IRU7NBOT.js +141 -0
  75. package/dist/chunk-IRU7NBOT.js.map +1 -0
  76. package/dist/chunk-J4CKQXQ6.js +806 -0
  77. package/dist/chunk-J4CKQXQ6.js.map +1 -0
  78. package/dist/chunk-JKGSJGCC.js +311 -0
  79. package/dist/chunk-JKGSJGCC.js.map +1 -0
  80. package/dist/chunk-JQOKQKQT.js +158 -0
  81. package/dist/chunk-JQOKQKQT.js.map +1 -0
  82. package/dist/chunk-JRFUTIEH.js +426 -0
  83. package/dist/chunk-JRFUTIEH.js.map +1 -0
  84. package/dist/chunk-K2BPYEH5.js +491 -0
  85. package/dist/chunk-K2BPYEH5.js.map +1 -0
  86. package/dist/chunk-KCQC7YBK.js +7795 -0
  87. package/dist/chunk-KCQC7YBK.js.map +1 -0
  88. package/dist/chunk-KDAV2GUT.js +1357 -0
  89. package/dist/chunk-KDAV2GUT.js.map +1 -0
  90. package/dist/chunk-KDDXZBMC.js +583 -0
  91. package/dist/chunk-KDDXZBMC.js.map +1 -0
  92. package/dist/chunk-KMWHZSEG.js +41 -0
  93. package/dist/chunk-KMWHZSEG.js.map +1 -0
  94. package/dist/chunk-KRI4R7EM.js +25 -0
  95. package/dist/chunk-KRI4R7EM.js.map +1 -0
  96. package/dist/chunk-LNJ3WZZX.js +186 -0
  97. package/dist/chunk-LNJ3WZZX.js.map +1 -0
  98. package/dist/chunk-MWXA4PFE.js +103 -0
  99. package/dist/chunk-MWXA4PFE.js.map +1 -0
  100. package/dist/chunk-MY62SSKC.js +183 -0
  101. package/dist/chunk-MY62SSKC.js.map +1 -0
  102. package/dist/chunk-NAGAJ5UM.js +145 -0
  103. package/dist/chunk-NAGAJ5UM.js.map +1 -0
  104. package/dist/chunk-NJ7WRKIQ.js +532 -0
  105. package/dist/chunk-NJ7WRKIQ.js.map +1 -0
  106. package/dist/chunk-OS6NUIBJ.js +38 -0
  107. package/dist/chunk-OS6NUIBJ.js.map +1 -0
  108. package/dist/chunk-PXU2OS26.js +238 -0
  109. package/dist/chunk-PXU2OS26.js.map +1 -0
  110. package/dist/chunk-QO4LBDVI.js +496 -0
  111. package/dist/chunk-QO4LBDVI.js.map +1 -0
  112. package/dist/chunk-QRZPQNLX.js +65 -0
  113. package/dist/chunk-QRZPQNLX.js.map +1 -0
  114. package/dist/chunk-SNVAMWB7.js +40 -0
  115. package/dist/chunk-SNVAMWB7.js.map +1 -0
  116. package/dist/chunk-SPRVUATR.js +430 -0
  117. package/dist/chunk-SPRVUATR.js.map +1 -0
  118. package/dist/chunk-SY7G5QEI.js +35 -0
  119. package/dist/chunk-SY7G5QEI.js.map +1 -0
  120. package/dist/chunk-SZNBUIDR.js +6438 -0
  121. package/dist/chunk-SZNBUIDR.js.map +1 -0
  122. package/dist/chunk-TQ2NA4Z4.js +24 -0
  123. package/dist/chunk-TQ2NA4Z4.js.map +1 -0
  124. package/dist/chunk-TYULB6ZY.js +2959 -0
  125. package/dist/chunk-TYULB6ZY.js.map +1 -0
  126. package/dist/chunk-UJYFTXHV.js +296 -0
  127. package/dist/chunk-UJYFTXHV.js.map +1 -0
  128. package/dist/chunk-VC6OKCJF.js +184 -0
  129. package/dist/chunk-VC6OKCJF.js.map +1 -0
  130. package/dist/chunk-VL2NWCZV.js +118 -0
  131. package/dist/chunk-VL2NWCZV.js.map +1 -0
  132. package/dist/chunk-VL7BGD47.js +514 -0
  133. package/dist/chunk-VL7BGD47.js.map +1 -0
  134. package/dist/chunk-VQVUJYYY.js +244 -0
  135. package/dist/chunk-VQVUJYYY.js.map +1 -0
  136. package/dist/chunk-VZQG2JDV.js +9 -0
  137. package/dist/chunk-VZQG2JDV.js.map +1 -0
  138. package/dist/chunk-XFZQVYIN.js +115 -0
  139. package/dist/chunk-XFZQVYIN.js.map +1 -0
  140. package/dist/chunk-XGTTOO4R.js +84 -0
  141. package/dist/chunk-XGTTOO4R.js.map +1 -0
  142. package/dist/chunk-XQFT4PEP.js +60 -0
  143. package/dist/chunk-XQFT4PEP.js.map +1 -0
  144. package/dist/chunk-YDD3ES2K.js +571 -0
  145. package/dist/chunk-YDD3ES2K.js.map +1 -0
  146. package/dist/chunk-ZY2MZ2KQ.js +1140 -0
  147. package/dist/chunk-ZY2MZ2KQ.js.map +1 -0
  148. package/dist/compile-57EEIUMB.js +161 -0
  149. package/dist/compile-57EEIUMB.js.map +1 -0
  150. package/dist/config-4EJ3D7QJ.js +438 -0
  151. package/dist/config-4EJ3D7QJ.js.map +1 -0
  152. package/dist/doctor-EEV6P5CH.js +111 -0
  153. package/dist/doctor-EEV6P5CH.js.map +1 -0
  154. package/dist/environment-WFEG4DAT.js +2745 -0
  155. package/dist/environment-WFEG4DAT.js.map +1 -0
  156. package/dist/github-BSMQD72A.js +114 -0
  157. package/dist/github-BSMQD72A.js.map +1 -0
  158. package/dist/harness-VX3PNVQW.js +746 -0
  159. package/dist/harness-VX3PNVQW.js.map +1 -0
  160. package/dist/help-AW2HKX63.js +2079 -0
  161. package/dist/help-AW2HKX63.js.map +1 -0
  162. package/dist/help-BVFOZD7E.js +1892 -0
  163. package/dist/help-BVFOZD7E.js.map +1 -0
  164. package/dist/index.d.ts +164 -1
  165. package/dist/index.js +50 -59246
  166. package/dist/index.js.map +1 -1
  167. package/dist/init-SPN2GEZ4.js +873 -0
  168. package/dist/init-SPN2GEZ4.js.map +1 -0
  169. package/dist/lock-K2LLUU7H.js +455 -0
  170. package/dist/lock-K2LLUU7H.js.map +1 -0
  171. package/dist/marketplace-VEKSWGX3.js +495 -0
  172. package/dist/marketplace-VEKSWGX3.js.map +1 -0
  173. package/dist/mcp-T6DKIKSF.js +202 -0
  174. package/dist/mcp-T6DKIKSF.js.map +1 -0
  175. package/dist/migrate-OO37WSB2.js +1043 -0
  176. package/dist/migrate-OO37WSB2.js.map +1 -0
  177. package/dist/open-3V3QK5RK.js +32 -0
  178. package/dist/open-3V3QK5RK.js.map +1 -0
  179. package/dist/pack-V32UPC7W.js +99 -0
  180. package/dist/pack-V32UPC7W.js.map +1 -0
  181. package/dist/plugin-KOBNQ7GT.js +64 -0
  182. package/dist/plugin-KOBNQ7GT.js.map +1 -0
  183. package/dist/plugin-from-project-X3VO3MB6.js +16 -0
  184. package/dist/plugin-from-project-X3VO3MB6.js.map +1 -0
  185. package/dist/policy-F5MKZNOC.js +105 -0
  186. package/dist/policy-F5MKZNOC.js.map +1 -0
  187. package/dist/profile-H4PMH4XT.js +1886 -0
  188. package/dist/profile-H4PMH4XT.js.map +1 -0
  189. package/dist/project-QVNEJJGH.js +1392 -0
  190. package/dist/project-QVNEJJGH.js.map +1 -0
  191. package/dist/resource-GL4RLSGI.js +555 -0
  192. package/dist/resource-GL4RLSGI.js.map +1 -0
  193. package/dist/version-PBHZK44K.js +17 -0
  194. package/dist/version-PBHZK44K.js.map +1 -0
  195. package/package.json +21 -14
  196. package/schemas/ap-package.v1.json +36 -0
  197. package/schemas/fixtures/catalog-missing-schema.ap.json +13 -0
  198. package/schemas/fixtures/confidence.ap.json +13 -0
  199. package/schemas/fixtures/context7.ap.json +13 -0
  200. package/schemas/fixtures/minimal-with-schema.ap.json +13 -0
  201. package/schemas/fixtures/superpowers.ap.json +13 -0
  202. package/schemas/fixtures/third-party-skills.ap.json +13 -0
@@ -0,0 +1,1043 @@
1
+ import {
2
+ formatResourceSelectionLabel,
3
+ sortResourcesByUpdatedAt,
4
+ toResourceListRows
5
+ } from "./chunk-BIBUCC2E.js";
6
+ import {
7
+ isLegacyPluginTomlPath,
8
+ isLegacyTomlTransportPath,
9
+ legacyTomlTransportRejection,
10
+ loadVerifiedPackageFiles
11
+ } from "./chunk-MY62SSKC.js";
12
+ import "./chunk-GRJY22U6.js";
13
+ import {
14
+ formatEnvironmentToml,
15
+ importEnvironmentToml,
16
+ listEnvironmentDocuments
17
+ } from "./chunk-IRU7NBOT.js";
18
+ import {
19
+ toPluginChoices
20
+ } from "./chunk-IBOABSIA.js";
21
+ import "./chunk-KRI4R7EM.js";
22
+ import "./chunk-XGTTOO4R.js";
23
+ import "./chunk-PXU2OS26.js";
24
+ import {
25
+ promptForSearchableChoice,
26
+ promptForValue,
27
+ shouldUseWizard
28
+ } from "./chunk-NAGAJ5UM.js";
29
+ import {
30
+ initializeSchema
31
+ } from "./chunk-IK524ZDW.js";
32
+ import {
33
+ getLatestSnapshot
34
+ } from "./chunk-XQFT4PEP.js";
35
+ import "./chunk-3IZ7SEGT.js";
36
+ import "./chunk-I6XFZLTJ.js";
37
+ import "./chunk-7L2K4N25.js";
38
+ import "./chunk-JRFUTIEH.js";
39
+ import {
40
+ getHarnessPreference,
41
+ listProjects,
42
+ registeredFromLegacyParts,
43
+ setHarnessPreference
44
+ } from "./chunk-UJYFTXHV.js";
45
+ import "./chunk-3IWTJCPA.js";
46
+ import "./chunk-HVVPTCKR.js";
47
+ import "./chunk-SPRVUATR.js";
48
+ import "./chunk-EWBCFAF3.js";
49
+ import {
50
+ ManifestValidationError,
51
+ assertArchiveMembersContained,
52
+ assertPluginsCleanForShare,
53
+ buildApPackageFiles,
54
+ buildApPackageFilesForResource,
55
+ envelopeFromFiles,
56
+ getPlugin,
57
+ getPluginById,
58
+ getPluginResources,
59
+ getResource,
60
+ importApPackageFiles,
61
+ isApEnvelopePath,
62
+ isCompositionResourceType,
63
+ listContainedFiles,
64
+ listPluginDependencies,
65
+ listPlugins,
66
+ listResources,
67
+ parseApEnvelope,
68
+ parseResourceSelector,
69
+ readApEnvelope,
70
+ readApPackageFiles,
71
+ resolutionKey,
72
+ resolveComposition,
73
+ resolveResource,
74
+ setPluginResourceOverride,
75
+ slugifyApName,
76
+ writeApEnvelope,
77
+ writeApPackageFiles
78
+ } from "./chunk-2EIJYDNI.js";
79
+ import "./chunk-6BY4BV5G.js";
80
+ import "./chunk-GQKKX7OE.js";
81
+ import {
82
+ configureCommandGroup
83
+ } from "./chunk-G26HZZDJ.js";
84
+ import {
85
+ parseOutputFormat,
86
+ printJson
87
+ } from "./chunk-TQ2NA4Z4.js";
88
+ import {
89
+ fail,
90
+ failCaught
91
+ } from "./chunk-DXKAKKLP.js";
92
+ import {
93
+ formatCount,
94
+ ui
95
+ } from "./chunk-YDD3ES2K.js";
96
+ import "./chunk-ZY2MZ2KQ.js";
97
+ import {
98
+ loadSettings
99
+ } from "./chunk-VQVUJYYY.js";
100
+ import {
101
+ getDb,
102
+ getHarnesstapDir,
103
+ skippedInvalidPluginExport
104
+ } from "./chunk-DWVAR4BP.js";
105
+
106
+ // src/services/migrate-scope.ts
107
+ import { existsSync as existsSync3, statSync as statSync3 } from "fs";
108
+ import { extname, join as join2, resolve as resolve3 } from "path";
109
+
110
+ // src/services/migrate.ts
111
+ import {
112
+ cpSync,
113
+ existsSync,
114
+ mkdirSync,
115
+ mkdtempSync,
116
+ readFileSync,
117
+ readdirSync,
118
+ rmSync,
119
+ statSync,
120
+ writeFileSync
121
+ } from "fs";
122
+ import { tmpdir } from "os";
123
+ import { join, resolve } from "path";
124
+ import { execSync } from "child_process";
125
+ function selectionFromArchive(raw) {
126
+ const rec = raw ?? {};
127
+ if (Array.isArray(rec.registered_harnesses)) {
128
+ return {
129
+ registered_harnesses: rec.registered_harnesses.filter(
130
+ (entry) => typeof entry === "string"
131
+ )
132
+ };
133
+ }
134
+ return {
135
+ registered_harnesses: registeredFromLegacyParts(
136
+ typeof rec.main_harness === "string" ? rec.main_harness : null,
137
+ Array.isArray(rec.alias_harnesses) ? rec.alias_harnesses.filter((entry) => typeof entry === "string") : []
138
+ )
139
+ };
140
+ }
141
+ var MIGRATE_MANIFEST_VERSION_V1 = 1;
142
+ var MIGRATE_MANIFEST_VERSION = 2;
143
+ function writeJson(path, data) {
144
+ writeFileSync(path, JSON.stringify(data, null, 2), "utf-8");
145
+ }
146
+ function listArchiveMembers(archivePath) {
147
+ const listing = execSync(`tar -tzf "${archivePath}"`, {
148
+ encoding: "utf-8",
149
+ stdio: ["ignore", "pipe", "pipe"]
150
+ });
151
+ return listing.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
152
+ }
153
+ function extractArchive(archivePath, destDir) {
154
+ const resolved = resolve(archivePath);
155
+ if (resolved.endsWith(".json") && !resolved.endsWith(".ap.json")) {
156
+ mkdirSync(join(destDir, "state"), { recursive: true });
157
+ cpSync(resolved, join(destDir, "state", "migrate.json"));
158
+ return;
159
+ }
160
+ assertArchiveMembersContained(destDir, listArchiveMembers(resolved));
161
+ execSync(`tar -xzf "${resolved}" -C "${destDir}"`, { stdio: "pipe" });
162
+ listContainedFiles(destDir);
163
+ }
164
+ function createArchive(sourceDir, outputPath) {
165
+ const resolved = resolve(outputPath);
166
+ if (resolved.endsWith(".json") && !resolved.endsWith(".ap.json")) {
167
+ const manifest = readFileSync(join(sourceDir, "manifest.json"), "utf-8");
168
+ const environmentsDir = join(sourceDir, "environments");
169
+ const pluginsDir = join(sourceDir, "plugins");
170
+ const plugins = [];
171
+ if (existsSync(pluginsDir)) {
172
+ for (const entry of readdirSync(pluginsDir)) {
173
+ const packageDir = join(pluginsDir, entry);
174
+ if (!statSync(packageDir).isDirectory()) continue;
175
+ if (!existsSync(join(packageDir, "plugin.json"))) {
176
+ throw new Error(
177
+ `Archive plugin directory ${entry} is missing plugin.json`
178
+ );
179
+ }
180
+ plugins.push(envelopeFromFiles(readApPackageFiles(packageDir)));
181
+ }
182
+ }
183
+ const state = {
184
+ manifest: JSON.parse(manifest),
185
+ harness: existsSync(join(sourceDir, "harness.json")) ? JSON.parse(readFileSync(join(sourceDir, "harness.json"), "utf-8")) : null,
186
+ config: existsSync(join(sourceDir, "config.json")) ? JSON.parse(readFileSync(join(sourceDir, "config.json"), "utf-8")) : null,
187
+ active_profile: existsSync(join(sourceDir, "active-profile.json")) ? JSON.parse(readFileSync(join(sourceDir, "active-profile.json"), "utf-8")) : null,
188
+ plugins
189
+ };
190
+ if (existsSync(environmentsDir)) {
191
+ state.environments = readdirSync(environmentsDir).filter((f) => f.endsWith(".toml")).map((f) => readFileSync(join(environmentsDir, f), "utf-8"));
192
+ }
193
+ writeFileSync(resolved, JSON.stringify(state, null, 2), "utf-8");
194
+ return;
195
+ }
196
+ execSync(`tar -czf "${resolved}" -C "${sourceDir}" .`, { stdio: "pipe" });
197
+ }
198
+ function dirnameSafe(path) {
199
+ const idx = path.lastIndexOf("/");
200
+ return idx >= 0 ? path.slice(0, idx) : ".";
201
+ }
202
+ function isMigrateManifestV1(manifest) {
203
+ return manifest.version === MIGRATE_MANIFEST_VERSION_V1;
204
+ }
205
+ function exportMigrationState(opts) {
206
+ const workDir = mkdtempSync(join(tmpdir(), "harnesstap-migrate-"));
207
+ const pluginsDir = join(workDir, "plugins");
208
+ const environmentsDir = join(workDir, "environments");
209
+ mkdirSync(pluginsDir, { recursive: true });
210
+ mkdirSync(environmentsDir, { recursive: true });
211
+ const plugins = listPlugins();
212
+ const pluginNames = [];
213
+ for (const plugin of plugins) {
214
+ const slug = slugifyApName(plugin.name);
215
+ const packageDir = join(pluginsDir, slug);
216
+ try {
217
+ writeApPackageFiles(buildApPackageFiles(plugin.id), packageDir);
218
+ pluginNames.push(slug);
219
+ } catch (error) {
220
+ if (error instanceof ManifestValidationError) {
221
+ opts.onSkip?.(skippedInvalidPluginExport(plugin.name));
222
+ continue;
223
+ }
224
+ throw error;
225
+ }
226
+ }
227
+ const environments = listEnvironmentDocuments();
228
+ for (const environment of environments) {
229
+ writeFileSync(
230
+ join(environmentsDir, `${environment.name}.toml`),
231
+ formatEnvironmentToml(environment),
232
+ "utf-8"
233
+ );
234
+ }
235
+ const harness = getHarnessPreference();
236
+ if (harness) {
237
+ writeJson(join(workDir, "harness.json"), harness);
238
+ }
239
+ const config = loadSettings(getHarnesstapDir());
240
+ writeJson(join(workDir, "config.json"), config);
241
+ const harnesstapDir = getHarnesstapDir();
242
+ const activeProfilePath = join(harnesstapDir, "active-profile.json");
243
+ const includesActiveProfile = existsSync(activeProfilePath);
244
+ if (includesActiveProfile) {
245
+ cpSync(activeProfilePath, join(workDir, "active-profile.json"));
246
+ }
247
+ const manifest = {
248
+ version: MIGRATE_MANIFEST_VERSION,
249
+ exported_at: (/* @__PURE__ */ new Date()).toISOString(),
250
+ plugin_count: plugins.length,
251
+ environment_count: environments.length,
252
+ plugins: pluginNames,
253
+ include_plugins: opts.includePlugins ?? false,
254
+ includes_active_profile: includesActiveProfile
255
+ };
256
+ writeJson(join(workDir, "manifest.json"), manifest);
257
+ mkdirSync(dirnameSafe(resolve(opts.outputPath)), { recursive: true });
258
+ createArchive(workDir, opts.outputPath);
259
+ rmSync(workDir, { recursive: true, force: true });
260
+ return manifest;
261
+ }
262
+ function importEnvironmentsFromDir(environmentsDir) {
263
+ if (!existsSync(environmentsDir)) {
264
+ return 0;
265
+ }
266
+ let imported = 0;
267
+ for (const file of readdirSync(environmentsDir)) {
268
+ if (!file.endsWith(".toml")) continue;
269
+ importEnvironmentToml(readFileSync(join(environmentsDir, file), "utf-8"));
270
+ imported++;
271
+ }
272
+ return imported;
273
+ }
274
+ function importPluginsFromDir(pluginsDir) {
275
+ if (!existsSync(pluginsDir)) {
276
+ return 0;
277
+ }
278
+ let imported = 0;
279
+ for (const entry of readdirSync(pluginsDir)) {
280
+ const packageDir = join(pluginsDir, entry);
281
+ if (!statSync(packageDir).isDirectory()) {
282
+ if (isLegacyPluginTomlPath(entry) || entry.endsWith(".toml")) {
283
+ throw new Error(
284
+ "This archive stores plugins as TOML, which is no longer supported. Re-export with a current CLI to produce Agent Plugins packages."
285
+ );
286
+ }
287
+ continue;
288
+ }
289
+ if (!existsSync(join(packageDir, "plugin.json"))) {
290
+ throw new Error(
291
+ `Archive plugin directory ${entry} is missing plugin.json`
292
+ );
293
+ }
294
+ importApPackageFiles(readApPackageFiles(packageDir));
295
+ imported++;
296
+ }
297
+ return imported;
298
+ }
299
+ function importMigrationState(opts) {
300
+ const workDir = mkdtempSync(join(tmpdir(), "harnesstap-migrate-import-"));
301
+ try {
302
+ extractArchive(opts.archivePath, workDir);
303
+ let manifest;
304
+ let pluginsDir;
305
+ let environmentsDir;
306
+ let harnessPath;
307
+ let configPath;
308
+ if (existsSync(join(workDir, "state", "migrate.json"))) {
309
+ const state = JSON.parse(
310
+ readFileSync(join(workDir, "state", "migrate.json"), "utf-8")
311
+ );
312
+ manifest = state.manifest;
313
+ pluginsDir = join(workDir, "import-plugins");
314
+ environmentsDir = join(workDir, "import-environments");
315
+ mkdirSync(pluginsDir, { recursive: true });
316
+ mkdirSync(environmentsDir, { recursive: true });
317
+ for (let i = 0; i < state.plugins.length; i++) {
318
+ const packageDir = join(pluginsDir, `plugin-${i}`);
319
+ const envelopeRaw = JSON.stringify(state.plugins[i]);
320
+ const files = parseApEnvelope(envelopeRaw, `archive plugin ${i}`);
321
+ writeApPackageFiles(files, packageDir);
322
+ }
323
+ if (state.environments) {
324
+ for (let i = 0; i < state.environments.length; i++) {
325
+ writeFileSync(
326
+ join(environmentsDir, `environment-${i}.toml`),
327
+ state.environments[i] ?? "",
328
+ "utf-8"
329
+ );
330
+ }
331
+ }
332
+ if (state.harness) {
333
+ writeJson(join(workDir, "harness.json"), state.harness);
334
+ }
335
+ writeJson(join(workDir, "config.json"), state.config);
336
+ if (state.active_profile) {
337
+ writeJson(join(workDir, "active-profile.json"), state.active_profile);
338
+ }
339
+ harnessPath = join(workDir, "harness.json");
340
+ configPath = join(workDir, "config.json");
341
+ } else {
342
+ manifest = JSON.parse(
343
+ readFileSync(join(workDir, "manifest.json"), "utf-8")
344
+ );
345
+ pluginsDir = join(workDir, "plugins");
346
+ environmentsDir = join(workDir, "environments");
347
+ harnessPath = join(workDir, "harness.json");
348
+ configPath = join(workDir, "config.json");
349
+ }
350
+ const activeProfilePath = join(workDir, "active-profile.json");
351
+ if (isMigrateManifestV1(manifest)) {
352
+ throw new Error(
353
+ "This archive uses manifest version 1, which stored plugins as TOML. Version 1 archives were never released and are not supported."
354
+ );
355
+ }
356
+ const manifestVersion = manifest.version;
357
+ if (manifestVersion !== MIGRATE_MANIFEST_VERSION) {
358
+ throw new Error(`Unsupported migration manifest version: ${manifestVersion}`);
359
+ }
360
+ const pluginsImported = importPluginsFromDir(pluginsDir);
361
+ const environmentsImported = importEnvironmentsFromDir(environmentsDir);
362
+ if (existsSync(harnessPath)) {
363
+ const harness = JSON.parse(
364
+ readFileSync(harnessPath, "utf-8")
365
+ );
366
+ setHarnessPreference(selectionFromArchive(harness));
367
+ }
368
+ if (existsSync(configPath)) {
369
+ const config = JSON.parse(
370
+ readFileSync(configPath, "utf-8")
371
+ );
372
+ const targetDir = getHarnesstapDir();
373
+ mkdirSync(targetDir, { recursive: true });
374
+ writeJson(join(targetDir, "config.json"), config);
375
+ }
376
+ if (existsSync(activeProfilePath)) {
377
+ const activeProfile = JSON.parse(
378
+ readFileSync(activeProfilePath, "utf-8")
379
+ );
380
+ const targetDir = getHarnesstapDir();
381
+ mkdirSync(targetDir, { recursive: true });
382
+ writeJson(join(targetDir, "active-profile.json"), activeProfile);
383
+ }
384
+ return {
385
+ manifest,
386
+ plugins_imported: pluginsImported,
387
+ environments_imported: environmentsImported
388
+ };
389
+ } finally {
390
+ rmSync(workDir, { recursive: true, force: true });
391
+ }
392
+ }
393
+
394
+ // src/services/resource-import-export.ts
395
+ import { existsSync as existsSync2, statSync as statSync2 } from "fs";
396
+ import { resolve as resolve2 } from "path";
397
+ function formatResourceSelector(resource) {
398
+ const namePart = resource.namespace ? `${resource.name}@${resource.namespace}` : resource.name;
399
+ return `${resource.type}:${namePart}`;
400
+ }
401
+ function exportResourceToFile(selector, filePath, options) {
402
+ const parsed = parseResourceSelector(selector);
403
+ if (parsed.type && isCompositionResourceType(parsed.type)) {
404
+ throw new Error(
405
+ `Cannot export composition resource type: ${parsed.type}`
406
+ );
407
+ }
408
+ const resolved = resolveResource(selector);
409
+ if (resolved.status !== "found") {
410
+ throw new Error(
411
+ resolved.status === "ambiguous" ? `Ambiguous resource selector: ${selector}` : `Resource not found: ${selector}`
412
+ );
413
+ }
414
+ if (isCompositionResourceType(resolved.resource.type)) {
415
+ throw new Error(
416
+ `Cannot export composition resource type: ${resolved.resource.type}`
417
+ );
418
+ }
419
+ const out = resolve2(filePath);
420
+ const files = buildApPackageFilesForResource(resolved.resource.id);
421
+ const singleFile = options?.singleFile === true || isApEnvelopePath(out);
422
+ const written = singleFile ? (writeApEnvelope(files, out), Object.keys(files).sort()) : writeApPackageFiles(files, out);
423
+ const { id: _id, created_at: _c, updated_at: _u, source: _s, ...payload } = resolved.resource;
424
+ return {
425
+ ...payload,
426
+ files: written
427
+ };
428
+ }
429
+ function importResourceFromFile(filePath) {
430
+ const resolved = resolve2(filePath);
431
+ if (!existsSync2(resolved)) {
432
+ throw new Error(`Path not found: ${resolved}`);
433
+ }
434
+ const packageFiles = statSync2(resolved).isDirectory() ? readApPackageFiles(resolved) : isApEnvelopePath(resolved) ? readApEnvelope(resolved) : (() => {
435
+ throw new Error(
436
+ `${resolved} is not an Agent Plugins package directory or .ap.json envelope.`
437
+ );
438
+ })();
439
+ const plugin = importApPackageFiles(packageFiles);
440
+ const resources = getPluginResources(plugin.id);
441
+ const resource = resources[0];
442
+ if (!resource) {
443
+ throw new Error(`Package ${resolved} did not contain any resources.`);
444
+ }
445
+ const stored = getResource(resource.id) ?? resource;
446
+ return {
447
+ resource: stored,
448
+ action: "created"
449
+ };
450
+ }
451
+
452
+ // src/services/migrate-scope.ts
453
+ function countScopeFlags(opts) {
454
+ let count = 0;
455
+ if (opts.workspace) count++;
456
+ if (opts.plugin) count++;
457
+ if (opts.resource) count++;
458
+ return count;
459
+ }
460
+ function assertExclusiveScopeFlags(opts) {
461
+ if (countScopeFlags(opts) > 1) {
462
+ throw new Error("Choose only one of --workspace, --plugin, or --resource.");
463
+ }
464
+ }
465
+ function rejectEnvironmentScope(opts) {
466
+ if (opts.environment) {
467
+ throw new Error(
468
+ "Environments are no longer exported on their own: they are machine-local secret references. Use --workspace to back them up with everything else."
469
+ );
470
+ }
471
+ }
472
+ function embedPlugins(opts) {
473
+ return opts.includePlugins ?? opts.embedPlugins ?? false;
474
+ }
475
+ function resolvePluginOrThrow(selector) {
476
+ const first = selector.split(",")[0]?.trim() ?? selector;
477
+ const plugin = getPlugin(first);
478
+ if (!plugin) {
479
+ throw new Error(`Plugin not found: ${first}`);
480
+ }
481
+ return plugin;
482
+ }
483
+ function resolveExportScope(opts) {
484
+ rejectEnvironmentScope(opts);
485
+ assertExclusiveScopeFlags(opts);
486
+ const outputPath = opts.outputFile ?? opts.file;
487
+ const resolvedExplicit = outputPath && outputPath.length > 0 ? resolve3(outputPath) : void 0;
488
+ const singleFile = opts.singleFile === true || resolvedExplicit != null && isApEnvelopePath(resolvedExplicit);
489
+ if (opts.plugin) {
490
+ const firstPlugin = opts.plugin.split(",")[0]?.trim() ?? "plugin";
491
+ const apName = slugifyApName(firstPlugin);
492
+ const path = resolvedExplicit ?? resolve3(singleFile ? `${apName}.ap.json` : apName);
493
+ return {
494
+ scope: "plugin",
495
+ outputPath: path,
496
+ pluginSelector: opts.plugin,
497
+ singleFile
498
+ };
499
+ }
500
+ if (opts.resource) {
501
+ const colon = opts.resource.indexOf(":");
502
+ const rest = colon === -1 ? opts.resource : opts.resource.slice(colon + 1);
503
+ const name = slugifyApName(rest.split("@")[0] ?? "export");
504
+ const path = resolvedExplicit ?? resolve3(singleFile ? `${name}.ap.json` : name);
505
+ return {
506
+ scope: "resource",
507
+ outputPath: path,
508
+ resourceSelector: opts.resource,
509
+ singleFile
510
+ };
511
+ }
512
+ if (opts.workspace) {
513
+ if (!outputPath || outputPath.length === 0) {
514
+ throw new Error("Output path is required for workspace export.");
515
+ }
516
+ return { scope: "workspace", outputPath: resolve3(outputPath), singleFile: false };
517
+ }
518
+ if (outputPath && outputPath.length > 0) {
519
+ const resolvedOutput = resolve3(outputPath);
520
+ const lower = resolvedOutput.toLowerCase();
521
+ if (lower.endsWith(".tar.gz")) {
522
+ return { scope: "workspace", outputPath: resolvedOutput, singleFile: false };
523
+ }
524
+ if (extname(resolvedOutput).toLowerCase() === ".json" && !isApEnvelopePath(resolvedOutput)) {
525
+ return { scope: "workspace", outputPath: resolvedOutput, singleFile: false };
526
+ }
527
+ }
528
+ throw new Error(
529
+ "Specify export scope: --workspace, --plugin <name>, or --resource <selector>."
530
+ );
531
+ }
532
+ function detectImportScopeFromFile(filePath) {
533
+ const resolved = resolve3(filePath);
534
+ if (statSync3(resolved).isDirectory()) {
535
+ if (!existsSync3(join2(resolved, "plugin.json"))) {
536
+ throw new Error(
537
+ `${resolved} is a directory but has no plugin.json: expected an Agent Plugins package.`
538
+ );
539
+ }
540
+ return "plugin";
541
+ }
542
+ const lower = resolved.toLowerCase();
543
+ if (lower.endsWith(".tar.gz")) return "workspace";
544
+ if (isApEnvelopePath(resolved) || lower.endsWith(".zip")) return "plugin";
545
+ if (isLegacyTomlTransportPath(resolved)) {
546
+ throw new Error(legacyTomlTransportRejection(resolved));
547
+ }
548
+ throw new Error(
549
+ `Cannot tell what ${resolved} is. Pass an Agent Plugins package directory, an .ap.json envelope, or a .tar.gz workspace archive.`
550
+ );
551
+ }
552
+ function resolveImportScope(opts) {
553
+ rejectEnvironmentScope(opts);
554
+ assertExclusiveScopeFlags({
555
+ workspace: opts.workspace,
556
+ plugin: opts.plugin,
557
+ resource: opts.resource
558
+ });
559
+ if (!opts.file || opts.file.length === 0) {
560
+ throw new Error("Import file path is required.");
561
+ }
562
+ let scope;
563
+ if (opts.workspace) {
564
+ scope = "workspace";
565
+ } else if (opts.plugin) {
566
+ scope = "plugin";
567
+ } else if (opts.resource) {
568
+ scope = "resource";
569
+ } else {
570
+ return detectImportScopeFromFile(opts.file);
571
+ }
572
+ const detected = detectImportScopeFromFile(opts.file);
573
+ if (detected !== scope) {
574
+ throw new Error(
575
+ `Import file looks like ${detected} data but --${scope} was specified.`
576
+ );
577
+ }
578
+ return scope;
579
+ }
580
+ function exportScopedMigration(resolved, opts) {
581
+ const includePlugins = embedPlugins(opts);
582
+ switch (resolved.scope) {
583
+ case "workspace": {
584
+ const manifest = exportMigrationState({
585
+ outputPath: resolved.outputPath,
586
+ includePlugins,
587
+ ...opts.onSkip ? { onSkip: opts.onSkip } : {}
588
+ });
589
+ return {
590
+ scope: "workspace",
591
+ output: resolved.outputPath,
592
+ manifest
593
+ };
594
+ }
595
+ case "plugin": {
596
+ if (!resolved.pluginSelector) {
597
+ throw new Error("Plugin selector is required for plugin export.");
598
+ }
599
+ const plugin = resolvePluginOrThrow(resolved.pluginSelector);
600
+ assertPluginsCleanForShare([plugin]);
601
+ const files = buildApPackageFiles(plugin.id);
602
+ let written;
603
+ if (resolved.singleFile) {
604
+ writeApEnvelope(files, resolved.outputPath);
605
+ written = Object.keys(files).sort();
606
+ } else {
607
+ written = writeApPackageFiles(files, resolved.outputPath);
608
+ }
609
+ return {
610
+ scope: "plugin",
611
+ output: resolved.outputPath,
612
+ plugins: [plugin.name],
613
+ files: written
614
+ };
615
+ }
616
+ case "resource": {
617
+ if (!resolved.resourceSelector) {
618
+ throw new Error("Resource selector is required for resource export.");
619
+ }
620
+ const exportDoc = exportResourceToFile(
621
+ resolved.resourceSelector,
622
+ resolved.outputPath,
623
+ { singleFile: resolved.singleFile }
624
+ );
625
+ return {
626
+ scope: "resource",
627
+ output: resolved.outputPath,
628
+ resource: formatResourceSelector(exportDoc),
629
+ files: exportDoc.files
630
+ };
631
+ }
632
+ default: {
633
+ const neverScope = resolved.scope;
634
+ throw new Error(`Unsupported export scope: ${neverScope}`);
635
+ }
636
+ }
637
+ }
638
+ function importScopedMigration(scope, filePath) {
639
+ const resolved = resolve3(filePath);
640
+ switch (scope) {
641
+ case "workspace": {
642
+ const result = importMigrationState({ archivePath: resolved });
643
+ return {
644
+ scope: "workspace",
645
+ manifest: result.manifest,
646
+ plugins_imported: result.plugins_imported,
647
+ environments_imported: result.environments_imported
648
+ };
649
+ }
650
+ case "plugin": {
651
+ const files = loadVerifiedPackageFiles(resolved);
652
+ const plugin = importApPackageFiles(files);
653
+ return {
654
+ scope: "plugin",
655
+ plugin: plugin.name,
656
+ plugins: [plugin.name],
657
+ resources_imported: getPluginResources(plugin.id).length
658
+ };
659
+ }
660
+ case "resource": {
661
+ const result = importResourceFromFile(resolved);
662
+ return {
663
+ scope: "resource",
664
+ resource: formatResourceSelector(result.resource),
665
+ action: result.action
666
+ };
667
+ }
668
+ default: {
669
+ const neverScope = scope;
670
+ throw new Error(`Unsupported import scope: ${neverScope}`);
671
+ }
672
+ }
673
+ }
674
+
675
+ // src/services/order-to-override-migration.ts
676
+ function migrateOrderToOverrides(options = {}) {
677
+ const report = {
678
+ projectsWithSnapshot: 0,
679
+ projectsWithoutSnapshot: 0,
680
+ overridesWritten: [],
681
+ warnings: []
682
+ };
683
+ const dryRun = options.dryRun === true;
684
+ for (const project of listProjects()) {
685
+ const snapshot = getLatestSnapshot(project.id);
686
+ const state = snapshot?.state;
687
+ const rootPlugin = state?.plugins?.[state.plugins.length - 1];
688
+ if (!rootPlugin) {
689
+ report.projectsWithoutSnapshot += 1;
690
+ continue;
691
+ }
692
+ report.projectsWithSnapshot += 1;
693
+ let resolution;
694
+ try {
695
+ resolution = resolveComposition({ rootSelectors: [rootPlugin.name] });
696
+ } catch {
697
+ report.warnings.push(
698
+ `${project.name}: ${rootPlugin.name} no longer resolves; run \`ht plugin apply ${rootPlugin.name} --explain\` to inspect.`
699
+ );
700
+ continue;
701
+ }
702
+ const previousWinnerByKey = /* @__PURE__ */ new Map();
703
+ for (const resource of state?.resources ?? []) {
704
+ const owner = ownerPluginName(resource.id, resolution.selected);
705
+ if (owner) {
706
+ previousWinnerByKey.set(resolutionKey(resource), owner);
707
+ }
708
+ }
709
+ for (const decision of resolution.decisions) {
710
+ const previous = previousWinnerByKey.get(decision.key);
711
+ if (!previous || previous === decision.winner.pluginName) continue;
712
+ if (!dryRun) {
713
+ setPluginResourceOverride(resolution.root.pluginId, decision.key, previous);
714
+ }
715
+ report.overridesWritten.push({
716
+ root: resolution.root.name,
717
+ key: decision.key,
718
+ winner: previous
719
+ });
720
+ }
721
+ }
722
+ if (report.projectsWithoutSnapshot > 0) {
723
+ for (const project of listProjects()) {
724
+ if (getLatestSnapshot(project.id)) continue;
725
+ const contested = collectContestedKeys();
726
+ if (contested.keys.length > 0) {
727
+ report.warnings.push(
728
+ `${project.name}: no apply snapshot recorded, so previous winners are unknown. Contested: ${contested.keys.join(", ")}. Run \`ht plugin apply ${contested.explainRoot} --explain\` to inspect.`
729
+ );
730
+ } else {
731
+ report.warnings.push(
732
+ `${project.name}: no apply snapshot recorded, so previous winners are unknown.`
733
+ );
734
+ }
735
+ }
736
+ }
737
+ return report;
738
+ }
739
+ function collectContestedKeys() {
740
+ const keys = [];
741
+ let explainRoot = "<root>";
742
+ for (const plugin of listPlugins()) {
743
+ if (listPluginDependencies(plugin.id).length === 0) continue;
744
+ try {
745
+ const resolution = resolveComposition({ rootSelectors: [plugin.name] });
746
+ for (const decision of resolution.decisions) {
747
+ if (decision.losers.length === 0) continue;
748
+ if (!keys.includes(decision.key)) {
749
+ keys.push(decision.key);
750
+ }
751
+ }
752
+ if (explainRoot === "<root>") {
753
+ explainRoot = plugin.name;
754
+ }
755
+ } catch {
756
+ }
757
+ }
758
+ return { keys, explainRoot };
759
+ }
760
+ function ownerPluginName(resourceId, selected) {
761
+ for (const frame of selected) {
762
+ const plugin = getPluginById(frame.pluginId);
763
+ if (!plugin) continue;
764
+ if (getPluginResources(plugin.id).some((resource) => resource.id === resourceId)) {
765
+ return plugin.name;
766
+ }
767
+ }
768
+ return void 0;
769
+ }
770
+
771
+ // src/services/wizards/migrate-export.ts
772
+ import inquirer from "inquirer";
773
+ async function runMigrateExportWizard() {
774
+ const { scope } = await inquirer.prompt([
775
+ {
776
+ type: "list",
777
+ name: "scope",
778
+ message: "What should be exported?",
779
+ choices: [
780
+ { name: "Workspace (full local library)", value: "workspace" },
781
+ { name: "Plugin", value: "plugin" },
782
+ { name: "Resource", value: "resource" }
783
+ ]
784
+ }
785
+ ]);
786
+ if (scope === "plugin") {
787
+ const choices = toPluginChoices();
788
+ const plugin = choices.length > 0 ? await promptForSearchableChoice({ message: "Which plugin?", choices }) : await promptForValue({ message: "Plugin name or ID" });
789
+ const firstPlugin = plugin.split(",")[0]?.trim() ?? "plugin";
790
+ const apName = slugifyApName(firstPlugin);
791
+ const { singleFile } = await inquirer.prompt([
792
+ {
793
+ type: "confirm",
794
+ name: "singleFile",
795
+ message: "Write a single .ap.json envelope?",
796
+ default: false
797
+ }
798
+ ]);
799
+ const outputPath2 = await promptForValue({
800
+ message: "Output path",
801
+ default: singleFile ? `./${apName}.ap.json` : `./${apName}`
802
+ });
803
+ return { scope, plugin, outputPath: outputPath2, singleFile };
804
+ }
805
+ if (scope === "resource") {
806
+ const resources = sortResourcesByUpdatedAt(
807
+ toResourceListRows(listResources()).filter(
808
+ (resource2) => !isCompositionResourceType(resource2.type)
809
+ )
810
+ );
811
+ if (resources.length === 0) {
812
+ throw new Error(
813
+ "No exportable resources in workspace. Scan or create resources first."
814
+ );
815
+ }
816
+ const choices = resources.map((resource2) => ({
817
+ name: formatResourceSelectionLabel(resource2),
818
+ value: `${resource2.type}:${resource2.name}${resource2.namespace ? `@${resource2.namespace}` : ""}`
819
+ }));
820
+ const resource = await promptForSearchableChoice({
821
+ message: "Which resource?",
822
+ choices
823
+ });
824
+ const rest = resource.split(":")[1] ?? "resource";
825
+ const name = slugifyApName(rest.split("@")[0] ?? "resource");
826
+ const { singleFile } = await inquirer.prompt([
827
+ {
828
+ type: "confirm",
829
+ name: "singleFile",
830
+ message: "Write a single .ap.json envelope?",
831
+ default: false
832
+ }
833
+ ]);
834
+ const outputPath2 = await promptForValue({
835
+ message: "Output path",
836
+ default: singleFile ? `./${name}.ap.json` : `./${name}`
837
+ });
838
+ return { scope, resource, outputPath: outputPath2, singleFile };
839
+ }
840
+ const outputPath = await promptForValue({
841
+ message: "Output archive path",
842
+ default: "./harnesstap-backup.tar.gz"
843
+ });
844
+ const { embed } = await inquirer.prompt([
845
+ {
846
+ type: "confirm",
847
+ name: "embed",
848
+ message: "Embed plugin trees in plugin exports?",
849
+ default: false
850
+ }
851
+ ]);
852
+ return { scope, outputPath, embedPlugins: embed };
853
+ }
854
+
855
+ // src/services/wizards/migrate-import.ts
856
+ async function runMigrateImportWizard() {
857
+ const file = await promptForValue({ message: "Import file path" });
858
+ const scope = detectImportScopeFromFile(file);
859
+ return { file, scope };
860
+ }
861
+
862
+ // src/cli/commands/migrate.ts
863
+ function printMigrateExportHuman(result) {
864
+ switch (result.scope) {
865
+ case "workspace":
866
+ ui.success(
867
+ `Exported migration archive ${ui.icons.hint} ${result.output} ${ui.icons.bullet} ${result.manifest.plugin_count} plugins, ${result.manifest.environment_count} environments`
868
+ );
869
+ return;
870
+ case "plugin":
871
+ ui.success(
872
+ `Exported plugin ${ui.theme.accent(result.plugins.join(", "))} ${ui.icons.hint} ${result.output}`
873
+ );
874
+ return;
875
+ case "resource":
876
+ ui.success(
877
+ `Exported resource ${ui.theme.accent(result.resource)} ${ui.icons.hint} ${result.output}`
878
+ );
879
+ return;
880
+ default: {
881
+ const neverResult = result;
882
+ throw new Error(`Unsupported export result: ${String(neverResult)}`);
883
+ }
884
+ }
885
+ }
886
+ function printMigrateImportHuman(result) {
887
+ switch (result.scope) {
888
+ case "workspace":
889
+ ui.success(
890
+ `Imported migration archive ${ui.icons.bullet} ${formatCount(result.plugins_imported, "plugin")}, ${formatCount(result.environments_imported, "environment")}`
891
+ );
892
+ return;
893
+ case "plugin":
894
+ ui.success(
895
+ `Imported plugin ${ui.theme.accent(result.plugin)} ${ui.icons.bullet} ${formatCount(result.resources_imported, "resource")}`
896
+ );
897
+ return;
898
+ case "resource":
899
+ ui.success(
900
+ `Imported resource ${ui.theme.accent(result.resource)} ${ui.icons.bullet} ${result.action}`
901
+ );
902
+ return;
903
+ default: {
904
+ const neverResult = result;
905
+ throw new Error(`Unsupported import result: ${String(neverResult)}`);
906
+ }
907
+ }
908
+ }
909
+ async function handleMigrateExportCommand(file, opts) {
910
+ const db = getDb();
911
+ initializeSchema(db, { allowLegacyRead: true });
912
+ const format = parseOutputFormat(opts.format);
913
+ let exportOpts = {
914
+ ...opts,
915
+ file: opts.file ?? file
916
+ };
917
+ const useWizard = shouldUseWizard({
918
+ interactive: opts.interactive,
919
+ noInteractive: opts.noInteractive,
920
+ format: opts.format,
921
+ missingRequiredArgs: !exportOpts.file && !exportOpts.plugin && !exportOpts.resource && !exportOpts.environment && !exportOpts.workspace
922
+ });
923
+ if (useWizard) {
924
+ const wizard = await runMigrateExportWizard();
925
+ exportOpts = {
926
+ ...exportOpts,
927
+ file: wizard.outputPath,
928
+ workspace: wizard.scope === "workspace" ? true : void 0,
929
+ plugin: wizard.plugin,
930
+ resource: wizard.resource,
931
+ includePlugins: wizard.embedPlugins,
932
+ singleFile: wizard.singleFile
933
+ };
934
+ }
935
+ try {
936
+ const resolved = resolveExportScope(exportOpts);
937
+ const result = exportScopedMigration(resolved, {
938
+ ...exportOpts,
939
+ onSkip: (message) => ui.warn(message)
940
+ });
941
+ if (format === "json") {
942
+ if (result.scope === "workspace") {
943
+ printJson({ ...result.manifest, output: result.output, scope: result.scope });
944
+ return;
945
+ }
946
+ printJson(result);
947
+ return;
948
+ }
949
+ printMigrateExportHuman(result);
950
+ } catch (err) {
951
+ fail(err instanceof Error ? err.message : String(err));
952
+ process.exitCode = 1;
953
+ }
954
+ }
955
+ async function handleMigrateImportCommand(file, opts = {}) {
956
+ const db = getDb();
957
+ initializeSchema(db);
958
+ const format = parseOutputFormat(opts.format);
959
+ let importFile = file;
960
+ let scopeOverride;
961
+ const useWizard = shouldUseWizard({
962
+ interactive: opts.interactive,
963
+ noInteractive: opts.noInteractive,
964
+ format: opts.format,
965
+ missingRequiredArgs: !importFile
966
+ });
967
+ if (useWizard) {
968
+ const wizard = await runMigrateImportWizard();
969
+ importFile = wizard.file;
970
+ scopeOverride = wizard.scope;
971
+ }
972
+ if (!importFile) {
973
+ fail("Import file path is required.");
974
+ process.exitCode = 1;
975
+ return;
976
+ }
977
+ try {
978
+ const scope = scopeOverride ?? resolveImportScope({ ...opts, file: importFile });
979
+ const result = importScopedMigration(scope, importFile);
980
+ if (format === "json") {
981
+ printJson(result);
982
+ return;
983
+ }
984
+ printMigrateImportHuman(result);
985
+ } catch (err) {
986
+ failCaught(err);
987
+ }
988
+ }
989
+ function printMigrateResolveOrderHuman(report, dryRun) {
990
+ const dryRunSuffix = dryRun ? ` ${ui.icons.bullet} dry-run` : "";
991
+ if (report.overridesWritten.length === 0) {
992
+ const aligned = report.projectsWithSnapshot > 0 ? "Last applied winners already match current resolution. No overrides to write" : "No apply snapshots to compare. No overrides to write";
993
+ ui.success(`${aligned}${dryRunSuffix}`);
994
+ } else {
995
+ const overrideCount = formatCount(report.overridesWritten.length, "override");
996
+ const projectCount = formatCount(report.projectsWithSnapshot, "project");
997
+ const verb = dryRun ? "Would write" : "Wrote";
998
+ ui.success(
999
+ `${verb} ${overrideCount} across ${projectCount}${dryRunSuffix}`
1000
+ );
1001
+ }
1002
+ for (const warning of report.warnings) {
1003
+ ui.warn(warning);
1004
+ }
1005
+ }
1006
+ function handleMigrateResolveOrderCommand(opts) {
1007
+ const db = getDb();
1008
+ initializeSchema(db, { allowLegacyRead: true });
1009
+ const format = parseOutputFormat(opts.format);
1010
+ const dryRun = opts.dryRun === true;
1011
+ const report = migrateOrderToOverrides({ dryRun });
1012
+ if (format === "json") {
1013
+ printJson(report);
1014
+ return;
1015
+ }
1016
+ printMigrateResolveOrderHuman(report, dryRun);
1017
+ }
1018
+ function registerMigrateCommands(root) {
1019
+ const migrateCmd = configureCommandGroup(
1020
+ root.command("migrate").alias("m").description("Export or import workspace, plugins, or resources for offline sharing")
1021
+ );
1022
+ migrateCmd.command("export").argument(
1023
+ "[file]",
1024
+ "Output path (package directory, .ap.json envelope, or .tar.gz workspace archive)"
1025
+ ).option("--workspace", "Export full workspace archive").option("--plugin <name>", "Export plugin(s); comma-separated names or IDs").option("--resource <selector>", "Export one resource (type:name or type:name@namespace)").option(
1026
+ "--environment <name>",
1027
+ "Removed: environments are machine-local; use --workspace"
1028
+ ).option("--single-file", "Write a .ap.json envelope instead of a package directory").option("-o, --file <path>", "Output path (overrides positional)").option("--include-plugins", "Embed plugin trees (workspace scope)").option("--embed-plugins", "Alias for --include-plugins").option("--format <mode>", "Output format: human or json", "human").description("Export workspace, plugin, or resource for offline sharing").action(handleMigrateExportCommand);
1029
+ migrateCmd.command("import").argument(
1030
+ "[file]",
1031
+ "package directory, .ap.json envelope, or .tar.gz workspace archive"
1032
+ ).option("--workspace", "Force workspace archive import").option("--plugin", "Force Agent Plugins package import").option("--resource", "Force single-resource package import").option(
1033
+ "--environment",
1034
+ "Removed: environments are machine-local; use --workspace"
1035
+ ).option("--format <mode>", "Output format: human or json", "human").description("Import workspace, plugin, or resource from file").action(handleMigrateImportCommand);
1036
+ migrateCmd.command("resolve-order").option("--dry-run", "Report what would be written without writing").option("--format <mode>", "Output format: human or json", "human").description(
1037
+ "Pin last-applied resource winners as overrides where current resolution would pick a different plugin"
1038
+ ).action(handleMigrateResolveOrderCommand);
1039
+ }
1040
+ export {
1041
+ registerMigrateCommands
1042
+ };
1043
+ //# sourceMappingURL=migrate-OO37WSB2.js.map