@lesliechan721/aw 0.1.0-beta.85 → 0.1.0-beta.87

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 (233) hide show
  1. package/dist/authoring/assets/command-runtime-config.d.mts +9 -0
  2. package/dist/authoring/assets/command-runtime-config.mjs +106 -0
  3. package/dist/authoring/assets/command-runtime-config.mjs.map +1 -0
  4. package/dist/authoring/scripts/validate-plugin.mjs +17 -22
  5. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
  6. package/dist/scripts/aw-skill-eval-materializer.d.ts +4 -0
  7. package/dist/scripts/aw-skill-eval-materializer.js +27 -0
  8. package/dist/scripts/aw-skill-eval-materializer.js.map +1 -1
  9. package/dist/scripts/bundle-plugins.js +1 -1
  10. package/dist/scripts/bundle-plugins.js.map +1 -1
  11. package/dist/scripts/test-plugin-scripts.js +13 -2
  12. package/dist/scripts/test-plugin-scripts.js.map +1 -1
  13. package/dist/src/commands/aw-capabilities.d.ts +1 -1
  14. package/dist/src/commands/aw-capabilities.js +2 -2
  15. package/dist/src/commands/catalog-source.d.ts +2 -1
  16. package/dist/src/commands/catalog-source.js +8 -7
  17. package/dist/src/commands/catalog-source.js.map +1 -1
  18. package/dist/src/commands/deployment-confirmation.d.ts +8 -1
  19. package/dist/src/commands/deployment-confirmation.js +79 -11
  20. package/dist/src/commands/deployment-confirmation.js.map +1 -1
  21. package/dist/src/commands/lifecycle-command-package.d.ts +44 -0
  22. package/dist/src/commands/lifecycle-command-package.js +195 -0
  23. package/dist/src/commands/lifecycle-command-package.js.map +1 -0
  24. package/dist/src/commands/managed-commands.d.ts +6 -0
  25. package/dist/src/commands/managed-commands.js +203 -152
  26. package/dist/src/commands/managed-commands.js.map +1 -1
  27. package/dist/src/commands/operation-plan.d.ts +22 -21
  28. package/dist/src/commands/operation-plan.js +2 -5
  29. package/dist/src/commands/operation-plan.js.map +1 -1
  30. package/dist/src/commands/permission-batch.d.ts +5 -0
  31. package/dist/src/commands/permission-batch.js +80 -0
  32. package/dist/src/commands/permission-batch.js.map +1 -0
  33. package/dist/src/commands/plugin-capabilities.js +17 -13
  34. package/dist/src/commands/plugin-capabilities.js.map +1 -1
  35. package/dist/src/commands/public-config-confirmation.d.ts +8 -2
  36. package/dist/src/commands/public-config-confirmation.js +22 -5
  37. package/dist/src/commands/public-config-confirmation.js.map +1 -1
  38. package/dist/src/commands/public-lifecycle-result.d.ts +4 -4
  39. package/dist/src/commands/public-lifecycle-result.js +55 -14
  40. package/dist/src/commands/public-lifecycle-result.js.map +1 -1
  41. package/dist/src/commands/public-lifecycle.js +49 -8
  42. package/dist/src/commands/public-lifecycle.js.map +1 -1
  43. package/dist/src/commands/rebuild-command.d.ts +4 -0
  44. package/dist/src/commands/rebuild-command.js +160 -101
  45. package/dist/src/commands/rebuild-command.js.map +1 -1
  46. package/dist/src/commands/rebuild-integration.d.ts +17 -6
  47. package/dist/src/commands/rebuild-integration.js +76 -183
  48. package/dist/src/commands/rebuild-integration.js.map +1 -1
  49. package/dist/src/commands/rebuild-operations.d.ts +2 -1
  50. package/dist/src/commands/rebuild-operations.js +2 -0
  51. package/dist/src/commands/rebuild-operations.js.map +1 -1
  52. package/dist/src/commands/rebuild-platform-integration.d.ts +5 -3
  53. package/dist/src/commands/rebuild-platform-integration.js +166 -135
  54. package/dist/src/commands/rebuild-platform-integration.js.map +1 -1
  55. package/dist/src/commands/skill-eval.js +10 -1
  56. package/dist/src/commands/skill-eval.js.map +1 -1
  57. package/dist/src/generators/local-plugin.js +14 -15
  58. package/dist/src/generators/local-plugin.js.map +1 -1
  59. package/dist/src/generators/permissions.d.ts +14 -6
  60. package/dist/src/generators/permissions.js +59 -61
  61. package/dist/src/generators/permissions.js.map +1 -1
  62. package/dist/src/index.js +77 -40
  63. package/dist/src/index.js.map +1 -1
  64. package/dist/src/output/command-receipt.js +7 -8
  65. package/dist/src/output/command-receipt.js.map +1 -1
  66. package/dist/src/output/component-delivery.d.ts +7 -0
  67. package/dist/src/output/component-delivery.js +59 -3
  68. package/dist/src/output/component-delivery.js.map +1 -1
  69. package/dist/src/output/public-result.d.ts +15 -0
  70. package/dist/src/output/public-result.js +75 -12
  71. package/dist/src/output/public-result.js.map +1 -1
  72. package/dist/src/output/rebuild-progress.js +7 -4
  73. package/dist/src/output/rebuild-progress.js.map +1 -1
  74. package/dist/src/output/receipt-projection.js +39 -27
  75. package/dist/src/output/receipt-projection.js.map +1 -1
  76. package/dist/src/platforms/antigravity-permissions.d.ts +50 -0
  77. package/dist/src/platforms/antigravity-permissions.js +388 -0
  78. package/dist/src/platforms/antigravity-permissions.js.map +1 -0
  79. package/dist/src/platforms/contracts.d.ts +10 -1
  80. package/dist/src/platforms/discovery.d.ts +2 -0
  81. package/dist/src/platforms/discovery.js.map +1 -1
  82. package/dist/src/platforms/grok-permission-config.d.ts +22 -0
  83. package/dist/src/platforms/grok-permission-config.js +184 -0
  84. package/dist/src/platforms/grok-permission-config.js.map +1 -0
  85. package/dist/src/platforms/grok-permission-document.d.ts +4 -0
  86. package/dist/src/platforms/grok-permission-document.js +145 -0
  87. package/dist/src/platforms/grok-permission-document.js.map +1 -0
  88. package/dist/src/platforms/grok-permissions.d.ts +17 -0
  89. package/dist/src/platforms/grok-permissions.js +311 -0
  90. package/dist/src/platforms/grok-permissions.js.map +1 -0
  91. package/dist/src/platforms/host-permission-policy.d.ts +38 -0
  92. package/dist/src/platforms/host-permission-policy.js +86 -0
  93. package/dist/src/platforms/host-permission-policy.js.map +1 -0
  94. package/dist/src/platforms/inspection-grok.js +47 -5
  95. package/dist/src/platforms/inspection-grok.js.map +1 -1
  96. package/dist/src/platforms/layout.d.ts +8 -0
  97. package/dist/src/platforms/layout.js +53 -8
  98. package/dist/src/platforms/layout.js.map +1 -1
  99. package/dist/src/platforms/lifecycle.js +39 -17
  100. package/dist/src/platforms/lifecycle.js.map +1 -1
  101. package/dist/src/platforms/opencode-permission-config.d.ts +13 -0
  102. package/dist/src/platforms/opencode-permission-config.js +253 -0
  103. package/dist/src/platforms/opencode-permission-config.js.map +1 -0
  104. package/dist/src/platforms/opencode-permissions.d.ts +39 -0
  105. package/dist/src/platforms/opencode-permissions.js +212 -0
  106. package/dist/src/platforms/opencode-permissions.js.map +1 -0
  107. package/dist/src/platforms/opencode-related-permissions.d.ts +40 -0
  108. package/dist/src/platforms/opencode-related-permissions.js +177 -0
  109. package/dist/src/platforms/opencode-related-permissions.js.map +1 -0
  110. package/dist/src/platforms/permission-ownership.d.ts +89 -0
  111. package/dist/src/platforms/permission-ownership.js +543 -0
  112. package/dist/src/platforms/permission-ownership.js.map +1 -0
  113. package/dist/src/platforms/permission-sidecar.d.ts +70 -0
  114. package/dist/src/platforms/permission-sidecar.js +215 -0
  115. package/dist/src/platforms/permission-sidecar.js.map +1 -0
  116. package/dist/src/platforms/projection.js +58 -8
  117. package/dist/src/platforms/projection.js.map +1 -1
  118. package/dist/src/recovery/coordinator.d.ts +2 -0
  119. package/dist/src/recovery/coordinator.js +24 -27
  120. package/dist/src/recovery/coordinator.js.map +1 -1
  121. package/dist/src/recovery/joint-coordinator.js +103 -47
  122. package/dist/src/recovery/joint-coordinator.js.map +1 -1
  123. package/dist/src/recovery/joint-demand.js +1 -1
  124. package/dist/src/recovery/joint-demand.js.map +1 -1
  125. package/dist/src/recovery/joint-install-execution.js +2 -1
  126. package/dist/src/recovery/joint-install-execution.js.map +1 -1
  127. package/dist/src/recovery/retirement.js +11 -17
  128. package/dist/src/recovery/retirement.js.map +1 -1
  129. package/dist/src/recovery/status.js +32 -2
  130. package/dist/src/recovery/status.js.map +1 -1
  131. package/dist/src/review/eval-source-input.d.ts +1 -0
  132. package/dist/src/review/eval-source-input.js +7 -1
  133. package/dist/src/review/eval-source-input.js.map +1 -1
  134. package/dist/src/review/review-selection.js +12 -5
  135. package/dist/src/review/review-selection.js.map +1 -1
  136. package/dist/src/review/skill-materialization.d.ts +1 -1
  137. package/dist/src/review/skill-materialization.js +3 -7
  138. package/dist/src/review/skill-materialization.js.map +1 -1
  139. package/dist/src/tui/console-app-v4.js +37 -30
  140. package/dist/src/tui/console-app-v4.js.map +1 -1
  141. package/dist/src/tui/controller-runtime.js +71 -6
  142. package/dist/src/tui/controller-runtime.js.map +1 -1
  143. package/dist/src/tui/controller.d.ts +4 -1
  144. package/dist/src/tui/controller.js.map +1 -1
  145. package/dist/src/tui/deployment-view.d.ts +1 -1
  146. package/dist/src/tui/deployment-view.js +16 -3
  147. package/dist/src/tui/deployment-view.js.map +1 -1
  148. package/dist/src/tui/diagnostic-projection.js +11 -6
  149. package/dist/src/tui/diagnostic-projection.js.map +1 -1
  150. package/dist/src/tui/entity-cards.js +1 -1
  151. package/dist/src/tui/entity-cards.js.map +1 -1
  152. package/dist/src/tui/operation-review-planner.js +130 -70
  153. package/dist/src/tui/operation-review-planner.js.map +1 -1
  154. package/dist/src/types.d.ts +8 -20
  155. package/dist/src/types.js.map +1 -1
  156. package/dist/src/utils/artifact-plan.d.ts +3 -36
  157. package/dist/src/utils/artifact-plan.js +11 -77
  158. package/dist/src/utils/artifact-plan.js.map +1 -1
  159. package/dist/src/utils/artifact-renderer.d.ts +0 -59
  160. package/dist/src/utils/artifact-renderer.js +2 -49
  161. package/dist/src/utils/artifact-renderer.js.map +1 -1
  162. package/dist/src/utils/artifact-request.d.ts +3 -26
  163. package/dist/src/utils/artifact-request.js +13 -36
  164. package/dist/src/utils/artifact-request.js.map +1 -1
  165. package/dist/src/utils/artifact-sources.d.ts +0 -8
  166. package/dist/src/utils/artifact-sources.js +0 -8
  167. package/dist/src/utils/artifact-sources.js.map +1 -1
  168. package/dist/src/utils/bundle-layout.js +2 -7
  169. package/dist/src/utils/bundle-layout.js.map +1 -1
  170. package/dist/src/utils/catalog-source-references.js +10 -0
  171. package/dist/src/utils/catalog-source-references.js.map +1 -1
  172. package/dist/src/utils/component-command-preparation.d.ts +6 -11
  173. package/dist/src/utils/component-command-preparation.js +109 -228
  174. package/dist/src/utils/component-command-preparation.js.map +1 -1
  175. package/dist/src/utils/managed-command-cli-review.d.ts +43 -0
  176. package/dist/src/utils/managed-command-cli-review.js +389 -0
  177. package/dist/src/utils/managed-command-cli-review.js.map +1 -0
  178. package/dist/src/utils/managed-command-closure.d.ts +14 -3
  179. package/dist/src/utils/managed-command-closure.js +144 -23
  180. package/dist/src/utils/managed-command-closure.js.map +1 -1
  181. package/dist/src/utils/managed-command-errors.d.ts +5 -0
  182. package/dist/src/utils/managed-command-errors.js +10 -0
  183. package/dist/src/utils/managed-command-errors.js.map +1 -0
  184. package/dist/src/utils/managed-command-materialization.d.ts +77 -113
  185. package/dist/src/utils/managed-command-materialization.js +324 -323
  186. package/dist/src/utils/managed-command-materialization.js.map +1 -1
  187. package/dist/src/utils/managed-command-preparation.d.ts +28 -65
  188. package/dist/src/utils/managed-command-preparation.js +33 -140
  189. package/dist/src/utils/managed-command-preparation.js.map +1 -1
  190. package/dist/src/utils/managed-command-review.d.ts +11 -4
  191. package/dist/src/utils/managed-command-review.js +33 -21
  192. package/dist/src/utils/managed-command-review.js.map +1 -1
  193. package/dist/src/utils/managed-command-runtime.d.ts +1 -0
  194. package/dist/src/utils/managed-command-runtime.js +6 -3
  195. package/dist/src/utils/managed-command-runtime.js.map +1 -1
  196. package/dist/src/utils/managed-command-snapshots.d.ts +17 -0
  197. package/dist/src/utils/managed-command-snapshots.js +84 -0
  198. package/dist/src/utils/managed-command-snapshots.js.map +1 -0
  199. package/dist/src/utils/managed-command-store.d.ts +65 -78
  200. package/dist/src/utils/managed-command-store.js +446 -383
  201. package/dist/src/utils/managed-command-store.js.map +1 -1
  202. package/dist/src/utils/multi-source-catalog.d.ts +2 -0
  203. package/dist/src/utils/multi-source-catalog.js +3 -1
  204. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  205. package/dist/src/utils/native-tool-context.d.ts +6 -3
  206. package/dist/src/utils/native-tool-context.js +3 -1
  207. package/dist/src/utils/native-tool-context.js.map +1 -1
  208. package/dist/src/utils/native-tool-review.d.ts +2 -12
  209. package/dist/src/utils/native-tool-review.js +6 -108
  210. package/dist/src/utils/native-tool-review.js.map +1 -1
  211. package/dist/src/utils/ownership.d.ts +7 -0
  212. package/dist/src/utils/ownership.js.map +1 -1
  213. package/dist/src/utils/platform-empty-state.d.ts +2 -1
  214. package/dist/src/utils/platform-empty-state.js +13 -12
  215. package/dist/src/utils/platform-empty-state.js.map +1 -1
  216. package/dist/src/utils/plugin-config-command-apply.d.ts +33 -0
  217. package/dist/src/utils/plugin-config-command-apply.js +134 -0
  218. package/dist/src/utils/plugin-config-command-apply.js.map +1 -0
  219. package/dist/src/utils/plugin-config-impact.d.ts +19 -9
  220. package/dist/src/utils/plugin-config-impact.js +56 -37
  221. package/dist/src/utils/plugin-config-impact.js.map +1 -1
  222. package/dist/src/utils/plugin-config-write.d.ts +19 -19
  223. package/dist/src/utils/plugin-config-write.js +194 -772
  224. package/dist/src/utils/plugin-config-write.js.map +1 -1
  225. package/dist/src/utils/rendered-contract.js +12 -6
  226. package/dist/src/utils/rendered-contract.js.map +1 -1
  227. package/package.json +4 -3
  228. package/dist/src/platforms/managed-command-placement.d.ts +0 -8
  229. package/dist/src/platforms/managed-command-placement.js +0 -79
  230. package/dist/src/platforms/managed-command-placement.js.map +0 -1
  231. package/dist/src/utils/managed-command-evidence.d.ts +0 -7
  232. package/dist/src/utils/managed-command-evidence.js +0 -10
  233. package/dist/src/utils/managed-command-evidence.js.map +0 -1
@@ -2,18 +2,23 @@ import crypto from 'node:crypto';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import fs from 'fs-extra';
5
+ import { sealPermissionBatches } from './permission-batch.js';
6
+ import { COMMAND_ROUTE_UNREACHABLE, HOST_PERMISSION_ADDITIONAL_IMPACT, publicHostPermissionResource } from '../output/component-delivery.js';
5
7
  import { createMarketplaceManifestEntry, getComponentFeatureRequirements, normalizeStaticPluginComponents } from '@lesliechan721/aw-plugin-core/manifest';
6
8
  import { selectNativeProduct, supportsSharedNativeProbe } from '../platforms/discovery.js';
7
9
  import { getAgentPluginAdapter } from '../platforms/registry.js';
8
10
  import { getAntigravityUnsupportedSkillControls, getQualifiedPlatformProfile } from '../platforms/capabilities.js';
9
- import { getDeploymentLayout, getDeploymentResourceKey, getInvocationPolicyPhysicalKey, isAntigravityProjectDirectory } from '../platforms/layout.js';
10
- import { getPhysicalKey } from '../platforms/identity.js';
11
+ import { getDeploymentLayout, getDeploymentResourceKey, getInvocationPolicyPhysicalKey, scopedPermissionPath, isAntigravityProjectDirectory } from '../platforms/layout.js';
12
+ import { getPhysicalKey, identityDigest } from '../platforms/identity.js';
11
13
  import { antigravityLegacyProjectComponent, deploymentPackageComponent, inspectStaticSupplements, requiredDeploymentActivation } from '../platforms/inspection.js';
12
14
  import { hasCompleteDeliveryDeclaration } from '../platforms/lifecycle.js';
13
15
  import { piAgentConsumerDiagnostic, piProjectListContainsOnly } from '../platforms/inspection-pi.js';
14
16
  import { grokRegistrationOwned, piProjectEmptyDeliveryObserved, piProjectRegistrationHidden, piProjectRemovalConfirmed } from '../platforms/lifecycle-native.js';
15
17
  import { createNativeLifecycleServices } from '../platforms/lifecycle-native-services.js';
16
18
  import { cursorWorkspaceOpenCommand } from '../platforms/projection.js';
19
+ import { grokProjectPermissionsAuthorized } from '../platforms/grok-permission-config.js';
20
+ import { isPermissionHost } from '../platforms/host-permission-policy.js';
21
+ import { hostPermissionFingerprint, missingPermissionOwnershipWarning, pendingRelatedProjectNotices, permissionComponent, permissionOwnerContentDigest, updateHostPermissions } from '../platforms/permission-ownership.js';
17
22
  import { cursorHookEntryCommand, cursorHooks } from '../platforms/cursor-workspace-hook.js';
18
23
  import { gapSupplementFiles, ownedSupplementFile, staticSupplementFiles } from '../platforms/supplement-layout.js';
19
24
  import { projectPlatformMarketplace } from '../platforms/projection-marketplace.js';
@@ -26,8 +31,6 @@ import { cleanupOwnedComponents, createSharedOwnerToken, inspectOwnedComponents,
26
31
  import { createPlatformInputEvidence, platformPackageInputDigest, platformPermissionNotices, readPlatformPackageContentDigest, writePlatformEmptyState } from '../utils/platform-empty-state.js';
27
32
  import { writePlatformSupplementState } from '../platforms/supplement-state.js';
28
33
  import { atomicReplaceSafeFile, assertSafeFileMutationPath } from '../utils/safe-fs.js';
29
- import { assertManagedCommandBindingIdentities, captureManagedCommandBindingRecoveryEvidence, publishManagedCommandBindings, listManagedCommands, readInstalledCommandProducer, revokeManagedCommandBindings } from '../utils/managed-command-store.js';
30
- import { captureNativeToolChanges } from '../utils/native-tool-review.js';
31
34
  import { captureManagedCommandReviewEvidence } from '../utils/managed-command-review.js';
32
35
  import { readClaudeSettings } from '../adapters/helpers.js';
33
36
  import { skillInvocationWarning } from '../utils/skill-invocation-warning.js';
@@ -40,15 +43,26 @@ export function nativeInstallResources(plans) {
40
43
  if (!plans.length)
41
44
  return [{ kind: 'exclusive' }];
42
45
  const paths = new Set();
46
+ const readPaths = new Set();
43
47
  for (const plan of plans) {
44
48
  const { binding, evidence } = plan;
45
49
  const { layout } = evidence;
46
50
  paths.add(layout.packageRoot);
51
+ for (const project of evidence.permissionBatch?.relatedProjects ?? [])
52
+ paths.add(project.path);
47
53
  for (const { component } of evidence.ownership) {
48
54
  if ('path' in component)
49
55
  paths.add(component.path);
50
56
  else if (component.kind === 'shared-config' && component.locator.kind === 'claude-permissions')
51
57
  paths.add(component.locator.settingsPath);
58
+ else if (component.kind === 'shared-config' && component.locator.kind === 'host-permissions') {
59
+ const { settingsPath } = component.locator;
60
+ // A plugin with no current permissions may still own rules from an earlier version.
61
+ if (plan.effects.some((effect) => effect.destination === settingsPath))
62
+ paths.add(settingsPath);
63
+ else
64
+ readPaths.add(settingsPath);
65
+ }
52
66
  else if (component.kind === 'shared-config' && component.locator.kind === 'cursor-workspace-hook')
53
67
  paths.add(component.locator.hooksPath);
54
68
  }
@@ -63,6 +77,9 @@ export function nativeInstallResources(plans) {
63
77
  // Grok inspects the entire project's packages and rules in one inventory.
64
78
  // Keep peers out until this write and its confirming inspection finish.
65
79
  if (binding.route === 'grok-directory') {
80
+ const entry = binding.consumers.find((consumer) => consumer.entry?.kind === 'cli')?.entry;
81
+ if (entry?.kind === 'cli')
82
+ readPaths.add(path.join(entry.configRoot, 'config.toml'));
66
83
  if (plan.effects.length)
67
84
  paths.add(layout.activationPath);
68
85
  continue;
@@ -80,7 +97,10 @@ export function nativeInstallResources(plans) {
80
97
  paths.add(consumer.entry.configRoot);
81
98
  }
82
99
  }
83
- return [...paths].map((value) => ({ kind: 'path', value }));
100
+ return [
101
+ ...Array.from(paths, (value) => ({ kind: 'path', value })),
102
+ ...[...readPaths].filter((value) => !paths.has(value)).map((value) => ({ kind: 'path', value, access: 'read' })),
103
+ ];
84
104
  }
85
105
  function matchesGrokComponentOrder(before, after, publishedRoots) {
86
106
  // Leave newly added or removed identities out of both sides. Every other
@@ -206,10 +226,12 @@ async function pathEvidence(location) {
206
226
  throw new Error('deploymentEvidenceInvalid: a deployment resource is not a regular file.');
207
227
  return { mode: stat.mode & 0o777, digest: crypto.createHash('sha256').update(await fs.readFile(location)).digest('hex') };
208
228
  }
209
- async function ownedContentDigest(component) {
229
+ async function ownedContentDigest(component, ctx) {
210
230
  if (component.kind === 'owned-directory' || component.kind === 'skill-directory')
211
231
  return readPlatformPackageContentDigest(component.path);
212
232
  if (component.kind === 'shared-config') {
233
+ if (component.locator.kind === 'host-permissions')
234
+ return permissionOwnerContentDigest(ctx, component.locator);
213
235
  let value;
214
236
  if (component.locator.kind === 'claude-permissions') {
215
237
  const permissions = (await readClaudeSettings(component.locator.settingsPath)).awGenerated?.permissions?.[component.locator.ownerKey];
@@ -259,7 +281,7 @@ async function ownedSupplements(binding, root, physicalKey) {
259
281
  return result;
260
282
  }
261
283
  function readContext(context, cwd) {
262
- return { cwd, env: context.env, runner: context.nativeCliRunner, signal: context.signal,
284
+ return { cwd, invocationCwd: context.invocationCwd, env: context.env, runner: context.nativeCliRunner, signal: context.signal,
263
285
  codexObservationSession: context.codexObservationSession };
264
286
  }
265
287
  function operation(input) {
@@ -286,6 +308,9 @@ function contributionComponent(binding, contribution, physicalKey) {
286
308
  sourceIdentity: binding.plugin.sourceIdentity, physicalKey,
287
309
  platform: binding.platform, scope: binding.scope.kind, artifactKey: path.basename(contribution.destination) };
288
310
  if (contribution.kind === 'config-entry') {
311
+ if (isPermissionHost(binding.platform) && contribution.mergeKey?.startsWith(`${binding.platform}-permissions:`)) {
312
+ return permissionComponent(binding, contribution.destination, physicalKey);
313
+ }
289
314
  if (binding.platform === 'claude' && contribution.mergeKey?.startsWith('claude-permissions:')) {
290
315
  const owner = { ...identity, artifactKey: contribution.mergeKey.replace(':', '-') };
291
316
  return { kind: 'shared-config', identity: owner, label: contribution.destination,
@@ -475,6 +500,22 @@ export class PlatformRebuildSession {
475
500
  published = new Map();
476
501
  nativeEffects = new Map();
477
502
  piProjectRegisteredRoots = new Map();
503
+ // A sibling target can update the same permission file. Only the exact pair
504
+ // of host and sidecar bytes confirmed by our own write inherits its baseline.
505
+ permissionWrites = new Map();
506
+ openCodeProjectBatches = new Map();
507
+ pendingOpenCodeProjectNotices(interrupted) {
508
+ return [...this.openCodeProjectBatches.values()].flatMap((batch) => pendingRelatedProjectNotices(batch, interrupted));
509
+ }
510
+ grokPermissionWrites = new Map();
511
+ recordPermissionWrite(target, previous, current, host) {
512
+ const last = this.permissionWrites.get(target);
513
+ this.permissionWrites.set(target, { previous: last?.current === previous ? last.previous : previous, current });
514
+ if (host && host.previous !== host.current) {
515
+ const earlier = this.grokPermissionWrites.get(target);
516
+ this.grokPermissionWrites.set(target, { previous: earlier && earlier.current === host.previous ? earlier.previous : host.previous, current: host.current });
517
+ }
518
+ }
478
519
  grokPublications = new Map();
479
520
  grokProjectRetirements = new Map();
480
521
  exclusions = new Map();
@@ -587,9 +628,7 @@ export class PlatformRebuildSession {
587
628
  userContentDigest: user.nativePackageContentDigest, userPhysicalKey: user.physicalKey });
588
629
  }
589
630
  async dispose() {
590
- for (const result of await Promise.allSettled(this.units.values()))
591
- if (result.status === 'fulfilled')
592
- await result.value.finalized.cleanup();
631
+ await Promise.allSettled(this.units.values());
593
632
  if (this.staging)
594
633
  await fs.remove(await this.staging);
595
634
  this.staging = undefined;
@@ -700,6 +739,7 @@ export class PlatformRebuildSession {
700
739
  this.marketplaceTargets.add(target);
701
740
  targets = [...this.marketplaceTargets];
702
741
  await this.freezeSharedPreApplyActions(targets);
742
+ await sealPermissionBatches(targets, (target) => readContext(this.context, target.identity.cwd), this.adapterFor);
703
743
  const retained = new Map(targets.flatMap((target) => (target.platformDeployment?.plans ?? [])
704
744
  .filter((plan) => plan.evidence.retainPackage).map((plan) => [plan.binding.physicalKey, plan.expected.unmet])));
705
745
  for (const target of targets)
@@ -780,10 +820,6 @@ export class PlatformRebuildSession {
780
820
  prepared.plans.splice(prepared.plans.findIndex((plan) => plan.binding.id === deployment.plan.binding.id), 1, next.prepared.plan);
781
821
  }
782
822
  }
783
- for (const target of targets)
784
- if (target.platformDeployment) {
785
- target.nativeToolChanges = await target.platformDeployment.captureNativeToolChanges();
786
- }
787
823
  }
788
824
  async verifyMarketplace(plan) {
789
825
  if (!plan.evidence.layout.marketplaceRoot || !plan.evidence.marketplace)
@@ -914,7 +950,7 @@ export class PlatformRebuildSession {
914
950
  const finalized = await finalizePlatformSkillProducers({ plugin: input.plugin, plugins: this.context.referencePlugins,
915
951
  platform: input.platform, renderUnit: commonUnit, prepared, skillWorkRoot: path.join(await this.root(), artifactValueDigest(unit.physicalKey).slice(7), 'skills'),
916
952
  cwd: input.cwd, env: this.context.env, signal: this.context.signal, scriptTimeoutMs: this.context.scriptTimeoutMs,
917
- packagePreparationCache: this.context.packagePreparationCache });
953
+ commandRecord: input.commandRecord });
918
954
  return { unit: commonUnit, prepared: finalized.prepared, finalized,
919
955
  evidenceInput: { renderUnit: commonUnit, capabilities, config } };
920
956
  })();
@@ -929,57 +965,18 @@ export class PlatformRebuildSession {
929
965
  const checks = new Map();
930
966
  const shadowedUsers = new Map();
931
967
  let initialDiscoveryCheck;
932
- const priorProducers = new Map();
933
- const priorResourceRoots = new Map();
934
- const bindingRecoveryEvidence = [];
935
968
  const emptyStates = new Map();
936
969
  const gapStates = new Map();
937
970
  const inputDigests = new Map();
938
971
  const supplementInputDigests = new Map();
939
- const commandInventory = await listManagedCommands(this.context.env);
940
- for (const entry of observed)
941
- priorProducers.set(entry.binding.id, commandInventory.commands.flatMap((command) => {
942
- if (command.owner.kind !== 'plugin')
943
- return [];
944
- const producer = command.owner.producer;
945
- return producer.kind !== 'package' && producer.sourceId === entry.binding.plugin.sourceId
946
- && producer.sourceIdentity === entry.binding.plugin.sourceIdentity && producer.pluginName === input.plugin.manifest.name
947
- && producer.platform === entry.binding.platform && producer.placementKey === entry.binding.physicalKey ? [producer] : [];
948
- }));
949
- for (const entry of observed) {
950
- const component = deploymentPackageComponent(entry.binding, entry.layout);
951
- if (component.kind !== 'owned-directory')
952
- continue;
953
- const marker = await readSkillOwnerMarker({ skillRoot: component.path, allowedRoot: component.allowedRoot,
954
- expectedIdentity: component.identity }).catch(() => null);
955
- for (const mapping of marker?.nativeProjection?.components ?? []) {
956
- if (!mapping.relativeOutputs.includes(`skills/${mapping.nativeName}/SKILL.md`))
957
- continue;
958
- const root = path.join(component.path, 'skills', mapping.nativeName);
959
- const record = await readInstalledCommandProducer(root).catch(() => null);
960
- const producer = record?.producer;
961
- if (!producer || producer.kind === 'package' || producer.sourceId !== entry.binding.plugin.sourceId
962
- || producer.sourceIdentity !== entry.binding.plugin.sourceIdentity || producer.pluginName !== input.plugin.manifest.name
963
- || producer.platform !== entry.binding.platform || producer.placementKey !== entry.binding.physicalKey
964
- || mapping.id !== (producer.kind === 'static-skill' ? `skill:${producer.key}` : producer.key))
965
- continue;
966
- priorProducers.get(entry.binding.id).push(producer);
967
- priorResourceRoots.set(entry.binding.id, [...priorResourceRoots.get(entry.binding.id) ?? [], root]);
968
- if (!removing) {
969
- // An unreadable index has no authority. Only the installed canonical
970
- // producer and its owned resources can establish its former identity.
971
- const recovery = await captureManagedCommandBindingRecoveryEvidence({ producer, resourceRoot: root,
972
- env: this.context.env }).catch(() => null);
973
- if (recovery)
974
- bindingRecoveryEvidence.push(recovery);
975
- }
976
- }
977
- }
978
- await assertManagedCommandBindingIdentities({ producers: [...preparedUnits.values()].flatMap((unit) => unit.finalized.commandCandidates),
979
- env: this.context.env, bindingRecoveryEvidence });
980
972
  for (const entry of observed) {
981
973
  const units = entry.binding.renderUnitIds.flatMap((id) => preparedUnits.has(id) ? [preparedUnits.get(id)] : []);
982
974
  const projections = [];
975
+ const hostEntry = entry.binding.consumers[0]?.entry;
976
+ const hostRoot = hostEntry && hostEntry.kind !== 'generic' ? hostEntry.configRoot : undefined;
977
+ const grokProjectBlocked = entry.binding.platform === 'grok' && entry.binding.scope.kind === 'project'
978
+ && (entry.observation.grokScopeAuthorization !== 'granted' || !hostRoot
979
+ || !await grokProjectPermissionsAuthorized(ctx, hostRoot, entry.binding.scope.projectRoot));
983
980
  for (const unit of units) {
984
981
  const sameScope = units.filter((candidate) => artifactValueDigest(candidate.unit.renderScope) === artifactValueDigest(unit.unit.renderScope));
985
982
  const components = mergeExpectedComponentSets(sameScope.map((candidate) => candidate.prepared.expected)).components;
@@ -988,19 +985,24 @@ export class PlatformRebuildSession {
988
985
  files: sameScope.flatMap((candidate) => candidate.prepared.resources.files),
989
986
  commandResources: sameScope.flatMap((candidate) => candidate.prepared.resources.commandResources),
990
987
  digest: artifactValueDigest(sameScope.map((candidate) => candidate.prepared.resources.digest)) };
991
- const projection = await adapter.project({ ...ctx, stagingRoot: path.join(await this.root(), 'projection'), commandResolver: unit.finalized.commandResolver }, {
988
+ const projection = await adapter.project({ ...ctx, stagingRoot: path.join(await this.root(), 'projection') }, {
992
989
  binding: entry.binding, renderUnit: unit.unit, capabilities: adapter.capabilities({ ...entry, renderUnit: unit.unit, profile: getQualifiedPlatformProfile(input.platform) }),
993
- components, resources, policy: components.length ? unit.finalized.invocationPolicy.policy : { platform: input.platform, permissions: [] }
990
+ components, resources, policy: unit.finalized.invocationPolicy.policy,
991
+ ...(grokProjectBlocked ? { grokScopeAuthorization: 'denied' } : {})
994
992
  });
995
993
  for (const notice of unit.finalized.invocationPolicy.diagnostics) {
996
994
  projection.diagnostics.push({ ...notice, subject: { ...notice.subject, scope: entry.binding.scope.kind } });
997
995
  }
998
996
  projections.push(projection);
999
997
  }
1000
- const policyKey = input.platform === 'codex' || input.platform === 'claude' ? await getInvocationPolicyPhysicalKey(ctx, entry.binding) : undefined;
998
+ const hostPolicyPath = isPermissionHost(input.platform) && (input.platform !== 'antigravity' || entry.binding.route === 'antigravity-cli')
999
+ ? await scopedPermissionPath(ctx, input.platform, entry.binding.scope, hostEntry && hostEntry.kind !== 'generic' ? hostEntry.configRoot : undefined)
1000
+ : undefined;
1001
+ const policyKey = hostPolicyPath || input.platform === 'codex' || input.platform === 'claude'
1002
+ ? await getInvocationPolicyPhysicalKey(ctx, entry.binding) : undefined;
1001
1003
  const expected = mergeExpectedComponentSets(units.map((unit) => unit.prepared.expected));
1002
1004
  const currentComponents = [deploymentPackageComponent(entry.binding, entry.layout),
1003
- ...projections.flatMap((projection) => projection.supplements.map((contribution) => contributionComponent(entry.binding, contribution, policyKey && (contribution.mergeKey?.startsWith('claude-permissions:') || input.platform === 'codex' && contribution.destination.endsWith('.rules'))
1005
+ ...projections.flatMap((projection) => projection.supplements.map((contribution) => contributionComponent(entry.binding, contribution, policyKey && (contribution.mergeKey?.startsWith(`${input.platform}-permissions:`) || input.platform === 'codex' && contribution.destination.endsWith('.rules'))
1004
1006
  ? policyKey : entry.layout.renderUnits.find((unit) => unit.id === projection.renderUnitId).physicalKey)))];
1005
1007
  const historical = await ownedSupplements(entry.binding, entry.layout.supplementRoot, entry.layout.renderUnits.find((unit) => unit.output === 'supplement')?.physicalKey);
1006
1008
  const antigravityProject = isAntigravityProjectDirectory(entry.binding);
@@ -1010,6 +1012,9 @@ export class PlatformRebuildSession {
1010
1012
  historical.push(legacyPackage);
1011
1013
  if (entry.binding.platform === 'codex' && policyKey)
1012
1014
  historical.push(...await ownedSupplements(entry.binding, path.join(entry.layout.activationPath, 'rules'), policyKey));
1015
+ if (hostPolicyPath && policyKey && !grokProjectBlocked) {
1016
+ historical.push(permissionComponent(entry.binding, hostPolicyPath, policyKey));
1017
+ }
1013
1018
  if (entry.binding.platform === 'claude' && policyKey) {
1014
1019
  const destination = path.join(entry.layout.activationPath, entry.binding.scope.kind === 'project' ? 'settings.local.json' : 'settings.json');
1015
1020
  historical.push(contributionComponent(entry.binding, { id: 'policy:claude-permissions', componentIds: [], kind: 'config-entry',
@@ -1042,12 +1047,22 @@ export class PlatformRebuildSession {
1042
1047
  }
1043
1048
  const inspected = await inspectOwnedComponents({ components, executor: this.ownership });
1044
1049
  const managedCommandReview = await captureManagedCommandReviewEvidence({ binding: entry.binding,
1045
- renderUnits: entry.layout.renderUnits, components: units.flatMap((unit) => unit.prepared.expected.components), projections });
1050
+ renderUnits: entry.layout.renderUnits, inactivePermissions: units.flatMap((unit) => unit.finalized.invocationPolicy.inactivePermissions), projections });
1046
1051
  const currentMutable = async (batch) => {
1047
1052
  const observation = await adapter.inspect(batch ? { ...ctx, ...batch } : ctx, entry.binding);
1048
1053
  return { observation, references: await sharedReferences(this.context, entry.binding, observation, entry.layout),
1049
- paths: await Promise.all(components.map(async (component) => 'path' in component ? pathEvidence(component.path) : {
1050
- ownership: await inspectOwnedComponents({ components: [component], executor: this.ownership }), contentDigest: await ownedContentDigest(component),
1054
+ paths: await Promise.all(components.map(async (component) => {
1055
+ if ('path' in component)
1056
+ return pathEvidence(component.path);
1057
+ const ownership = await inspectOwnedComponents({ components: [component], executor: this.ownership });
1058
+ if (component.kind === 'shared-config' && component.locator.kind === 'host-permissions') {
1059
+ const locator = component.locator;
1060
+ const plannedWrite = projections.some((projection) => projection.supplements.some((item) => item.destination === locator.settingsPath));
1061
+ const fingerprint = await hostPermissionFingerprint(ctx, locator, plannedWrite);
1062
+ const last = this.permissionWrites.get(component.locator.settingsPath);
1063
+ return { ownership, fingerprint: last?.current === fingerprint ? last.previous : fingerprint };
1064
+ }
1065
+ return { ownership, contentDigest: await ownedContentDigest(component, ctx) };
1051
1066
  })) };
1052
1067
  };
1053
1068
  const shadowedUser = operation(input) === 'ensure' ? await grokUserBehindProject(ctx, entry.binding, entry.observation) : undefined;
@@ -1115,8 +1130,10 @@ export class PlatformRebuildSession {
1115
1130
  const retirements = binding.route === 'grok-directory' && operation(input) === 'ensure'
1116
1131
  ? [...this.grokProjectRetirements.values()].filter((item) => item.projectRoot === scopeRoot) : [];
1117
1132
  const baselineDigest = artifactValueDigest(mutableBaseline);
1118
- if (!publications.length && !retirements.length)
1119
- return artifactValueDigest(current) === baselineDigest;
1133
+ if (artifactValueDigest(current) === baselineDigest)
1134
+ return true;
1135
+ if (!scopeRoot || !publications.length && !retirements.length && !this.grokPermissionWrites.size)
1136
+ return false;
1120
1137
  const before = mutableBaseline.observation.prerequisites.nativeSources;
1121
1138
  const after = current.observation.prerequisites.nativeSources;
1122
1139
  const priorEvidence = before?.grokScopeEvidence;
@@ -1124,6 +1141,22 @@ export class PlatformRebuildSession {
1124
1141
  if (before?.observation !== 'complete' || after?.observation !== 'complete' || !scopeEvidence || !priorEvidence
1125
1142
  || scopeEvidence.scopeDigest !== priorEvidence.scopeDigest)
1126
1143
  return false;
1144
+ let permissionChanged = false;
1145
+ if (scopeEvidence.permissionConfigs.length !== priorEvidence.permissionConfigs.length)
1146
+ return false;
1147
+ for (const [index, file] of scopeEvidence.permissionConfigs.entries()) {
1148
+ const prior = priorEvidence.permissionConfigs[index];
1149
+ if (prior.path !== file.path)
1150
+ return false;
1151
+ if (prior.digest === file.digest)
1152
+ continue;
1153
+ const write = this.grokPermissionWrites.get(file.path);
1154
+ if (!write || write.previous !== prior.digest || write.current !== file.digest)
1155
+ return false;
1156
+ permissionChanged = true;
1157
+ }
1158
+ if (!permissionChanged && scopeEvidence.permissionInventoryDigest !== priorEvidence.permissionInventoryDigest)
1159
+ return false;
1127
1160
  const paths = after.sources.map((source) => path.normalize(source.path));
1128
1161
  const priorPaths = before.sources.map((source) => path.normalize(source.path));
1129
1162
  if (new Set(paths).size !== paths.length || new Set(priorPaths).size !== priorPaths.length)
@@ -1135,7 +1168,7 @@ export class PlatformRebuildSession {
1135
1168
  const orderChecks = [priorEvidence];
1136
1169
  const instructions = [...scopeEvidence.instructions];
1137
1170
  const retiredSources = new Set();
1138
- let adjusted = false;
1171
+ let adjusted = permissionChanged;
1139
1172
  for (const retirement of retirements) {
1140
1173
  const { name, projectPackage, projectDigest, userPackage, userDigest, userSource, userContentDigest, userPhysicalKey } = retirement;
1141
1174
  if (!priorPaths.includes(projectPackage))
@@ -1259,8 +1292,8 @@ export class PlatformRebuildSession {
1259
1292
  return false;
1260
1293
  }
1261
1294
  const normalizedSources = { ...after, sources: sources.filter((_, index) => !addedSources.has(paths[index])),
1262
- configurationEvidence: before.configurationEvidence, grokScopeEvidence: { ...scopeEvidence, instructions,
1263
- hookOrder: priorEvidence.hookOrder, resourceOrder: priorEvidence.resourceOrder,
1295
+ configurationEvidence: before.configurationEvidence, grokScopeEvidence: { ...scopeEvidence, instructions, permissionConfigs: priorEvidence.permissionConfigs,
1296
+ permissionInventoryDigest: priorEvidence.permissionInventoryDigest, hookOrder: priorEvidence.hookOrder, resourceOrder: priorEvidence.resourceOrder,
1264
1297
  sourceDigests: sourceDigests.filter((_, index) => !addedSources.has(paths[index])) } };
1265
1298
  const observation = { ...current.observation, prerequisites: { ...current.observation.prerequisites, nativeSources: normalizedSources } };
1266
1299
  const normalizedBefore = { ...before, sources: before.sources.filter((_, index) => !retiredSources.has(priorPaths[index])),
@@ -1352,13 +1385,21 @@ export class PlatformRebuildSession {
1352
1385
  } });
1353
1386
  const evidence = { fingerprint: initial, managedCommandReview, layout: entry.layout, renderUnits: entry.layout.renderUnits,
1354
1387
  ownership: await Promise.all(inspected.components.map(async ({ component, state }) => ({ component, state,
1355
- contentDigest: state === 'present' ? await ownedContentDigest(component) : undefined,
1388
+ contentDigest: state === 'present' ? await ownedContentDigest(component, ctx) : undefined,
1356
1389
  physicalKey: component.identity.physicalKey ?? entry.binding.physicalKey }))),
1357
1390
  sharedReferences: await sharedReferences(this.context, entry.binding, preparationObservation, entry.layout),
1358
1391
  nativeIdentity: preparationObservation.nativeIdentity ?? entry.layout.nativeIdentity,
1359
1392
  contentMatches: projections.some((projection) => projection.bundle !== null)
1360
1393
  && (!antigravityProject || preparationObservation.ownership === 'aw')
1361
1394
  && await readPlatformPackageContentDigest(entry.layout.packageRoot) === projections.find((projection) => projection.bundle !== null)?.bundle?.contentDigest };
1395
+ if (removing && isPermissionHost(entry.binding.platform) && (entry.binding.platform === 'opencode' || hostPolicyPath)) {
1396
+ const permission = historical.find((component) => component.kind === 'shared-config' && component.locator.kind === 'host-permissions');
1397
+ const settingsPath = permission?.kind === 'shared-config' && permission.locator.kind === 'host-permissions'
1398
+ ? permission.locator.settingsPath : undefined;
1399
+ const notice = await missingPermissionOwnershipWarning(ctx, entry.binding.plugin.pluginId, entry.binding.scope.kind, settingsPath ?? hostPolicyPath, entry.binding.platform, grokProjectBlocked);
1400
+ if (notice)
1401
+ evidence.permissionOwnershipWarning = notice;
1402
+ }
1362
1403
  if (entry.binding.platform === 'codex') {
1363
1404
  const hostEntry = entry.binding.consumers.find((consumer) => consumer.entry?.kind === 'cli'
1364
1405
  || removing && consumer.entry?.kind === 'directory')?.entry;
@@ -1399,16 +1440,17 @@ export class PlatformRebuildSession {
1399
1440
  const hasNativeCopy = ['grok-cli', 'antigravity-cli'].includes(entry.binding.route) && preparationObservation.registration === 'present';
1400
1441
  const previousCopyUnconfirmed = hasNativeCopy && (!old?.nativeProjection
1401
1442
  || old.nativeProjection.contentDigest !== preparationObservation.nativePackageContentDigest);
1402
- evidence.retainPackage = expected.unmet.some((gap) => !isDeliveryCapabilityGap(gap)) || previousCopyUnconfirmed
1443
+ evidence.retainPackage = expected.unmet.some((gap) => !isDeliveryCapabilityGap(gap) && gap.reasonCode !== COMMAND_ROUTE_UNREACHABLE) || previousCopyUnconfirmed
1403
1444
  || !evidence.contentMatches && (!previousContentsVerified || dropsPriorComponent
1404
1445
  && (!complete || evidence.sharedReferences !== 'none' || preparationObservation.ownership !== 'aw'));
1405
1446
  }
1406
1447
  if (!removing) {
1407
- const inputEvidence = await createPlatformInputEvidence({ plugin: input.plugin, binding: entry.binding, units: units.map((unit) => unit.evidenceInput) });
1448
+ const inputEvidence = await createPlatformInputEvidence({ plugin: input.plugin, commandRoutes: input.commandRecord?.routes, binding: entry.binding, units: units.map((unit) => unit.evidenceInput) });
1408
1449
  const packageComponents = projections.find((projection) => projection.bundle)?.components;
1409
1450
  inputDigests.set(entry.binding.id, platformPackageInputDigest(inputEvidence, packageComponents));
1410
1451
  if (expected.unmet.every(isDeliveryCapabilityGap)) {
1411
- const permissionNotices = platformPermissionNotices(projections.flatMap(({ diagnostics }) => diagnostics));
1452
+ const permissionNotices = platformPermissionNotices(projections.flatMap(({ diagnostics }) => diagnostics)
1453
+ .filter((notice) => !notice.subject?.pluginId || notice.subject.pluginId === entry.binding.plugin.pluginId));
1412
1454
  const noticeFields = permissionNotices.length ? { permissionNotices } : {};
1413
1455
  if (expected.unmet.length || expected.components.length && permissionNotices.length)
1414
1456
  gapStates.set(entry.binding.id, { ...inputEvidence,
@@ -1444,7 +1486,6 @@ export class PlatformRebuildSession {
1444
1486
  }
1445
1487
  target.ownedComponents = plans.flatMap((plan) => plan.evidence.ownership.map((item) => item.component));
1446
1488
  target.desiredOwnedComponents = target.ownedComponents;
1447
- let frozenNativeTools;
1448
1489
  const verifyChecks = async (selected, batch) => {
1449
1490
  for (const check of selected)
1450
1491
  if (await check(batch) !== true)
@@ -1457,7 +1498,7 @@ export class PlatformRebuildSession {
1457
1498
  const canVerifyAtExecution = () => {
1458
1499
  const prepared = deployments[0];
1459
1500
  if (!prepared || deployments.length !== 1 || plans.length !== 1 || plans[0] !== prepared.plan || blockedReceipts.length
1460
- || target.operationActions === undefined || target.operationActions.some((action) => action.kind === 'runPreApply' || action.kind === 'syncManagedCommandPackage'))
1501
+ || target.operationActions === undefined || target.operationActions.some((action) => action.kind === 'runPreApply' || action.kind === 'syncManagedCommandPackage' || action.kind === 'removeManagedCommandPackage'))
1461
1502
  return false;
1462
1503
  const { plan, driverState } = prepared;
1463
1504
  const hiddenEmptyPiProject = piProjectRegistrationHidden(plan.binding, driverState.before)
@@ -1493,31 +1534,7 @@ export class PlatformRebuildSession {
1493
1534
  },
1494
1535
  } : undefined;
1495
1536
  target.platformDeployment = { deployments, plans, blockedReceipts, cleanupResults, privatePackage,
1496
- writesManagedCommands: [...preparedUnits.values()].some((unit) => unit.finalized.commandCandidates.length > 0)
1497
- || [...priorProducers.values()].some((producers) => producers.length > 0),
1498
1537
  canVerifyAtExecution,
1499
- captureNativeToolChanges: async () => {
1500
- const signature = artifactValueDigest(deployments.map(({ plan }) => ({ bindingId: plan.binding.id,
1501
- retainPackage: plan.evidence.retainPackage, effects: plan.effects })));
1502
- if (frozenNativeTools?.signature === signature)
1503
- return frozenNativeTools.changes;
1504
- const changes = [];
1505
- for (const { plan } of deployments) {
1506
- const root = plan.evidence.layout.packageRoot;
1507
- const publishes = plan.effects.some((effect) => effect.kind === 'publish-package' && effect.destination === root);
1508
- const removes = plan.effects.some((effect) => effect.kind === 'remove-owned' && effect.destination === root);
1509
- if (plan.evidence.retainPackage || !publishes && !removes)
1510
- continue;
1511
- const next = publishes ? [...preparedUnits.values()].flatMap((unit) => unit.finalized.commandCandidates)
1512
- .filter((candidate) => candidate.producer.kind !== 'package' && candidate.producer.placementKey === plan.binding.physicalKey) : [];
1513
- changes.push(...await captureNativeToolChanges({ actions: [],
1514
- producers: [...priorProducers.get(plan.binding.id) ?? [], ...next.map((candidate) => candidate.producer)],
1515
- nextProducers: next, removed: removes, env: this.context.env,
1516
- resourceRoots: [...priorResourceRoots.get(plan.binding.id) ?? [], ...(removes ? [root] : [])] }));
1517
- }
1518
- frozenNativeTools = { signature, changes };
1519
- return changes;
1520
- },
1521
1538
  verify,
1522
1539
  postcheck: async (receipts, options) => {
1523
1540
  let incomplete = false;
@@ -1669,10 +1686,16 @@ export class PlatformRebuildSession {
1669
1686
  cleanupResults.length = 0;
1670
1687
  const receipts = [...blockedReceipts];
1671
1688
  for (const prepared of deployments) {
1689
+ const batch = prepared.plan.evidence.permissionBatch;
1690
+ let relatedProjectBatch;
1691
+ if (batch && prepared.plan.binding.platform === 'opencode' && prepared.plan.binding.scope.kind === 'user') {
1692
+ const key = identityDigest({ owners: batch.owners, projects: batch.relatedProjects });
1693
+ relatedProjectBatch = this.openCodeProjectBatches.get(key) ?? { writes: new Map(), pending: new Map() };
1694
+ this.openCodeProjectBatches.set(key, relatedProjectBatch);
1695
+ }
1672
1696
  const supplementFiles = componentSupplementFiles(prepared.plan);
1673
1697
  const writtenFiles = new Map();
1674
- const commandPreparationFailed = prepared.plan.binding.renderUnitIds.some((unitId) => preparedUnits.get(unitId)?.finalized.producerResolutions
1675
- .some((resolution) => resolution.state === 'failed'));
1698
+ const appliedPermissionNotices = [];
1676
1699
  let receipt;
1677
1700
  const peers = prepared.plan.binding.route === 'codex-marketplace' ? [...this.mutableChecks.values()].filter((check) => check.physicalKey !== prepared.plan.binding.physicalKey && check.marketplaceRoot === prepared.plan.evidence.layout.marketplaceRoot
1678
1701
  && check.sourceId === prepared.plan.binding.plugin.sourceId && check.sourceIdentity === prepared.plan.binding.plugin.sourceIdentity) : [];
@@ -1712,7 +1735,7 @@ export class PlatformRebuildSession {
1712
1735
  components: prepared.plan.projections.filter((projection) => projection.bundle !== null).flatMap((projection) => projection.components),
1713
1736
  inputDigest: inputDigests.get(prepared.plan.binding.id), contentDigest: bundle.contentDigest,
1714
1737
  ...(bundle.piExtensionDigest ? { piExtensionDigest: bundle.piExtensionDigest } : {}),
1715
- preparation: prepared.plan.expected.unmet.some((gap) => !isDeliveryCapabilityGap(gap)) || commandPreparationFailed ? 'partial' : 'complete',
1738
+ preparation: prepared.plan.expected.unmet.some((gap) => !isDeliveryCapabilityGap(gap)) ? 'partial' : 'complete',
1716
1739
  physicalIdentity: (await getDeploymentLayout(ctx, prepared.plan.binding)).physicalIdentity,
1717
1740
  }, stagedPackage);
1718
1741
  this.published.set(prepared.plan.binding.physicalKey, publication);
@@ -1739,13 +1762,28 @@ export class PlatformRebuildSession {
1739
1762
  await atomicReplaceSafeFile({ filePath: component.locator.hooksPath, allowedRoot: path.dirname(component.locator.hooksPath), label: 'Cursor workspaceOpen',
1740
1763
  content: `${JSON.stringify({ ...value, hooks: { ...hooks, workspaceOpen: [...entries.filter((item) => cursorHookEntryCommand(item) !== locator.command), ...desired] } }, null, 2)}\n` });
1741
1764
  }
1765
+ else if (component.kind === 'shared-config' && component.locator.kind === 'host-permissions') {
1766
+ const locator = component.locator;
1767
+ const changed = await updateHostPermissions(ctx, locator, await jsonObject(contribution.stagingPath), (previous, current, target = locator.settingsPath, host) => this.recordPermissionWrite(target, previous, current, locator.platform === 'grok' ? host : undefined), batch, (notices) => appliedPermissionNotices.push(...notices), undefined, relatedProjectBatch);
1768
+ return { mutation: changed ? 'confirmed' : 'none', changed };
1769
+ }
1742
1770
  else if (component.kind === 'shared-config' && component.locator.kind === 'claude-permissions') {
1743
1771
  const content = await jsonObject(contribution.stagingPath);
1744
1772
  if (content.kind !== 'claude-permissions')
1745
1773
  throw new Error('platformContributionUnsupported');
1746
- await applyPlannedOperationAction({ kind: 'updateSharedConfig', pluginId: prepared.plan.binding.plugin.pluginId,
1774
+ const added = await applyPlannedOperationAction({ kind: 'updateSharedConfig', pluginId: prepared.plan.binding.plugin.pluginId,
1747
1775
  platform: 'claude', scope: prepared.plan.binding.scope.kind, owner: component.identity, locator: component.locator,
1748
1776
  contentDigest: contribution.contentDigest, mutation: { kind: 'claude-permissions', permissions: content.permissions } });
1777
+ for (const projection of prepared.plan.projections) {
1778
+ for (const notice of projection.diagnostics) {
1779
+ const { permissionAction, permissionResource, path } = notice.detail ?? {};
1780
+ if (notice.code === HOST_PERMISSION_ADDITIONAL_IMPACT && path === contribution.destination
1781
+ && permissionAction && permissionResource
1782
+ && added[permissionAction].some((rule) => publicHostPermissionResource(rule) === permissionResource)) {
1783
+ appliedPermissionNotices.push(notice);
1784
+ }
1785
+ }
1786
+ }
1749
1787
  }
1750
1788
  else
1751
1789
  throw new Error('platformContributionUnsupported');
@@ -1762,13 +1800,31 @@ export class PlatformRebuildSession {
1762
1800
  });
1763
1801
  }
1764
1802
  }
1765
- const result = await cleanupOwnedComponents({ components: [component], executor: this.ownership });
1803
+ const locator = component.kind === 'shared-config' && component.locator.kind === 'host-permissions' ? component.locator : undefined;
1804
+ const restorations = [];
1805
+ let permissionFailure;
1806
+ const executor = locator ? { ...this.ownership, removeShared: async () => {
1807
+ try {
1808
+ await updateHostPermissions(ctx, locator, undefined, (previous, current, target = locator.settingsPath, host) => this.recordPermissionWrite(target, previous, current, locator.platform === 'grok' ? host : undefined), batch, (notices) => {
1809
+ for (const notice of notices) {
1810
+ (notice.code === 'hostPermissionRestored' ? restorations : appliedPermissionNotices).push(notice);
1811
+ }
1812
+ }, undefined, relatedProjectBatch);
1813
+ }
1814
+ catch (error) {
1815
+ permissionFailure = error;
1816
+ throw error;
1817
+ }
1818
+ } } : this.ownership;
1819
+ const result = await cleanupOwnedComponents({ components: [component], executor });
1766
1820
  cleanupResults.push(result);
1767
1821
  if (result.failures.length || result.residual.length || result.quarantined.length) {
1822
+ if (permissionFailure)
1823
+ throw permissionFailure;
1768
1824
  throw Object.assign(new Error('deploymentCleanupIncomplete'), result.removed.length || result.quarantined.length
1769
1825
  ? { mutation: 'confirmed' } : {});
1770
1826
  }
1771
- return { mutation: result.removed.length ? 'confirmed' : 'none', changed: result.removed.length > 0 };
1827
+ return { mutation: result.removed.length ? 'confirmed' : 'none', changed: result.removed.length > 0, diagnostics: restorations };
1772
1828
  },
1773
1829
  } }, prepared);
1774
1830
  }
@@ -1783,6 +1839,7 @@ export class PlatformRebuildSession {
1783
1839
  unmet: prepared.plan.expected.unmet.map((gap) => ({ ...gap, productIds: prepared.plan.binding.consumers.map(({ id }) => id) })),
1784
1840
  reload: 'unknown', diagnostics: [diagnostic] };
1785
1841
  }
1842
+ receipt.diagnostics.push(...appliedPermissionNotices);
1786
1843
  receipts.push(receipt);
1787
1844
  if (receipt.diagnostics.some(({ code }) => code === 'processCleanupUnconfirmed'))
1788
1845
  return receipts;
@@ -1795,13 +1852,6 @@ export class PlatformRebuildSession {
1795
1852
  : 'The shared package was kept for another scope.',
1796
1853
  subject: { target: prepared.plan.binding.platform, pluginId: prepared.plan.binding.plugin.pluginId, scope: prepared.plan.binding.scope.kind } });
1797
1854
  }
1798
- for (const unitId of prepared.plan.binding.renderUnitIds)
1799
- for (const resolution of preparedUnits.get(unitId)?.finalized.producerResolutions ?? []) {
1800
- if (resolution.state !== 'failed')
1801
- continue;
1802
- receipt.diagnostics.push({ code: 'managedCommandProducerFailed', severity: 'error', message: resolution.error.message,
1803
- subject: { target: prepared.plan.binding.platform, pluginId: prepared.plan.binding.plugin.pluginId, scope: prepared.plan.binding.scope.kind } });
1804
- }
1805
1855
  const publish = prepared.plan.effects.find((effect) => effect.kind === 'publish-package');
1806
1856
  const publication = receipt.effects.find((result) => result.id === publish?.id && result.status === 'applied');
1807
1857
  try {
@@ -1840,18 +1890,8 @@ export class PlatformRebuildSession {
1840
1890
  this.piProjectRegisteredRoots.set(piInventoryKey, registered);
1841
1891
  }
1842
1892
  try {
1843
- const candidates = [...preparedUnits.values()].flatMap((unit) => unit.finalized.commandCandidates)
1844
- .filter((candidate) => candidate.producer.kind !== 'package' && candidate.producer.placementKey === prepared.plan.binding.physicalKey);
1845
1893
  const root = prepared.plan.evidence.layout.packageRoot;
1846
1894
  const mappings = prepared.plan.projections.filter((projection) => projection.bundle !== null).flatMap((projection) => projection.components);
1847
- for (const candidate of candidates) {
1848
- const componentId = candidate.producer.kind === 'static-skill' ? `skill:${candidate.producer.key}` : candidate.producer.key;
1849
- const mapping = mappings.find((item) => item.id === componentId);
1850
- if (!mapping || !mapping.relativeOutputs.some((output) => output === `skills/${mapping.nativeName}/SKILL.md`))
1851
- throw new Error('commandProducerProjectionMissing');
1852
- await publishManagedCommandBindings({ ...candidate, resourceRoot: path.join(root, 'skills', mapping.nativeName),
1853
- env: this.context.env, bindingRecoveryEvidence });
1854
- }
1855
1895
  const bundle = prepared.plan.projections.find((projection) => projection.bundle)?.bundle;
1856
1896
  const packageOwner = prepared.plan.evidence.ownership.find((slot) => 'path' in slot.component && slot.component.path === root)?.component;
1857
1897
  if (bundle && packageOwner?.kind === 'owned-directory' && prepared.plan.evidence.contentMatches
@@ -1860,7 +1900,7 @@ export class PlatformRebuildSession {
1860
1900
  && await readPlatformPackageContentDigest(root) === bundle.contentDigest) {
1861
1901
  const marker = await readSkillOwnerMarker({ skillRoot: root, allowedRoot: packageOwner.allowedRoot, expectedIdentity: packageOwner.identity });
1862
1902
  const projection = { components: mappings, contentDigest: bundle.contentDigest,
1863
- inputDigest: inputDigests.get(prepared.plan.binding.id), preparation: prepared.plan.expected.unmet.some((gap) => !isDeliveryCapabilityGap(gap)) || commandPreparationFailed ? 'partial' : 'complete',
1903
+ inputDigest: inputDigests.get(prepared.plan.binding.id), preparation: prepared.plan.expected.unmet.some((gap) => !isDeliveryCapabilityGap(gap)) ? 'partial' : 'complete',
1864
1904
  ...(bundle.piExtensionDigest && marker?.nativeProjection?.piExtensionDigest === bundle.piExtensionDigest
1865
1905
  ? { piExtensionDigest: bundle.piExtensionDigest } : {}),
1866
1906
  physicalIdentity: (await getDeploymentLayout(ctx, prepared.plan.binding)).physicalIdentity };
@@ -1872,15 +1912,6 @@ export class PlatformRebuildSession {
1872
1912
  receipt.after = await adapter.inspect(ctx, prepared.plan.binding);
1873
1913
  }
1874
1914
  }
1875
- const packageRemoved = !await fs.pathExists(root);
1876
- for (const producer of priorProducers.get(prepared.plan.binding.id) ?? []) {
1877
- if (candidates.some((candidate) => artifactValueDigest(candidate.producer) === artifactValueDigest(producer)))
1878
- continue;
1879
- const componentId = producer.kind === 'static-skill' ? `skill:${producer.key}` : producer.key;
1880
- if (packageRemoved || publication && !prepared.plan.expected.unmet.some((gap) => gap.id === componentId)) {
1881
- await revokeManagedCommandBindings(producer, this.context.env);
1882
- }
1883
- }
1884
1915
  const emptyState = gapStates.get(prepared.plan.binding.id) ?? emptyStates.get(prepared.plan.binding.id);
1885
1916
  const removedByCommand = piProjectRemovalConfirmed(prepared.plan, receipt);
1886
1917
  const inactiveScope = removedByCommand || receipt.after.registration === 'absent'
@@ -1912,7 +1943,7 @@ export class PlatformRebuildSession {
1912
1943
  }
1913
1944
  }
1914
1945
  catch (error) {
1915
- receipt.diagnostics.push({ code: 'managedCommandPublicationFailed', severity: 'error',
1946
+ receipt.diagnostics.push({ code: 'platformProjectionEvidenceFailed', severity: 'error',
1916
1947
  message: error instanceof Error ? error.message : String(error),
1917
1948
  subject: { target: prepared.plan.binding.platform, pluginId: prepared.plan.binding.plugin.pluginId, scope: prepared.plan.binding.scope.kind } });
1918
1949
  }