@lesliechan721/aw 0.1.0-beta.101 → 0.1.0-beta.103

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 (199) hide show
  1. package/dist/src/commands/catalog-generation.d.ts +2 -5
  2. package/dist/src/commands/catalog-generation.js +2 -4
  3. package/dist/src/commands/catalog-generation.js.map +1 -1
  4. package/dist/src/commands/lifecycle-command-package.d.ts +1 -1
  5. package/dist/src/commands/lifecycle-command-package.js +40 -2
  6. package/dist/src/commands/lifecycle-command-package.js.map +1 -1
  7. package/dist/src/commands/managed-commands.d.ts +2 -1
  8. package/dist/src/commands/managed-commands.js +4 -2
  9. package/dist/src/commands/managed-commands.js.map +1 -1
  10. package/dist/src/commands/operation-plan.d.ts +2 -8
  11. package/dist/src/commands/operation-plan.js.map +1 -1
  12. package/dist/src/commands/public-config-confirmation.d.ts +16 -10
  13. package/dist/src/commands/public-config-confirmation.js +87 -52
  14. package/dist/src/commands/public-config-confirmation.js.map +1 -1
  15. package/dist/src/commands/public-lifecycle.d.ts +1 -1
  16. package/dist/src/commands/public-lifecycle.js +36 -8
  17. package/dist/src/commands/public-lifecycle.js.map +1 -1
  18. package/dist/src/commands/public-plugin-query.js +6 -4
  19. package/dist/src/commands/public-plugin-query.js.map +1 -1
  20. package/dist/src/commands/rebuild-command.d.ts +22 -6
  21. package/dist/src/commands/rebuild-command.js +273 -557
  22. package/dist/src/commands/rebuild-command.js.map +1 -1
  23. package/dist/src/commands/rebuild-integration.d.ts +12 -39
  24. package/dist/src/commands/rebuild-integration.js +67 -303
  25. package/dist/src/commands/rebuild-integration.js.map +1 -1
  26. package/dist/src/commands/rebuild-operations.d.ts +0 -4
  27. package/dist/src/commands/rebuild-operations.js +9 -8
  28. package/dist/src/commands/rebuild-operations.js.map +1 -1
  29. package/dist/src/commands/rebuild-platform-integration.d.ts +14 -6
  30. package/dist/src/commands/rebuild-platform-integration.js +310 -101
  31. package/dist/src/commands/rebuild-platform-integration.js.map +1 -1
  32. package/dist/src/commands/status-v6.d.ts +3 -117
  33. package/dist/src/commands/status-v6.js +0 -2886
  34. package/dist/src/commands/status-v6.js.map +1 -1
  35. package/dist/src/commands/write-commands.js +0 -3
  36. package/dist/src/commands/write-commands.js.map +1 -1
  37. package/dist/src/index.js +44 -36
  38. package/dist/src/index.js.map +1 -1
  39. package/dist/src/intent/deployment-preferences.js +4 -3
  40. package/dist/src/intent/deployment-preferences.js.map +1 -1
  41. package/dist/src/intent/intent-store.js +3 -2
  42. package/dist/src/intent/intent-store.js.map +1 -1
  43. package/dist/src/output/command-receipt.d.ts +0 -6
  44. package/dist/src/output/command-receipt.js +0 -15
  45. package/dist/src/output/command-receipt.js.map +1 -1
  46. package/dist/src/output/receipt-projection.js +2 -1
  47. package/dist/src/output/receipt-projection.js.map +1 -1
  48. package/dist/src/platforms/capabilities.js +8 -2
  49. package/dist/src/platforms/capabilities.js.map +1 -1
  50. package/dist/src/platforms/contracts.d.ts +2 -0
  51. package/dist/src/platforms/discovery.d.ts +2 -0
  52. package/dist/src/platforms/discovery.js +95 -49
  53. package/dist/src/platforms/discovery.js.map +1 -1
  54. package/dist/src/platforms/inspection-native.d.ts +7 -1
  55. package/dist/src/platforms/inspection-native.js +6 -3
  56. package/dist/src/platforms/inspection-native.js.map +1 -1
  57. package/dist/src/platforms/inspection-query.d.ts +28 -14
  58. package/dist/src/platforms/inspection-query.js +102 -8
  59. package/dist/src/platforms/inspection-query.js.map +1 -1
  60. package/dist/src/platforms/lifecycle-native-services.d.ts +1 -1
  61. package/dist/src/platforms/lifecycle-native-services.js +7 -2
  62. package/dist/src/platforms/lifecycle-native-services.js.map +1 -1
  63. package/dist/src/platforms/lifecycle-native.js +20 -3
  64. package/dist/src/platforms/lifecycle-native.js.map +1 -1
  65. package/dist/src/platforms/lifecycle.js +5 -0
  66. package/dist/src/platforms/lifecycle.js.map +1 -1
  67. package/dist/src/platforms/supplement-state.js +11 -2
  68. package/dist/src/platforms/supplement-state.js.map +1 -1
  69. package/dist/src/portable/commands.d.ts +1 -0
  70. package/dist/src/portable/commands.js.map +1 -1
  71. package/dist/src/portable/materializer.d.ts +2 -0
  72. package/dist/src/portable/materializer.js +4 -4
  73. package/dist/src/portable/materializer.js.map +1 -1
  74. package/dist/src/portable/recovery.d.ts +1 -0
  75. package/dist/src/portable/recovery.js +3 -2
  76. package/dist/src/portable/recovery.js.map +1 -1
  77. package/dist/src/recovery/coordinator.d.ts +6 -1
  78. package/dist/src/recovery/coordinator.js +113 -108
  79. package/dist/src/recovery/coordinator.js.map +1 -1
  80. package/dist/src/recovery/demand.d.ts +1 -2
  81. package/dist/src/recovery/demand.js +4 -11
  82. package/dist/src/recovery/demand.js.map +1 -1
  83. package/dist/src/recovery/install-concurrency.d.ts +12 -0
  84. package/dist/src/recovery/install-concurrency.js +39 -0
  85. package/dist/src/recovery/install-concurrency.js.map +1 -1
  86. package/dist/src/recovery/joint-coordinator.d.ts +3 -4
  87. package/dist/src/recovery/joint-coordinator.js +324 -188
  88. package/dist/src/recovery/joint-coordinator.js.map +1 -1
  89. package/dist/src/recovery/joint-demand.js +4 -3
  90. package/dist/src/recovery/joint-demand.js.map +1 -1
  91. package/dist/src/recovery/joint-install-execution.js +46 -2
  92. package/dist/src/recovery/joint-install-execution.js.map +1 -1
  93. package/dist/src/recovery/joint-install-native-rebase.js +5 -2
  94. package/dist/src/recovery/joint-install-native-rebase.js.map +1 -1
  95. package/dist/src/recovery/locked-prepared-execution.d.ts +32 -0
  96. package/dist/src/recovery/locked-prepared-execution.js +67 -0
  97. package/dist/src/recovery/locked-prepared-execution.js.map +1 -0
  98. package/dist/src/recovery/status.d.ts +20 -6
  99. package/dist/src/recovery/status.js +153 -98
  100. package/dist/src/recovery/status.js.map +1 -1
  101. package/dist/src/review/skill-materialization.d.ts +1 -0
  102. package/dist/src/review/skill-materialization.js.map +1 -1
  103. package/dist/src/tui/console-app-v4.js +4 -14
  104. package/dist/src/tui/console-app-v4.js.map +1 -1
  105. package/dist/src/tui/controller-runtime.js +201 -57
  106. package/dist/src/tui/controller-runtime.js.map +1 -1
  107. package/dist/src/tui/controller.d.ts +8 -9
  108. package/dist/src/tui/controller.js +5 -6
  109. package/dist/src/tui/controller.js.map +1 -1
  110. package/dist/src/tui/operation-review-planner.js +14 -103
  111. package/dist/src/tui/operation-review-planner.js.map +1 -1
  112. package/dist/src/types.d.ts +5 -1
  113. package/dist/src/types.js.map +1 -1
  114. package/dist/src/utils/agent-version.js +1 -0
  115. package/dist/src/utils/agent-version.js.map +1 -1
  116. package/dist/src/utils/artifact-renderer.d.ts +10 -0
  117. package/dist/src/utils/artifact-renderer.js +28 -2
  118. package/dist/src/utils/artifact-renderer.js.map +1 -1
  119. package/dist/src/utils/aw-home-mutation-lock.d.ts +8 -0
  120. package/dist/src/utils/aw-home-mutation-lock.js +44 -8
  121. package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
  122. package/dist/src/utils/bundle-integrity.js +126 -33
  123. package/dist/src/utils/bundle-integrity.js.map +1 -1
  124. package/dist/src/utils/catalog-generation-resolver.d.ts +4 -0
  125. package/dist/src/utils/catalog-generation-resolver.js +4 -0
  126. package/dist/src/utils/catalog-generation-resolver.js.map +1 -1
  127. package/dist/src/utils/catalog-generation-service.d.ts +50 -11
  128. package/dist/src/utils/catalog-generation-service.js +276 -130
  129. package/dist/src/utils/catalog-generation-service.js.map +1 -1
  130. package/dist/src/utils/catalog-generation-state.js +6 -1
  131. package/dist/src/utils/catalog-generation-state.js.map +1 -1
  132. package/dist/src/utils/catalog-generation-store.d.ts +5 -0
  133. package/dist/src/utils/catalog-generation-store.js +36 -13
  134. package/dist/src/utils/catalog-generation-store.js.map +1 -1
  135. package/dist/src/utils/catalog-operation-context.d.ts +17 -3
  136. package/dist/src/utils/catalog-operation-context.js +220 -22
  137. package/dist/src/utils/catalog-operation-context.js.map +1 -1
  138. package/dist/src/utils/catalog-performance.d.ts +3 -0
  139. package/dist/src/utils/catalog-performance.js +26 -0
  140. package/dist/src/utils/catalog-performance.js.map +1 -0
  141. package/dist/src/utils/catalog-snapshot.d.ts +5 -2
  142. package/dist/src/utils/catalog-snapshot.js +3 -2
  143. package/dist/src/utils/catalog-snapshot.js.map +1 -1
  144. package/dist/src/utils/catalog-source-impact.d.ts +2 -1
  145. package/dist/src/utils/catalog-source-impact.js +2 -2
  146. package/dist/src/utils/catalog-source-impact.js.map +1 -1
  147. package/dist/src/utils/catalog-source-references.d.ts +2 -0
  148. package/dist/src/utils/catalog-source-references.js +284 -148
  149. package/dist/src/utils/catalog-source-references.js.map +1 -1
  150. package/dist/src/utils/codex-executable-discovery.js +1 -0
  151. package/dist/src/utils/codex-executable-discovery.js.map +1 -1
  152. package/dist/src/utils/codex-manager.js +1 -0
  153. package/dist/src/utils/codex-manager.js.map +1 -1
  154. package/dist/src/utils/codex-native-observation.d.ts +5 -2
  155. package/dist/src/utils/codex-native-observation.js +8 -4
  156. package/dist/src/utils/codex-native-observation.js.map +1 -1
  157. package/dist/src/utils/component-command-preparation.d.ts +1 -0
  158. package/dist/src/utils/component-command-preparation.js.map +1 -1
  159. package/dist/src/utils/git-catalog-provider.d.ts +38 -5
  160. package/dist/src/utils/git-catalog-provider.js +365 -156
  161. package/dist/src/utils/git-catalog-provider.js.map +1 -1
  162. package/dist/src/utils/managed-command-closure.d.ts +3 -1
  163. package/dist/src/utils/managed-command-closure.js +10 -5
  164. package/dist/src/utils/managed-command-closure.js.map +1 -1
  165. package/dist/src/utils/managed-command-materialization.d.ts +2 -0
  166. package/dist/src/utils/managed-command-materialization.js +4 -3
  167. package/dist/src/utils/managed-command-materialization.js.map +1 -1
  168. package/dist/src/utils/managed-command-preparation.js +1 -1
  169. package/dist/src/utils/managed-command-preparation.js.map +1 -1
  170. package/dist/src/utils/multi-source-catalog.d.ts +1 -1
  171. package/dist/src/utils/multi-source-catalog.js +3 -3
  172. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  173. package/dist/src/utils/native-cli.d.ts +6 -1
  174. package/dist/src/utils/native-cli.js +67 -32
  175. package/dist/src/utils/native-cli.js.map +1 -1
  176. package/dist/src/utils/platform-empty-state.d.ts +2 -0
  177. package/dist/src/utils/platform-empty-state.js +5 -5
  178. package/dist/src/utils/platform-empty-state.js.map +1 -1
  179. package/dist/src/utils/plugin-config-command-apply.d.ts +14 -4
  180. package/dist/src/utils/plugin-config-command-apply.js +49 -5
  181. package/dist/src/utils/plugin-config-command-apply.js.map +1 -1
  182. package/dist/src/utils/plugin-config-impact.d.ts +42 -0
  183. package/dist/src/utils/plugin-config-impact.js +170 -14
  184. package/dist/src/utils/plugin-config-impact.js.map +1 -1
  185. package/dist/src/utils/plugin-config-references.d.ts +3 -1
  186. package/dist/src/utils/plugin-config-references.js +3 -5
  187. package/dist/src/utils/plugin-config-references.js.map +1 -1
  188. package/dist/src/utils/plugin-config-write.d.ts +14 -5
  189. package/dist/src/utils/plugin-config-write.js +213 -117
  190. package/dist/src/utils/plugin-config-write.js.map +1 -1
  191. package/dist/src/utils/plugin-config.d.ts +2 -0
  192. package/dist/src/utils/plugin-config.js.map +1 -1
  193. package/dist/src/utils/plugin-scripts.d.ts +2 -0
  194. package/dist/src/utils/plugin-scripts.js +102 -3
  195. package/dist/src/utils/plugin-scripts.js.map +1 -1
  196. package/package.json +3 -5
  197. package/dist/src/utils/codex-reconciler.d.ts +0 -123
  198. package/dist/src/utils/codex-reconciler.js +0 -322
  199. package/dist/src/utils/codex-reconciler.js.map +0 -1
@@ -1,9 +1,11 @@
1
1
  import crypto from 'node:crypto';
2
2
  import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
3
4
  import fs from 'fs-extra';
4
5
  import { calculateCatalogSourceIdentity, canonicalizeCatalogGitUrl, } from './catalog-source-identity.js';
5
6
  import { CatalogProviderCompatibilityError } from './catalog-public-error.js';
6
7
  import { validateCatalogSnapshotTransport } from './catalog-snapshot.js';
8
+ import { measureCatalogPerformanceStage } from './catalog-performance.js';
7
9
  import { readCatalogSnapshotLogicalIdentity } from './catalog-generation-store.js';
8
10
  import { resolveCatalogSourceRef } from './catalog-sources.js';
9
11
  import { checkAwCapabilitySupport } from './manifest.js';
@@ -119,10 +121,23 @@ function gitEnvironment(env) {
119
121
  output.GCM_INTERACTIVE = 'Never';
120
122
  return output;
121
123
  }
124
+ function localGitEnvironment(env) {
125
+ const output = gitEnvironment(env);
126
+ for (const key of Object.keys(output)) {
127
+ if (/^GIT_(?:CONFIG(?:_|$)|TEMPLATE_DIR$|ATTR_SOURCE$)/iu.test(key))
128
+ delete output[key];
129
+ }
130
+ output.GIT_CONFIG_NOSYSTEM = '1';
131
+ output.GIT_CONFIG_GLOBAL = '/dev/null';
132
+ output.GIT_ATTR_NOSYSTEM = '1';
133
+ return output;
134
+ }
122
135
  function tarEnvironment(env) {
123
136
  const output = { ...env };
124
- delete output.TAR_OPTIONS;
125
- delete output.TAPE;
137
+ for (const key of Object.keys(output)) {
138
+ if (/^(?:TAR_OPTIONS|TAPE)$/iu.test(key))
139
+ delete output[key];
140
+ }
126
141
  return output;
127
142
  }
128
143
  async function runCatalogProcess(options) {
@@ -135,6 +150,7 @@ async function runCatalogProcess(options) {
135
150
  env: options.env,
136
151
  signal: options.signal,
137
152
  timeoutMs: options.timeoutMs,
153
+ cleanupAudit: options.cleanupAudit,
138
154
  });
139
155
  }
140
156
  catch (error) {
@@ -147,9 +163,11 @@ async function runGit(options) {
147
163
  command: 'git',
148
164
  args: [
149
165
  ...(options.gitDir ? [`--git-dir=${options.gitDir}`] : []),
166
+ ...(options.local ? ['-c', 'core.hooksPath=/dev/null'] : []),
150
167
  ...options.args,
151
168
  ],
152
- env: gitEnvironment(options.env),
169
+ env: options.local ? localGitEnvironment(options.env) : gitEnvironment(options.env),
170
+ cleanupAudit: options.cleanupAudit ?? (options.local ? 'on-failure' : 'always'),
153
171
  signal: options.deadline.signal,
154
172
  timeoutMs: options.deadline.remainingMs(),
155
173
  });
@@ -197,7 +215,7 @@ function classifyGitDiagnostic(error, depth = 0) {
197
215
  safeMessage: 'Git is not installed or cannot be found.',
198
216
  cause: { code: 'ENOENT', safeMessage: 'The Git executable was not found.' },
199
217
  };
200
- if (/(?:authentication failed|permission denied \(publickey\)|could not read username|terminal prompts disabled)/iu
218
+ if (/(?:authentication failed|permission denied \([^)\r\n]*(?:publickey|password|keyboard-interactive|gssapi-with-mic|gssapi-keyex|hostbased)[^)\r\n]*\)|could not read (?:username|password)|terminal prompts disabled|invalid username or token|requested URL returned error: (?:401|403))/iu
201
219
  .test(`${error.stderr}\n${error.stdout}`)) {
202
220
  return {
203
221
  code: 'catalogGitAuthorizationFailed', stage: 'catalogGit',
@@ -218,6 +236,7 @@ async function resolveEffectiveGitUrl(options) {
218
236
  args: ['ls-remote', '--get-url', '--', options.configuredTransport],
219
237
  env: options.env,
220
238
  deadline: options.deadline,
239
+ cleanupAudit: 'on-failure',
221
240
  })).stdout.trim();
222
241
  }
223
242
  catch (error) {
@@ -238,104 +257,245 @@ function parseLsRemote(stdout) {
238
257
  });
239
258
  }
240
259
  function resolveAdvertisedRef(requestedRef, refs) {
260
+ let direct;
241
261
  if (requestedRef.startsWith('refs/')) {
242
- const exact = refs.find((entry) => entry.ref === requestedRef);
243
- if (!exact)
244
- throw new CatalogGitPolicyError(`Catalog Git ref "${requestedRef}" does not exist.`);
245
- return refs.find((entry) => entry.ref === `${requestedRef}^{}`) ?? exact;
246
- }
247
- const branch = refs.find((entry) => entry.ref === `refs/heads/${requestedRef}`);
248
- const tag = refs.find((entry) => entry.ref === `refs/tags/${requestedRef}`);
249
- if (branch && tag) {
250
- throw new CatalogGitPolicyError(`Catalog Git ref "${requestedRef}" is ambiguous between a branch and tag.`);
251
- }
252
- const selected = branch ?? tag;
253
- if (!selected)
262
+ direct = refs.find((entry) => entry.ref === requestedRef);
263
+ }
264
+ else {
265
+ const branch = refs.find((entry) => entry.ref === `refs/heads/${requestedRef}`);
266
+ const tag = refs.find((entry) => entry.ref === `refs/tags/${requestedRef}`);
267
+ if (branch && tag)
268
+ throw new CatalogGitPolicyError(`Catalog Git ref "${requestedRef}" is ambiguous between a branch and tag.`);
269
+ direct = branch ?? tag;
270
+ }
271
+ if (!direct)
254
272
  throw new CatalogGitPolicyError(`Catalog Git ref "${requestedRef}" does not exist.`);
255
- return tag
256
- ? refs.find((entry) => entry.ref === `${tag.ref}^{}`) ?? tag
257
- : selected;
273
+ return { direct, peeled: refs.find((entry) => entry.ref === `${direct.ref}^{}`) };
274
+ }
275
+ /** Advisory format for an already URL-checked local transport. Fetch still
276
+ * selects the ref and proves that the commit is available from that source. */
277
+ async function readLocalGitTransport(transport, env, deadline) {
278
+ const location = /^file:/iu.test(transport) ? fileURLToPath(transport) : transport;
279
+ if (!path.isAbsolute(location) || (process.platform === 'win32' && /^[/\\]{2}/u.test(location)))
280
+ return undefined;
281
+ // Explicit git-dir prevents Git from discovering an unrelated parent when
282
+ // the configured directory isn't itself a repository. A .git file is valid
283
+ // for linked worktrees. A bundle is a regular file, and Git can list its
284
+ // advertised heads without importing objects into a repository.
285
+ if ((await fs.stat(location).catch(() => undefined))?.isFile()) {
286
+ try {
287
+ const result = await runGit({
288
+ args: ['bundle', 'list-heads', '--', location], local: true, env, deadline,
289
+ });
290
+ const bundleHeads = result.stdout.split(/\r?\n/u).flatMap((line) => {
291
+ const match = /^([0-9a-f]{40}|[0-9a-f]{64}) (.+)$/u.exec(line);
292
+ return match ? [{ sha: match[1], ref: match[2] }] : [];
293
+ });
294
+ const sha = bundleHeads[0]?.sha;
295
+ return sha ? { objectFormat: sha.length === 64 ? 'sha256' : 'sha1', bundleHeads } : undefined;
296
+ }
297
+ catch (error) {
298
+ if (error instanceof NativeCliError && error.reason === 'exit' && !error.cleanupError)
299
+ return undefined;
300
+ throw error;
301
+ }
302
+ }
303
+ const dotGit = path.join(location, '.git');
304
+ const dotGitStat = await fs.stat(dotGit).catch(() => undefined);
305
+ const gitDir = dotGitStat?.isDirectory() || dotGitStat?.isFile() ? dotGit : location;
306
+ if (gitDir === location && !(await fs.stat(path.join(location, 'HEAD')).catch(() => undefined))?.isFile()) {
307
+ return undefined;
308
+ }
309
+ try {
310
+ const result = await runGit({
311
+ gitDir, args: ['rev-parse', '--show-object-format'], local: true, env, deadline,
312
+ });
313
+ // Older Git can echo an unrecognized rev-parse option as-is.
314
+ const format = result.stdout.trim();
315
+ return format === 'sha1' || format === 'sha256' ? { objectFormat: format } : undefined;
316
+ }
317
+ catch (error) {
318
+ if (error instanceof NativeCliError && error.reason === 'exit' && !error.cleanupError)
319
+ return undefined;
320
+ throw error;
321
+ }
322
+ }
323
+ function advertisedFetchTarget(advertised) {
324
+ const { direct, peeled } = advertised;
325
+ const selected = peeled ?? direct;
326
+ const observation = peeled
327
+ ? { resolvedCommit: peeled.sha, ...(direct.sha === peeled.sha ? {} : { resolvedRefObject: direct.sha }) }
328
+ : direct.ref.startsWith('refs/heads/')
329
+ ? { resolvedCommit: direct.sha }
330
+ : { unpeeledRefObject: direct.sha };
331
+ return { fetchSpec: selected.sha, objectFormat: selected.sha.length === 64 ? 'sha256' : 'sha1', observation };
332
+ }
333
+ /** Reuse the commit only when a known Active ref object is advertised again.
334
+ * A lightweight tag may itself be the already verified commit. */
335
+ export function matchObservedGitRef(observed, active) {
336
+ if (observed.resolvedCommit !== undefined)
337
+ return observed.resolvedCommit === active.resolvedCommit
338
+ ? { resolvedCommit: observed.resolvedCommit,
339
+ ...(observed.resolvedRefObject ? { resolvedRefObject: observed.resolvedRefObject } : {}) }
340
+ : undefined;
341
+ if (observed.unpeeledRefObject === active.resolvedCommit)
342
+ return { resolvedCommit: active.resolvedCommit };
343
+ if (observed.requestedRef === active.requestedRef && observed.unpeeledRefObject === active.resolvedRefObject)
344
+ return {
345
+ resolvedCommit: active.resolvedCommit, resolvedRefObject: active.resolvedRefObject,
346
+ };
347
+ return undefined;
348
+ }
349
+ // Only resolutions originating from this provider's private, validated staging
350
+ // can skip a repeated transport scan or authorize moving their snapshot tree.
351
+ const gitTransportValidation = new WeakMap();
352
+ export function getGitCatalogTransportValidation(resolution) {
353
+ return gitTransportValidation.get(resolution);
354
+ }
355
+ export function takeGitCatalogTransportValidation(resolution) {
356
+ const validation = gitTransportValidation.get(resolution);
357
+ gitTransportValidation.delete(resolution);
358
+ return validation;
258
359
  }
259
360
  async function resolveFetchTarget(options) {
260
361
  if (COMMIT_PATTERN.test(options.requestedRef)) {
261
362
  return {
262
363
  fetchSpec: options.requestedRef,
263
364
  objectFormat: options.requestedRef.length === 64 ? 'sha256' : 'sha1',
365
+ observation: { resolvedCommit: options.requestedRef },
264
366
  };
265
367
  }
368
+ const patterns = options.requestedRef.startsWith('refs/')
369
+ ? [options.requestedRef, `${options.requestedRef}^{}`]
370
+ : [
371
+ `refs/heads/${options.requestedRef}`,
372
+ `refs/tags/${options.requestedRef}`,
373
+ `refs/tags/${options.requestedRef}^{}`,
374
+ ];
266
375
  let advertised;
267
376
  try {
268
- advertised = parseLsRemote((await runGit({
269
- args: ['ls-remote', '--', options.transport],
377
+ advertised = parseLsRemote((await measureCatalogPerformanceStage(options.debugLogger, 'catalog.git.probe', () => runGit({
378
+ gitDir: options.gitDir,
379
+ args: ['ls-remote', '--', options.transport, ...patterns],
270
380
  env: options.env,
271
381
  deadline: options.deadline,
272
- })).stdout);
382
+ }))).stdout);
273
383
  }
274
384
  catch (error) {
275
385
  throw new CatalogGitRemoteUnavailableError('Catalog Git remote ref listing failed.', error);
276
386
  }
277
- const selected = resolveAdvertisedRef(options.requestedRef, advertised);
278
- return {
279
- fetchSpec: selected.sha,
280
- objectFormat: selected.sha.length === 64 ? 'sha256' : 'sha1',
281
- };
387
+ return advertisedFetchTarget(resolveAdvertisedRef(options.requestedRef, advertised));
388
+ }
389
+ /** A complete ref is a literal name, never a wildcard, refspec, or revision expression. */
390
+ function assertLiteralFullRef(ref) {
391
+ if (/[~^:?*\[\\]|\.\.|@\{/u.test(ref)) {
392
+ throw new CatalogGitPolicyError(`Catalog Git ref "${ref}" does not exist.`);
393
+ }
394
+ }
395
+ async function initializeObjects(options) {
396
+ await runGit({
397
+ args: [
398
+ '-c', 'init.defaultRefFormat=files', 'init', '--bare', '--template=',
399
+ `--object-format=${options.objectFormat}`, options.objectsDir,
400
+ ],
401
+ local: true,
402
+ env: options.env,
403
+ deadline: options.deadline,
404
+ });
405
+ }
406
+ function isGitFetchRejection(error, message) {
407
+ return error instanceof NativeCliError && error.reason === 'exit' && !error.cleanupError
408
+ && message.test(error.stderr);
282
409
  }
283
410
  async function fetchCommit(options) {
284
411
  const temporaryRef = `refs/aw/catalog/${crypto.randomUUID()}`;
285
- let cleanupConfirmed = true;
412
+ const fetch = (shallow) => measureCatalogPerformanceStage(options.debugLogger, 'catalog.git.fetch', () => runGit({
413
+ gitDir: options.objectsDir,
414
+ args: [
415
+ '-c', 'fetch.fsckObjects=true',
416
+ 'fetch', ...(shallow ? ['--depth=1'] : []), '--force', '--no-tags', '--write-fetch-head', '--',
417
+ options.transport, `${options.fetchSpec}:${temporaryRef}`,
418
+ ],
419
+ env: options.env,
420
+ deadline: options.deadline,
421
+ }));
286
422
  try {
287
- try {
288
- await runGit({
289
- gitDir: options.objectsDir,
290
- args: [
291
- '-c',
292
- 'fetch.fsckObjects=true',
293
- 'fetch',
294
- '--force',
295
- '--no-tags',
296
- '--',
297
- options.transport,
298
- `${options.fetchSpec}:${temporaryRef}`,
299
- ],
300
- env: options.env,
301
- deadline: options.deadline,
302
- });
303
- }
304
- catch (error) {
305
- if (error instanceof NativeCliError && error.cleanupError) {
306
- cleanupConfirmed = false;
423
+ let objectFormat = options.objectFormat;
424
+ let shallow = true;
425
+ let formatProbed = false;
426
+ for (;;) {
427
+ try {
428
+ await fetch(shallow);
429
+ break;
430
+ }
431
+ catch (error) {
432
+ if (shallow && isGitFetchRejection(error, /(?:does not support shallow (?:clients|capabilities)|shallow (?:fetch|requests?) (?:is|are) not (?:supported|allowed)|shallow capabilities? (?:is|are) not supported|shallow SHA (?:fetch|requests?) (?:is|are) not (?:supported|allowed))/iu)) {
433
+ shallow = false;
434
+ continue;
435
+ }
436
+ if (!formatProbed && options.fetchSpec.startsWith('refs/') && objectFormat === 'sha1'
437
+ && error instanceof NativeCliError && error.reason === 'exit' && !error.cleanupError
438
+ && classifyGitDiagnostic(error) === undefined
439
+ && !isGitFetchRejection(error, /could(?: not|n't) find remote ref/iu)) {
440
+ // A clean ordinary failure does not prove an object-format mismatch.
441
+ // Confirm the literal ref's advertised format once, retaining the
442
+ // shallow capability already established. Never retry a guess.
443
+ formatProbed = true;
444
+ const target = await resolveFetchTarget({
445
+ ...options, gitDir: options.objectsDir, requestedRef: options.fetchSpec,
446
+ });
447
+ if (target.objectFormat !== 'sha256')
448
+ throw error;
449
+ objectFormat = target.objectFormat;
450
+ await fs.remove(options.objectsDir);
451
+ await initializeObjects({ ...options, objectFormat });
452
+ continue;
453
+ }
454
+ throw error;
307
455
  }
308
- throw new CatalogGitRemoteUnavailableError('Catalog Git fetch failed.', error);
309
- }
310
- const commit = (await runGit({
311
- gitDir: options.objectsDir,
312
- args: ['rev-parse', '--verify', `${temporaryRef}^{commit}`],
313
- env: options.env,
314
- deadline: options.deadline,
315
- })).stdout.trim();
316
- if (!COMMIT_PATTERN.test(commit)) {
317
- throw new CatalogGitPolicyError('Catalog Git ref did not resolve to a complete commit SHA.');
318
456
  }
319
- return commit;
320
457
  }
321
458
  catch (error) {
322
- if (error instanceof NativeCliError && error.cleanupError)
323
- cleanupConfirmed = false;
324
- throw error;
325
- }
326
- finally {
327
- if (cleanupConfirmed && !options.deadline.signal?.aborted) {
328
- await runGit({
329
- gitDir: options.objectsDir,
330
- args: ['update-ref', '-d', temporaryRef],
331
- env: options.env,
332
- deadline: options.deadline,
333
- }).catch((error) => {
334
- if (error instanceof NativeCliError && error.cleanupError)
335
- throw error;
336
- });
459
+ if (error instanceof CatalogGitPolicyError)
460
+ throw error;
461
+ if (options.fetchSpec.startsWith('refs/')
462
+ && isGitFetchRejection(error, /could(?: not|n't) find remote ref/iu)) {
463
+ throw new CatalogGitPolicyError(`Catalog Git ref "${options.fetchSpec}" does not exist.`, error);
337
464
  }
338
- }
465
+ throw new CatalogGitRemoteUnavailableError('Catalog Git fetch failed.', error);
466
+ }
467
+ let refObject = options.fetchSpec;
468
+ if (options.fetchSpec.startsWith('refs/')) {
469
+ // Git's non-wildcard refspec matching still does DWIM expansion: a missing
470
+ // refs/heads/x can fetch refs/heads/refs/heads/x. FETCH_HEAD records the
471
+ // actual advertised source name, so do not accept that implicit fallback.
472
+ const prefix = [
473
+ ['refs/heads/', 'branch '],
474
+ ['refs/tags/', 'tag '],
475
+ ['refs/remotes/', 'remote-tracking branch '],
476
+ ].find(([refPrefix]) => options.fetchSpec.startsWith(refPrefix));
477
+ const description = prefix
478
+ ? `${prefix[1]}'${options.fetchSpec.slice(prefix[0].length)}' of `
479
+ : `'${options.fetchSpec}' of `;
480
+ const fetchHead = (await fs.readFile(path.join(options.objectsDir, 'FETCH_HEAD'), 'utf8')).trimEnd();
481
+ const entry = /^([0-9a-f]{40}|[0-9a-f]{64})\t[^\t]*\t([^\r\n]+)$/u.exec(fetchHead);
482
+ if (!entry?.[2]?.startsWith(description)) {
483
+ throw new CatalogGitPolicyError(`Catalog Git ref "${options.fetchSpec}" does not exist.`);
484
+ }
485
+ refObject = entry[1];
486
+ }
487
+ const commit = (await runGit({
488
+ gitDir: options.objectsDir,
489
+ args: ['rev-parse', '--verify', `${temporaryRef}^{commit}`],
490
+ local: true,
491
+ env: options.env,
492
+ deadline: options.deadline,
493
+ })).stdout.trim();
494
+ if (!COMMIT_PATTERN.test(commit)) {
495
+ throw new CatalogGitPolicyError('Catalog Git ref did not resolve to a complete commit SHA.');
496
+ }
497
+ // The entire temporary bare repo is removed by cleanup; no update-ref needed.
498
+ return { resolvedCommit: commit, ...(refObject === commit ? {} : { resolvedRefObject: refObject }) };
339
499
  }
340
500
  async function materializeCommit(options) {
341
501
  throwIfAborted(options.deadline.signal);
@@ -351,6 +511,7 @@ async function materializeCommit(options) {
351
511
  '-c', 'core.autocrlf=false', '-c', 'core.eol=lf',
352
512
  'archive', '--format=tar', `--output=${archivePath}`, treeish,
353
513
  ],
514
+ local: true,
354
515
  env: options.env,
355
516
  deadline: options.deadline,
356
517
  });
@@ -360,6 +521,7 @@ async function materializeCommit(options) {
360
521
  args: ['-xf', path.basename(archivePath), '-C', path.basename(options.destination)],
361
522
  cwd: path.dirname(options.destination),
362
523
  env: tarEnvironment(options.env),
524
+ cleanupAudit: 'on-failure',
363
525
  signal: options.deadline.signal,
364
526
  timeoutMs: options.deadline.remainingMs(),
365
527
  });
@@ -377,7 +539,14 @@ async function materializeCommit(options) {
377
539
  }
378
540
  }
379
541
  async function resolveGitCatalogSource(source, options) {
380
- return resolveGitCatalogSourceDirect(source, options);
542
+ const prepared = await prepareGitCatalogSource(source, options);
543
+ try {
544
+ return await prepared.materialize();
545
+ }
546
+ catch (error) {
547
+ await prepared.cleanup().catch(() => undefined);
548
+ throw error;
549
+ }
381
550
  }
382
551
  async function probeGitCatalogSourceRef(source, options) {
383
552
  const env = options.env ?? process.env;
@@ -407,12 +576,13 @@ async function probeGitCatalogSourceRef(source, options) {
407
576
  requestedRef,
408
577
  env,
409
578
  deadline,
579
+ debugLogger: options.debugLogger,
410
580
  });
411
581
  return {
412
582
  sourceId: source.id,
413
583
  sourceIdentity,
414
584
  requestedRef,
415
- resolvedCommit: target.fetchSpec,
585
+ ...target.observation,
416
586
  fixed: false,
417
587
  };
418
588
  }
@@ -434,13 +604,14 @@ async function probeGitCatalogSourceRef(source, options) {
434
604
  /** @internal Provider bridge for the multi-source resolver. */
435
605
  export const catalogGitProviderInternal = {
436
606
  resolve: resolveGitCatalogSource,
607
+ prepare: prepareGitCatalogSource,
437
608
  probeRef: probeGitCatalogSourceRef,
438
609
  classifyDiagnostic: classifyGitDiagnostic,
439
610
  gitEnvironment,
440
611
  remoteTimeout: readRemoteTimeout,
441
612
  refProbeTimeout: readRefProbeTimeout,
442
613
  };
443
- async function resolveGitCatalogSourceDirect(source, options) {
614
+ async function prepareGitCatalogSource(source, options) {
444
615
  const env = options.env ?? process.env;
445
616
  if (options.signal?.aborted) {
446
617
  throw createPublicGitError(source.id, options.signal.reason ?? new Error('Catalog Git resolution aborted.'), [source.url]);
@@ -448,96 +619,134 @@ async function resolveGitCatalogSourceDirect(source, options) {
448
619
  canonicalizeCatalogGitUrl(source.url);
449
620
  const sourceIdentity = await calculateCatalogSourceIdentity(source);
450
621
  const requestedRef = resolveCatalogSourceRef(source.refPolicy, options.cliVersion);
622
+ const fixed = COMMIT_PATTERN.test(requestedRef);
623
+ const fullRef = requestedRef.startsWith('refs/');
451
624
  const deadline = createDeadlineSignal(options.signal, readRemoteTimeout(env));
452
- const temporaryRoot = path.join(canonicalizePathThroughExistingAncestorSync(resolveAwHome(env)), 'tmp');
453
- await ensureRegularDirectoryPath(temporaryRoot, 'Catalog provider temporary directory');
454
- const refreshRoot = await fs.mkdtemp(path.join(temporaryRoot, 'catalog-git-'));
455
- const objectsDir = path.join(refreshRoot, 'objects.git');
456
- const stagingRoot = path.join(refreshRoot, 'snapshot');
457
- let returned = false;
625
+ let refreshRoot;
458
626
  let effectiveTransport;
627
+ let cleaned = false;
628
+ let resolution;
629
+ const cleanup = async () => {
630
+ if (cleaned)
631
+ return;
632
+ cleaned = true;
633
+ deadline.dispose();
634
+ if (resolution)
635
+ gitTransportValidation.delete(resolution);
636
+ if (refreshRoot)
637
+ await fs.remove(refreshRoot);
638
+ };
639
+ const publicFailure = (error) => {
640
+ const failure = deadline.signal?.aborted && deadline.signal.reason instanceof Error
641
+ ? deadline.signal.reason
642
+ : error;
643
+ if (failure instanceof CatalogProviderCompatibilityError)
644
+ return failure;
645
+ return createPublicGitError(source.id, failure, [
646
+ source.url,
647
+ effectiveTransport ?? '',
648
+ ...(failure instanceof CatalogGitPolicyError ? failure.sensitiveTransports : []),
649
+ ]);
650
+ };
459
651
  try {
652
+ if (fullRef)
653
+ assertLiteralFullRef(requestedRef);
654
+ const temporaryRoot = path.join(canonicalizePathThroughExistingAncestorSync(resolveAwHome(env)), 'tmp');
655
+ await ensureRegularDirectoryPath(temporaryRoot, 'Catalog provider temporary directory');
656
+ refreshRoot = await fs.mkdtemp(path.join(temporaryRoot, 'catalog-git-'));
657
+ const objectsDir = path.join(refreshRoot, 'objects.git');
658
+ const stagingRoot = path.join(refreshRoot, 'snapshot');
659
+ const initialFormat = fixed && requestedRef.length === 64 ? 'sha256' : 'sha1';
660
+ await initializeObjects({ objectsDir, objectFormat: initialFormat, env, deadline });
661
+ // Check URL rewrite in exactly the same isolated repository context used by fetch.
460
662
  effectiveTransport = await resolveEffectiveGitUrl({
461
- configuredTransport: source.url,
462
- env,
463
- deadline,
464
- });
465
- const target = await resolveFetchTarget({
466
- transport: source.url,
467
- requestedRef,
468
- env,
469
- deadline,
470
- });
471
- await runGit({
472
- args: ['-c', 'init.defaultRefFormat=files', 'init', '--bare', `--object-format=${target.objectFormat}`, objectsDir],
473
- env,
474
- deadline,
663
+ gitDir: objectsDir,
664
+ configuredTransport: source.url, env, deadline,
475
665
  });
476
- const commit = await fetchCommit({
477
- objectsDir,
478
- transport: source.url,
479
- fetchSpec: target.fetchSpec,
480
- env,
481
- deadline,
482
- });
483
- await materializeCommit({
484
- objectsDir,
485
- commit,
486
- subdir: source.subdir,
487
- destination: stagingRoot,
488
- env,
489
- deadline,
490
- });
491
- const validation = await validateCatalogSnapshotTransport(stagingRoot);
492
- throwIfAborted(deadline.signal);
493
- const requiredCapabilities = validation.manifest.requires.aw.capabilities ?? [];
494
- const support = checkAwCapabilitySupport(requiredCapabilities, IMPLEMENTED_AW_CAPABILITIES);
495
- if (!support.supported) {
496
- throw new CatalogProviderCompatibilityError({
497
- sourceId: source.id,
498
- requiredCapabilities,
499
- missingCapabilities: support.missing,
500
- availableCapabilities: IMPLEMENTED_AW_CAPABILITIES,
501
- });
666
+ const local = fullRef ? await readLocalGitTransport(effectiveTransport, env, deadline) : undefined;
667
+ const bundleTag = fullRef && requestedRef.startsWith('refs/tags/') && local?.bundleHeads !== undefined;
668
+ const target = bundleTag
669
+ ? { ...advertisedFetchTarget(resolveAdvertisedRef(requestedRef, local.bundleHeads)), fetchSpec: requestedRef }
670
+ : fullRef || fixed
671
+ ? { fetchSpec: requestedRef, objectFormat: local?.objectFormat ?? initialFormat }
672
+ : await resolveFetchTarget({
673
+ gitDir: objectsDir, transport: source.url, requestedRef, env, deadline,
674
+ debugLogger: options.debugLogger,
675
+ });
676
+ if (target.objectFormat !== initialFormat) {
677
+ await fs.remove(objectsDir);
678
+ await initializeObjects({ objectsDir, objectFormat: target.objectFormat, env, deadline });
502
679
  }
503
- returned = true;
504
- let cleaned = false;
680
+ const fetch = async () => {
681
+ const result = await fetchCommit({ objectsDir, transport: source.url, ...target, env, deadline, debugLogger: options.debugLogger });
682
+ // A peeled advertisement binds the direct ref object to the fetched
683
+ // commit. For an unpeeled fetch, fetchCommit proves that relation itself.
684
+ const observed = target.observation;
685
+ return !result.resolvedRefObject && observed?.resolvedCommit === result.resolvedCommit && observed.resolvedRefObject
686
+ ? { ...result, resolvedRefObject: observed.resolvedRefObject } : result;
687
+ };
688
+ // Full non-bundle refs and fixed SHAs keep the direct fetch. Short refs
689
+ // and already listed local bundle tags may defer payload materialization.
690
+ let fetched = (fullRef && !bundleTag || fixed) ? await fetch() : undefined;
691
+ const observation = fetched ?? target.observation;
692
+ if (!observation)
693
+ throw new CatalogGitPolicyError('Catalog Git ref observation is unavailable.');
694
+ let materializing;
695
+ const materialize = async () => {
696
+ try {
697
+ throwIfAborted(deadline.signal);
698
+ fetched ??= await fetch();
699
+ await materializeCommit({
700
+ objectsDir, commit: fetched.resolvedCommit, subdir: source.subdir, destination: stagingRoot, env, deadline,
701
+ });
702
+ const validation = await validateCatalogSnapshotTransport(stagingRoot, options.debugLogger);
703
+ throwIfAborted(deadline.signal);
704
+ const requiredCapabilities = validation.manifest.requires.aw.capabilities ?? [];
705
+ const support = checkAwCapabilitySupport(requiredCapabilities, IMPLEMENTED_AW_CAPABILITIES);
706
+ if (!support.supported) {
707
+ throw new CatalogProviderCompatibilityError({
708
+ sourceId: source.id,
709
+ requiredCapabilities,
710
+ missingCapabilities: support.missing,
711
+ availableCapabilities: IMPLEMENTED_AW_CAPABILITIES,
712
+ });
713
+ }
714
+ resolution = {
715
+ sourceId: source.id, sourceIdentity,
716
+ logicalIdentity: await readCatalogSnapshotLogicalIdentity(stagingRoot),
717
+ requestedRef, ...fetched, rootDir: stagingRoot,
718
+ manifest: validation.manifest,
719
+ manifestDigest: validation.manifestDigest,
720
+ snapshotDigest: validation.snapshotDigest,
721
+ transport: 'git',
722
+ cleanup,
723
+ };
724
+ gitTransportValidation.set(resolution, Object.freeze({ ...validation }));
725
+ return resolution;
726
+ }
727
+ catch (error) {
728
+ throw publicFailure(error);
729
+ }
730
+ finally {
731
+ deadline.dispose();
732
+ }
733
+ };
505
734
  return {
506
- sourceId: source.id,
507
- sourceIdentity,
508
- logicalIdentity: await readCatalogSnapshotLogicalIdentity(stagingRoot),
509
- requestedRef,
510
- resolvedCommit: commit,
511
- rootDir: stagingRoot,
512
- manifest: validation.manifest,
513
- manifestDigest: validation.manifestDigest,
514
- snapshotDigest: validation.snapshotDigest,
515
- transport: 'git',
516
- async cleanup() {
735
+ sourceId: source.id, sourceIdentity, requestedRef,
736
+ ...observation,
737
+ fixed,
738
+ materialize() {
517
739
  if (cleaned)
518
- return;
519
- cleaned = true;
520
- await fs.remove(refreshRoot);
740
+ throw new Error('Cannot materialize cleaned Catalog Git staging.');
741
+ return materializing ??= materialize();
521
742
  },
743
+ cleanup,
522
744
  };
523
745
  }
524
746
  catch (error) {
525
- const failure = deadline.signal?.aborted && deadline.signal.reason instanceof Error
526
- ? deadline.signal.reason
527
- : error;
528
- if (failure instanceof CatalogProviderCompatibilityError)
529
- throw failure;
530
- const sensitiveTransports = [
531
- source.url,
532
- effectiveTransport ?? '',
533
- ...(failure instanceof CatalogGitPolicyError ? failure.sensitiveTransports : []),
534
- ];
535
- throw createPublicGitError(source.id, failure, sensitiveTransports);
536
- }
537
- finally {
538
- deadline.dispose();
539
- if (!returned)
540
- await fs.remove(refreshRoot).catch(() => undefined);
747
+ const failure = publicFailure(error);
748
+ await cleanup().catch(() => undefined);
749
+ throw failure;
541
750
  }
542
751
  }
543
752
  //# sourceMappingURL=git-catalog-provider.js.map