@lesliechan721/aw 0.1.0-beta.51 → 0.1.0-beta.53

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.
@@ -1,3 +1,5 @@
1
+ import { getPluginConfigReferenceChoices } from '@lesliechan721/aw-plugin-core';
2
+ import { configReferenceKey, configReferenceScalars } from './config-references.js';
1
3
  import crypto from 'node:crypto';
2
4
  import path from 'node:path';
3
5
  import { flattenStatusTargets, statusCommandV8, statusTargetActivation, statusTargetIntent, statusTargetOwnershipState, } from '../commands/status-v6.js';
@@ -9,7 +11,7 @@ import { readCliPackageInfo } from '../utils/local-marketplace.js';
9
11
  import { createCodexNativeObservationSession, } from '../utils/codex-native-observation.js';
10
12
  import { readCatalogSourcesConfigSnapshot, recoverInvalidCatalogSourcesConfig, } from '../utils/catalog-sources.js';
11
13
  import { withResolvedCatalogPlugin, withResolvedMultiSourceCatalog, formatPluginId, parsePluginId, } from '../utils/multi-source-catalog.js';
12
- import { coercePluginConfigUpdates, inspectPluginConfigResetTarget, listNamespacedPluginConfigStoreIdentities, readPluginConfigStore, resolveConfigRead, resolveEffectivePluginConfig, resolvePluginConfigStorePath, } from '../utils/plugin-config.js';
14
+ import { coercePluginConfigUpdates, inspectPluginConfigResetTarget, listNamespacedPluginConfigStoreIdentities, readPluginConfigStore, resolveConfigRead, resolveEffectivePluginConfig, resolveEffectivePluginConfigFromStores, resolveAwProjectRoot, resolvePluginConfigStorePath, } from '../utils/plugin-config.js';
13
15
  import { assertProjectSharedConfigPathVisible } from '../utils/project-boundary.js';
14
16
  import { calculatePluginIntentDigest, readPluginIntentState, } from '../utils/plugin-intent-state.js';
15
17
  import { applyPluginConfigWrite, replayConfigRuntimeWrites, resolveConfigPreApplyAuthorization, resetPluginConfigWithHelper, } from '../utils/plugin-config-write.js';
@@ -2852,6 +2854,61 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2852
2854
  },
2853
2855
  });
2854
2856
  },
2857
+ async getConfigReferenceContext(pluginId, scope, draft, signal) {
2858
+ const packageInfo = await readCliPackageInfo();
2859
+ return withResolvedCatalogPlugin({
2860
+ selector: pluginId, cliVersion: packageInfo.version, env: context.env, signal,
2861
+ ...(sessionContextForPlugin(pluginId) ? { operationContext: sessionContextForPlugin(pluginId) } : {}),
2862
+ consume: async ({ plugin }) => {
2863
+ const definition = plugin.manifest.config;
2864
+ if (!definition)
2865
+ throw new TuiOperationBlockedError('configSchemaUnavailable', '这个插件没有设置 schema。');
2866
+ const scalars = Object.values(definition.fields).flatMap(configReferenceScalars);
2867
+ if (!scalars.length)
2868
+ return { selections: {} };
2869
+ const stores = await readConfigStoresForTui({
2870
+ sourceId: plugin.sourceId, sourceIdentity: plugin.sourceIdentity,
2871
+ logicalIdentity: plugin.catalogLogicalIdentity, pluginName: plugin.manifest.name,
2872
+ schema: definition.fields, scope, signal,
2873
+ });
2874
+ const edited = scope === 'user' ? stores.user : stores.project;
2875
+ const values = { ...edited.values };
2876
+ for (const key of draft.removes)
2877
+ delete values[key];
2878
+ Object.assign(values, draft.updates);
2879
+ const candidateStores = { ...stores, [scope]: { ...edited, values } };
2880
+ const effective = await resolveEffectivePluginConfigFromStores({
2881
+ manifest: plugin.manifest, targetScope: scope,
2882
+ projectRoot: resolveAwProjectRoot(context.cwd), stores: candidateStores,
2883
+ });
2884
+ // Keep invalid raw sources for Core validation; effective.values omits them.
2885
+ // Preserve active branches in other references that reserve source values.
2886
+ // Only source choices and entry digests leave this boundary.
2887
+ const candidate = {};
2888
+ for (const key of Object.keys(definition.fields)) {
2889
+ const source = effective.sources[key];
2890
+ if (source === 'default')
2891
+ candidate[key] = definition.fields[key].default;
2892
+ else if (source === 'user')
2893
+ candidate[key] = candidateStores.user.values[key];
2894
+ else if (source === 'project')
2895
+ candidate[key] = candidateStores.project?.values[key];
2896
+ }
2897
+ const result = { selections: {} };
2898
+ for (const scalar of scalars) {
2899
+ const ref = scalar.valueRef;
2900
+ const selection = getPluginConfigReferenceChoices(definition, scalar, candidate);
2901
+ const entries = candidate[ref.field];
2902
+ result.selections[configReferenceKey(scalar)] = {
2903
+ ...selection, source: effective.sources[ref.field] ?? 'missing',
2904
+ entries: Array.isArray(entries) ? Object.fromEntries(entries.flatMap((entry) => entry && typeof entry === 'object' && Object.hasOwn(entry, ref.key)
2905
+ ? [[JSON.stringify(entry[ref.key]), digest(entry)]] : [])) : {},
2906
+ };
2907
+ }
2908
+ return result;
2909
+ },
2910
+ });
2911
+ },
2855
2912
  async getConfigResetAvailability(pluginId, layer, signal) {
2856
2913
  const parsed = parsePluginId(pluginId);
2857
2914
  if (!parsed.sourceId || !parsed.pluginName) {