@lesliechan721/aw 0.1.0-beta.7 → 0.1.0-beta.8

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 (237) hide show
  1. package/dist/authoring/scripts/init-plugin.mjs +4 -33
  2. package/dist/authoring/scripts/init-plugin.mjs.map +1 -1
  3. package/dist/authoring/scripts/lib/plugin-version-check.mjs +1 -1
  4. package/dist/authoring/scripts/plugin-status.mjs +8 -11
  5. package/dist/authoring/scripts/plugin-status.mjs.map +1 -1
  6. package/dist/authoring/scripts/remove-plugin.mjs +1 -0
  7. package/dist/authoring/scripts/remove-plugin.mjs.map +1 -1
  8. package/dist/authoring/scripts/validate-plugin.mjs +104 -54
  9. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
  10. package/dist/scripts/codex-eval-app-server.d.ts +2 -0
  11. package/dist/scripts/codex-eval-app-server.js +107 -1
  12. package/dist/scripts/codex-eval-app-server.js.map +1 -1
  13. package/dist/scripts/eval-plugin-skills.js +5 -2
  14. package/dist/scripts/eval-plugin-skills.js.map +1 -1
  15. package/dist/scripts/plugin-eval-contract.d.ts +5 -1
  16. package/dist/scripts/plugin-eval-contract.js +54 -4
  17. package/dist/scripts/plugin-eval-contract.js.map +1 -1
  18. package/dist/scripts/plugin-staging.d.ts +6 -7
  19. package/dist/scripts/plugin-staging.js +11 -23
  20. package/dist/scripts/plugin-staging.js.map +1 -1
  21. package/dist/scripts/test-plugin-scripts.js +2 -33
  22. package/dist/scripts/test-plugin-scripts.js.map +1 -1
  23. package/dist/src/adapters/helpers.js +2 -2
  24. package/dist/src/adapters/helpers.js.map +1 -1
  25. package/dist/src/authoring/workspace-commands.d.ts +17 -2
  26. package/dist/src/authoring/workspace-commands.js +21 -4
  27. package/dist/src/authoring/workspace-commands.js.map +1 -1
  28. package/dist/src/commands/aw-capabilities.d.ts +78 -0
  29. package/dist/src/commands/aw-capabilities.js +259 -0
  30. package/dist/src/commands/aw-capabilities.js.map +1 -0
  31. package/dist/src/commands/catalog-context.d.ts +52 -0
  32. package/dist/src/commands/catalog-context.js +156 -0
  33. package/dist/src/commands/catalog-context.js.map +1 -0
  34. package/dist/src/commands/catalog-dev-source.d.ts +112 -0
  35. package/dist/src/commands/catalog-dev-source.js +481 -0
  36. package/dist/src/commands/catalog-dev-source.js.map +1 -0
  37. package/dist/src/commands/catalog-generation.d.ts +26 -0
  38. package/dist/src/commands/catalog-generation.js +14 -0
  39. package/dist/src/commands/catalog-generation.js.map +1 -0
  40. package/dist/src/commands/catalog-publication-inspection.d.ts +1 -1
  41. package/dist/src/commands/catalog-publication-inspection.js +4 -5
  42. package/dist/src/commands/catalog-publication-inspection.js.map +1 -1
  43. package/dist/src/commands/catalog-publication-target.d.ts +17 -0
  44. package/dist/src/commands/catalog-publication-target.js +60 -0
  45. package/dist/src/commands/catalog-publication-target.js.map +1 -0
  46. package/dist/src/commands/catalog-publish.d.ts +8 -1
  47. package/dist/src/commands/catalog-publish.js +25 -2
  48. package/dist/src/commands/catalog-publish.js.map +1 -1
  49. package/dist/src/commands/catalog-source.d.ts +23 -1
  50. package/dist/src/commands/catalog-source.js +126 -40
  51. package/dist/src/commands/catalog-source.js.map +1 -1
  52. package/dist/src/commands/catalog-status.d.ts +18 -2
  53. package/dist/src/commands/catalog-status.js +122 -18
  54. package/dist/src/commands/catalog-status.js.map +1 -1
  55. package/dist/src/commands/init.js +1 -1
  56. package/dist/src/commands/init.js.map +1 -1
  57. package/dist/src/commands/offline-cleanup-evidence.d.ts +23 -0
  58. package/dist/src/commands/offline-cleanup-evidence.js +38 -0
  59. package/dist/src/commands/offline-cleanup-evidence.js.map +1 -0
  60. package/dist/src/commands/options.d.ts +1 -0
  61. package/dist/src/commands/options.js +1 -0
  62. package/dist/src/commands/options.js.map +1 -1
  63. package/dist/src/commands/plugin-capabilities.js +1 -1
  64. package/dist/src/commands/plugin-capabilities.js.map +1 -1
  65. package/dist/src/commands/rebuild-command.d.ts +19 -7
  66. package/dist/src/commands/rebuild-command.js +415 -205
  67. package/dist/src/commands/rebuild-command.js.map +1 -1
  68. package/dist/src/commands/rebuild-integration.d.ts +10 -3
  69. package/dist/src/commands/rebuild-integration.js +71 -76
  70. package/dist/src/commands/rebuild-integration.js.map +1 -1
  71. package/dist/src/commands/rebuild-operations.d.ts +0 -8
  72. package/dist/src/commands/rebuild-operations.js +17 -115
  73. package/dist/src/commands/rebuild-operations.js.map +1 -1
  74. package/dist/src/commands/runtime.js +21 -34
  75. package/dist/src/commands/runtime.js.map +1 -1
  76. package/dist/src/commands/{status-v4.d.ts → status-v5.d.ts} +67 -21
  77. package/dist/src/commands/{status-v4.js → status-v5.js} +260 -30
  78. package/dist/src/commands/status-v5.js.map +1 -0
  79. package/dist/src/commands/wizard.d.ts +2 -2
  80. package/dist/src/commands/wizard.js +2 -2
  81. package/dist/src/commands/wizard.js.map +1 -1
  82. package/dist/src/commands/write-commands.js +73 -17
  83. package/dist/src/commands/write-commands.js.map +1 -1
  84. package/dist/src/constants.d.ts +6 -1
  85. package/dist/src/constants.js +6 -1
  86. package/dist/src/constants.js.map +1 -1
  87. package/dist/src/generators/local-plugin.js +57 -3
  88. package/dist/src/generators/local-plugin.js.map +1 -1
  89. package/dist/src/index.d.ts +4 -1
  90. package/dist/src/index.js +562 -85
  91. package/dist/src/index.js.map +1 -1
  92. package/dist/src/output/model.d.ts +1 -34
  93. package/dist/src/output/model.js +1 -144
  94. package/dist/src/output/model.js.map +1 -1
  95. package/dist/src/output/rebuild-progress.js +0 -3
  96. package/dist/src/output/rebuild-progress.js.map +1 -1
  97. package/dist/src/portable/commands.d.ts +4 -0
  98. package/dist/src/portable/commands.js +61 -4
  99. package/dist/src/portable/commands.js.map +1 -1
  100. package/dist/src/portable/materializer.d.ts +3 -0
  101. package/dist/src/portable/materializer.js +61 -10
  102. package/dist/src/portable/materializer.js.map +1 -1
  103. package/dist/src/tui/catalog-generation.d.ts +56 -0
  104. package/dist/src/tui/catalog-generation.js +244 -0
  105. package/dist/src/tui/catalog-generation.js.map +1 -0
  106. package/dist/src/tui/console-app-v4.d.ts +1 -1
  107. package/dist/src/tui/console-app-v4.js +446 -126
  108. package/dist/src/tui/console-app-v4.js.map +1 -1
  109. package/dist/src/tui/controller-runtime.d.ts +8 -2
  110. package/dist/src/tui/controller-runtime.js +606 -92
  111. package/dist/src/tui/controller-runtime.js.map +1 -1
  112. package/dist/src/tui/controller.d.ts +71 -6
  113. package/dist/src/tui/controller.js +377 -83
  114. package/dist/src/tui/controller.js.map +1 -1
  115. package/dist/src/tui/index.d.ts +1 -0
  116. package/dist/src/tui/index.js +1 -0
  117. package/dist/src/tui/index.js.map +1 -1
  118. package/dist/src/tui/input-display.d.ts +8 -0
  119. package/dist/src/tui/input-display.js +36 -0
  120. package/dist/src/tui/input-display.js.map +1 -0
  121. package/dist/src/tui/model.d.ts +27 -7
  122. package/dist/src/tui/model.js +273 -65
  123. package/dist/src/tui/model.js.map +1 -1
  124. package/dist/src/tui/router.d.ts +26 -0
  125. package/dist/src/tui/router.js.map +1 -1
  126. package/dist/src/tui/source-ref-presets.d.ts +3 -0
  127. package/dist/src/tui/source-ref-presets.js +11 -0
  128. package/dist/src/tui/source-ref-presets.js.map +1 -0
  129. package/dist/src/tui/views.js +31 -3
  130. package/dist/src/tui/views.js.map +1 -1
  131. package/dist/src/types.d.ts +90 -6
  132. package/dist/src/types.js.map +1 -1
  133. package/dist/src/utils/agent-version.d.ts +3 -0
  134. package/dist/src/utils/agent-version.js +13 -5
  135. package/dist/src/utils/agent-version.js.map +1 -1
  136. package/dist/src/utils/aw-home-mutation-lock.d.ts +1 -0
  137. package/dist/src/utils/aw-home-mutation-lock.js +32 -4
  138. package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
  139. package/dist/src/utils/bundle-integrity.d.ts +0 -1
  140. package/dist/src/utils/bundle-integrity.js +0 -25
  141. package/dist/src/utils/bundle-integrity.js.map +1 -1
  142. package/dist/src/utils/bundle-layout.js +8 -6
  143. package/dist/src/utils/bundle-layout.js.map +1 -1
  144. package/dist/src/utils/catalog-digests.js +13 -2
  145. package/dist/src/utils/catalog-digests.js.map +1 -1
  146. package/dist/src/utils/catalog-generation-error.d.ts +12 -0
  147. package/dist/src/utils/catalog-generation-error.js +16 -0
  148. package/dist/src/utils/catalog-generation-error.js.map +1 -0
  149. package/dist/src/utils/catalog-generation-resolver.d.ts +13 -0
  150. package/dist/src/utils/catalog-generation-resolver.js +129 -0
  151. package/dist/src/utils/catalog-generation-resolver.js.map +1 -0
  152. package/dist/src/utils/catalog-generation-service.d.ts +52 -0
  153. package/dist/src/utils/catalog-generation-service.js +620 -0
  154. package/dist/src/utils/catalog-generation-service.js.map +1 -0
  155. package/dist/src/utils/catalog-generation-state.d.ts +13 -0
  156. package/dist/src/utils/catalog-generation-state.js +201 -0
  157. package/dist/src/utils/catalog-generation-state.js.map +1 -0
  158. package/dist/src/utils/catalog-generation-store.d.ts +44 -0
  159. package/dist/src/utils/catalog-generation-store.js +387 -0
  160. package/dist/src/utils/catalog-generation-store.js.map +1 -0
  161. package/dist/src/utils/catalog-manifest-v5.d.ts +5 -0
  162. package/dist/src/utils/{catalog-manifest-v4.js → catalog-manifest-v5.js} +39 -35
  163. package/dist/src/utils/{catalog-manifest-v4.js.map → catalog-manifest-v5.js.map} +1 -1
  164. package/dist/src/utils/catalog-operation-context.d.ts +28 -0
  165. package/dist/src/utils/catalog-operation-context.js +242 -0
  166. package/dist/src/utils/catalog-operation-context.js.map +1 -0
  167. package/dist/src/utils/catalog-public-error.d.ts +7 -3
  168. package/dist/src/utils/catalog-public-error.js +20 -4
  169. package/dist/src/utils/catalog-public-error.js.map +1 -1
  170. package/dist/src/utils/catalog-snapshot.d.ts +5 -3
  171. package/dist/src/utils/catalog-snapshot.js +11 -3
  172. package/dist/src/utils/catalog-snapshot.js.map +1 -1
  173. package/dist/src/utils/catalog-source-cache.d.ts +1 -1
  174. package/dist/src/utils/catalog-source-cache.js +37 -12
  175. package/dist/src/utils/catalog-source-cache.js.map +1 -1
  176. package/dist/src/utils/catalog-source-identity.d.ts +1 -0
  177. package/dist/src/utils/catalog-source-identity.js +21 -2
  178. package/dist/src/utils/catalog-source-identity.js.map +1 -1
  179. package/dist/src/utils/catalog-sources.d.ts +1 -0
  180. package/dist/src/utils/catalog-sources.js +30 -11
  181. package/dist/src/utils/catalog-sources.js.map +1 -1
  182. package/dist/src/utils/codex-config.js +4 -4
  183. package/dist/src/utils/codex-config.js.map +1 -1
  184. package/dist/src/utils/codex-manager.d.ts +33 -0
  185. package/dist/src/utils/codex-manager.js +656 -0
  186. package/dist/src/utils/codex-manager.js.map +1 -0
  187. package/dist/src/utils/codex-skill-staging.d.ts +2 -0
  188. package/dist/src/utils/codex-skill-staging.js.map +1 -1
  189. package/dist/src/utils/dynamic-skill-tree.d.ts +4 -0
  190. package/dist/src/utils/dynamic-skill-tree.js +35 -5
  191. package/dist/src/utils/dynamic-skill-tree.js.map +1 -1
  192. package/dist/src/utils/git-catalog-provider.js +10 -25
  193. package/dist/src/utils/git-catalog-provider.js.map +1 -1
  194. package/dist/src/utils/lifecycle-active-store.d.ts +0 -28
  195. package/dist/src/utils/lifecycle-active-store.js +35 -247
  196. package/dist/src/utils/lifecycle-active-store.js.map +1 -1
  197. package/dist/src/utils/multi-source-catalog.d.ts +3 -0
  198. package/dist/src/utils/multi-source-catalog.js +120 -10
  199. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  200. package/dist/src/utils/native-cli.d.ts +15 -6
  201. package/dist/src/utils/native-cli.js +31 -39
  202. package/dist/src/utils/native-cli.js.map +1 -1
  203. package/dist/src/utils/orphan-marketplace-cleanup.js +0 -3
  204. package/dist/src/utils/orphan-marketplace-cleanup.js.map +1 -1
  205. package/dist/src/utils/ownership.d.ts +10 -1
  206. package/dist/src/utils/ownership.js +52 -24
  207. package/dist/src/utils/ownership.js.map +1 -1
  208. package/dist/src/utils/path-catalog-provider.js +12 -8
  209. package/dist/src/utils/path-catalog-provider.js.map +1 -1
  210. package/dist/src/utils/plugin-config-write.js +18 -35
  211. package/dist/src/utils/plugin-config-write.js.map +1 -1
  212. package/dist/src/utils/plugin-config.d.ts +1 -12
  213. package/dist/src/utils/plugin-config.js +107 -226
  214. package/dist/src/utils/plugin-config.js.map +1 -1
  215. package/dist/src/utils/plugin-scripts.d.ts +1 -1
  216. package/dist/src/utils/plugin-scripts.js +1 -1
  217. package/dist/src/utils/plugin-scripts.js.map +1 -1
  218. package/dist/src/utils/state-paths.js +7 -2
  219. package/dist/src/utils/state-paths.js.map +1 -1
  220. package/dist/src/utils/target-eligibility.d.ts +7 -2
  221. package/dist/src/utils/target-eligibility.js +6 -3
  222. package/dist/src/utils/target-eligibility.js.map +1 -1
  223. package/package.json +4 -3
  224. package/dist/authoring/scripts/check-plugin-versions.d.mts +0 -2
  225. package/dist/authoring/scripts/check-plugin-versions.mjs +0 -5
  226. package/dist/authoring/scripts/check-plugin-versions.mjs.map +0 -1
  227. package/dist/src/commands/status-v4.js.map +0 -1
  228. package/dist/src/commands/status.d.ts +0 -93
  229. package/dist/src/commands/status.js +0 -442
  230. package/dist/src/commands/status.js.map +0 -1
  231. package/dist/src/utils/active-marketplace-runtime-lock.d.ts +0 -12
  232. package/dist/src/utils/active-marketplace-runtime-lock.js +0 -133
  233. package/dist/src/utils/active-marketplace-runtime-lock.js.map +0 -1
  234. package/dist/src/utils/catalog-manifest-v3.d.ts +0 -2
  235. package/dist/src/utils/catalog-manifest-v3.js +0 -3
  236. package/dist/src/utils/catalog-manifest-v3.js.map +0 -1
  237. package/dist/src/utils/catalog-manifest-v4.d.ts +0 -5
@@ -1,10 +1,8 @@
1
1
  import crypto from 'node:crypto';
2
2
  import path from 'node:path';
3
3
  import fs from 'fs-extra';
4
- import { calculateFileDigest, calculatePluginBundleFingerprintV2, } from './bundle-integrity.js';
5
- import { acquireActiveMarketplaceLifecycleLeaseAtRoot, markActiveMarketplaceDurableCommit, releaseActiveMarketplaceCoordinationLease, resolveActiveMarketplaceRuntimeCoordinationRoot, withActiveMarketplaceLifecycleLease, } from './active-marketplace-runtime-lock.js';
4
+ import { calculateFileDigest, calculatePluginBundleFingerprint, } from './bundle-integrity.js';
6
5
  import { PLUGIN_LIFECYCLE_EVENTS } from './plugin-script-contract.js';
7
- import { acquireProcessLock, } from './process-lock.js';
8
6
  import { canonicalizePathThroughExistingAncestor, createProjectLocationKey, getClaudeHome, getCodexHome, resolveCanonicalRepoProjectKey, resolveAwHome, resolveAwHomeCanonical, resolveRepoRoot, } from './state-paths.js';
9
7
  import { assertTestWritablePath } from './test-path-fence.js';
10
8
  export const LIFECYCLE_ACTIVE_DIR = 'lifecycle-active';
@@ -30,18 +28,12 @@ const ARTIFACT_TARGETS = new Set([
30
28
  'claude.skill',
31
29
  ]);
32
30
  const ARTIFACT_STATES = new Set(['present', 'disabled']);
33
- const preparedContexts = new WeakMap();
34
- const readContexts = new WeakMap();
35
- const releasedReads = new WeakSet();
31
+ const preparedLoaders = new WeakMap();
36
32
  const finalizedPrepared = new WeakSet();
37
33
  let beforePruneStagingRootForTests;
38
- let processLockFileSystemForTests;
39
34
  export function setLifecycleActiveBeforePruneForTests(hook) {
40
35
  beforePruneStagingRootForTests = hook;
41
36
  }
42
- export function setLifecycleActiveLockFileSystemForTests(fileSystem) {
43
- processLockFileSystemForTests = fileSystem;
44
- }
45
37
  export class LifecycleActiveSnapshotError extends Error {
46
38
  code = 'invalidLifecycleActiveSnapshot';
47
39
  constructor(message, options) {
@@ -125,12 +117,8 @@ export async function resolveLifecycleActiveTarget(options) {
125
117
  const rawPlatformHome = path.resolve(platform === 'codex' ? getCodexHome(env) : getClaudeHome(env));
126
118
  const platformHome = await canonicalizePathThroughExistingAncestor(rawPlatformHome);
127
119
  const locationKey = projectKey ? createLifecycleProjectLocationKey(projectKey) : 'user';
128
- const coordinationRoot = resolveActiveMarketplaceRuntimeCoordinationRoot(env);
129
120
  const storeRoot = assertWritableStorePath(path.join(awHome, LIFECYCLE_ACTIVE_DIR));
130
121
  const targetRoot = assertWritableStorePath(path.join(storeRoot, ...(options.sourceId ? [options.sourceId] : []), platform, scope, locationKey, options.pluginName));
131
- const lockParent = assertWritableStorePath(path.join(coordinationRoot, 'lifecycle-locks', platform, scope, locationKey));
132
- const lockPath = assertWritableStorePath(path.join(lockParent, `.${options.sourceId ? `${options.sourceId}.` : ''}${options.pluginName}.lock`));
133
- const operationLockPath = assertWritableStorePath(path.join(lockParent, `.${options.sourceId ? `${options.sourceId}.` : ''}${options.pluginName}.operation.lock`));
134
122
  return {
135
123
  ...(options.sourceId ? {
136
124
  sourceId: options.sourceId,
@@ -143,13 +131,10 @@ export async function resolveLifecycleActiveTarget(options) {
143
131
  projectKey,
144
132
  locationKey,
145
133
  awHome,
146
- coordinationRoot,
147
134
  storeRoot,
148
135
  targetRoot,
149
136
  activeRoot: path.join(targetRoot, 'active'),
150
137
  stagingRoot: path.join(targetRoot, 'staging'),
151
- lockPath,
152
- operationLockPath,
153
138
  artifactOutputRoots: [awHome, platformHome, ...(projectKey ? [projectKey] : [])],
154
139
  pathAliases: [
155
140
  { source: rawAwHome, canonical: awHome },
@@ -215,59 +200,6 @@ async function assertExistingDirectoryBoundary(target, candidatePath, fieldName)
215
200
  fail(`${fieldName} escapes the canonical lifecycle active store.`);
216
201
  }
217
202
  }
218
- async function acquireTargetLock(target, lifecycleLeaseHeld = false) {
219
- const lifecycleLease = lifecycleLeaseHeld
220
- ? undefined
221
- : await acquireActiveMarketplaceLifecycleLeaseAtRoot(target.coordinationRoot);
222
- const lockParent = path.dirname(target.lockPath);
223
- let targetLease;
224
- try {
225
- await assertExistingPathChainHasNoSymlinks(target.coordinationRoot, lockParent);
226
- await fs.ensureDir(lockParent);
227
- await assertExistingPathChainHasNoSymlinks(target.coordinationRoot, lockParent);
228
- targetLease = await acquireProcessLock({
229
- lockPath: target.lockPath,
230
- fileSystem: processLockFileSystemForTests,
231
- });
232
- }
233
- catch (error) {
234
- try {
235
- if (lifecycleLease)
236
- await releaseActiveMarketplaceCoordinationLease(lifecycleLease);
237
- }
238
- catch (releaseError) {
239
- emitLifecycleReleaseWarning('Lifecycle target lock acquisition failed, and lifecycle lease release also failed', releaseError);
240
- }
241
- throw error;
242
- }
243
- let targetReleased = false;
244
- let lifecycleReleased = false;
245
- return {
246
- lockPath: targetLease.lockPath,
247
- owner: targetLease.owner,
248
- release: async () => {
249
- if (!targetReleased) {
250
- await targetLease.release();
251
- targetReleased = true;
252
- }
253
- if (lifecycleLease && !lifecycleReleased) {
254
- await lifecycleLease.release();
255
- lifecycleReleased = true;
256
- }
257
- },
258
- };
259
- }
260
- export async function acquireLifecycleOperationLock(options) {
261
- const target = await resolveLifecycleActiveTarget(options);
262
- const lockParent = path.dirname(target.operationLockPath);
263
- await assertExistingPathChainHasNoSymlinks(target.coordinationRoot, lockParent);
264
- await fs.ensureDir(lockParent);
265
- await assertExistingPathChainHasNoSymlinks(target.coordinationRoot, lockParent);
266
- return acquireProcessLock({
267
- lockPath: target.operationLockPath,
268
- fileSystem: processLockFileSystemForTests,
269
- });
270
- }
271
203
  async function assertNoSymlinks(rootPath) {
272
204
  const rootStat = await fs.lstat(rootPath);
273
205
  if (rootStat.isSymbolicLink() || !rootStat.isDirectory()) {
@@ -692,7 +624,7 @@ async function validateSnapshotRoot(snapshotRoot, target, loadPlugin) {
692
624
  const metadata = parseMetadata(rawMetadata, target);
693
625
  const [manifestDigest, bundleFingerprint] = await Promise.all([
694
626
  calculateFileDigest(resolvedManifestPath),
695
- calculatePluginBundleFingerprintV2(resolvedBundleRoot),
627
+ calculatePluginBundleFingerprint(resolvedBundleRoot),
696
628
  ]);
697
629
  if (manifestDigest !== metadata.sourceManifestDigest) {
698
630
  fail('Lifecycle active manifest digest does not match metadata.');
@@ -830,47 +762,16 @@ async function cleanupTransientState(target, loadPlugin) {
830
762
  await recoverTransientBackup(target, loadPlugin);
831
763
  await cleanupOrphanStages(target);
832
764
  }
833
- function attachPreparedLock(prepared, lock, loadPlugin) {
834
- preparedContexts.set(prepared, { lock, loadPlugin });
765
+ function attachPreparedLoader(prepared, loadPlugin) {
766
+ preparedLoaders.set(prepared, loadPlugin);
835
767
  return prepared;
836
768
  }
837
- function requirePreparedContext(prepared) {
838
- const context = preparedContexts.get(prepared);
839
- if (!context) {
840
- fail('Lifecycle active prepared snapshot no longer owns its target lock.');
841
- }
842
- return context;
843
- }
844
- function isRetryableReleaseError(error) {
845
- return new Set(['EACCES', 'EBUSY', 'EINTR', 'EIO', 'ENOTEMPTY', 'EPERM']).has(error.code ?? '');
846
- }
847
- function isPostCommitReleaseWarning(error) {
848
- const code = error.code ?? '';
849
- return code === 'EBUSY' || code === 'EPERM';
850
- }
851
- async function releaseLeaseWithRetry(lock) {
852
- let lastError;
853
- for (let attempt = 0; attempt < 3; attempt += 1) {
854
- try {
855
- await lock.release();
856
- return;
857
- }
858
- catch (error) {
859
- lastError = error;
860
- if (!isRetryableReleaseError(error))
861
- throw error;
862
- }
863
- }
864
- await lock.release().catch(() => undefined);
865
- throw lastError;
866
- }
867
- function emitLifecycleReleaseWarning(message, _releaseError) {
868
- try {
869
- process.emitWarning(`${message}.`, { code: 'AW_LIFECYCLE_LOCK_RELEASE_FAILED' });
870
- }
871
- catch {
872
- // Diagnostics cannot replace the primary lifecycle error.
769
+ function requirePreparedLoader(prepared) {
770
+ const loadPlugin = preparedLoaders.get(prepared);
771
+ if (!loadPlugin) {
772
+ fail('Lifecycle active prepared snapshot is no longer valid.');
873
773
  }
774
+ return loadPlugin;
874
775
  }
875
776
  function emitLifecycleHousekeepingWarning() {
876
777
  try {
@@ -893,7 +794,6 @@ export async function prepareLifecycleActiveSnapshot(options) {
893
794
  cwd: options.cwd,
894
795
  env,
895
796
  });
896
- const lock = await acquireTargetLock(target, options.lifecycleLeaseHeld);
897
797
  let stageRoot = null;
898
798
  try {
899
799
  await cleanupTransientState(target, options.loadPlugin);
@@ -921,15 +821,15 @@ export async function prepareLifecycleActiveSnapshot(options) {
921
821
  await fs.remove(stageRoot);
922
822
  stageRoot = null;
923
823
  await pruneEmptyStagingRoot(target.stagingRoot);
924
- return attachPreparedLock({
824
+ return attachPreparedLoader({
925
825
  status: 'not-required',
926
826
  reason: 'no-uninstall-lifecycle',
927
827
  target,
928
- }, lock, options.loadPlugin);
828
+ }, options.loadPlugin);
929
829
  }
930
830
  const [sourceManifestDigest, bundleFingerprint] = await Promise.all([
931
831
  calculateFileDigest(stagedPlugin.manifestPath),
932
- calculatePluginBundleFingerprintV2(bundleRoot),
832
+ calculatePluginBundleFingerprint(bundleRoot),
933
833
  ]);
934
834
  const payload = {
935
835
  schemaVersion: target.sourceId ? LIFECYCLE_ACTIVE_SCHEMA_VERSION : 1,
@@ -958,19 +858,13 @@ export async function prepareLifecycleActiveSnapshot(options) {
958
858
  if (stableStringify(validated.metadata) !== stableStringify(metadata)) {
959
859
  fail('Lifecycle active staged metadata changed during validation.');
960
860
  }
961
- return attachPreparedLock({ status: 'staged', target, stageId, stageRoot, metadata }, lock, options.loadPlugin);
861
+ return attachPreparedLoader({ status: 'staged', target, stageId, stageRoot, metadata }, options.loadPlugin);
962
862
  }
963
863
  catch (error) {
964
864
  if (stageRoot) {
965
865
  await fs.remove(stageRoot).catch(() => undefined);
966
866
  await pruneEmptyStagingRoot(target.stagingRoot).catch(() => undefined);
967
867
  }
968
- try {
969
- await releaseLeaseWithRetry(lock);
970
- }
971
- catch (releaseError) {
972
- emitLifecycleReleaseWarning('Lifecycle active prepare failed, and its target lock could not be released', releaseError);
973
- }
974
868
  throw error;
975
869
  }
976
870
  }
@@ -998,7 +892,7 @@ async function restoreBackupAfterFailedPromote(options) {
998
892
  }
999
893
  }
1000
894
  export async function promoteLifecycleActiveSnapshot(prepared) {
1001
- const { lock, loadPlugin } = requirePreparedContext(prepared);
895
+ const loadPlugin = requirePreparedLoader(prepared);
1002
896
  let backupPath = null;
1003
897
  let installedNewActive = false;
1004
898
  let durableCommit = false;
@@ -1008,7 +902,6 @@ export async function promoteLifecycleActiveSnapshot(prepared) {
1008
902
  if (prepared.status === 'not-required') {
1009
903
  await removeLifecycleSnapshotDataLocked(prepared.target);
1010
904
  durableCommit = true;
1011
- markActiveMarketplaceDurableCommit();
1012
905
  return null;
1013
906
  }
1014
907
  const expectedStageRoot = path.join(prepared.target.stagingRoot, prepared.stageId);
@@ -1032,7 +925,6 @@ export async function promoteLifecycleActiveSnapshot(prepared) {
1032
925
  fail('Lifecycle active promoted generation changed during promotion.');
1033
926
  }
1034
927
  durableCommit = true;
1035
- markActiveMarketplaceDurableCommit();
1036
928
  if (backupPath) {
1037
929
  try {
1038
930
  await fs.remove(backupPath);
@@ -1067,36 +959,18 @@ export async function promoteLifecycleActiveSnapshot(prepared) {
1067
959
  throw error;
1068
960
  }
1069
961
  finally {
1070
- try {
1071
- await releaseLeaseWithRetry(lock);
1072
- }
1073
- catch (releaseError) {
1074
- if (primaryError !== undefined) {
1075
- emitLifecycleReleaseWarning('Lifecycle active promote failed, and its target lock could not be released', releaseError);
1076
- }
1077
- else if (durableCommit && isPostCommitReleaseWarning(releaseError)) {
1078
- emitLifecycleReleaseWarning('Lifecycle active promote committed, but its target lock could not be released', releaseError);
1079
- }
1080
- else {
1081
- throw releaseError;
1082
- }
1083
- }
1084
- finally {
1085
- finalizedPrepared.add(prepared);
1086
- preparedContexts.delete(prepared);
1087
- }
962
+ finalizedPrepared.add(prepared);
963
+ preparedLoaders.delete(prepared);
1088
964
  }
1089
965
  }
1090
966
  export async function discardLifecycleActiveSnapshot(prepared) {
1091
- const context = preparedContexts.get(prepared);
1092
- if (!context && finalizedPrepared.has(prepared)) {
967
+ const loadPlugin = preparedLoaders.get(prepared);
968
+ if (!loadPlugin && finalizedPrepared.has(prepared)) {
1093
969
  return;
1094
970
  }
1095
- if (!context) {
1096
- fail('Lifecycle active prepared snapshot no longer owns its target lock.');
971
+ if (!loadPlugin) {
972
+ fail('Lifecycle active prepared snapshot is no longer valid.');
1097
973
  }
1098
- const { lock } = context;
1099
- let primaryError;
1100
974
  try {
1101
975
  if (prepared.status === 'staged') {
1102
976
  const expectedStageRoot = path.join(prepared.target.stagingRoot, prepared.stageId);
@@ -1108,23 +982,9 @@ export async function discardLifecycleActiveSnapshot(prepared) {
1108
982
  await pruneEmptyStagingRoot(prepared.target.stagingRoot);
1109
983
  }
1110
984
  }
1111
- catch (error) {
1112
- primaryError = error;
1113
- throw error;
1114
- }
1115
985
  finally {
1116
- try {
1117
- await releaseLeaseWithRetry(lock);
1118
- }
1119
- catch (releaseError) {
1120
- if (primaryError !== undefined) {
1121
- emitLifecycleReleaseWarning('Lifecycle active discard failed, and its target lock could not be released', releaseError);
1122
- throw primaryError;
1123
- }
1124
- throw releaseError;
1125
- }
1126
986
  finalizedPrepared.add(prepared);
1127
- preparedContexts.delete(prepared);
987
+ preparedLoaders.delete(prepared);
1128
988
  }
1129
989
  }
1130
990
  async function readLifecycleActiveSnapshotUnlocked(options) {
@@ -1144,56 +1004,11 @@ async function readLifecycleActiveSnapshotUnlocked(options) {
1144
1004
  }
1145
1005
  }
1146
1006
  export async function readLifecycleActiveSnapshot(options) {
1147
- return withActiveMarketplaceLifecycleLease(options.env, () => readLifecycleActiveSnapshotUnlocked(options));
1007
+ return readLifecycleActiveSnapshotUnlocked(options);
1148
1008
  }
1149
- // Catalog reference inventory can run while the runtime coordination lease is held.
1150
- // Active publication also needs that lease, so inventory must not acquire lifecycle after runtime.
1151
1009
  export async function inspectLifecycleActiveSnapshotForInventory(options) {
1152
1010
  return readLifecycleActiveSnapshotUnlocked(options);
1153
1011
  }
1154
- export async function leaseLifecycleActiveSnapshot(options) {
1155
- const target = await resolveLifecycleActiveTarget(options);
1156
- const lock = await acquireTargetLock(target, options.lifecycleLeaseHeld);
1157
- let snapshot;
1158
- try {
1159
- await assertExistingPathChainHasNoSymlinks(target.awHome, target.activeRoot);
1160
- if (!await lstatIfExists(target.activeRoot)) {
1161
- snapshot = null;
1162
- }
1163
- else {
1164
- snapshot = createReadSnapshot(target, await validateSnapshotRoot(target.activeRoot, target, options.loadPlugin));
1165
- }
1166
- }
1167
- catch (error) {
1168
- const primaryError = error instanceof LifecycleActiveSnapshotError
1169
- ? error
1170
- : new LifecycleActiveSnapshotError('Lifecycle active snapshot is corrupt.', { cause: error });
1171
- try {
1172
- await releaseLeaseWithRetry(lock);
1173
- }
1174
- catch (releaseError) {
1175
- emitLifecycleReleaseWarning('Lifecycle active read failed, and its target lock could not be released', releaseError);
1176
- }
1177
- throw primaryError;
1178
- }
1179
- if (!snapshot) {
1180
- await releaseLeaseWithRetry(lock);
1181
- return null;
1182
- }
1183
- readContexts.set(snapshot, lock);
1184
- return snapshot;
1185
- }
1186
- export async function releaseLifecycleActiveSnapshot(snapshot) {
1187
- const lock = readContexts.get(snapshot);
1188
- if (!lock && releasedReads.has(snapshot))
1189
- return;
1190
- if (!lock) {
1191
- fail('Lifecycle active read snapshot no longer owns its target lock.');
1192
- }
1193
- await releaseLeaseWithRetry(lock);
1194
- readContexts.delete(snapshot);
1195
- releasedReads.add(snapshot);
1196
- }
1197
1012
  export function restoreLifecycleActiveScriptInputs(snapshot) {
1198
1013
  return { currentPlugin: snapshot.plugin, artifacts: snapshot.artifacts };
1199
1014
  }
@@ -1231,46 +1046,19 @@ async function removeTransientBackupsLocked(target) {
1231
1046
  }
1232
1047
  export async function removeLifecycleActiveSnapshot(options) {
1233
1048
  const target = await resolveLifecycleActiveTarget(options);
1234
- const lock = await acquireTargetLock(target, options.lifecycleLeaseHeld);
1235
- let durableCommit = false;
1236
- let primaryError;
1237
- try {
1238
- if (options.expectedMetadataIntegrityDigest !== undefined) {
1239
- await assertExistingDirectoryBoundary(target, target.activeRoot, 'activeRoot');
1240
- const metadata = await fs.readJson(path.join(target.activeRoot, LIFECYCLE_ACTIVE_METADATA_FILE));
1241
- if (metadata === null
1242
- || typeof metadata !== 'object'
1243
- || Array.isArray(metadata)
1244
- || metadata.metadataIntegrityDigest
1245
- !== options.expectedMetadataIntegrityDigest) {
1246
- fail('stateInventoryFailed: lifecycle active generation changed before removal.');
1247
- }
1248
- }
1249
- await cleanupOrphanStages(target);
1250
- await removeTransientBackupsLocked(target);
1251
- await removeLifecycleSnapshotDataLocked(target);
1252
- durableCommit = true;
1253
- markActiveMarketplaceDurableCommit();
1254
- }
1255
- catch (error) {
1256
- primaryError = error;
1257
- throw error;
1258
- }
1259
- finally {
1260
- try {
1261
- await releaseLeaseWithRetry(lock);
1262
- }
1263
- catch (releaseError) {
1264
- if (primaryError !== undefined) {
1265
- emitLifecycleReleaseWarning('Lifecycle active remove failed, and its target lock could not be released', releaseError);
1266
- }
1267
- else if (durableCommit && isPostCommitReleaseWarning(releaseError)) {
1268
- emitLifecycleReleaseWarning('Lifecycle active remove committed, but its target lock could not be released', releaseError);
1269
- }
1270
- else {
1271
- throw releaseError;
1272
- }
1049
+ if (options.expectedMetadataIntegrityDigest !== undefined) {
1050
+ await assertExistingDirectoryBoundary(target, target.activeRoot, 'activeRoot');
1051
+ const metadata = await fs.readJson(path.join(target.activeRoot, LIFECYCLE_ACTIVE_METADATA_FILE));
1052
+ if (metadata === null
1053
+ || typeof metadata !== 'object'
1054
+ || Array.isArray(metadata)
1055
+ || metadata.metadataIntegrityDigest
1056
+ !== options.expectedMetadataIntegrityDigest) {
1057
+ fail('stateInventoryFailed: lifecycle active generation changed before removal.');
1273
1058
  }
1274
1059
  }
1060
+ await cleanupOrphanStages(target);
1061
+ await removeTransientBackupsLocked(target);
1062
+ await removeLifecycleSnapshotDataLocked(target);
1275
1063
  }
1276
1064
  //# sourceMappingURL=lifecycle-active-store.js.map