@ai-primitives-hub/app 0.0.1-alpha.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 (206) hide show
  1. package/README.md +26 -0
  2. package/dist/collection/generate-skill.d.ts +43 -0
  3. package/dist/collection/generate-skill.d.ts.map +1 -0
  4. package/dist/collection/generate-skill.js +244 -0
  5. package/dist/collection/generate-skill.js.map +1 -0
  6. package/dist/collection/index.d.ts +8 -0
  7. package/dist/collection/index.d.ts.map +1 -0
  8. package/dist/collection/index.js +23 -0
  9. package/dist/collection/index.js.map +1 -0
  10. package/dist/collection/read-collection.d.ts +60 -0
  11. package/dist/collection/read-collection.d.ts.map +1 -0
  12. package/dist/collection/read-collection.js +291 -0
  13. package/dist/collection/read-collection.js.map +1 -0
  14. package/dist/context-detection/detector.d.ts +126 -0
  15. package/dist/context-detection/detector.d.ts.map +1 -0
  16. package/dist/context-detection/detector.js +408 -0
  17. package/dist/context-detection/detector.js.map +1 -0
  18. package/dist/context-detection/index.d.ts +11 -0
  19. package/dist/context-detection/index.d.ts.map +1 -0
  20. package/dist/context-detection/index.js +14 -0
  21. package/dist/context-detection/index.js.map +1 -0
  22. package/dist/context-detection/types.d.ts +74 -0
  23. package/dist/context-detection/types.d.ts.map +1 -0
  24. package/dist/context-detection/types.js +13 -0
  25. package/dist/context-detection/types.js.map +1 -0
  26. package/dist/discovery/index.d.ts +7 -0
  27. package/dist/discovery/index.d.ts.map +1 -0
  28. package/dist/discovery/index.js +23 -0
  29. package/dist/discovery/index.js.map +1 -0
  30. package/dist/discovery/profile-generator.d.ts +31 -0
  31. package/dist/discovery/profile-generator.d.ts.map +1 -0
  32. package/dist/discovery/profile-generator.js +55 -0
  33. package/dist/discovery/profile-generator.js.map +1 -0
  34. package/dist/discovery/recommendation-engine.d.ts +76 -0
  35. package/dist/discovery/recommendation-engine.d.ts.map +1 -0
  36. package/dist/discovery/recommendation-engine.js +210 -0
  37. package/dist/discovery/recommendation-engine.js.map +1 -0
  38. package/dist/index.d.ts +31 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +49 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/install/index.d.ts +14 -0
  43. package/dist/install/index.d.ts.map +1 -0
  44. package/dist/install/index.js +20 -0
  45. package/dist/install/index.js.map +1 -0
  46. package/dist/install/install-bundle.d.ts +31 -0
  47. package/dist/install/install-bundle.d.ts.map +1 -0
  48. package/dist/install/install-bundle.js +23 -0
  49. package/dist/install/install-bundle.js.map +1 -0
  50. package/dist/install/layout-resolver.d.ts +31 -0
  51. package/dist/install/layout-resolver.d.ts.map +1 -0
  52. package/dist/install/layout-resolver.js +70 -0
  53. package/dist/install/layout-resolver.js.map +1 -0
  54. package/dist/install/pipeline.d.ts +111 -0
  55. package/dist/install/pipeline.d.ts.map +1 -0
  56. package/dist/install/pipeline.js +138 -0
  57. package/dist/install/pipeline.js.map +1 -0
  58. package/dist/install/uninstall-bundle.d.ts +36 -0
  59. package/dist/install/uninstall-bundle.d.ts.map +1 -0
  60. package/dist/install/uninstall-bundle.js +37 -0
  61. package/dist/install/uninstall-bundle.js.map +1 -0
  62. package/dist/install/uninstall-pipeline.d.ts +119 -0
  63. package/dist/install/uninstall-pipeline.d.ts.map +1 -0
  64. package/dist/install/uninstall-pipeline.js +187 -0
  65. package/dist/install/uninstall-pipeline.js.map +1 -0
  66. package/dist/registry/activate-registry-profile.d.ts +67 -0
  67. package/dist/registry/activate-registry-profile.d.ts.map +1 -0
  68. package/dist/registry/activate-registry-profile.js +150 -0
  69. package/dist/registry/activate-registry-profile.js.map +1 -0
  70. package/dist/registry/create-source-adapter.d.ts +43 -0
  71. package/dist/registry/create-source-adapter.d.ts.map +1 -0
  72. package/dist/registry/create-source-adapter.js +53 -0
  73. package/dist/registry/create-source-adapter.js.map +1 -0
  74. package/dist/registry/deactivate-registry-profile.d.ts +38 -0
  75. package/dist/registry/deactivate-registry-profile.d.ts.map +1 -0
  76. package/dist/registry/deactivate-registry-profile.js +45 -0
  77. package/dist/registry/deactivate-registry-profile.js.map +1 -0
  78. package/dist/registry/detect-updates.d.ts +12 -0
  79. package/dist/registry/detect-updates.d.ts.map +1 -0
  80. package/dist/registry/detect-updates.js +76 -0
  81. package/dist/registry/detect-updates.js.map +1 -0
  82. package/dist/registry/hub-manager.d.ts +229 -0
  83. package/dist/registry/hub-manager.d.ts.map +1 -0
  84. package/dist/registry/hub-manager.js +473 -0
  85. package/dist/registry/hub-manager.js.map +1 -0
  86. package/dist/registry/index.d.ts +23 -0
  87. package/dist/registry/index.d.ts.map +1 -0
  88. package/dist/registry/index.js +39 -0
  89. package/dist/registry/index.js.map +1 -0
  90. package/dist/registry/install-registry-bundle.d.ts +56 -0
  91. package/dist/registry/install-registry-bundle.d.ts.map +1 -0
  92. package/dist/registry/install-registry-bundle.js +150 -0
  93. package/dist/registry/install-registry-bundle.js.map +1 -0
  94. package/dist/registry/list-all-profiles.d.ts +27 -0
  95. package/dist/registry/list-all-profiles.d.ts.map +1 -0
  96. package/dist/registry/list-all-profiles.js +52 -0
  97. package/dist/registry/list-all-profiles.js.map +1 -0
  98. package/dist/registry/list-installed-bundles.d.ts +37 -0
  99. package/dist/registry/list-installed-bundles.d.ts.map +1 -0
  100. package/dist/registry/list-installed-bundles.js +27 -0
  101. package/dist/registry/list-installed-bundles.js.map +1 -0
  102. package/dist/registry/load-hub-sources.d.ts +56 -0
  103. package/dist/registry/load-hub-sources.d.ts.map +1 -0
  104. package/dist/registry/load-hub-sources.js +123 -0
  105. package/dist/registry/load-hub-sources.js.map +1 -0
  106. package/dist/registry/local-profile-crud.d.ts +58 -0
  107. package/dist/registry/local-profile-crud.d.ts.map +1 -0
  108. package/dist/registry/local-profile-crud.js +85 -0
  109. package/dist/registry/local-profile-crud.js.map +1 -0
  110. package/dist/registry/profile-lifecycle.d.ts +190 -0
  111. package/dist/registry/profile-lifecycle.d.ts.map +1 -0
  112. package/dist/registry/profile-lifecycle.js +400 -0
  113. package/dist/registry/profile-lifecycle.js.map +1 -0
  114. package/dist/registry/registry-settings.d.ts +32 -0
  115. package/dist/registry/registry-settings.d.ts.map +1 -0
  116. package/dist/registry/registry-settings.js +145 -0
  117. package/dist/registry/registry-settings.js.map +1 -0
  118. package/dist/registry/resolve-installation-bundle.d.ts +46 -0
  119. package/dist/registry/resolve-installation-bundle.d.ts.map +1 -0
  120. package/dist/registry/resolve-installation-bundle.js +98 -0
  121. package/dist/registry/resolve-installation-bundle.js.map +1 -0
  122. package/dist/registry/search-registry-bundles.d.ts +47 -0
  123. package/dist/registry/search-registry-bundles.d.ts.map +1 -0
  124. package/dist/registry/search-registry-bundles.js +129 -0
  125. package/dist/registry/search-registry-bundles.js.map +1 -0
  126. package/dist/registry/uninstall-installed-bundle.d.ts +48 -0
  127. package/dist/registry/uninstall-installed-bundle.d.ts.map +1 -0
  128. package/dist/registry/uninstall-installed-bundle.js +45 -0
  129. package/dist/registry/uninstall-installed-bundle.js.map +1 -0
  130. package/dist/registry/update-registry-bundle.d.ts +36 -0
  131. package/dist/registry/update-registry-bundle.d.ts.map +1 -0
  132. package/dist/registry/update-registry-bundle.js +113 -0
  133. package/dist/registry/update-registry-bundle.js.map +1 -0
  134. package/dist/registry/user-config-paths.d.ts +24 -0
  135. package/dist/registry/user-config-paths.d.ts.map +1 -0
  136. package/dist/registry/user-config-paths.js +82 -0
  137. package/dist/registry/user-config-paths.js.map +1 -0
  138. package/dist/registry/version-consolidator.d.ts +123 -0
  139. package/dist/registry/version-consolidator.d.ts.map +1 -0
  140. package/dist/registry/version-consolidator.js +231 -0
  141. package/dist/registry/version-consolidator.js.map +1 -0
  142. package/dist/search/export-profile.d.ts +63 -0
  143. package/dist/search/export-profile.d.ts.map +1 -0
  144. package/dist/search/export-profile.js +138 -0
  145. package/dist/search/export-profile.js.map +1 -0
  146. package/dist/search/index.d.ts +6 -0
  147. package/dist/search/index.d.ts.map +1 -0
  148. package/dist/search/index.js +22 -0
  149. package/dist/search/index.js.map +1 -0
  150. package/dist/stores/index.d.ts +8 -0
  151. package/dist/stores/index.d.ts.map +1 -0
  152. package/dist/stores/index.js +24 -0
  153. package/dist/stores/index.js.map +1 -0
  154. package/dist/stores/json-lockfile-store.d.ts +203 -0
  155. package/dist/stores/json-lockfile-store.d.ts.map +1 -0
  156. package/dist/stores/json-lockfile-store.js +277 -0
  157. package/dist/stores/json-lockfile-store.js.map +1 -0
  158. package/dist/transform/index.d.ts +10 -0
  159. package/dist/transform/index.d.ts.map +1 -0
  160. package/dist/transform/index.js +26 -0
  161. package/dist/transform/index.js.map +1 -0
  162. package/dist/transform/transformer-registry.d.ts +52 -0
  163. package/dist/transform/transformer-registry.d.ts.map +1 -0
  164. package/dist/transform/transformer-registry.js +53 -0
  165. package/dist/transform/transformer-registry.js.map +1 -0
  166. package/dist/transform/transformers/claude-code-transformer.d.ts +67 -0
  167. package/dist/transform/transformers/claude-code-transformer.d.ts.map +1 -0
  168. package/dist/transform/transformers/claude-code-transformer.js +140 -0
  169. package/dist/transform/transformers/claude-code-transformer.js.map +1 -0
  170. package/dist/transform/transformers/kiro-transformer.d.ts +51 -0
  171. package/dist/transform/transformers/kiro-transformer.d.ts.map +1 -0
  172. package/dist/transform/transformers/kiro-transformer.js +128 -0
  173. package/dist/transform/transformers/kiro-transformer.js.map +1 -0
  174. package/dist/transform/transformers/noop-transformer.d.ts +25 -0
  175. package/dist/transform/transformers/noop-transformer.d.ts.map +1 -0
  176. package/dist/transform/transformers/noop-transformer.js +20 -0
  177. package/dist/transform/transformers/noop-transformer.js.map +1 -0
  178. package/dist/transform/transformers/windsurf-transformer.d.ts +63 -0
  179. package/dist/transform/transformers/windsurf-transformer.d.ts.map +1 -0
  180. package/dist/transform/transformers/windsurf-transformer.js +125 -0
  181. package/dist/transform/transformers/windsurf-transformer.js.map +1 -0
  182. package/dist/update/auto-update.d.ts +84 -0
  183. package/dist/update/auto-update.d.ts.map +1 -0
  184. package/dist/update/auto-update.js +217 -0
  185. package/dist/update/auto-update.js.map +1 -0
  186. package/dist/update/check-updates.d.ts +51 -0
  187. package/dist/update/check-updates.d.ts.map +1 -0
  188. package/dist/update/check-updates.js +168 -0
  189. package/dist/update/check-updates.js.map +1 -0
  190. package/dist/update/index.d.ts +8 -0
  191. package/dist/update/index.d.ts.map +1 -0
  192. package/dist/update/index.js +24 -0
  193. package/dist/update/index.js.map +1 -0
  194. package/dist/update/log-event.d.ts +15 -0
  195. package/dist/update/log-event.d.ts.map +1 -0
  196. package/dist/update/log-event.js +11 -0
  197. package/dist/update/log-event.js.map +1 -0
  198. package/dist/writers/file-tree-writer.d.ts +136 -0
  199. package/dist/writers/file-tree-writer.d.ts.map +1 -0
  200. package/dist/writers/file-tree-writer.js +337 -0
  201. package/dist/writers/file-tree-writer.js.map +1 -0
  202. package/dist/writers/index.d.ts +7 -0
  203. package/dist/writers/index.d.ts.map +1 -0
  204. package/dist/writers/index.js +23 -0
  205. package/dist/writers/index.js.map +1 -0
  206. package/package.json +50 -0
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLocalProfile = createLocalProfile;
4
+ exports.updateLocalProfile = updateLocalProfile;
5
+ exports.deleteLocalProfile = deleteLocalProfile;
6
+ exports.listLocalProfiles = listLocalProfiles;
7
+ exports.exportLocalProfile = exportLocalProfile;
8
+ exports.importLocalProfile = importLocalProfile;
9
+ /**
10
+ * Create a new local profile, stamping `createdAt`/`updatedAt`.
11
+ * @param store Local profile storage.
12
+ * @param profile The profile to create (timestamps are set here).
13
+ * @returns The created profile, including its stamped timestamps.
14
+ */
15
+ async function createLocalProfile(store, profile) {
16
+ const fullProfile = {
17
+ ...profile,
18
+ createdAt: new Date().toISOString(),
19
+ updatedAt: new Date().toISOString()
20
+ };
21
+ await store.addProfile(fullProfile);
22
+ return fullProfile;
23
+ }
24
+ /**
25
+ * Update a local profile, stamping a new `updatedAt`.
26
+ * @param store Local profile storage.
27
+ * @param profileId Profile to update.
28
+ * @param updates Partial fields to merge in.
29
+ * @returns The updated profile, or `undefined` if it could not be
30
+ * found afterward (mirrors the original's conditional event-fire).
31
+ */
32
+ async function updateLocalProfile(store, profileId, updates) {
33
+ await store.updateProfile(profileId, {
34
+ ...updates,
35
+ updatedAt: new Date().toISOString()
36
+ });
37
+ const profiles = await store.getProfiles();
38
+ return profiles.find((p) => p.id === profileId);
39
+ }
40
+ /**
41
+ * Delete a local profile.
42
+ * @param store Local profile storage.
43
+ * @param profileId Profile to delete.
44
+ */
45
+ async function deleteLocalProfile(store, profileId) {
46
+ await store.removeProfile(profileId);
47
+ }
48
+ /**
49
+ * List only local profiles (excludes hub-provided ones).
50
+ * @param store Local profile storage.
51
+ * @returns All local profiles.
52
+ */
53
+ async function listLocalProfiles(store) {
54
+ return await store.getProfiles();
55
+ }
56
+ /**
57
+ * Serialize a single local profile as pretty-printed JSON.
58
+ * @param store Local profile storage.
59
+ * @param profileId Profile to export.
60
+ * @returns The serialized profile.
61
+ */
62
+ async function exportLocalProfile(store, profileId) {
63
+ const profiles = await store.getProfiles();
64
+ const profile = profiles.find((p) => p.id === profileId);
65
+ if (!profile) {
66
+ throw new Error(`Profile '${profileId}' not found`);
67
+ }
68
+ return JSON.stringify(profile, null, 2);
69
+ }
70
+ /**
71
+ * Import a single local profile from JSON, resetting its timestamps
72
+ * and forcing it inactive.
73
+ * @param store Local profile storage.
74
+ * @param profileData Serialized profile JSON.
75
+ * @returns The imported profile.
76
+ */
77
+ async function importLocalProfile(store, profileData) {
78
+ const profile = JSON.parse(profileData);
79
+ profile.createdAt = new Date().toISOString();
80
+ profile.updatedAt = new Date().toISOString();
81
+ profile.active = false;
82
+ await store.addProfile(profile);
83
+ return profile;
84
+ }
85
+ //# sourceMappingURL=local-profile-crud.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-profile-crud.js","sourceRoot":"","sources":["../../src/registry/local-profile-crud.ts"],"names":[],"mappings":";;AAwBA,gDAaC;AAUD,gDAYC;AAOD,gDAEC;AAOD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EAAE,KAAK,SAAS,CAAC,CAAC;IAEzD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,YAAY,SAAS,aAAa,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,kBAAkB,CAAC,KAAmB,EAAE,WAAmB;IAC/E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAY,CAAC;IAEnD,OAAO,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC7C,OAAO,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC7C,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;IAEvB,MAAM,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAEhC,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Profile activation/deactivation lifecycle + conflict detection —
3
+ * ported from the extension's `src/services/hub-manager.ts`. Stage 4
4
+ * of the staged HubManager port (migration plan §7.5, HubManager item;
5
+ * see `hub-manager.ts`'s module doc for the full stage list).
6
+ *
7
+ * Deliberately a set of standalone functions taking an explicit
8
+ * `ProfileLifecycleDeps` bag, rather than methods on `HubManager`
9
+ * (Stage 1/3's class) — mirrors Stage 2's `load-hub-sources.ts`: this
10
+ * subsystem is large and self-contained enough to warrant its own
11
+ * module, and (unlike Stage 3's favorites, which needed the class's
12
+ * own `listHubs()`) every function here only needs the store/
13
+ * activation-store/optional-registry-sync bag, nothing else from
14
+ * `HubManager`.
15
+ *
16
+ * Deliberately excludes `listAllHubProfiles`/`listActiveHubProfiles`:
17
+ * those are simple read-projections over already-ported Stage 1
18
+ * primitives (`listHubs`/`getActiveHub`), not activation/conflict
19
+ * logic, and stay extension-side unchanged.
20
+ * @module registry/profile-lifecycle
21
+ */
22
+ import type { ConflictResolutionDialog, HubConfig, HubProfile, HubProfileBundle, HubReference, ProfileActivationOptions, ProfileActivationResult, ProfileActivationState, ProfileChanges, ProfileDeactivationResult, ProfileLifecycleSync } from '@ai-primitives-hub/core';
23
+ import type { LoadHubResult, ProfileActivationStore } from '@ai-primitives-hub/infra';
24
+ import type { OnLogEvent } from '../update/log-event';
25
+ /**
26
+ * Narrow, structural view of `infra`'s `HubStore` — just enough to
27
+ * read/write hub configs (load/save/list), deliberately excluding
28
+ * `remove`/`getMetadata`/`has` which this module never needs.
29
+ *
30
+ * Typed as a plain interface rather than reusing `HubStore` (a
31
+ * concrete class with private fields) so callers can pass a
32
+ * structurally-compatible adapter instead of the real class — the
33
+ * extension's own `HubManager` does exactly this, wrapping its
34
+ * `HubStorage` facade's cache-aware `saveHub`/`loadHub`/`listHubs`
35
+ * rather than the raw, cache-bypassing `HubStore` instance, so that
36
+ * `activateProfile`/`deactivateProfile`'s config mutations stay
37
+ * visible to `HubStorage`'s own in-memory cache.
38
+ */
39
+ export interface HubConfigStore {
40
+ load(id: string): Promise<LoadHubResult>;
41
+ save(id: string, config: HubConfig, reference: HubReference): Promise<void>;
42
+ list(): Promise<string[]>;
43
+ }
44
+ /**
45
+ * Dependencies shared by every function in this module.
46
+ */
47
+ export interface ProfileLifecycleDeps {
48
+ store: HubConfigStore;
49
+ activationStore: ProfileActivationStore;
50
+ /**
51
+ * Optional registry integration for properly deactivating a
52
+ * previously-active profile (uninstalling its bundles) and
53
+ * installing the newly-activated profile's bundles. When absent,
54
+ * `activateProfile` falls back to flag-only bookkeeping for other
55
+ * active profiles and skips bundle installation entirely — mirrors
56
+ * the extension's own `if (this.registryManager)` branching.
57
+ */
58
+ profileSync?: ProfileLifecycleSync;
59
+ }
60
+ export interface ResolvedBundle {
61
+ bundle: HubProfileBundle;
62
+ url: string;
63
+ }
64
+ /**
65
+ * Get the activation state for a hub, if any of its profiles is
66
+ * currently active.
67
+ * @param deps Store dependencies.
68
+ * @param hubId Hub identifier.
69
+ * @returns The active profile's activation state, or null.
70
+ */
71
+ export declare function getActiveProfile(deps: ProfileLifecycleDeps, hubId: string): Promise<ProfileActivationState | null>;
72
+ /**
73
+ * List every recorded activation state, across all hubs.
74
+ * @param deps Store dependencies.
75
+ * @returns All activation states.
76
+ */
77
+ export declare function listAllActiveProfiles(deps: ProfileLifecycleDeps): Promise<ProfileActivationState[]>;
78
+ /**
79
+ * List every profile in a hub, with `active` re-derived from the
80
+ * activation store (treated as the source of truth; the hub config's
81
+ * own `active` flag can go briefly stale relative to it).
82
+ * @param deps Store dependencies.
83
+ * @param hubId Hub identifier.
84
+ * @param onLog Optional sink for diagnostic log events.
85
+ * @returns Profiles from the hub, enriched with activation state.
86
+ */
87
+ export declare function listProfilesFromHub(deps: ProfileLifecycleDeps, hubId: string, onLog?: OnLogEvent): Promise<HubProfile[]>;
88
+ /**
89
+ * Get a single profile from a hub. Throws when the hub or profile
90
+ * doesn't exist.
91
+ * @param deps Store dependencies.
92
+ * @param hubId Hub identifier.
93
+ * @param profileId Profile identifier.
94
+ * @param onLog Optional sink for diagnostic log events.
95
+ * @returns The requested profile.
96
+ */
97
+ export declare function getHubProfile(deps: ProfileLifecycleDeps, hubId: string, profileId: string, onLog?: OnLogEvent): Promise<HubProfile>;
98
+ /**
99
+ * Resolve every bundle declared in a profile. URLs are never resolved
100
+ * here (installation looks bundles up by id against sources instead),
101
+ * so `url` is always empty — kept on the return shape for backward
102
+ * compatibility with the extension's pre-existing `ProfileActivationResult`.
103
+ * @param deps Store dependencies.
104
+ * @param hubId Hub identifier.
105
+ * @param profileId Profile identifier.
106
+ * @param onLog Optional sink for diagnostic log events.
107
+ * @returns Resolved bundles.
108
+ */
109
+ export declare function resolveProfileBundles(deps: ProfileLifecycleDeps, hubId: string, profileId: string, onLog?: OnLogEvent): Promise<ResolvedBundle[]>;
110
+ /**
111
+ * Set a profile's `active` flag within its hub's config and persist
112
+ * it. Throws when the profile doesn't exist.
113
+ * @param store Hub store.
114
+ * @param hubId Hub identifier.
115
+ * @param profileId Profile identifier.
116
+ * @param active New active flag value.
117
+ */
118
+ export declare function setProfileActiveFlag(store: HubConfigStore, hubId: string, profileId: string, active: boolean): Promise<void>;
119
+ /**
120
+ * Activate a hub profile: deactivates every other currently-active
121
+ * profile across all hubs (enforcing a single globally-active
122
+ * profile), resolves and records the profile's bundles as an
123
+ * activation state, flags the profile active in its hub config, and
124
+ * (when requested and a registry sync is available) installs the
125
+ * profile's bundles.
126
+ *
127
+ * Never throws — failures are captured in the returned result's
128
+ * `success`/`error` fields, mirroring the extension's original
129
+ * contract.
130
+ * @param deps Store/registry-sync dependencies.
131
+ * @param hubId Hub identifier.
132
+ * @param profileId Profile identifier.
133
+ * @param options Activation options.
134
+ * @param onLog Optional sink for diagnostic log events.
135
+ * @returns The activation result.
136
+ */
137
+ export declare function activateProfile(deps: ProfileLifecycleDeps, hubId: string, profileId: string, options: ProfileActivationOptions, onLog?: OnLogEvent): Promise<ProfileActivationResult>;
138
+ /**
139
+ * Re-activate a profile to refresh its activation state (e.g. after
140
+ * detecting upstream changes via `getProfileChanges`). Never installs
141
+ * bundles.
142
+ * @param deps Store/registry-sync dependencies.
143
+ * @param hubId Hub identifier.
144
+ * @param profileId Profile identifier.
145
+ * @param onLog Optional sink for diagnostic log events.
146
+ * @returns The activation result.
147
+ */
148
+ export declare function syncProfile(deps: ProfileLifecycleDeps, hubId: string, profileId: string, onLog?: OnLogEvent): Promise<ProfileActivationResult>;
149
+ /**
150
+ * Deactivate a profile: removes its activation state and clears its
151
+ * hub config's `active` flag. Never throws — failures are captured in
152
+ * the returned result.
153
+ * @param deps Store dependencies.
154
+ * @param hubId Hub identifier.
155
+ * @param profileId Profile identifier.
156
+ * @returns The deactivation result.
157
+ */
158
+ export declare function deactivateProfile(deps: ProfileLifecycleDeps, hubId: string, profileId: string): Promise<ProfileDeactivationResult>;
159
+ /**
160
+ * Diff an active profile's recorded activation state against its
161
+ * current hub config to detect bundle/metadata drift.
162
+ * @param deps Store dependencies.
163
+ * @param hubId Hub identifier.
164
+ * @param profileId Profile identifier.
165
+ * @returns The detected changes, or null if the profile isn't active.
166
+ */
167
+ export declare function getProfileChanges(deps: ProfileLifecycleDeps, hubId: string, profileId: string): Promise<ProfileChanges | null>;
168
+ /**
169
+ * Check whether an active profile has any detected changes.
170
+ * @param deps Store dependencies.
171
+ * @param hubId Hub identifier.
172
+ * @param profileId Profile identifier.
173
+ * @returns true iff `getProfileChanges` would return a non-empty result.
174
+ */
175
+ export declare function hasProfileChanges(deps: ProfileLifecycleDeps, hubId: string, profileId: string): Promise<boolean>;
176
+ /**
177
+ * Format detected profile changes as a human-readable, newline-joined
178
+ * summary.
179
+ * @param changes Changes to format.
180
+ * @returns The formatted summary.
181
+ */
182
+ export declare function formatChangeSummary(changes: ProfileChanges): string;
183
+ /**
184
+ * Build a dialog description for resolving a profile's detected
185
+ * changes (sync / review / cancel).
186
+ * @param changes Changes to summarize in the dialog.
187
+ * @returns The dialog description.
188
+ */
189
+ export declare function createConflictResolutionDialog(changes: ProfileChanges): ConflictResolutionDialog;
190
+ //# sourceMappingURL=profile-lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile-lifecycle.d.ts","sourceRoot":"","sources":["../../src/registry/profile-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EACV,wBAAwB,EACxB,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACd,yBAAyB,EACzB,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,aAAa,EACb,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAEV,UAAU,EACX,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;GAaG;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G;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,cAAc,GAAG,wBAAwB,CAgBhG"}
@@ -0,0 +1,400 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getActiveProfile = getActiveProfile;
4
+ exports.listAllActiveProfiles = listAllActiveProfiles;
5
+ exports.listProfilesFromHub = listProfilesFromHub;
6
+ exports.getHubProfile = getHubProfile;
7
+ exports.resolveProfileBundles = resolveProfileBundles;
8
+ exports.setProfileActiveFlag = setProfileActiveFlag;
9
+ exports.activateProfile = activateProfile;
10
+ exports.syncProfile = syncProfile;
11
+ exports.deactivateProfile = deactivateProfile;
12
+ exports.getProfileChanges = getProfileChanges;
13
+ exports.hasProfileChanges = hasProfileChanges;
14
+ exports.formatChangeSummary = formatChangeSummary;
15
+ exports.createConflictResolutionDialog = createConflictResolutionDialog;
16
+ function log(onLog, level, message, error) {
17
+ onLog?.({ level, message, error });
18
+ }
19
+ /**
20
+ * Get the activation state for a hub, if any of its profiles is
21
+ * currently active.
22
+ * @param deps Store dependencies.
23
+ * @param hubId Hub identifier.
24
+ * @returns The active profile's activation state, or null.
25
+ */
26
+ async function getActiveProfile(deps, hubId) {
27
+ const all = await deps.activationStore.listAll();
28
+ return all.find((s) => s.hubId === hubId) ?? null;
29
+ }
30
+ /**
31
+ * List every recorded activation state, across all hubs.
32
+ * @param deps Store dependencies.
33
+ * @returns All activation states.
34
+ */
35
+ async function listAllActiveProfiles(deps) {
36
+ return deps.activationStore.listAll();
37
+ }
38
+ /**
39
+ * List every profile in a hub, with `active` re-derived from the
40
+ * activation store (treated as the source of truth; the hub config's
41
+ * own `active` flag can go briefly stale relative to it).
42
+ * @param deps Store dependencies.
43
+ * @param hubId Hub identifier.
44
+ * @param onLog Optional sink for diagnostic log events.
45
+ * @returns Profiles from the hub, enriched with activation state.
46
+ */
47
+ async function listProfilesFromHub(deps, hubId, onLog) {
48
+ const hub = await deps.store.load(hubId);
49
+ const profiles = hub.config.profiles || [];
50
+ try {
51
+ const activeState = await getActiveProfile(deps, hubId);
52
+ if (activeState) {
53
+ return profiles.map((profile) => ({
54
+ ...profile,
55
+ active: activeState.profileId === profile.id
56
+ }));
57
+ }
58
+ }
59
+ catch (error) {
60
+ log(onLog, 'warn', `Failed to check profile activation state for hub ${hubId}`, error instanceof Error ? error : new Error(String(error)));
61
+ }
62
+ return profiles;
63
+ }
64
+ /**
65
+ * Get a single profile from a hub. Throws when the hub or profile
66
+ * doesn't exist.
67
+ * @param deps Store dependencies.
68
+ * @param hubId Hub identifier.
69
+ * @param profileId Profile identifier.
70
+ * @param onLog Optional sink for diagnostic log events.
71
+ * @returns The requested profile.
72
+ */
73
+ async function getHubProfile(deps, hubId, profileId, onLog) {
74
+ const profiles = await listProfilesFromHub(deps, hubId, onLog);
75
+ log(onLog, 'info', `Found ${profiles.length} profiles in hub ${hubId}`);
76
+ const profile = profiles.find((p) => p.id === profileId);
77
+ if (!profile) {
78
+ log(onLog, 'error', `Profile ${profileId} not found in hub ${hubId}. Available: ${profiles.map((p) => p.id).join(', ')}`);
79
+ throw new Error(`Profile not found: ${profileId} in hub ${hubId}`);
80
+ }
81
+ log(onLog, 'info', `Found profile ${profileId}: ${profile.name}`);
82
+ log(onLog, 'info', `Profile bundles: ${JSON.stringify(profile.bundles?.map((b) => ({ id: b.id, version: b.version })) ?? [])}`);
83
+ return profile;
84
+ }
85
+ /**
86
+ * Resolve every bundle declared in a profile. URLs are never resolved
87
+ * here (installation looks bundles up by id against sources instead),
88
+ * so `url` is always empty — kept on the return shape for backward
89
+ * compatibility with the extension's pre-existing `ProfileActivationResult`.
90
+ * @param deps Store dependencies.
91
+ * @param hubId Hub identifier.
92
+ * @param profileId Profile identifier.
93
+ * @param onLog Optional sink for diagnostic log events.
94
+ * @returns Resolved bundles.
95
+ */
96
+ async function resolveProfileBundles(deps, hubId, profileId, onLog) {
97
+ const profile = await getHubProfile(deps, hubId, profileId, onLog);
98
+ const resolved = [];
99
+ log(onLog, 'info', `Resolving bundles for profile ${profileId} in hub ${hubId}`);
100
+ log(onLog, 'info', `Profile has ${profile.bundles?.length ?? 0} bundles`);
101
+ if (!profile.bundles || profile.bundles.length === 0) {
102
+ log(onLog, 'warn', `No bundles found in profile ${profileId}`);
103
+ return resolved;
104
+ }
105
+ for (const bundle of profile.bundles) {
106
+ log(onLog, 'info', `Resolving bundle: ${bundle.id} v${bundle.version} from source: ${bundle.source}`);
107
+ resolved.push({ bundle, url: '' });
108
+ }
109
+ log(onLog, 'info', `Resolved ${resolved.length} bundles total`);
110
+ return resolved;
111
+ }
112
+ /**
113
+ * Set a profile's `active` flag within its hub's config and persist
114
+ * it. Throws when the profile doesn't exist.
115
+ * @param store Hub store.
116
+ * @param hubId Hub identifier.
117
+ * @param profileId Profile identifier.
118
+ * @param active New active flag value.
119
+ */
120
+ async function setProfileActiveFlag(store, hubId, profileId, active) {
121
+ const { config, reference } = await store.load(hubId);
122
+ const profile = config.profiles.find((p) => p.id === profileId);
123
+ if (!profile) {
124
+ throw new Error(`Profile not found: ${profileId} in hub ${hubId}`);
125
+ }
126
+ profile.active = active;
127
+ await store.save(hubId, config, reference);
128
+ }
129
+ /**
130
+ * Activate a hub profile: deactivates every other currently-active
131
+ * profile across all hubs (enforcing a single globally-active
132
+ * profile), resolves and records the profile's bundles as an
133
+ * activation state, flags the profile active in its hub config, and
134
+ * (when requested and a registry sync is available) installs the
135
+ * profile's bundles.
136
+ *
137
+ * Never throws — failures are captured in the returned result's
138
+ * `success`/`error` fields, mirroring the extension's original
139
+ * contract.
140
+ * @param deps Store/registry-sync dependencies.
141
+ * @param hubId Hub identifier.
142
+ * @param profileId Profile identifier.
143
+ * @param options Activation options.
144
+ * @param onLog Optional sink for diagnostic log events.
145
+ * @returns The activation result.
146
+ */
147
+ async function activateProfile(deps, hubId, profileId, options, onLog) {
148
+ try {
149
+ log(onLog, 'info', `activateProfile called: hubId=${hubId}, profileId=${profileId}, installBundles=${options.installBundles}`);
150
+ // Verify hub and profile exist (throws if not found)
151
+ await getHubProfile(deps, hubId, profileId, onLog);
152
+ // Deactivate ALL active hub profiles across ALL hubs (enforce single active profile globally).
153
+ const allHubIds = await deps.store.list();
154
+ for (const currentHubId of allHubIds) {
155
+ const hubData = await deps.store.load(currentHubId);
156
+ const activeProfile = hubData.config.profiles.find((p) => p.active);
157
+ if (activeProfile && activeProfile.id !== profileId) {
158
+ log(onLog, 'info', `Deactivating hub profile from hub ${currentHubId}: ${activeProfile.id}`);
159
+ if (deps.profileSync) {
160
+ try {
161
+ await deps.profileSync.deactivateProfile(activeProfile.id);
162
+ }
163
+ catch (error) {
164
+ log(onLog, 'error', `Failed to deactivate profile ${activeProfile.id}`, error instanceof Error ? error : new Error(String(error)));
165
+ }
166
+ }
167
+ else {
168
+ await setProfileActiveFlag(deps.store, currentHubId, activeProfile.id, false);
169
+ await deps.activationStore.delete(currentHubId, activeProfile.id);
170
+ }
171
+ }
172
+ }
173
+ // Resolve all bundles in the profile.
174
+ const resolvedBundles = await resolveProfileBundles(deps, hubId, profileId, onLog);
175
+ // Create activation state with bundle versions.
176
+ const syncedBundleVersions = {};
177
+ for (const rb of resolvedBundles) {
178
+ syncedBundleVersions[rb.bundle.id] = rb.bundle.version;
179
+ }
180
+ const activationState = {
181
+ hubId,
182
+ profileId,
183
+ activatedAt: new Date().toISOString(),
184
+ syncedBundles: resolvedBundles.map((rb) => rb.bundle.id),
185
+ syncedBundleVersions
186
+ };
187
+ // Save activation state.
188
+ await deps.activationStore.save(hubId, profileId, activationState);
189
+ // Mark profile as active in hub config.
190
+ await setProfileActiveFlag(deps.store, hubId, profileId, true);
191
+ // Install bundles if requested and a registry sync is available.
192
+ if (options.installBundles && deps.profileSync) {
193
+ log(onLog, 'info', `Installing ${resolvedBundles.length} bundles for profile ${profileId}`);
194
+ const bundlesToInstall = resolvedBundles.map((rb) => ({
195
+ bundleId: rb.bundle.id,
196
+ options: {
197
+ scope: 'user',
198
+ force: false,
199
+ profileId
200
+ }
201
+ }));
202
+ try {
203
+ await deps.profileSync.installBundles(bundlesToInstall);
204
+ log(onLog, 'info', 'Bundle installation complete');
205
+ }
206
+ catch (error) {
207
+ log(onLog, 'error', 'Batch bundle installation failed', error instanceof Error ? error : new Error(String(error)));
208
+ }
209
+ }
210
+ else if (options.installBundles && !deps.profileSync) {
211
+ log(onLog, 'warn', 'Bundle installation requested but registry sync not available');
212
+ }
213
+ return {
214
+ success: true,
215
+ hubId,
216
+ profileId,
217
+ resolvedBundles: resolvedBundles.map((rb) => ({ bundle: rb.bundle, url: rb.url }))
218
+ };
219
+ }
220
+ catch (error) {
221
+ return {
222
+ success: false,
223
+ hubId,
224
+ profileId,
225
+ resolvedBundles: [],
226
+ error: error instanceof Error ? error.message : 'Unknown error'
227
+ };
228
+ }
229
+ }
230
+ /**
231
+ * Re-activate a profile to refresh its activation state (e.g. after
232
+ * detecting upstream changes via `getProfileChanges`). Never installs
233
+ * bundles.
234
+ * @param deps Store/registry-sync dependencies.
235
+ * @param hubId Hub identifier.
236
+ * @param profileId Profile identifier.
237
+ * @param onLog Optional sink for diagnostic log events.
238
+ * @returns The activation result.
239
+ */
240
+ async function syncProfile(deps, hubId, profileId, onLog) {
241
+ return activateProfile(deps, hubId, profileId, { installBundles: false }, onLog);
242
+ }
243
+ /**
244
+ * Deactivate a profile: removes its activation state and clears its
245
+ * hub config's `active` flag. Never throws — failures are captured in
246
+ * the returned result.
247
+ * @param deps Store dependencies.
248
+ * @param hubId Hub identifier.
249
+ * @param profileId Profile identifier.
250
+ * @returns The deactivation result.
251
+ */
252
+ async function deactivateProfile(deps, hubId, profileId) {
253
+ try {
254
+ // Verify profile exists (throws if not found).
255
+ await getHubProfile(deps, hubId, profileId);
256
+ // Get current activation state to track removed bundles.
257
+ const currentState = await deps.activationStore.get(hubId, profileId);
258
+ const removedBundles = currentState ? currentState.syncedBundles : [];
259
+ // Remove activation state.
260
+ await deps.activationStore.delete(hubId, profileId);
261
+ // Mark profile as inactive.
262
+ await setProfileActiveFlag(deps.store, hubId, profileId, false);
263
+ return { success: true, hubId, profileId, removedBundles };
264
+ }
265
+ catch (error) {
266
+ return {
267
+ success: false,
268
+ hubId,
269
+ profileId,
270
+ error: error instanceof Error ? error.message : String(error)
271
+ };
272
+ }
273
+ }
274
+ /**
275
+ * Diff an active profile's recorded activation state against its
276
+ * current hub config to detect bundle/metadata drift.
277
+ * @param deps Store dependencies.
278
+ * @param hubId Hub identifier.
279
+ * @param profileId Profile identifier.
280
+ * @returns The detected changes, or null if the profile isn't active.
281
+ */
282
+ async function getProfileChanges(deps, hubId, profileId) {
283
+ const state = await deps.activationStore.get(hubId, profileId);
284
+ if (!state) {
285
+ return null;
286
+ }
287
+ const currentProfile = await getHubProfile(deps, hubId, profileId);
288
+ const syncedBundles = state.syncedBundles;
289
+ const currentBundleIds = currentProfile.bundles.map((b) => b.id);
290
+ const bundlesAdded = currentProfile.bundles.filter((b) => !syncedBundles.includes(b.id));
291
+ const bundlesRemoved = syncedBundles.filter((id) => !currentBundleIds.includes(id));
292
+ const bundlesUpdated = [];
293
+ const profileUpdated = new Date(currentProfile.updatedAt) > new Date(state.activatedAt);
294
+ if (state.syncedBundleVersions) {
295
+ for (const bundle of currentProfile.bundles) {
296
+ const syncedVersion = state.syncedBundleVersions[bundle.id];
297
+ if (syncedVersion && syncedVersion !== bundle.version) {
298
+ bundlesUpdated.push({ id: bundle.id, oldVersion: syncedVersion, newVersion: bundle.version });
299
+ }
300
+ }
301
+ }
302
+ const metadataChanged = {};
303
+ if (profileUpdated) {
304
+ metadataChanged.name = true;
305
+ metadataChanged.description = true;
306
+ }
307
+ const changes = {};
308
+ if (bundlesAdded.length > 0) {
309
+ changes.bundlesAdded = bundlesAdded;
310
+ }
311
+ if (bundlesRemoved.length > 0) {
312
+ changes.bundlesRemoved = bundlesRemoved;
313
+ }
314
+ if (bundlesUpdated.length > 0) {
315
+ changes.bundlesUpdated = bundlesUpdated;
316
+ }
317
+ if (Object.keys(metadataChanged).length > 0) {
318
+ changes.metadataChanged = metadataChanged;
319
+ }
320
+ return changes;
321
+ }
322
+ /**
323
+ * Check whether an active profile has any detected changes.
324
+ * @param deps Store dependencies.
325
+ * @param hubId Hub identifier.
326
+ * @param profileId Profile identifier.
327
+ * @returns true iff `getProfileChanges` would return a non-empty result.
328
+ */
329
+ async function hasProfileChanges(deps, hubId, profileId) {
330
+ const changes = await getProfileChanges(deps, hubId, profileId);
331
+ if (!changes) {
332
+ return false;
333
+ }
334
+ return ((changes.bundlesAdded !== undefined && changes.bundlesAdded.length > 0)
335
+ || (changes.bundlesRemoved !== undefined && changes.bundlesRemoved.length > 0)
336
+ || (changes.bundlesUpdated !== undefined && changes.bundlesUpdated.length > 0)
337
+ || (changes.metadataChanged !== undefined && Object.keys(changes.metadataChanged).length > 0));
338
+ }
339
+ /**
340
+ * Format detected profile changes as a human-readable, newline-joined
341
+ * summary.
342
+ * @param changes Changes to format.
343
+ * @returns The formatted summary.
344
+ */
345
+ function formatChangeSummary(changes) {
346
+ const lines = [];
347
+ if (changes.bundlesAdded && changes.bundlesAdded.length > 0) {
348
+ lines.push('Added bundles:');
349
+ for (const bundle of changes.bundlesAdded) {
350
+ lines.push(` + ${bundle.id} v${bundle.version}`);
351
+ }
352
+ }
353
+ if (changes.bundlesRemoved && changes.bundlesRemoved.length > 0) {
354
+ lines.push('Removed bundles:');
355
+ for (const bundleId of changes.bundlesRemoved) {
356
+ lines.push(` - ${bundleId}`);
357
+ }
358
+ }
359
+ if (changes.bundlesUpdated && changes.bundlesUpdated.length > 0) {
360
+ lines.push('Updated bundles:');
361
+ for (const update of changes.bundlesUpdated) {
362
+ lines.push(` ~ ${update.id}: ${update.oldVersion} → ${update.newVersion}`);
363
+ }
364
+ }
365
+ if (changes.metadataChanged && Object.keys(changes.metadataChanged).length > 0) {
366
+ lines.push('Metadata changes:');
367
+ if (changes.metadataChanged.name) {
368
+ lines.push(' ~ name changed');
369
+ }
370
+ if (changes.metadataChanged.description) {
371
+ lines.push(' ~ description changed');
372
+ }
373
+ if (changes.metadataChanged.icon) {
374
+ lines.push(' ~ icon changed');
375
+ }
376
+ }
377
+ return lines.join('\n');
378
+ }
379
+ /**
380
+ * Build a dialog description for resolving a profile's detected
381
+ * changes (sync / review / cancel).
382
+ * @param changes Changes to summarize in the dialog.
383
+ * @returns The dialog description.
384
+ */
385
+ function createConflictResolutionDialog(changes) {
386
+ const changeCount = (changes.bundlesAdded?.length ?? 0)
387
+ + (changes.bundlesRemoved?.length ?? 0)
388
+ + (changes.bundlesUpdated?.length ?? 0)
389
+ + (changes.metadataChanged ? 1 : 0);
390
+ return {
391
+ title: 'Profile Updates Available',
392
+ message: `${changeCount} change${changeCount > 1 ? 's' : ''} detected in the profile`,
393
+ options: [
394
+ { label: 'Sync Now', description: 'Accept all changes and update profile', action: 'sync' },
395
+ { label: 'Review Changes', description: 'View detailed changes before syncing', action: 'review' },
396
+ { label: 'Cancel', description: 'Keep current profile version', action: 'cancel' }
397
+ ]
398
+ };
399
+ }
400
+ //# sourceMappingURL=profile-lifecycle.js.map