@lesliechan721/aw 0.1.0-beta.82 → 0.1.0-beta.83

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.
@@ -29,8 +29,8 @@ import { calculateCatalogSourceConfigFingerprint, calculateCatalogSourceIdentity
29
29
  import { checkAwCapabilitySupport, readPluginManifest } from '../utils/manifest.js';
30
30
  import { withAwHomeMutationLock } from '../utils/aw-home-mutation-lock.js';
31
31
  import { IMPLEMENTED_AW_CAPABILITIES } from '../commands/aw-capabilities.js';
32
- import { calculateCatalogGenerationSetDigest, resolveActiveCatalogGeneration, } from '../utils/catalog-generation-resolver.js';
33
- import { resolveCatalogOperationContext, resolvePartialCatalogOperationContext, selectCatalogOperationContext, } from '../utils/catalog-operation-context.js';
32
+ import { calculateCatalogGenerationSetDigest, createCatalogPreparationStoreKey, resolveActiveCatalogGeneration, } from '../utils/catalog-generation-resolver.js';
33
+ import { CatalogPreparationReadScope, resolveCatalogOperationContext, resolvePartialCatalogOperationContext, selectCatalogOperationContext, } from '../utils/catalog-operation-context.js';
34
34
  import { createCatalogStoreKey, readCatalogStoreEntry, } from '../utils/catalog-generation-store.js';
35
35
  import { activateCatalogSourceGeneration, compareCatalogGenerationFreshness, probeCatalogSourceFreshness, probeCatalogSourceGeneration, probeCatalogSourceRepairGeneration, recoverCatalogGenerationStateAndActivate, repairCatalogSourceGeneration, replaceDamagedCatalogSourceGeneration, } from '../utils/catalog-generation-service.js';
36
36
  import { calculateCatalogSourceImpactDigest, inspectCatalogSourceImpact, } from '../utils/catalog-source-impact.js';
@@ -38,9 +38,30 @@ import { readCatalogGenerationState } from '../utils/catalog-generation-state.js
38
38
  import { CatalogGenerationError } from '../utils/catalog-generation-error.js';
39
39
  import { CatalogProviderCompatibilityError } from '../utils/catalog-public-error.js';
40
40
  import { loadCatalogGenerationViewModels } from './catalog-generation.js';
41
+ import { recoveryReason } from './glossary.js';
41
42
  import { executePortableRetry, installPortableSkills, preparePortableInstall, preparePortableRetry, PortableCommandError, recheckPortableInstall, } from '../portable/commands.js';
42
43
  import { projectPluginContentOverview, } from './plugin-content.js';
43
44
  import { executeCatalogStoreTask, inspectCatalogStoreTask, prepareCatalogStoreTask, } from './catalog-store-task.js';
45
+ function installSourceBinding(catalog, sourceId) {
46
+ const generation = catalog?.generationSet.sources.find((source) => source.sourceId === sourceId);
47
+ const resolution = catalog?.catalog.sources.find((source) => source.sourceId === sourceId)?.resolution;
48
+ return generation && resolution && createCatalogPreparationStoreKey({ ...generation, requestedRef: resolution.requestedRef });
49
+ }
50
+ function homeGenerationsMatch(catalog, generations, configured) {
51
+ if (generations.length !== catalog.catalog.sources.length)
52
+ return false;
53
+ return generations.every((view) => {
54
+ const bound = catalog.generationSet.sources.find((source) => source.sourceId === view.sourceId);
55
+ const source = catalog.catalog.sources.find((item) => item.sourceId === view.sourceId);
56
+ if (!bound)
57
+ return source?.error !== undefined && catalogSourceErrorCode(source.error)
58
+ === (view.configMismatch ? 'catalogGenerationIdentityMismatch' : view.errorCode);
59
+ const config = configured.sources.find((item) => item.id === view.sourceId);
60
+ return view.state === 'ready' && view.active?.storeKey === bound.storeKey
61
+ && view.active.resolvedCommit === bound.resolvedCommit && view.active.requestedRef === source?.resolution?.requestedRef
62
+ && config?.sourceIdentity === bound.sourceIdentity && calculateCatalogSourceConfigFingerprint(config) === bound.sourceConfigFingerprint;
63
+ });
64
+ }
44
65
  function reusableCandidateEvidenceIsComplete(candidate) {
45
66
  const evidence = candidate.probe.candidate;
46
67
  return [
@@ -597,13 +618,15 @@ function createReviewStageReporter(options) {
597
618
  export function createTuiControllerDependencies(context, progressFeed, options = {}) {
598
619
  const readInventory = options.inventoryCatalogSourceReferences
599
620
  ?? inventoryCatalogSourceReferences;
600
- const validatedStoreEntries = new Map();
601
- const validatingStoreEntries = new Map();
602
- const loadCatalogGenerations = async () => {
621
+ let validatedStoreEntries = new Map();
622
+ let validatingStoreEntries = new Map();
623
+ const loadCatalogGenerations = async (entries, signal, preparation) => {
603
624
  const generations = await loadCatalogGenerationViewModels({
604
625
  env: context.env,
605
- validatedStoreEntries,
606
- validatingStoreEntries,
626
+ signal,
627
+ preparation,
628
+ validatedStoreEntries: entries,
629
+ validatingStoreEntries: new Map(),
607
630
  onStage: (event) => context.debugLogger.log({
608
631
  type: 'performance:stage',
609
632
  level: 'debug',
@@ -615,9 +638,9 @@ export function createTuiControllerDependencies(context, progressFeed, options =
615
638
  const retained = new Set(generations.flatMap((source) => [
616
639
  source.active?.storeKey,
617
640
  ].filter((value) => value !== undefined)));
618
- for (const storeKey of validatedStoreEntries.keys()) {
641
+ for (const storeKey of entries.keys()) {
619
642
  if (!retained.has(storeKey))
620
- validatedStoreEntries.delete(storeKey);
643
+ entries.delete(storeKey);
621
644
  }
622
645
  return generations;
623
646
  };
@@ -632,6 +655,8 @@ export function createTuiControllerDependencies(context, progressFeed, options =
632
655
  let sessionCatalogOperationContext;
633
656
  let sessionStatusResult;
634
657
  let sessionRecoveryStatus;
658
+ let latestStatusRead = 0;
659
+ let bindNewCatalog = true;
635
660
  const sessionContextForPlugin = (pluginId) => {
636
661
  const sourceId = parsePluginId(pluginId).sourceId;
637
662
  if (!sourceId || !sessionCatalogOperationContext)
@@ -678,14 +703,14 @@ export function createTuiControllerDependencies(context, progressFeed, options =
678
703
  };
679
704
  const loadStatus = async (signal) => {
680
705
  signal.throwIfAborted();
706
+ const read = ++latestStatusRead;
707
+ const pinnedContext = bindNewCatalog ? undefined : sessionCatalogOperationContext;
708
+ const sessionStoreEntries = validatedStoreEntries;
681
709
  const packageInfo = await readCliPackageInfo();
682
- const catalogOperationContext = sessionCatalogOperationContext
683
- ?? await resolvePartialCatalogOperationContext({
684
- env: context.env,
685
- signal,
686
- validatedStoreEntries,
687
- validatingStoreEntries,
688
- }).catch(async (error) => {
710
+ for (let attempt = 0; attempt < 3; attempt += 1) {
711
+ const catalogReadScope = pinnedContext ? undefined : new CatalogPreparationReadScope({ env: context.env, signal });
712
+ const catalogOperationContext = pinnedContext ?? await catalogReadScope?.resolve({}).catch(async (error) => {
713
+ signal.throwIfAborted();
689
714
  if (!(error instanceof CatalogGenerationError)
690
715
  || error.code !== 'catalogGenerationStateInvalid')
691
716
  return undefined;
@@ -711,21 +736,16 @@ export function createTuiControllerDependencies(context, progressFeed, options =
711
736
  },
712
737
  };
713
738
  });
714
- if (catalogOperationContext)
715
- sessionCatalogOperationContext = catalogOperationContext;
716
- for (let attempt = 0; attempt < 3; attempt += 1) {
717
739
  const result = await loadCatalogView({ context, cliVersion: packageInfo.version, signal,
718
740
  ...(catalogOperationContext ? { catalogOperationContext } : {}) });
719
- const snapshot = await readJointDemand({ cwd: context.cwd, env: context.env, signal, catalogOperationContext });
741
+ const snapshot = await readJointDemand({ cwd: context.cwd, env: context.env, signal, catalogOperationContext, catalogReadScope,
742
+ ...(catalogOperationContext ? { resolveCatalog: async () => ({
743
+ context: catalogOperationContext,
744
+ configured: new Set(catalogOperationContext.catalog.sources.map((source) => source.sourceId)),
745
+ }) } : {}),
746
+ });
720
747
  const current = await readRecoveryStatus({ cwd: context.cwd, env: context.env, signal,
721
- cliVersion: packageInfo.version, nativeCliRunner: context.nativeCliRunner, catalogOperationContext }, snapshot);
722
- signal.throwIfAborted();
723
- const configured = await listCatalogSources({ env: context.env });
724
- signal.throwIfAborted();
725
- if (result.payload.catalog.configDigest !== configured.configDigest)
726
- continue;
727
- sessionStatusResult = result;
728
- sessionRecoveryStatus = current;
748
+ cliVersion: packageInfo.version, nativeCliRunner: context.nativeCliRunner, catalogOperationContext, catalogReadScope }, snapshot);
729
749
  const dependencyOverviews = await loadDependencyOverviews({
730
750
  context,
731
751
  cliVersion: packageInfo.version,
@@ -741,7 +761,9 @@ export function createTuiControllerDependencies(context, progressFeed, options =
741
761
  ...(catalogOperationContext ? { catalogOperationContext } : {}),
742
762
  });
743
763
  signal.throwIfAborted();
744
- const catalogGenerations = await loadCatalogGenerations();
764
+ const storeEntries = new Map(catalogReadScope ? undefined : sessionStoreEntries);
765
+ const catalogGenerations = await loadCatalogGenerations(storeEntries, signal, catalogReadScope
766
+ ? { scope: catalogReadScope, context: catalogOperationContext } : undefined);
745
767
  signal.throwIfAborted();
746
768
  const configStoreInventory = (await Promise.all(['user'].map(async (scope) => {
747
769
  try {
@@ -764,9 +786,16 @@ export function createTuiControllerDependencies(context, progressFeed, options =
764
786
  return [];
765
787
  }
766
788
  }))).flat();
789
+ const configured = await listCatalogSources({ env: context.env });
767
790
  signal.throwIfAborted();
791
+ if (result.payload.catalog.configDigest !== configured.configDigest
792
+ || catalogOperationContext && !homeGenerationsMatch(catalogOperationContext, catalogGenerations, configured)) {
793
+ if (pinnedContext)
794
+ break;
795
+ continue;
796
+ }
768
797
  const statusById = new Map(result.payload.catalog.sources.map((source) => [source.id, source]));
769
- return {
798
+ const status = {
770
799
  cliChannel: packageInfo.version.includes('-') ? 'beta' : 'latest',
771
800
  ...(current.coverage.projectRoot ? { projectRoot: current.coverage.projectRoot } : {}),
772
801
  scopedRecovery: { user: { ...scopedCurrentStatus(current, snapshot, 'user'), dependencyOverviews },
@@ -805,8 +834,18 @@ export function createTuiControllerDependencies(context, progressFeed, options =
805
834
  };
806
835
  }),
807
836
  };
837
+ // Details and Review consume the same accepted read as the home view.
838
+ if (read === latestStatusRead) {
839
+ bindNewCatalog = false;
840
+ sessionCatalogOperationContext = catalogOperationContext;
841
+ sessionStatusResult = result;
842
+ sessionRecoveryStatus = current;
843
+ validatedStoreEntries = storeEntries;
844
+ validatingStoreEntries = new Map();
845
+ }
846
+ return status;
808
847
  }
809
- throw new TuiOperationBlockedError('operationReviewStale', '状态读取期间来源配置持续变化。请重试。');
848
+ throw new TuiOperationBlockedError('operationReviewStale', '状态读取期间 Catalog 持续变化。请按 H 重新加载。');
810
849
  };
811
850
  const loadPluginContent = async (pluginId, signal) => {
812
851
  signal.throwIfAborted();
@@ -1784,34 +1823,38 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1784
1823
  previewAgentSettings: (preferences, pluginId) => previewAgentSettings(context, preferences, pluginId),
1785
1824
  saveAgentSettings: (request) => saveAgentSettings(context, request),
1786
1825
  beginCatalogSession(sessionOptions) {
1787
- sessionCatalogOperationContext = undefined;
1788
- if (sessionOptions?.reuseValidatedGenerations !== true) {
1789
- validatedStoreEntries.clear();
1790
- validatingStoreEntries.clear();
1791
- }
1826
+ latestStatusRead += 1;
1827
+ bindNewCatalog = true;
1828
+ validatedStoreEntries = sessionOptions?.reuseValidatedGenerations === true
1829
+ ? new Map(validatedStoreEntries) : new Map();
1830
+ validatingStoreEntries = new Map();
1792
1831
  },
1793
1832
  loadStatus,
1794
1833
  async loadScopedStatus(scope, signal) {
1795
1834
  signal.throwIfAborted();
1835
+ const read = latestStatusRead;
1836
+ const pinnedContext = sessionCatalogOperationContext;
1837
+ const catalogView = sessionStatusResult;
1838
+ const storeEntries = { validatedStoreEntries, validatingStoreEntries };
1796
1839
  const packageInfo = await readCliPackageInfo();
1797
1840
  const currentCatalog = await resolvePartialCatalogOperationContext({
1798
- env: context.env, signal, validatedStoreEntries, validatingStoreEntries,
1841
+ env: context.env, signal, ...storeEntries,
1799
1842
  });
1800
1843
  signal.throwIfAborted();
1801
- if (sessionCatalogOperationContext
1802
- && currentCatalog.generationSetDigest !== sessionCatalogOperationContext.generationSetDigest) {
1844
+ if (pinnedContext && currentCatalog.generationSetDigest !== pinnedContext.generationSetDigest) {
1803
1845
  throw new TuiOperationBlockedError('catalogSessionReloadRequired', 'Catalog 已变化。请按 H 重新加载,再检查清单。');
1804
1846
  }
1805
- const catalogOperationContext = sessionCatalogOperationContext ?? currentCatalog;
1847
+ const catalogOperationContext = pinnedContext ?? currentCatalog;
1806
1848
  const snapshot = await readJointDemand({ scope, cwd: context.cwd, env: context.env, signal, catalogOperationContext });
1807
1849
  const status = await readRecoveryStatus({ scope, cwd: context.cwd, env: context.env, cliVersion: packageInfo.version,
1808
1850
  nativeCliRunner: context.nativeCliRunner, catalogOperationContext, signal }, snapshot);
1809
1851
  signal.throwIfAborted();
1810
- sessionRecoveryStatus = status;
1811
- const source = sessionStatusResult ?? await loadCatalogView({ context, cliVersion: packageInfo.version, signal, catalogOperationContext });
1852
+ const source = catalogView ?? await loadCatalogView({ context, cliVersion: packageInfo.version, signal, catalogOperationContext });
1812
1853
  const dependencyOverviews = await loadDependencyOverviews({ context, cliVersion: packageInfo.version, status,
1813
1854
  pluginSummaries: source.pluginSummaries, signal, catalogOperationContext });
1814
1855
  signal.throwIfAborted();
1856
+ if (read === latestStatusRead)
1857
+ sessionRecoveryStatus = status;
1815
1858
  return { ...scopedCurrentStatus(status, snapshot, scope), dependencyOverviews };
1816
1859
  },
1817
1860
  async prepareScopedTask(request, signal) {
@@ -1839,6 +1882,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1839
1882
  }
1840
1883
  const packageInfo = await readCliPackageInfo();
1841
1884
  signal.throwIfAborted();
1885
+ const pinned = sessionCatalogOperationContext;
1842
1886
  const plan = await prepareRecovery(request.command ?? 'sync', request.selectors, {
1843
1887
  signal,
1844
1888
  scope: request.scope, cwd: context.cwd, env: context.env,
@@ -1848,6 +1892,18 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1848
1892
  ...(request.targets ? { targets: request.targets } : {}),
1849
1893
  ...(request.force ? { force: true } : {}),
1850
1894
  ...(request.refresh ? { refresh: true } : {}),
1895
+ ...(request.command === 'install' && !request.refresh && pinned ? {
1896
+ checkInstallCatalog(current, roots) {
1897
+ for (const sourceId of new Set(roots.map((id) => parsePluginId(id).sourceId))) {
1898
+ if (!sourceId)
1899
+ continue;
1900
+ if (installSourceBinding(pinned, sourceId) !== installSourceBinding(current, sourceId)
1901
+ || (pinned.generationSet.primarySourceId === sourceId) !== (current?.generationSet.primarySourceId === sourceId)) {
1902
+ throw new TuiOperationBlockedError('catalogSessionReloadRequired', recoveryReason('catalogSessionReloadRequired'));
1903
+ }
1904
+ }
1905
+ },
1906
+ } : {}),
1851
1907
  ...(request.retireUnselectedTargets ? { retireUnselectedTargets: true } : {}),
1852
1908
  ...(request.scriptTimeoutMs !== undefined ? { scriptTimeoutMs: request.scriptTimeoutMs } : {}),
1853
1909
  ...(request.dependencyScopeOverrides?.length
@@ -1884,6 +1940,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1884
1940
  loadPluginContent,
1885
1941
  async probeCatalogFreshness(sourceId, freshnessOptions, signal) {
1886
1942
  signal.throwIfAborted();
1943
+ const storeEntries = { validatedStoreEntries, validatingStoreEntries };
1887
1944
  const packageInfo = await readCliPackageInfo();
1888
1945
  return probeCatalogSourceFreshness({
1889
1946
  sourceId,
@@ -1893,8 +1950,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1893
1950
  fullValidation: freshnessOptions.fullValidation,
1894
1951
  runtime: {
1895
1952
  ...options.catalogGenerationRuntime,
1896
- validatedStoreEntries,
1897
- validatingStoreEntries,
1953
+ ...storeEntries,
1898
1954
  },
1899
1955
  });
1900
1956
  },