@lesliechan721/aw 0.1.0-beta.6 → 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 +73 -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
@@ -14,12 +14,11 @@ import { buildCodexMarketplaceAddInvocation, buildCodexMarketplaceListInvocation
14
14
  import { OWNED_TEXT_HEADER_PREFIX, createSharedOwnerToken, createSkillOwnerMarkerContent, parseSharedOwnerToken, parseOwnedTextHeader, readSkillOwnerMarker, inspectOwnedComponents, writeOwnedTextFile, } from '../utils/ownership.js';
15
15
  import { resolveArtifactRenderConfig, runArtifactRenderer } from '../utils/artifact-renderer.js';
16
16
  import { validateArtifactPlan } from '../utils/artifact-plan.js';
17
- import { readPluginManifest } from '../utils/manifest.js';
17
+ import { createAwPluginRequirementsReceipt, readPluginManifest, } from '../utils/manifest.js';
18
18
  import { resolvePlatformEntries } from '../utils/platform-entries.js';
19
19
  import { resolveAwHome, resolveClaudePaths, resolveCodexPaths, resolveRepoRoot, getCodexHome, } from '../utils/paths.js';
20
20
  import { runLifecycleScript } from '../utils/plugin-scripts.js';
21
- import { atomicRemoveConfigFile, atomicReplaceConfigFile, withConfigFileLock, } from '../utils/plugin-config.js';
22
- import { withActiveMarketplaceLifecycleLease, withActiveMarketplaceRuntimeLease, } from '../utils/active-marketplace-runtime-lock.js';
21
+ import { atomicRemoveConfigFile, atomicReplaceConfigFile, withConfigFileMutation, } from '../utils/plugin-config.js';
23
22
  import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
24
23
  import { getNamespacedMarketplaceName, projectMarketplaceManifestForPlatform, replayNamespacedCodexSkillOverlays, } from '../utils/local-marketplace.js';
25
24
  import { cleanupOrphanNamespacedMarketplaceRoot, commitMarketplaceGenerationBackup, } from '../utils/orphan-marketplace-cleanup.js';
@@ -29,6 +28,17 @@ import { assertCanonicalProjectManagedRoots } from '../utils/project-boundary.js
29
28
  import { findCodexRoleNameConflict, resolveCodexRoleNamespace, } from '../utils/codex-roles.js';
30
29
  const MARKETPLACE_NAME = 'aw';
31
30
  const MCP_OWNER_ENV = 'AW_AGENT_WORKFLOWS_OWNER';
31
+ function requirementsReceipt(plugin) {
32
+ const receipt = createAwPluginRequirementsReceipt({ name: plugin.manifest.name, version: plugin.manifest.version }, plugin.manifest.requires?.aw.capabilities ?? []);
33
+ return Buffer.from(`${JSON.stringify(receipt, null, 2)}\n`, 'utf8');
34
+ }
35
+ function requireCodexManager(manager) {
36
+ if (!manager) {
37
+ throw new Error('codexManagerRequired: Codex native operation has no resolved manager.');
38
+ }
39
+ return manager;
40
+ }
41
+ const CODEX_REMOVE_RECOVERY = 'Codex residue was retained. Retry cleanup or uninstall, upgrade AW, or install a compatible official Codex CLI.';
32
42
  function ownerIdentity(plugin, artifactKey, platform, scope) {
33
43
  return { owner: 'agent-workflows', plugin, artifactKey, platform, scope };
34
44
  }
@@ -60,7 +70,7 @@ function pathComponent(options) {
60
70
  return {
61
71
  ...options,
62
72
  validateHealth: async () => {
63
- await validateSkillDirectory(options.path, options.identity.platform === 'codex' ? 'codex.skill' : 'claude.skill', { ownerMarkerPolicy: 'ignore' });
73
+ await validateSkillDirectory(options.path, options.identity.platform === 'codex' ? 'codex.skill' : 'claude.skill', { ownerMarkerPolicy: 'ignore', requirementsReceiptPolicy: 'allow' });
64
74
  },
65
75
  };
66
76
  }
@@ -278,7 +288,7 @@ function renderCodexHookGroups(groups) {
278
288
  return `${JSON.stringify({ hooks }, null, 2)}\n`;
279
289
  }
280
290
  export async function applyCodexHookGroupsTransactionFile(hooksPath, update, testHooks) {
281
- return withConfigFileLock({
291
+ return withConfigFileMutation({
282
292
  filePath: hooksPath,
283
293
  allowedRoot: path.dirname(hooksPath),
284
294
  action: async () => {
@@ -536,6 +546,8 @@ async function scanOwnedTextFiles(options) {
536
546
  }
537
547
  if (parsed?.identity.plugin !== options.pluginName
538
548
  || (options.sourceId !== undefined && parsed.identity.sourceId !== options.sourceId)
549
+ || (options.sourceIdentity !== undefined
550
+ && parsed.identity.sourceIdentity !== options.sourceIdentity)
539
551
  || parsed.identity.platform !== options.platform
540
552
  || parsed.identity.scope !== options.scope)
541
553
  continue;
@@ -566,6 +578,7 @@ async function scanOwnedSkills(options) {
566
578
  }).catch(() => null);
567
579
  if (marker?.plugin === options.pluginName
568
580
  && (options.sourceId === undefined || marker.sourceId === options.sourceId)
581
+ && (options.sourceIdentity === undefined || marker.sourceIdentity === options.sourceIdentity)
569
582
  && marker.platform === options.platform
570
583
  && marker.scope === options.scope) {
571
584
  output.push(pathComponent({
@@ -853,6 +866,7 @@ async function buildBundledCodexSkillWrites(options) {
853
866
  content: { files: {} },
854
867
  },
855
868
  sourceDirs: [skillSource],
869
+ sourceRequirementsReceiptPolicy: 'allow',
856
870
  });
857
871
  const skillPath = path.join(targetRoot, entry.name);
858
872
  const canRecoverPristine = options.scope === 'user'
@@ -903,6 +917,8 @@ async function buildClaudeWrites(options) {
903
917
  artifact,
904
918
  sourceDirs: dynamic.sourceDirs(artifact),
905
919
  requireReadme: true,
920
+ requirementsReceipt: requirementsReceipt(options.plugin),
921
+ sourceRequirementsReceiptPolicy: 'allow',
906
922
  });
907
923
  writes.push(dynamicSkillWrite({
908
924
  ...options,
@@ -971,6 +987,8 @@ async function buildCodexWrites(options) {
971
987
  artifact,
972
988
  sourceDirs: dynamic.sourceDirs(artifact),
973
989
  requireReadme: true,
990
+ requirementsReceipt: requirementsReceipt(options.plugin),
991
+ sourceRequirementsReceiptPolicy: 'allow',
974
992
  });
975
993
  writes.push(dynamicSkillWrite({
976
994
  ...options,
@@ -1608,6 +1626,23 @@ async function inspectCodexNativeResidue(options) {
1608
1626
  installedVersions: [], cacheVersions: [], enabled: false,
1609
1627
  };
1610
1628
  }
1629
+ export async function codexNativeRemovalRequired(options) {
1630
+ const residue = await inspectCodexNativeResidue(options);
1631
+ if (residue.state === 'present')
1632
+ return true;
1633
+ if (residue.state === 'foreign')
1634
+ return false;
1635
+ const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
1636
+ const marketplaceRoot = options.marketplaceRoot ?? resolveAwHome(options.env);
1637
+ const config = await readCodexConfigFile(resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath);
1638
+ const marketplace = config.snapshot.marketplaces[marketplaceName];
1639
+ const canonical = marketplace?.sourceType === 'local'
1640
+ && !marketplace.sourcePointsToManifest
1641
+ && path.normalize(marketplace.source ?? '') === path.normalize(marketplaceRoot);
1642
+ if (!canonical)
1643
+ return false;
1644
+ return (await discoverCodexNativeResidueNames(options)).length === 0;
1645
+ }
1611
1646
  export async function discoverCodexNativeResidueNames(options) {
1612
1647
  const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
1613
1648
  const marketplaceRoot = options.marketplaceRoot ?? resolveAwHome(options.env);
@@ -1633,6 +1668,8 @@ export async function discoverCodexNativeResidueNames(options) {
1633
1668
  const cacheRoot = path.join(getCodexHome(options.env), 'plugins', 'cache', marketplaceName);
1634
1669
  const cacheEntries = await readdirCodexResidueIfPresent(cacheRoot).catch((error) => probeFailure(cacheRoot, error));
1635
1670
  for (const entry of cacheEntries) {
1671
+ if (entry.isFile())
1672
+ continue;
1636
1673
  const entryPath = path.join(cacheRoot, entry.name);
1637
1674
  const pluginName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(entry.name)
1638
1675
  ? entry.name
@@ -1807,8 +1844,13 @@ function createCodexMarketplaceComponent(options) {
1807
1844
  || currentResidue.state === 'present'
1808
1845
  || await hasRemainingPlugins())
1809
1846
  return;
1810
- await runNativeCliChecked(buildCodexMarketplaceRemoveInvocation(options.marketplaceName, options.cwd, options.env), options.runner);
1811
- await runNativeCliChecked(buildCodexMarketplaceListInvocation(options.cwd, options.env), options.runner);
1847
+ try {
1848
+ await runNativeCliChecked(buildCodexMarketplaceRemoveInvocation(requireCodexManager(options.codexManager), options.marketplaceName, options.cwd, options.env), options.runner);
1849
+ await runNativeCliChecked(buildCodexMarketplaceListInvocation(requireCodexManager(options.codexManager), options.cwd, options.env), options.runner);
1850
+ }
1851
+ catch {
1852
+ throw new Error(`codexNativeRemoveFailed: ${CODEX_REMOVE_RECOVERY}`);
1853
+ }
1812
1854
  },
1813
1855
  };
1814
1856
  }
@@ -2412,7 +2454,7 @@ async function mirrorCatalog(catalog, env, target) {
2412
2454
  }
2413
2455
  function createNativeDriver(options) {
2414
2456
  const runner = options.context.nativeCliRunner;
2415
- const materializeLeaseHeld = new WeakSet();
2457
+ const codexManager = options.context.codexManager;
2416
2458
  const mirrorTransactions = new WeakMap();
2417
2459
  const finalizeNamespacedCleanup = async (target) => {
2418
2460
  const { sourceId, sourceIdentity, marketplaceRoot, marketplaceName } = target.identity;
@@ -2427,53 +2469,13 @@ function createNativeDriver(options) {
2427
2469
  });
2428
2470
  };
2429
2471
  return {
2430
- withOwnershipLease: (target, operation) => (!options.context.runtimeLeaseHeld
2431
- && target.identity.platform === 'codex'
2432
- && target.identity.scope === 'user'
2433
- && !materializeLeaseHeld.has(target)
2434
- ? withActiveMarketplaceRuntimeLease(options.context.env, operation)
2435
- : operation()),
2436
- withMaterializeLease: (target, operation) => {
2437
- if (!target.identity.sourceId)
2438
- return operation();
2439
- if (options.context.runtimeLeaseHeld && !options.context.lifecycleLeaseHeld) {
2440
- throw new Error('lockOrderViolation: namespaced materialization cannot acquire lifecycle after runtime.');
2441
- }
2442
- const runOperation = async () => {
2443
- const previousRuntimeHeld = options.context.runtimeLeaseHeld;
2444
- options.context.runtimeLeaseHeld = true;
2445
- materializeLeaseHeld.add(target);
2446
- try {
2447
- if (options.context.expectedCatalogConfigDigest) {
2448
- const current = await readCatalogSourcesConfigSnapshot(options.context.env);
2449
- if (current.digest !== options.context.expectedCatalogConfigDigest) {
2450
- throw new Error('catalogSourceConflict: catalog source config changed before owner publication.');
2451
- }
2452
- }
2453
- return await operation();
2454
- }
2455
- finally {
2456
- materializeLeaseHeld.delete(target);
2457
- options.context.runtimeLeaseHeld = previousRuntimeHeld;
2458
- }
2459
- };
2460
- const withRuntime = () => options.context.runtimeLeaseHeld
2461
- ? runOperation()
2462
- : withActiveMarketplaceRuntimeLease(options.context.env, runOperation);
2463
- if (options.context.lifecycleLeaseHeld)
2464
- return withRuntime();
2465
- return withActiveMarketplaceLifecycleLease(options.context.env, async () => {
2466
- const previousLifecycleHeld = options.context.lifecycleLeaseHeld;
2467
- options.context.lifecycleLeaseHeld = true;
2468
- try {
2469
- return await withRuntime();
2470
- }
2471
- finally {
2472
- options.context.lifecycleLeaseHeld = previousLifecycleHeld;
2473
- }
2474
- });
2475
- },
2476
2472
  preflightMaterialize: async (target) => {
2473
+ if (target.identity.sourceId && options.context.expectedCatalogConfigDigest) {
2474
+ const current = await readCatalogSourcesConfigSnapshot(options.context.env);
2475
+ if (current.digest !== options.context.expectedCatalogConfigDigest) {
2476
+ throw new Error('catalogSourceConflict: catalog source config changed before owner publication.');
2477
+ }
2478
+ }
2477
2479
  if (target.identity.platform === 'claude') {
2478
2480
  await assertNoClaudeUnboundNativeNameCollision({
2479
2481
  pluginName: target.identity.pluginName,
@@ -2594,7 +2596,12 @@ function createNativeDriver(options) {
2594
2596
  }
2595
2597
  if (before.state === 'absent')
2596
2598
  return;
2597
- await runNativeCliChecked(buildCodexPluginRemoveInvocation(component.pluginId, target.identity.cwd, options.context.env), runner);
2599
+ try {
2600
+ await runNativeCliChecked(buildCodexPluginRemoveInvocation(requireCodexManager(codexManager), component.pluginId, target.identity.cwd, options.context.env), runner);
2601
+ }
2602
+ catch {
2603
+ throw new Error(`codexNativeRemoveFailed: ${CODEX_REMOVE_RECOVERY}`);
2604
+ }
2598
2605
  const residue = await inspectCodexNativeResidue({
2599
2606
  pluginName: target.identity.pluginName,
2600
2607
  cwd: target.identity.cwd,
@@ -2603,7 +2610,7 @@ function createNativeDriver(options) {
2603
2610
  marketplaceRoot: target.identity.marketplaceRoot,
2604
2611
  });
2605
2612
  if (residue.state !== 'absent') {
2606
- throw new Error(`Codex native remove 后仍有残留:${residue.labels.join(',')}`);
2613
+ throw new Error(`codexNativeRemoveIncomplete: ${CODEX_REMOVE_RECOVERY}`);
2607
2614
  }
2608
2615
  }
2609
2616
  else {
@@ -2686,11 +2693,11 @@ function createNativeDriver(options) {
2686
2693
  const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
2687
2694
  const marketplace = config.snapshot.marketplaces[marketplaceName];
2688
2695
  if (path.normalize(marketplace?.source ?? '') !== path.normalize(marketplaceRoot)) {
2689
- await runNativeCliChecked(buildCodexMarketplaceAddInvocation(marketplaceRoot, target.identity.cwd, options.context.env), runner);
2696
+ await runNativeCliChecked(buildCodexMarketplaceAddInvocation(requireCodexManager(codexManager), marketplaceRoot, target.identity.cwd, options.context.env), runner);
2690
2697
  }
2691
- await runNativeCliChecked(buildCodexMarketplaceListInvocation(target.identity.cwd, options.context.env), runner);
2692
- await runNativeCliChecked(buildCodexPluginAddInvocation(pluginId, target.identity.cwd, options.context.env), runner);
2693
- await runNativeCliChecked(buildCodexPluginListInvocation(target.identity.cwd, options.context.env), runner);
2698
+ await runNativeCliChecked(buildCodexMarketplaceListInvocation(requireCodexManager(codexManager), target.identity.cwd, options.context.env), runner);
2699
+ await runNativeCliChecked(buildCodexPluginAddInvocation(requireCodexManager(codexManager), pluginId, target.identity.cwd, options.context.env), runner);
2700
+ await runNativeCliChecked(buildCodexPluginListInvocation(requireCodexManager(codexManager), target.identity.cwd, options.context.env), runner);
2694
2701
  await assertCodexNativeInstallState({
2695
2702
  pluginName: target.identity.pluginName,
2696
2703
  pluginVersion: target.identity.pluginVersion,
@@ -2739,11 +2746,7 @@ function createNativeDriver(options) {
2739
2746
  }
2740
2747
  }
2741
2748
  };
2742
- await (target.identity.sourceId
2743
- && !options.context.runtimeLeaseHeld
2744
- && !materializeLeaseHeld.has(target)
2745
- ? withActiveMarketplaceRuntimeLease(options.context.env, writeGeneration)
2746
- : writeGeneration());
2749
+ await writeGeneration();
2747
2750
  },
2748
2751
  writeArtifacts: async (target) => {
2749
2752
  const plan = options.plans.get(target);
@@ -2754,11 +2757,7 @@ function createNativeDriver(options) {
2754
2757
  await write.write();
2755
2758
  return plan.writes.map((write) => write.artifact);
2756
2759
  };
2757
- return !options.context.runtimeLeaseHeld
2758
- && !materializeLeaseHeld.has(target)
2759
- && target.identity.platform === 'codex' && target.identity.scope === 'user'
2760
- ? withActiveMarketplaceRuntimeLease(options.context.env, writeAll)
2761
- : writeAll();
2760
+ return writeAll();
2762
2761
  },
2763
2762
  runLifecycle: async (invocation) => {
2764
2763
  await runLifecycleScript({
@@ -2901,11 +2900,7 @@ export function createRebuildIntegration(options) {
2901
2900
  platform: input.platform,
2902
2901
  scope: input.scope,
2903
2902
  })));
2904
- const scannedSkills = (await (input.platform === 'codex'
2905
- && input.scope === 'user'
2906
- && input.readOnlyInspectionPlan !== true
2907
- ? withActiveMarketplaceRuntimeLease(options.context.env, scanSkills)
2908
- : scanSkills())).flat();
2903
+ const scannedSkills = (await scanSkills()).flat();
2909
2904
  const historicalComponents = await buildHistoricalComponents({
2910
2905
  sourceId: input.sourceId,
2911
2906
  sourceIdentity: input.sourceIdentity,
@@ -2939,7 +2934,8 @@ export function createRebuildIntegration(options) {
2939
2934
  });
2940
2935
  const nativeRequired = input.platform === 'claude'
2941
2936
  || (input.scope === 'user' && requiresCodexNativePlugin(input.plugin, input.scope));
2942
- const nativeCleanupCandidate = input.platform === 'claude' || input.scope === 'user';
2937
+ const nativeCleanupCandidate = (input.platform === 'claude' || input.scope === 'user')
2938
+ && input.includeNativeCleanupCandidate !== false;
2943
2939
  const nativePlugin = (nativeRequired || nativeCleanupCandidate)
2944
2940
  ? [{
2945
2941
  kind: 'native-plugin',
@@ -2953,6 +2949,7 @@ export function createRebuildIntegration(options) {
2953
2949
  const marketplace = input.platform === 'codex' && input.scope === 'user'
2954
2950
  ? [createCodexMarketplaceComponent({
2955
2951
  pluginName: input.plugin.manifest.name,
2952
+ codexManager: options.context.codexManager,
2956
2953
  cwd: input.cwd,
2957
2954
  env: options.context.env,
2958
2955
  runner: options.context.nativeCliRunner,