@lesliechan721/aw 0.1.0-beta.89 → 0.1.0-beta.90

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 (96) hide show
  1. package/dist/src/commands/aw-capabilities.d.ts +1 -1
  2. package/dist/src/commands/aw-capabilities.js +4 -1
  3. package/dist/src/commands/aw-capabilities.js.map +1 -1
  4. package/dist/src/commands/plugin-capabilities.js +4 -1
  5. package/dist/src/commands/plugin-capabilities.js.map +1 -1
  6. package/dist/src/commands/public-lifecycle-result.d.ts +3 -0
  7. package/dist/src/commands/public-lifecycle-result.js +30 -5
  8. package/dist/src/commands/public-lifecycle-result.js.map +1 -1
  9. package/dist/src/commands/public-lifecycle.js +8 -0
  10. package/dist/src/commands/public-lifecycle.js.map +1 -1
  11. package/dist/src/commands/public-plugin-query.js +6 -2
  12. package/dist/src/commands/public-plugin-query.js.map +1 -1
  13. package/dist/src/commands/rebuild-command.js +28 -17
  14. package/dist/src/commands/rebuild-command.js.map +1 -1
  15. package/dist/src/commands/rebuild-platform-integration.js +23 -3
  16. package/dist/src/commands/rebuild-platform-integration.js.map +1 -1
  17. package/dist/src/commands/reconcile-operation-plan.d.ts +3 -0
  18. package/dist/src/commands/reconcile-operation-plan.js +1 -0
  19. package/dist/src/commands/reconcile-operation-plan.js.map +1 -1
  20. package/dist/src/commands/status-v6.js +61 -9
  21. package/dist/src/commands/status-v6.js.map +1 -1
  22. package/dist/src/index.js +122 -28
  23. package/dist/src/index.js.map +1 -1
  24. package/dist/src/output/public-result.d.ts +1 -0
  25. package/dist/src/output/public-result.js +21 -3
  26. package/dist/src/output/public-result.js.map +1 -1
  27. package/dist/src/output/receipt-projection.js +19 -5
  28. package/dist/src/output/receipt-projection.js.map +1 -1
  29. package/dist/src/portable/recovery.d.ts +2 -7
  30. package/dist/src/portable/recovery.js +10 -0
  31. package/dist/src/portable/recovery.js.map +1 -1
  32. package/dist/src/recovery/coordinator.js +5 -0
  33. package/dist/src/recovery/coordinator.js.map +1 -1
  34. package/dist/src/recovery/joint-coordinator.js +12 -0
  35. package/dist/src/recovery/joint-coordinator.js.map +1 -1
  36. package/dist/src/recovery/status.d.ts +1 -0
  37. package/dist/src/recovery/status.js +151 -44
  38. package/dist/src/recovery/status.js.map +1 -1
  39. package/dist/src/review/source-binding.js +7 -4
  40. package/dist/src/review/source-binding.js.map +1 -1
  41. package/dist/src/tui/components.js +1 -0
  42. package/dist/src/tui/components.js.map +1 -1
  43. package/dist/src/tui/config-object-suggestions.d.ts +15 -0
  44. package/dist/src/tui/config-object-suggestions.js +71 -0
  45. package/dist/src/tui/config-object-suggestions.js.map +1 -0
  46. package/dist/src/tui/config-suggestions.d.ts +7 -2
  47. package/dist/src/tui/config-suggestions.js +22 -14
  48. package/dist/src/tui/config-suggestions.js.map +1 -1
  49. package/dist/src/tui/console-app-v4.js +569 -102
  50. package/dist/src/tui/console-app-v4.js.map +1 -1
  51. package/dist/src/tui/controller-runtime.js +14 -16
  52. package/dist/src/tui/controller-runtime.js.map +1 -1
  53. package/dist/src/tui/controller.d.ts +6 -4
  54. package/dist/src/tui/controller.js +59 -12
  55. package/dist/src/tui/controller.js.map +1 -1
  56. package/dist/src/tui/guided-setup.d.ts +25 -0
  57. package/dist/src/tui/guided-setup.js +101 -0
  58. package/dist/src/tui/guided-setup.js.map +1 -0
  59. package/dist/src/tui/model.d.ts +5 -0
  60. package/dist/src/tui/model.js +120 -49
  61. package/dist/src/tui/model.js.map +1 -1
  62. package/dist/src/tui/router.d.ts +5 -3
  63. package/dist/src/tui/router.js.map +1 -1
  64. package/dist/src/tui/scoped-flow.d.ts +2 -0
  65. package/dist/src/tui/scoped-flow.js.map +1 -1
  66. package/dist/src/tui/scoped-inventory.d.ts +1 -0
  67. package/dist/src/tui/screen-registry.d.ts +3 -2
  68. package/dist/src/utils/config-platforms.d.ts +21 -0
  69. package/dist/src/utils/config-platforms.js +51 -0
  70. package/dist/src/utils/config-platforms.js.map +1 -0
  71. package/dist/src/utils/managed-command-materialization.d.ts +1 -0
  72. package/dist/src/utils/managed-command-materialization.js +8 -3
  73. package/dist/src/utils/managed-command-materialization.js.map +1 -1
  74. package/dist/src/utils/plugin-config-command-apply.js +7 -1
  75. package/dist/src/utils/plugin-config-command-apply.js.map +1 -1
  76. package/dist/src/utils/plugin-config-diagnostics.d.ts +16 -0
  77. package/dist/src/utils/plugin-config-diagnostics.js +44 -0
  78. package/dist/src/utils/plugin-config-diagnostics.js.map +1 -0
  79. package/dist/src/utils/plugin-config-impact.js +46 -18
  80. package/dist/src/utils/plugin-config-impact.js.map +1 -1
  81. package/dist/src/utils/plugin-config-references.d.ts +5 -0
  82. package/dist/src/utils/plugin-config-references.js +19 -7
  83. package/dist/src/utils/plugin-config-references.js.map +1 -1
  84. package/dist/src/utils/plugin-config-suggestion-runner.d.ts +45 -12
  85. package/dist/src/utils/plugin-config-suggestion-runner.js +174 -33
  86. package/dist/src/utils/plugin-config-suggestion-runner.js.map +1 -1
  87. package/dist/src/utils/plugin-config-suggestions.d.ts +10 -7
  88. package/dist/src/utils/plugin-config-suggestions.js +41 -13
  89. package/dist/src/utils/plugin-config-suggestions.js.map +1 -1
  90. package/dist/src/utils/plugin-config-write.d.ts +2 -0
  91. package/dist/src/utils/plugin-config-write.js +44 -4
  92. package/dist/src/utils/plugin-config-write.js.map +1 -1
  93. package/dist/src/utils/plugin-config.d.ts +1 -0
  94. package/dist/src/utils/plugin-config.js +33 -8
  95. package/dist/src/utils/plugin-config.js.map +1 -1
  96. package/package.json +3 -3
@@ -1,10 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { guidedFieldAvailable, guidedSetupPreflight, guidedSkipWarning, guidedSuggestionValue } from './guided-setup.js';
2
3
  import { configReferenceKey, configReferenceValues, configReferenceScalars, configReferenceSelection, configReferenceMessage, configReferenceSource, configCrossLayerDependencies } from './config-references.js';
3
4
  import { arrayDraftChanged, arrayDraftValue, createConfigArrayDraft, editConfigArrayDraft, isNestedConfigObjectArray } from './config-array-draft.js';
4
5
  import { formatPluginConfigIssue, PLATFORM_TARGETS, PLUGIN_CONFIG_ARRAY_MAX_ITEMS } from '@lesliechan721/aw-plugin-core';
5
6
  import { presentConfigValue, safeConfigText } from './config-value-presentation.js';
6
7
  import { ConfigLeafEditor } from './config-leaf-editor.js';
7
- import { configSuggestionScalar, useConfigSuggestions } from './config-suggestions.js';
8
+ import { configSuggestionScalar, useConfigSuggestions, useConfigSuggestionsResponse } from './config-suggestions.js';
9
+ import { objectSuggestionContext, objectSuggestionFallback, objectSuggestionGroupKey, applyObjectSuggestionPatch } from './config-object-suggestions.js';
10
+ import { mergeObjectSuggestionPatches } from '../utils/plugin-config-suggestion-runner.js';
8
11
  import { Box, Text, useInput, useWindowSize } from 'ink';
9
12
  import { AgentManagement } from './agent-management.js';
10
13
  import { useEffect, useLayoutEffect, useRef, useState } from 'react';
@@ -529,7 +532,6 @@ function configArrayItemField(field, draft, item) {
529
532
  function configObjectValue(value) {
530
533
  return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
531
534
  }
532
- const CONFIG_PROFILE_KEYS = ['common', ...PLATFORM_TARGETS];
533
535
  function configReadOptions(layer) {
534
536
  return {
535
537
  ...(layer.profile === 'common' ? {} : { platform: layer.profile }),
@@ -1369,6 +1371,13 @@ export function ConsoleAppV4(props) {
1369
1371
  const [operationConfirmation, setOperationConfirmation] = useState();
1370
1372
  const [sourceTransportOverlay, setSourceTransportOverlay] = useState();
1371
1373
  const [scopedFlow, setScopedFlow] = useState();
1374
+ const [guidedSetup, setGuidedSetup] = useState();
1375
+ const [guidedBadges, setGuidedBadges] = useState({});
1376
+ const [guidedNotice, setGuidedNotice] = useState();
1377
+ const [guidedBusy, setGuidedBusy] = useState(false);
1378
+ const guidedTouched = useRef(new Set());
1379
+ const guidedPrefillKey = useRef(undefined);
1380
+ const guidedAbort = useRef(undefined);
1372
1381
  const [agentSettings, setAgentSettings] = useState();
1373
1382
  const [agentSettingsError, setAgentSettingsError] = useState();
1374
1383
  const [agentWelcome, setAgentWelcome] = useState(false);
@@ -1409,6 +1418,7 @@ export function ConsoleAppV4(props) {
1409
1418
  const [, setClockTick] = useState(0);
1410
1419
  const [dirty, setDirty] = useState(false);
1411
1420
  const [configPage, setConfigPage] = useState();
1421
+ const [configLayerInfo, setConfigLayerInfo] = useState();
1412
1422
  const [configLayerPages, setConfigLayerPages] = useState({});
1413
1423
  const [configDrafts, setConfigDrafts] = useState({});
1414
1424
  const [referenceContexts, setReferenceContexts] = useState({});
@@ -1487,7 +1497,8 @@ export function ConsoleAppV4(props) {
1487
1497
  return;
1488
1498
  setAgentSettings(settings);
1489
1499
  setAgentSettingsError(undefined);
1490
- if (!agentWelcomeSeen.current && settings.preferences.targets.length === 0) {
1500
+ if (!agentWelcomeSeen.current && settings.preferences.targets.length === 0
1501
+ && !props.controller.snapshot.router.current.route.name.startsWith('config')) {
1491
1502
  agentWelcomeSeen.current = true;
1492
1503
  setAgentWelcome(true);
1493
1504
  }
@@ -1515,8 +1526,7 @@ export function ConsoleAppV4(props) {
1515
1526
  ...(snapshot.router.currentFlowId ? { flowId: snapshot.router.currentFlowId } : {}),
1516
1527
  });
1517
1528
  }
1518
- const configDraftCount = CONFIG_PROFILE_KEYS.reduce((count, profile) => {
1519
- const draft = configDrafts[profile];
1529
+ const configDraftCount = Object.values(configDrafts).reduce((count, draft) => {
1520
1530
  return count + Object.keys(draft?.updates ?? {}).length + (draft?.removes.length ?? 0);
1521
1531
  }, 0);
1522
1532
  const editingProfile = 'layer' in route && route.layer ? route.layer.profile : undefined;
@@ -1745,6 +1755,11 @@ export function ConsoleAppV4(props) {
1745
1755
  const configRouteOwner = configRoute ? configOwnerKey(configRoute) : undefined;
1746
1756
  const configFlowPluginId = configRoute?.pluginId
1747
1757
  ?? (route.name === 'configLayer' ? route.pluginId : undefined);
1758
+ const currentLayerInfo = configLayerInfo?.pluginId === configFlowPluginId && configLayerInfo?.context === configContext
1759
+ && configLayerInfo.revision === configReadRevision ? configLayerInfo : undefined;
1760
+ const activeConfigLayers = currentLayerInfo?.configurableLayers ?? [];
1761
+ const activeConfigLayerSignature = activeConfigLayers.join(',');
1762
+ const residualConfigLayers = currentLayerInfo?.residualLayers ?? [];
1748
1763
  useEffect(() => {
1749
1764
  const previous = previousExternalDraftValues.current;
1750
1765
  if (previous.configDrafts !== configDrafts
@@ -1806,12 +1821,12 @@ export function ConsoleAppV4(props) {
1806
1821
  const hasReferenceFields = [configPage, ...Object.values(configLayerPages)]
1807
1822
  .some((page) => page?.groups.some((group) => group.fields.some((field) => configReferenceScalars(field.definition).length > 0)));
1808
1823
  useEffect(() => {
1809
- if (!configFlowPluginId || !hasReferenceFields)
1824
+ if (!configFlowPluginId || !hasReferenceFields || !activeConfigLayerSignature)
1810
1825
  return;
1811
1826
  const abort = new AbortController();
1812
1827
  setReferenceContexts({});
1813
1828
  setReferenceContextError(undefined);
1814
- void Promise.allSettled(CONFIG_PROFILE_KEYS.map(async (profile) => ({ profile,
1829
+ void Promise.allSettled(activeConfigLayers.map(async (profile) => ({ profile,
1815
1830
  context: await props.controller.getConfigReferenceContext(configFlowPluginId, configReadOptions({ profile, context: configContext }), configDrafts[profile] ?? { updates: {}, removes: [] }, abort.signal),
1816
1831
  }))).then((results) => {
1817
1832
  if (abort.signal.aborted)
@@ -1822,16 +1837,35 @@ export function ConsoleAppV4(props) {
1822
1837
  setReferenceContextError('引用来源读取失败。请返回修复来源配置后重新打开设置。');
1823
1838
  });
1824
1839
  return () => abort.abort();
1825
- }, [props.controller, configFlowPluginId, configDrafts, configContext, hasReferenceFields, configReadRevision]);
1840
+ }, [props.controller, configFlowPluginId, configDrafts, configContext, hasReferenceFields, configReadRevision, activeConfigLayerSignature]);
1826
1841
  const crossLayerDependencies = configCrossLayerDependencies(Object.fromEntries(Object.entries(configLayerPages).map(([profile, page]) => [profile,
1827
1842
  Object.fromEntries(page.groups.flatMap((group) => group.fields.map((field) => [field.key, field.definition])))])), configDrafts, referenceContexts);
1828
1843
  const referenceContext = editingProfile ? referenceContexts[editingProfile] : undefined;
1844
+ // A prefill finishes before dependent reference reads necessarily do.
1845
+ // Until those reads settle, the visible confirmation must not look ready.
1846
+ const configDraftInputsPending = Object.keys(configDrafts).some((profile) => !configLayerPages[profile]);
1847
+ const configDraftReferencePending = activeConfigLayers.some((profile) => !referenceContexts[profile]
1848
+ && Object.keys(configDrafts[profile]?.updates ?? {}).some((key) => configLayerPages[profile]?.groups.flatMap((group) => group.fields)
1849
+ .some((field) => field.key === key && configReferenceScalars(field.definition).length)));
1850
+ const guidedSavePending = guidedSetup && (guidedBusy || configDraftInputsPending || configDraftReferencePending);
1851
+ useEffect(() => {
1852
+ if (!guidedSetup || guidedSavePending)
1853
+ return;
1854
+ setConfigActionError((error) => error === '正在读取引用来源,请稍后保存。' || error === '正在读取设置,请稍后保存。'
1855
+ ? undefined : error);
1856
+ }, [guidedSetup?.flowId, guidedSavePending]);
1829
1857
  const configDraftIssues = (() => {
1830
1858
  const issues = [];
1831
- for (const profile of CONFIG_PROFILE_KEYS) {
1832
- const draft = configDrafts[profile];
1859
+ for (const [profile, draft] of Object.entries(configDrafts)) {
1833
1860
  if (!draft)
1834
1861
  continue;
1862
+ if (currentLayerInfo && !activeConfigLayers.includes(profile)) {
1863
+ for (const key of Object.keys(draft.updates))
1864
+ issues.push({ profile, key, source: 'update' });
1865
+ for (const key of draft.removes)
1866
+ issues.push({ profile, key, source: 'remove' });
1867
+ continue;
1868
+ }
1835
1869
  const page = configLayerPages[profile];
1836
1870
  if (!page)
1837
1871
  continue;
@@ -1862,20 +1896,28 @@ export function ConsoleAppV4(props) {
1862
1896
  return issues;
1863
1897
  })();
1864
1898
  useEffect(() => {
1865
- if (!configFlowPluginId)
1899
+ if (!configFlowPluginId) {
1900
+ setConfigLayerInfo(undefined);
1901
+ setConfigLayerPages({});
1902
+ setConfigPage(undefined);
1903
+ return;
1904
+ }
1905
+ if (!currentLayerInfo)
1866
1906
  return;
1867
1907
  const abort = new AbortController();
1868
- setConfigLayerPages({});
1869
- void Promise.allSettled(CONFIG_PROFILE_KEYS.map(async (profile) => ({
1908
+ const selected = configPage && configPage.pluginId === configFlowPluginId
1909
+ && configPage.context === configContext && activeConfigLayers.includes(configPage.profile) ? configPage : undefined;
1910
+ setConfigLayerPages(selected ? { [selected.profile]: selected } : {});
1911
+ void Promise.allSettled(activeConfigLayers.filter((profile) => profile !== selected?.profile).map(async (profile) => ({
1870
1912
  key: profile,
1871
1913
  page: await props.controller.getConfigPage(configFlowPluginId, configReadOptions({ profile, context: configContext }), abort.signal),
1872
1914
  }))).then((results) => {
1873
1915
  if (abort.signal.aborted)
1874
1916
  return;
1875
- setConfigLayerPages(Object.fromEntries(results.flatMap((result) => result.status === 'fulfilled' ? [[result.value.key, result.value.page]] : [])));
1917
+ setConfigLayerPages((current) => ({ ...Object.fromEntries(results.flatMap((result) => result.status === 'fulfilled' ? [[result.value.key, result.value.page]] : [])), ...current }));
1876
1918
  });
1877
1919
  return () => abort.abort();
1878
- }, [props.controller, configFlowPluginId, configContext, configReadRevision]);
1920
+ }, [props.controller, configFlowPluginId, configContext, configReadRevision, activeConfigLayerSignature, Boolean(currentLayerInfo)]);
1879
1921
  useEffect(() => {
1880
1922
  if (!configRoute)
1881
1923
  return;
@@ -1907,7 +1949,23 @@ export function ConsoleAppV4(props) {
1907
1949
  || expectedPluginId !== configRoute.pluginId
1908
1950
  || expectedLayer !== JSON.stringify(configRoute.layer))
1909
1951
  return;
1952
+ setConfigLayerInfo({
1953
+ pluginId: page.pluginId, context: page.context, revision: configReadRevision,
1954
+ configurableLayers: page.configurableLayers ?? [page.profile], residualLayers: page.residualLayers,
1955
+ });
1910
1956
  setConfigPage(page);
1957
+ const layers = page.configurableLayers ?? [page.profile];
1958
+ if (layers.includes(page.profile))
1959
+ setConfigLayerPages((pages) => ({ ...pages, [page.profile]: page }));
1960
+ if (layers.length > 0 && !layers.includes(configRoute.layer.profile)) {
1961
+ props.controller.replace({ name: 'configFields', pluginId: expectedPluginId,
1962
+ layer: { ...configRoute.layer, profile: layers[0] } });
1963
+ setFocus(0);
1964
+ setScrollOffset(0);
1965
+ }
1966
+ else if (layers.length === 0 && configRoute.name !== 'configFields') {
1967
+ props.controller.replace({ name: 'configFields', pluginId: expectedPluginId, layer: configRoute.layer });
1968
+ }
1911
1969
  })
1912
1970
  .catch((error) => {
1913
1971
  if (!abort.signal.aborted) {
@@ -1946,6 +2004,108 @@ export function ConsoleAppV4(props) {
1946
2004
  });
1947
2005
  return () => abort.abort();
1948
2006
  }, [configRoute?.pluginId, configRoute?.layer.profile, configContext, configReadRevision, props.controller]);
2007
+ useEffect(() => {
2008
+ if (guidedSetup && route.name === 'configFields' && route.pluginId === guidedSetup.target.pluginId
2009
+ && snapshot.router.currentFlowId === guidedSetup.flowId && route.layer.profile !== guidedSetup.target.profile
2010
+ && activeConfigLayers.includes(route.layer.profile)) {
2011
+ setGuidedSetup({ ...guidedSetup, target: { ...guidedSetup.target, profile: route.layer.profile } });
2012
+ }
2013
+ }, [guidedSetup, route.name, route.name === 'configFields' ? route.layer.profile : undefined, activeConfigLayers.join('\0')]);
2014
+ const guidedPage = guidedSetup && route.name === 'configFields' && !route.view
2015
+ && route.pluginId === guidedSetup.target.pluginId && route.layer.profile === guidedSetup.target.profile
2016
+ && snapshot.router.currentFlowId === guidedSetup.flowId && activeConfigLayers.includes(route.layer.profile) ? currentConfigPage : undefined;
2017
+ const prefillGuided = async (page, optional, abort) => {
2018
+ const guidance = guidedSetup;
2019
+ if (!guidance)
2020
+ return;
2021
+ setGuidedBusy(true);
2022
+ const fields = page.groups.flatMap((group) => group.fields).filter((field) => guidedFieldAvailable(field) && !guidedTouched.current.has(field.key)
2023
+ && !Object.hasOwn(configDrafts[page.profile]?.updates ?? {}, field.key)
2024
+ && !configDrafts[page.profile]?.removes.includes(field.key)
2025
+ && (optional ? !field.required && 'suggestions' in field.definition && field.definition.suggestions
2026
+ : field.required || guidance.target.fieldKeys.includes(field.key)));
2027
+ try {
2028
+ for (const field of fields) {
2029
+ if (abort.signal.aborted)
2030
+ break;
2031
+ const suggestions = 'suggestions' in field.definition ? field.definition.suggestions : undefined;
2032
+ let response = {
2033
+ schemaVersion: 2, status: 'no-probe', items: [],
2034
+ };
2035
+ if (suggestions) {
2036
+ try {
2037
+ response = await props.controller.getConfigSuggestions({
2038
+ pluginId: page.pluginId,
2039
+ options: configReadOptions({ profile: page.profile, context: page.context }),
2040
+ fieldPath: [field.key],
2041
+ // Unset object executor is intentionally omitted; the provider
2042
+ // interprets this as native, so all hints share one cache slot.
2043
+ }, false, abort.signal);
2044
+ }
2045
+ catch (error) {
2046
+ if (abort.signal.aborted || error instanceof Error && error.name === 'AbortError')
2047
+ return;
2048
+ response = { schemaVersion: 2, status: 'unavailable', items: [] };
2049
+ }
2050
+ }
2051
+ if (abort.signal.aborted || guidedTouched.current.has(field.key))
2052
+ continue;
2053
+ if (response.message)
2054
+ setGuidedNotice(safeConfigText(response.message));
2055
+ const recommended = guidedSuggestionValue(field, response, !optional);
2056
+ if (!recommended)
2057
+ continue;
2058
+ setConfigDrafts((drafts) => {
2059
+ const previous = drafts[page.profile] ?? { updates: {}, removes: [] };
2060
+ if (guidedTouched.current.has(field.key) || Object.hasOwn(previous.updates, field.key) || previous.removes.includes(field.key))
2061
+ return drafts;
2062
+ return { ...drafts, [page.profile]: { ...previous,
2063
+ updates: { ...previous.updates, [field.key]: recommended.value },
2064
+ ...(page.editEvidence ? { editEvidence: { ...previous.editEvidence, [field.key]: page.editEvidence } } : {}),
2065
+ } };
2066
+ });
2067
+ setGuidedBadges((badges) => ({ ...badges, [field.key]: recommended.badge }));
2068
+ setDirty(true);
2069
+ }
2070
+ }
2071
+ finally {
2072
+ if (!abort.signal.aborted)
2073
+ setGuidedBusy(false);
2074
+ }
2075
+ };
2076
+ useEffect(() => {
2077
+ if (!guidedPage || !guidedSetup || draftOwner !== guidedPage.pluginId
2078
+ || guidedPrefillKey.current === guidedSetup.flowId)
2079
+ return;
2080
+ const key = guidedSetup.flowId;
2081
+ const firstRequired = guidedPage.groups.flatMap((group) => group.fields).find((field) => guidedFieldAvailable(field) && (field.required || guidedSetup.target.fieldKeys.includes(field.key)));
2082
+ if (firstRequired) {
2083
+ const target = configFieldTarget(guidedPage, firstRequired.key);
2084
+ if (target) {
2085
+ props.controller.updatePageContext({ configGroupId: target.groupId, focusIndex: target.focusIndex, scrollOffset: 0 });
2086
+ setFocus(target.focusIndex);
2087
+ setScrollOffset(0);
2088
+ }
2089
+ }
2090
+ const abort = new AbortController();
2091
+ guidedAbort.current = abort;
2092
+ void prefillGuided(guidedPage, false, abort).then(() => {
2093
+ if (!abort.signal.aborted)
2094
+ guidedPrefillKey.current = key;
2095
+ });
2096
+ return () => {
2097
+ abort.abort();
2098
+ setGuidedBusy(false);
2099
+ };
2100
+ }, [guidedPage?.pluginId, guidedPage?.profile, guidedSetup?.flowId, draftOwner]);
2101
+ useEffect(() => {
2102
+ if (guidedSetup && snapshot.router.currentFlowId !== guidedSetup.flowId
2103
+ && !configRoute) {
2104
+ guidedAbort.current?.abort();
2105
+ setGuidedSetup(undefined);
2106
+ setGuidedBusy(false);
2107
+ }
2108
+ }, [snapshot.router.currentFlowId, guidedSetup?.flowId, configRoute?.pluginId]);
1949
2109
  useEffect(() => {
1950
2110
  if (route.name !== 'configUnavailable'
1951
2111
  || route.diagnosticCode === 'configValidationMemoryExhausted'
@@ -2143,9 +2303,10 @@ export function ConsoleAppV4(props) {
2143
2303
  setBatchTargetOffset(snapshot.router.current.context.entityLineOffset ?? 0);
2144
2304
  }, [snapshot.router.currentFrameId, route.name,
2145
2305
  route.name === 'review' || route.name === 'result' ? route.operationId : '']);
2146
- const activeTopField = route.name === 'configFieldEditor'
2147
- || route.name === 'configObjectPropertyEditor'
2148
- || route.name === 'configFieldAction'
2306
+ const activeTopField = editingProfile && activeConfigLayers.includes(editingProfile)
2307
+ && (route.name === 'configFieldEditor'
2308
+ || route.name === 'configObjectPropertyEditor'
2309
+ || route.name === 'configFieldAction')
2149
2310
  ? currentConfigPage?.groups.flatMap((group) => group.fields).find((field) => field.key === route.fieldKey)
2150
2311
  : undefined;
2151
2312
  const editorRoute = route.name === 'configFieldEditor' || route.name === 'configObjectPropertyEditor' ? route : undefined;
@@ -2212,6 +2373,7 @@ export function ConsoleAppV4(props) {
2212
2373
  || configRoute.name === 'configFields'
2213
2374
  || configRoute.name === 'configSave'
2214
2375
  || !currentConfigPage
2376
+ || !currentLayerInfo
2215
2377
  || activeField)
2216
2378
  return;
2217
2379
  props.controller.replace({
@@ -2257,8 +2419,13 @@ export function ConsoleAppV4(props) {
2257
2419
  ? activePropertyDefinition : undefined);
2258
2420
  const suggestionMenu = Boolean(suggestedScalar && (route.name === 'configFieldEditor' && route.mode !== 'custom'
2259
2421
  || route.name === 'configObjectPropertyEditor' && route.stage === 'choices'));
2422
+ const objectSuggestionDefinition = activeField?.definition.type === 'object' && !nestedArray
2423
+ ? activeField.definition : undefined;
2424
+ const objectSuggestions = objectSuggestionDefinition && activeObjectDraft
2425
+ ? objectSuggestionContext(objectSuggestionDefinition, activeObjectDraft) : undefined;
2426
+ const objectSuggestionMenu = route.name === 'configFieldEditor' && route.mode === 'suggestions' && Boolean(objectSuggestions);
2260
2427
  const suggestionLookup = (() => {
2261
- if (!suggestedScalar || !editorRoute || !activeTopField || !configFieldCanSet(activeTopField))
2428
+ if ((!suggestedScalar && !objectSuggestionMenu) || !editorRoute || !activeTopField || !configFieldCanSet(activeTopField))
2262
2429
  return undefined;
2263
2430
  const property = editorRoute.name === 'configObjectPropertyEditor' ? editorRoute.propertyKey : undefined;
2264
2431
  const selectedDraft = editorRoute.layer.profile === 'common' ? undefined : configDrafts[editorRoute.layer.profile];
@@ -2267,14 +2434,14 @@ export function ConsoleAppV4(props) {
2267
2434
  pluginId: editorRoute.pluginId,
2268
2435
  options: configReadOptions(editorRoute.layer),
2269
2436
  fieldPath: property === undefined ? activeFieldPath : [...activeFieldPath, property],
2270
- dependencyValues: property === undefined ? {} : activeObjectDraft,
2437
+ dependencyValues: objectSuggestionMenu ? objectSuggestions?.draft : property === undefined ? {} : activeObjectDraft,
2271
2438
  draftLayers: {
2272
2439
  ...(commonDraft ? { common: { updates: commonDraft.updates, removes: commonDraft.removes } } : {}),
2273
2440
  ...(selectedDraft ? { platform: { updates: selectedDraft.updates, removes: selectedDraft.removes } } : {}),
2274
2441
  },
2275
2442
  };
2276
- if (property !== undefined && activeObjectDraft) {
2277
- let workingObject = activeObjectDraft;
2443
+ if ((property !== undefined || objectSuggestionMenu) && activeObjectDraft) {
2444
+ let workingObject = objectSuggestionMenu ? objectSuggestions.draft : activeObjectDraft;
2278
2445
  if (nestedArray && arrayItem && activeArrayDraft && parentObjectDraft) {
2279
2446
  const workingArray = editConfigArrayDraft(activeArrayDraft, { kind: 'set', rowId: arrayItem.rowId, value: activeObjectDraft });
2280
2447
  workingObject = { ...parentObjectDraft, [nestedArray.propertyKey]: arrayDraftValue(workingArray) };
@@ -2286,7 +2453,14 @@ export function ConsoleAppV4(props) {
2286
2453
  }
2287
2454
  return lookup;
2288
2455
  })();
2289
- const suggestions = useConfigSuggestions(props.controller, snapshot.router.currentFrameId, suggestionLookup, suggestedScalar);
2456
+ const suggestions = useConfigSuggestions(props.controller, snapshot.router.currentFrameId, objectSuggestionMenu ? undefined : suggestionLookup, suggestedScalar);
2457
+ const compositeSuggestions = useConfigSuggestionsResponse(props.controller, snapshot.router.currentFrameId, objectSuggestionMenu ? suggestionLookup : undefined);
2458
+ useLayoutEffect(() => {
2459
+ if (objectSuggestionMenu) {
2460
+ setFocus(0);
2461
+ setScrollOffset(0);
2462
+ }
2463
+ }, [compositeSuggestions.response, objectSuggestionMenu]);
2290
2464
  useLayoutEffect(() => {
2291
2465
  if (suggestionMenu) {
2292
2466
  setFocus(0);
@@ -2498,7 +2672,8 @@ export function ConsoleAppV4(props) {
2498
2672
  });
2499
2673
  const suggestionActions = (scalar, current, select, custom) => [
2500
2674
  { label: '自定义', run: custom },
2501
- ...(suggestions.items.length ? suggestions.items : scalar.choices?.presets ?? []).map((item) => ({
2675
+ ...(suggestions.items.length ? suggestions.items
2676
+ : suggestions.status && suggestions.status !== 'not-applicable' ? scalar.choices?.presets ?? [] : []).map((item) => ({
2502
2677
  label: `${safeConfigText(item.title)}${item.recommended ? '(推荐)' : ''}`,
2503
2678
  description: item.description ? safeConfigText(item.description) : undefined,
2504
2679
  selected: item.value === current,
@@ -2625,6 +2800,10 @@ export function ConsoleAppV4(props) {
2625
2800
  return items.map((item) => item.pluginId);
2626
2801
  };
2627
2802
  const go = (next) => {
2803
+ if (guidedSetup && route.name === 'configFields') {
2804
+ guidedAbort.current?.abort();
2805
+ setGuidedBusy(false);
2806
+ }
2628
2807
  scopedFlowToken.current += 1;
2629
2808
  if (scopedFlow?.stage === 'preparing')
2630
2809
  props.controller.cancelScopedPreparation();
@@ -2673,7 +2852,7 @@ export function ConsoleAppV4(props) {
2673
2852
  setShowTechnical(false);
2674
2853
  setActionError(undefined);
2675
2854
  };
2676
- const beginScopedTask = (request, prepare = () => props.controller.prepareScopedTask(request)) => {
2855
+ const beginScopedTask = (request, prepare = () => props.controller.prepareScopedTask(request), continueGuided = false) => {
2677
2856
  if (scopedFlowBusy.current)
2678
2857
  return;
2679
2858
  scopedFlowBusy.current = true;
@@ -2681,12 +2860,31 @@ export function ConsoleAppV4(props) {
2681
2860
  setShowTechnical(false);
2682
2861
  setBatchTargetOffset(0);
2683
2862
  setScopedFlow({ stage: 'preparing', scope: request.scope, request: request.kind, focus: 0 });
2684
- void prepare().then((plan) => {
2863
+ void prepare().then(async (plan) => {
2685
2864
  if (scopedFlowToken.current !== token) {
2686
2865
  void props.controller.discardScopedPlan(plan);
2687
2866
  return;
2688
2867
  }
2868
+ if (plan.kind === 'recovery' && request.kind === 'recovery') {
2869
+ const preflight = guidedSetupPreflight(plan.plan);
2870
+ if (preflight.targets.length) {
2871
+ await props.controller.discardScopedPlan(plan);
2872
+ if (scopedFlowToken.current !== token)
2873
+ return;
2874
+ scopedFlowBusy.current = false;
2875
+ if (continueGuided) {
2876
+ openGuidedSetup(preflight.targets[0], request);
2877
+ }
2878
+ else {
2879
+ setScopedFlow({ stage: 'setup', scope: request.scope, request, preflight, focus: 0 });
2880
+ }
2881
+ return;
2882
+ }
2883
+ }
2689
2884
  scopedFlowBusy.current = false;
2885
+ if (plan.kind === 'recovery' && request.skippedConfigTargets?.length) {
2886
+ plan.skippedConfigTargets = request.skippedConfigTargets;
2887
+ }
2690
2888
  setScopedFlow({ stage: 'review', scope: request.scope, request, plan, focus: 0 });
2691
2889
  }).catch((error) => {
2692
2890
  if (scopedFlowToken.current !== token)
@@ -2696,6 +2894,33 @@ export function ConsoleAppV4(props) {
2696
2894
  errorCode: safeDiagnosticCode(error instanceof TuiOperationBlockedError ? error.code : error instanceof Error ? error.message : undefined, 'recoveryPreparationFailed'), focus: 0 });
2697
2895
  });
2698
2896
  };
2897
+ function openGuidedSetup(target, request) {
2898
+ setScopedFlow(undefined);
2899
+ guidedAbort.current?.abort();
2900
+ guidedTouched.current.clear();
2901
+ guidedPrefillKey.current = undefined;
2902
+ setGuidedBadges({});
2903
+ setGuidedNotice(undefined);
2904
+ setGuidedBusy(false);
2905
+ setConfigSaveState(undefined);
2906
+ setConfigActionError(undefined);
2907
+ const layer = { profile: target.profile, context: target.context };
2908
+ const flowId = props.controller.beginGuidedConfig(target.pluginId, layer);
2909
+ setGuidedSetup({ target, request, flowId });
2910
+ setFocus(0);
2911
+ setScrollOffset(0);
2912
+ }
2913
+ function openIssueConfig(issue, fallbackPluginId) {
2914
+ const layer = issue.configLayer ?? { profile: issue.platform ?? 'common', context: issue.scope ?? 'user' };
2915
+ if (issue.category === 'requiredConfigMissing' && (!issue.requiredFields?.length || issue.requiredFields.some((field) => field.type === 'missing-required'))) {
2916
+ openGuidedSetup({ pluginId: issue.pluginId ?? fallbackPluginId, profile: layer.profile,
2917
+ context: layer.context, fieldKeys: issue.requiredFields?.filter((field) => field.type === 'missing-required').map((field) => field.key) ?? [] });
2918
+ return;
2919
+ }
2920
+ props.controller.beginGuidedConfig(issue.pluginId ?? fallbackPluginId, layer);
2921
+ setFocus(0);
2922
+ setScrollOffset(0);
2923
+ }
2699
2924
  const agentSummaries = (pluginId) => {
2700
2925
  const entries = pluginId ? [pluginId] : props.controller.listPlugins({ mode: 'browse' }).map((entry) => entry.pluginId);
2701
2926
  return Object.fromEntries((agentSettings?.preferences.targets ?? []).map((target) => {
@@ -2766,8 +2991,7 @@ export function ConsoleAppV4(props) {
2766
2991
  errorCode: 'recoveryReprepareFailed', focus: 0 });
2767
2992
  return;
2768
2993
  }
2769
- setScopedFlow({ stage: 'review', scope: plan.scope,
2770
- request: nextRequest, plan: outcome.plan, focus: 0 });
2994
+ beginScopedTask(nextRequest, async () => outcome.plan);
2771
2995
  return;
2772
2996
  }
2773
2997
  setScopedFlow({ stage: 'result', scope: plan.scope, plan,
@@ -2930,6 +3154,14 @@ export function ConsoleAppV4(props) {
2930
3154
  setActionError(undefined);
2931
3155
  };
2932
3156
  const back = () => {
3157
+ if (route.name === 'configFields' && guidedSetup && snapshot.router.currentFlowId === guidedSetup.flowId && !route.view) {
3158
+ guidedAbort.current?.abort();
3159
+ setGuidedSetup(undefined);
3160
+ setGuidedBusy(false);
3161
+ props.controller.finishGuidedConfig(guidedSetup.flowId);
3162
+ restorePageContext();
3163
+ return;
3164
+ }
2933
3165
  if (route.name === 'pluginContent')
2934
3166
  setContentReader(undefined);
2935
3167
  if (route.name === 'sourceEdit'
@@ -3641,7 +3873,7 @@ export function ConsoleAppV4(props) {
3641
3873
  go({ name: 'sourceEdit', sourceId, owner });
3642
3874
  };
3643
3875
  const configLayerLabel = (layer) => layer.profile === 'common' ? '公共设置' : agentLabel(layer.profile);
3644
- const fieldValueText = (field, value, full = false, configured = value !== undefined) => presentConfigValue({
3876
+ const fieldValueText = (field, value, full = false, configured = value !== undefined) => !configFieldCanSet(field) && configFieldCanUnset(field) ? '[redacted]' : presentConfigValue({
3645
3877
  definition: field.definition,
3646
3878
  value,
3647
3879
  configured,
@@ -3671,14 +3903,14 @@ export function ConsoleAppV4(props) {
3671
3903
  return '将更新';
3672
3904
  return fieldValueText(targetField, value);
3673
3905
  };
3674
- const pendingFieldTargets = (field) => CONFIG_PROFILE_KEYS.flatMap((profile) => {
3906
+ const pendingFieldTargets = (field) => activeConfigLayers.flatMap((profile) => {
3675
3907
  const value = pendingFieldDisplay(field, profile);
3676
3908
  return value ? [{ profile, value }] : [];
3677
3909
  });
3678
3910
  const fieldEditor = (field) => {
3679
3911
  return field.type;
3680
3912
  };
3681
- const fieldEditorMode = (field) => (field.choices?.length ?? 0) > 0 || 'valueRef' in field.definition && field.definition.valueRef
3913
+ const fieldEditorMode = (field) => (field.choices?.length ?? 0) > 0 && !(field.definition.type === 'object' && field.definition.suggestions) || 'valueRef' in field.definition && field.definition.valueRef
3682
3914
  || configSuggestionScalar(field.definition) ? { mode: 'choices' } : {};
3683
3915
  const openConfigTarget = (candidate) => {
3684
3916
  const currentFlowId = snapshot.router.currentFlowId;
@@ -3757,7 +3989,7 @@ export function ConsoleAppV4(props) {
3757
3989
  go({
3758
3990
  name: 'configFieldEditor', pluginId: configRoute.pluginId, layer: configRoute.layer,
3759
3991
  fieldKey: activeField.key, editor: activeField.definition.items.type,
3760
- ...(activeField.definition.items.choices || 'valueRef' in activeField.definition.items && activeField.definition.items.valueRef
3992
+ ...(activeField.definition.items.choices && !(activeField.definition.items.type === 'object' && activeField.definition.items.suggestions) || 'valueRef' in activeField.definition.items && activeField.definition.items.valueRef
3761
3993
  || configSuggestionScalar(activeField.definition.items) ? { mode: 'choices' } : {}),
3762
3994
  arrayItem: { rowId },
3763
3995
  ...(nestedArray ? { nestedArray } : {}),
@@ -3902,30 +4134,44 @@ export function ConsoleAppV4(props) {
3902
4134
  const candidate = { ...activeObjectDraft, [propertyKey]: value };
3903
4135
  if (value === undefined)
3904
4136
  delete candidate[propertyKey];
4137
+ const variants = activeField.definition.variants;
4138
+ const variantSwitch = variants?.discriminator === propertyKey && activeObjectDraft[propertyKey] !== value;
3905
4139
  const issues = validatePluginConfigValue(activeField.definition, candidate, activeField.key)
3906
- .filter((issue) => issue.path.property === propertyKey);
4140
+ .filter((issue) => issue.path.property === propertyKey && (value !== undefined || variantSwitch));
3907
4141
  if (issues.length > 0) {
3908
4142
  setInputError(issues.slice(0, 2).map(objectIssueText).join(';'));
3909
4143
  return false;
3910
4144
  }
3911
- const variants = activeField.definition.variants;
3912
- if (variants?.discriminator === propertyKey && activeObjectDraft[propertyKey] !== value) {
4145
+ const removed = [];
4146
+ const removeProperty = (property) => {
4147
+ if (!Object.hasOwn(candidate, property))
4148
+ return;
4149
+ removed.push({ property, value: candidate[property] });
4150
+ delete candidate[property];
4151
+ };
4152
+ const changed = activeObjectDraft[propertyKey] !== value
4153
+ && !configValuesEqual(activeObjectDraft[propertyKey], value);
4154
+ if (changed && definition && 'clearsOnChange' in definition) {
4155
+ for (const property of definition.clearsOnChange ?? [])
4156
+ removeProperty(property);
4157
+ }
4158
+ if (variantSwitch) {
3913
4159
  const resolved = resolvePluginConfigObjectProperties(activeField.definition, candidate, activeField.key);
3914
4160
  if (resolved.issues.length) {
3915
4161
  setInputError(resolved.issues.slice(0, 2).map(objectIssueText).join(';'));
3916
4162
  return false;
3917
4163
  }
3918
- const removed = [];
3919
4164
  for (const property of Object.keys(candidate)) {
3920
4165
  const definition = resolved.properties[property];
3921
4166
  if (activeObjectProperties?.[property] && !definition
3922
4167
  || definition && 'const' in definition && definition.const !== undefined
3923
4168
  && Object.hasOwn(candidate, property) && candidate[property] !== definition.const) {
3924
- removed.push({ property, value: candidate[property] });
3925
- delete candidate[property];
4169
+ removeProperty(property);
3926
4170
  }
3927
4171
  }
3928
- setObjectVariantPreview({ routeKey, value: candidate, removed });
4172
+ }
4173
+ if (variantSwitch || removed.length) {
4174
+ setObjectVariantPreview({ routeKey, variantSwitch, value: candidate, removed });
3929
4175
  setFocus(0);
3930
4176
  setBatchTargetOffset(0);
3931
4177
  return false;
@@ -4003,6 +4249,12 @@ export function ConsoleAppV4(props) {
4003
4249
  const updates = { ...previous.updates };
4004
4250
  const removes = new Set(previous.removes);
4005
4251
  const editEvidence = { ...previous.editEvidence };
4252
+ if (guidedSetup?.target.pluginId === candidate.pluginId && guidedSetup.target.profile === layer.profile) {
4253
+ for (const key of Object.keys(selectedCandidate.mutations))
4254
+ guidedTouched.current.add(key);
4255
+ setGuidedBadges((badges) => Object.fromEntries(Object.entries(badges)
4256
+ .filter(([key]) => !guidedTouched.current.has(key))));
4257
+ }
4006
4258
  for (const [key, mutation] of Object.entries(selectedCandidate.mutations)) {
4007
4259
  const field = fields.get(key);
4008
4260
  if (selectedCandidate.editEvidence)
@@ -4129,7 +4381,7 @@ export function ConsoleAppV4(props) {
4129
4381
  const discardInvalidConfigDraftChanges = () => {
4130
4382
  if (!configRoute || configDraftIssues.length === 0)
4131
4383
  return;
4132
- const nextDrafts = Object.fromEntries(CONFIG_PROFILE_KEYS.flatMap((profile) => {
4384
+ const nextDrafts = Object.fromEntries(Object.keys(configDrafts).flatMap((profile) => {
4133
4385
  const draft = configDrafts[profile];
4134
4386
  if (!draft)
4135
4387
  return [];
@@ -4159,7 +4411,7 @@ export function ConsoleAppV4(props) {
4159
4411
  const configSaveIntent = (apply = false) => {
4160
4412
  if (!configRoute || configDraftCount === 0)
4161
4413
  return;
4162
- const groups = CONFIG_PROFILE_KEYS.flatMap((profile) => {
4414
+ const groups = activeConfigLayers.flatMap((profile) => {
4163
4415
  const draft = configDrafts[profile];
4164
4416
  const page = configLayerPages[profile];
4165
4417
  if (!draft || !page || page.pluginId !== configRoute.pluginId || page.context !== configContext)
@@ -4223,9 +4475,7 @@ export function ConsoleAppV4(props) {
4223
4475
  setConfigActionError(`请先保存来源配置,再编辑或保存引用配置:${[...new Set(crossLayerDependencies.map((entry) => entry.source))].join('、')}(公共设置)。请取消相关引用草稿后保存来源。`);
4224
4476
  return;
4225
4477
  }
4226
- if (CONFIG_PROFILE_KEYS.some((profile) => !referenceContexts[profile]
4227
- && Object.keys(configDrafts[profile]?.updates ?? {}).some((key) => configLayerPages[profile]?.groups.flatMap((group) => group.fields)
4228
- .some((field) => field.key === key && configReferenceScalars(field.definition).length)))) {
4478
+ if (configDraftReferencePending) {
4229
4479
  setConfigActionError(referenceContextError ?? '正在读取引用来源,请稍后保存。');
4230
4480
  return;
4231
4481
  }
@@ -4234,8 +4484,11 @@ export function ConsoleAppV4(props) {
4234
4484
  return;
4235
4485
  }
4236
4486
  const intent = configSaveIntent();
4237
- if (!intent)
4487
+ if (!intent) {
4488
+ if (guidedSetup)
4489
+ setConfigActionError('正在读取设置,请稍后保存。');
4238
4490
  return;
4491
+ }
4239
4492
  const profiles = intent.groups.map((group) => group.platform ?? 'common');
4240
4493
  const context = intent.context ?? 'user';
4241
4494
  const previouslySaved = configSaveState?.status === 'error' && configSaveState.pluginId === intent.pluginId
@@ -4245,7 +4498,7 @@ export function ConsoleAppV4(props) {
4245
4498
  try {
4246
4499
  const result = await props.controller.saveConfigDraft(intent);
4247
4500
  const saved = new Set(result.savedProfiles);
4248
- const pendingApply = CONFIG_PROFILE_KEYS.filter((profile) => saved.has(profile) || previouslySaved.includes(profile));
4501
+ const pendingApply = activeConfigLayers.filter((profile) => saved.has(profile) || previouslySaved.includes(profile));
4249
4502
  const nextDrafts = Object.fromEntries(Object.entries(configDrafts)
4250
4503
  .filter(([profile]) => !saved.has(profile))
4251
4504
  .map(([profile, draft]) => [profile, draft.editEvidence ? { ...draft, editEvidence: Object.fromEntries(Object.entries(draft.editEvidence).map(([key, evidence]) => [key, { ...evidence, storeDigests: {} }])) } : draft]));
@@ -4265,7 +4518,25 @@ export function ConsoleAppV4(props) {
4265
4518
  setConfigReadRevision((revision) => revision + 1);
4266
4519
  }
4267
4520
  if (result.status === 'succeeded') {
4268
- setConfigSaveState({ status: 'saved', pluginId: intent.pluginId, profiles: pendingApply, context });
4521
+ if (guidedSetup?.target.pluginId === intent.pluginId && snapshot.router.currentFlowId === guidedSetup.flowId) {
4522
+ const { request, flowId } = guidedSetup;
4523
+ guidedAbort.current?.abort();
4524
+ setGuidedSetup(undefined);
4525
+ setGuidedBusy(false);
4526
+ setConfigSaveState(undefined);
4527
+ props.controller.finishGuidedConfig(flowId);
4528
+ restorePageContext();
4529
+ await props.controller.load();
4530
+ if (props.controller.snapshot.phase === 'ready') {
4531
+ if (request)
4532
+ beginScopedTask(request, undefined, true);
4533
+ else
4534
+ void props.controller.refreshScopedInventory(context);
4535
+ }
4536
+ }
4537
+ else {
4538
+ setConfigSaveState({ status: 'saved', pluginId: intent.pluginId, profiles: pendingApply, context });
4539
+ }
4269
4540
  }
4270
4541
  else {
4271
4542
  const error = result.status === 'partial' ? '部分设置未保存。已保留未保存的草稿,请检查后重试。'
@@ -4425,7 +4696,11 @@ export function ConsoleAppV4(props) {
4425
4696
  description = flow.pluginId ? `选择 ${flow.pluginId.split('/').pop()} 在哪些 Agent 中使用`
4426
4697
  : '选择这台电脑上使用的 Agent';
4427
4698
  breadcrumb = flow.pluginId ? '插件 / Agent 管理' : '首页 / Agent 管理';
4428
- content = _jsx(AgentManagement, { controller: props.controller, settings: flow.settings, pluginId: flow.pluginId, columns: size.columns, rows: size.rows, summaries: agentSummaries(flow.pluginId), active: !overlay, onBack: closeScopedFlow, onExit: requestConfirmedExit, onSaved: setAgentSettings, onHome: () => { closeScopedFlow(); requestSessionNavigation('home'); }, onReload: () => { closeScopedFlow(); requestSessionNavigation('reload'); }, onHelp: () => { setOverlayFocus(0); setHelpPage(1); setOverlay('help'); }, onSync: () => beginScopedTask({ kind: 'recovery', command: 'sync', scope: flow.scope,
4699
+ content = _jsx(AgentManagement, { controller: props.controller, settings: flow.settings, pluginId: flow.pluginId, columns: size.columns, rows: size.rows, summaries: agentSummaries(flow.pluginId), active: !overlay, onBack: closeScopedFlow, onExit: requestConfirmedExit, onSaved: (settings) => {
4700
+ setAgentSettings(settings);
4701
+ if (configRoute)
4702
+ setConfigReadRevision((revision) => revision + 1);
4703
+ }, onHome: () => { closeScopedFlow(); requestSessionNavigation('home'); }, onReload: () => { closeScopedFlow(); requestSessionNavigation('reload'); }, onHelp: () => { setOverlayFocus(0); setHelpPage(1); setOverlay('help'); }, onSync: () => beginScopedTask({ kind: 'recovery', command: 'sync', scope: flow.scope,
4429
4704
  selectors: flow.pluginId ? [flow.pluginId] : [], retireUnselectedTargets: true }) });
4430
4705
  help = '↑↓ 移动 · Enter/Space 勾选 · s 保存 · r 重新检查 · Esc 返回';
4431
4706
  }
@@ -4482,10 +4757,28 @@ export function ConsoleAppV4(props) {
4482
4757
  help = '输入 · Enter 应用并重新准备 · Ctrl-U 清空 · Esc 保留原值';
4483
4758
  content = _jsx(InputCard, { focused: true, title: _jsx(InputDisplay, { value: scriptTimeoutInput, columns: Math.max(8, size.columns - 8) }), description: scriptTimeoutError ?? '此值只用于本次任务。', status: scriptTimeoutError ? 'error' : undefined });
4484
4759
  }
4760
+ else if (flow.stage === 'setup') {
4761
+ title = '需要初始化平台配置';
4762
+ description = '先完成所列插件的必填设置;保存后继续原安装或同步。';
4763
+ actions = [
4764
+ { label: '前往初始化配置(推荐)', run: () => openGuidedSetup(flow.preflight.targets[0], flow.request) },
4765
+ ...(flow.preflight.readyTargets.length > 0 ? [{
4766
+ label: '跳过未配置平台,仅继续已就绪平台',
4767
+ run: () => beginScopedTask({ ...flow.request,
4768
+ exactTargets: flow.preflight.readyTargets,
4769
+ skippedConfigTargets: [...flow.request.skippedConfigTargets ?? [], ...flow.preflight.targets],
4770
+ }),
4771
+ }] : []),
4772
+ { label: '取消', run: closeScopedFlow },
4773
+ ];
4774
+ readingText = flow.preflight.targets.map((target) => `${target.pluginId} · ${target.profile === 'common' ? '公共设置' : agentLabel(target.profile)} · ${target.fieldKeys.join('、') || '缺少必填设置'}`).join('\n');
4775
+ help = '←→ 阅读 · ↑↓ 选择 · Enter 确认 · Esc 取消';
4776
+ content = _jsxs(Box, { flexDirection: "column", children: [readingPage(readingText, size.columns - 6, Math.max(1, pageActionBudget(actions.length + 4))), _jsx(SemanticRows, { actions: actions, focus: flow.focus, kind: "action", compact: true })] });
4777
+ }
4485
4778
  else if (flow.stage === 'review') {
4486
4779
  title = '操作汇总';
4487
4780
  description = '确认需求、偏好、配置及输出影响。';
4488
- readingText = scopedPlanText(flow.plan, showTechnical);
4781
+ readingText = [flow.request.skippedConfigTargets?.length ? guidedSkipWarning(flow.request.skippedConfigTargets) : undefined, scopedPlanText(flow.plan, showTechnical)].filter(Boolean).join('\n');
4489
4782
  help = '←→ 阅读 · ↑↓ 操作 · Enter 选择 · d 详情 · Esc 返回';
4490
4783
  actions = [
4491
4784
  { label: flow.plan.kind === 'targets' ? '确认保存本机工具'
@@ -4519,7 +4812,7 @@ export function ConsoleAppV4(props) {
4519
4812
  else if (flow.stage === 'risk') {
4520
4813
  title = '操作汇总';
4521
4814
  description = '确认需求、偏好、配置及输出影响。';
4522
- readingText = scopedPlanText(flow.plan, showTechnical);
4815
+ readingText = [flow.request.skippedConfigTargets?.length ? guidedSkipWarning(flow.request.skippedConfigTargets) : undefined, scopedPlanText(flow.plan, showTechnical)].filter(Boolean).join('\n');
4523
4816
  actions = [
4524
4817
  { label: '返回检查', run: () => setScopedFlow({ ...flow, stage: 'review', focus: 0 }) },
4525
4818
  { label: '确认并执行', run: () => executeScopedReview(flow.plan) },
@@ -4531,10 +4824,13 @@ export function ConsoleAppV4(props) {
4531
4824
  title = '恢复结果';
4532
4825
  help = '←→ 阅读 · ↑↓ 操作 · Enter 选择 · d 详情 · Esc 返回';
4533
4826
  description = flow.errorCode ? recoveryReason(flow.errorCode)
4534
- : flow.receipt ? flow.receipt.ok ? '请求已完成。' : '请求仍有未完成目标。'
4827
+ : flow.receipt ? flow.receipt.ok ? flow.request?.skippedConfigTargets?.length ? '已就绪平台请求已完成;待配置平台仍保留。' : '请求已完成。' : '请求仍有未完成目标。'
4535
4828
  : '本机工具已保存。';
4536
4829
  readingText = flow.receipt ? scopedResultText(flow.receipt, showTechnical)
4537
4830
  : (flow.errorCode ? showTechnical ? flow.errorCode : recoveryReason(flow.errorCode) : undefined) ?? (flow.changed ? '本机工具已保存。' : '本机工具没有变化。');
4831
+ if (flow.request?.skippedConfigTargets?.length) {
4832
+ readingText = [guidedSkipWarning(flow.request.skippedConfigTargets), readingText].filter(Boolean).join('\n');
4833
+ }
4538
4834
  const failedPositions = flow.receipt?.targetResults.filter((target) => (target.execution === 'failed' || target.execution === 'partial')
4539
4835
  && (target.observation === 'missing' || target.content === 'absent')) ?? [];
4540
4836
  const retryTargets = flow.receipt ? recoveryRetryTargets(flow.receipt, failedPositions) : [];
@@ -4567,7 +4863,7 @@ export function ConsoleAppV4(props) {
4567
4863
  exactTargets: retryTargets,
4568
4864
  }) }] : []),
4569
4865
  ];
4570
- content = _jsxs(ResultSurface, { status: flow.errorCode || flow.receipt && !flow.receipt.ok ? 'warning' : 'success', title: description, children: [readingPage(readingText, size.columns - 6, Math.max(1, pageActionBudget(actions.length + (showTechnical ? 5 : 4)))), _jsx(SemanticRows, { actions: actions, focus: flow.focus, kind: "action", compact: true })] });
4866
+ content = _jsxs(ResultSurface, { status: flow.errorCode || flow.receipt && !flow.receipt.ok || flow.request?.skippedConfigTargets?.length ? 'warning' : 'success', title: description, children: [readingPage(readingText, size.columns - 6, Math.max(1, pageActionBudget(actions.length + (showTechnical ? 5 : 4)))), _jsx(SemanticRows, { actions: actions, focus: flow.focus, kind: "action", compact: true })] });
4571
4867
  }
4572
4868
  }
4573
4869
  else if (route.name === 'intentInventory') {
@@ -5902,17 +6198,15 @@ export function ConsoleAppV4(props) {
5902
6198
  const configField = issue?.requiredFields?.[0];
5903
6199
  if (issue?.group === 'config' || configField) {
5904
6200
  const fieldKey = configField?.key;
5905
- return [[`config:${target.pluginId}:${fieldKey ?? ''}`, {
6201
+ return [[`config:${target.pluginId}:${issue?.configLayer?.profile ?? target.platform}:${fieldKey ?? ''}`, {
5906
6202
  label: fieldKey ? `完成设置:${configField?.title ?? fieldKey}` : `检查 ${candidate.displayName} 的设置`,
5907
6203
  description: `${targetLabel};保存后返回任务重新读取当前证据`,
5908
6204
  status: 'warning',
5909
6205
  run: () => {
5910
- beginConfigFlow(target.pluginId);
5911
- props.controller.replace({
5912
- name: 'configFields',
5913
- pluginId: target.pluginId,
5914
- layer: { profile: 'common' },
5915
- });
6206
+ if (issue)
6207
+ openIssueConfig(issue, target.pluginId);
6208
+ else
6209
+ beginConfigFlow(target.pluginId);
5916
6210
  },
5917
6211
  }]];
5918
6212
  }
@@ -6639,14 +6933,42 @@ export function ConsoleAppV4(props) {
6639
6933
  else if (route.name === 'configFields' && plugin) {
6640
6934
  const readonly = false;
6641
6935
  breadcrumb = `${plugin.displayName} / 设置`;
6642
- title = '插件设置';
6936
+ title = guidedSetup ? '平台初始化引导' : '插件设置';
6643
6937
  description = undefined;
6644
6938
  if (configActionError)
6645
6939
  description = configActionError;
6646
6940
  help = 'Esc 返回';
6647
- if (!currentConfigPage) {
6941
+ if (!currentConfigPage || !currentLayerInfo) {
6648
6942
  content = _jsx(StatusCard, { status: "info", title: "\u6B63\u5728\u8BFB\u53D6\u63D2\u4EF6\u8BBE\u7F6E", children: _jsx(ProgressRow, { title: "\u8BFB\u53D6\u8BBE\u7F6E\u5B57\u6BB5", state: "active" }) });
6649
6943
  }
6944
+ else if (route.view === 'residuals') {
6945
+ title = '历史残留层';
6946
+ description = '这些设置层未启用或不再可配,仅可清理整层;不会自动删除。';
6947
+ actions = residualConfigLayers.map(({ profile, keys }) => ({
6948
+ label: `重置${configLayerLabel({ profile })}`,
6949
+ description: `${keys.length} 项 · ${keys.map(safeConfigText).join('、')}`,
6950
+ status: 'error',
6951
+ run: () => beginReview({ kind: 'configReset', pluginId: plugin.pluginId, scope: 'user',
6952
+ ...configReadOptions({ profile, context: route.layer.context }),
6953
+ changes: [{ key: 'residualLayer', title: `${configLayerLabel({ profile })}历史残留`,
6954
+ before: `${keys.length} 项 · ${keys.map(safeConfigText).join('、')}`, after: '删除整层' }],
6955
+ }),
6956
+ }));
6957
+ if (actions.length === 0)
6958
+ description = '已无历史残留层。';
6959
+ content = suggestionRows(actions);
6960
+ }
6961
+ else if (activeConfigLayers.length === 0) {
6962
+ title = '没有可配置的设置层';
6963
+ description = '这个插件在当前启用的 Agent 中没有可配置项。可到 Agent 管理启用适用的目标。';
6964
+ actions = [{ label: '打开 Agent 管理', run: () => openAgentManagement() },
6965
+ ...(residualConfigLayers.length ? [{ label: `历史残留层(${residualConfigLayers.length} 个)`,
6966
+ run: () => go({ ...route, view: 'residuals' }) }] : [])];
6967
+ content = _jsx(SemanticRows, { actions: actions, focus: focus, kind: "action", compact: true });
6968
+ }
6969
+ else if (!activeConfigLayers.includes(route.layer.profile)) {
6970
+ content = _jsx(ProgressRow, { title: "\u8BFB\u53D6\u6D3B\u8DC3\u8BBE\u7F6E\u5C42", state: "active" });
6971
+ }
6650
6972
  else {
6651
6973
  visibleConfigTabs = configTabs(currentConfigPage);
6652
6974
  const requestedTab = snapshot.router.current.context.configGroupId;
@@ -6680,20 +7002,22 @@ export function ConsoleAppV4(props) {
6680
7002
  description: field.description?.split('\n').map(safeConfigText).join('\n'),
6681
7003
  issue: field.invalidOverrideIssue?.split('\n').map(safeConfigText).join('\n'),
6682
7004
  invalid: Boolean(field.invalidOverrideIssue),
6683
- ...(targets.length ? { pending: '● 未保存' } : {}),
7005
+ ...(targets.length ? { pending: guidedSetup && guidedBadges[field.key] && !guidedTouched.current.has(field.key) ? guidedBadges[field.key] : '● 未保存' } : {}),
6684
7006
  };
6685
7007
  })(),
6686
7008
  configKey: field.key,
6687
7009
  run: () => go({ name: 'configFieldEditor', pluginId: plugin.pluginId, layer: mutableLayer,
6688
7010
  fieldKey: field.key, editor: fieldEditor(field), ...fieldEditorMode(field) }),
6689
7011
  }));
7012
+ const discardInvalidAction = configDraftIssues.length > 0 ? [{
7013
+ label: '放弃无法保存的修改', status: 'warning', run: discardInvalidConfigDraftChanges,
7014
+ }] : [];
6690
7015
  const operationActions = [
6691
7016
  ...(crossLayerDependencies.length ? [{ label: '取消相关引用草稿', status: 'warning',
6692
7017
  description: '保留来源设置修改,只放弃依赖这些未保存值的引用草稿。', run: discardDependentConfigDrafts }] : []),
6693
- ...(configDraftIssues.length > 0 ? [{ label: '放弃无法保存的修改',
6694
- status: 'warning', run: discardInvalidConfigDraftChanges }] : []),
7018
+ ...discardInvalidAction,
6695
7019
  { actionId: 'config-reset-profile', label: '恢复默认值 [u]', status: 'error',
6696
- description: '删除当前 Agent 设置中的覆盖值,恢复继承。',
7020
+ description: '删除当前 Agent 设置中的全部覆盖值,恢复继承。',
6697
7021
  run: () => beginReview({ kind: 'configReset', pluginId: plugin.pluginId, scope: 'user',
6698
7022
  ...configReadOptions(route.layer),
6699
7023
  changes: currentConfigPage.groups.flatMap((group) => group.fields).filter((field) => field.configured).map((field) => ({
@@ -6704,10 +7028,10 @@ export function ConsoleAppV4(props) {
6704
7028
  ];
6705
7029
  const configSaveAction = {
6706
7030
  actionId: 'config-save-summary',
6707
- label: '保存 [s]',
6708
- description: '保存设置后,可选择更新已安装的插件。',
7031
+ label: guidedSetup ? '确认保存并继续 [s]' : '保存 [s]',
7032
+ description: guidedSetup ? '仅确认后保存草稿并重新检查。' : '保存设置后,可选择更新已安装的插件。',
6709
7033
  status: configDraftCount > 0 ? 'info' : 'muted',
6710
- disabled: configDraftCount === 0 ? '没有待保存设置'
7034
+ disabled: guidedSavePending ? '正在读取推荐或引用来源' : configDraftCount === 0 ? '没有待保存设置'
6711
7035
  : configDraftIssues.length > 0 ? '请先放弃失效草稿' : undefined,
6712
7036
  run: () => {
6713
7037
  setFocus(0);
@@ -6715,7 +7039,33 @@ export function ConsoleAppV4(props) {
6715
7039
  onSaveConfig();
6716
7040
  },
6717
7041
  };
6718
- bottomActions = [configSaveAction, ...operationActions, {
7042
+ const residualAction = residualConfigLayers.length ? [{
7043
+ label: `历史残留层(${residualConfigLayers.length} 个)`, run: () => go({ ...route, view: 'residuals' }),
7044
+ }] : [];
7045
+ const optionalFields = guidedPage?.groups.flatMap((group) => group.fields)
7046
+ .filter((field) => !field.required && guidedFieldAvailable(field) && 'suggestions' in field.definition
7047
+ && field.definition.suggestions && !guidedTouched.current.has(field.key)
7048
+ && !Object.hasOwn(configDrafts[guidedPage.profile]?.updates ?? {}, field.key)) ?? [];
7049
+ const guidedActions = optionalFields.length ? [{
7050
+ actionId: 'guided-fill-optional',
7051
+ label: '按推荐预填全部可选档位',
7052
+ disabled: guidedBusy ? '正在获取推荐' : undefined,
7053
+ run: () => {
7054
+ const abort = new AbortController();
7055
+ guidedAbort.current?.abort();
7056
+ guidedAbort.current = abort;
7057
+ void prefillGuided(guidedPage, true, abort);
7058
+ },
7059
+ }] : [];
7060
+ guidedActions.push(...discardInvalidAction);
7061
+ if (guidedSetup && configDraftReferencePending && referenceContextError) {
7062
+ guidedActions.push({
7063
+ label: '重新读取引用来源',
7064
+ description: '保留所有未保存草稿。',
7065
+ run: () => setConfigReadRevision((revision) => revision + 1),
7066
+ });
7067
+ }
7068
+ bottomActions = guidedSetup ? [configSaveAction, ...guidedActions] : [configSaveAction, ...operationActions, ...residualAction, {
6719
7069
  label: '设置选项', run: () => go({ ...route, view: 'options' }),
6720
7070
  }];
6721
7071
  actions = [...tabActions, ...bottomActions];
@@ -6725,7 +7075,7 @@ export function ConsoleAppV4(props) {
6725
7075
  actions = [{ label: '查看当前值的来源', run: () => {
6726
7076
  setBatchTargetOffset(0);
6727
7077
  go({ ...route, view: 'values' });
6728
- } }, ...operationActions];
7078
+ } }, ...operationActions, ...residualAction];
6729
7079
  }
6730
7080
  const effectiveConfigFocus = Math.min(focus, Math.max(0, actions.length - 1));
6731
7081
  const focusedConfigField = activeGroup?.fields.find((field) => field.key === actions[effectiveConfigFocus]?.configKey);
@@ -6741,35 +7091,45 @@ export function ConsoleAppV4(props) {
6741
7091
  }
6742
7092
  if (!readonly) {
6743
7093
  const canUnsetFocused = focusedConfigField
6744
- ? CONFIG_PROFILE_KEYS.some((profile) => configLayerPages[profile]?.groups.flatMap((group) => group.fields)
7094
+ ? activeConfigLayers.some((profile) => configLayerPages[profile]?.groups.flatMap((group) => group.fields)
6745
7095
  .some((field) => field.key === focusedConfigField.key && configFieldCanUnset(field)))
6746
7096
  : false;
6747
7097
  help = `↑↓ 选择 · Enter ${focusedConfigField ? '修改' : '选择'}${!route.view && visibleConfigTabs.length > 1
6748
7098
  ? ' · ←→ 分组' : ''}${(configCardNavigation?.pageCount ?? 1) > 1 ? ' · PgUp/PgDn 卡片全文' : ''}`
6749
- + `${configDraftCount > 0 ? ' · s 保存' : ''}${canUnsetFocused ? ' · u 恢复默认值' : ''} · Esc 返回`;
7099
+ + `${configDraftCount > 0 ? ' · s 保存' : ''}${canUnsetFocused
7100
+ ? focusedConfigField && !configFieldCanSet(focusedConfigField) ? ' · u 删除旧键' : ' · u 恢复默认值'
7101
+ : ''} · Esc 返回`;
6750
7102
  }
6751
7103
  const totalFields = currentConfigPage.groups.reduce((count, group) => count + group.fields.length, 0);
6752
7104
  const countLabel = `${totalFields} 项${currentConfigPage.presets.length > 0 ? ` · ${currentConfigPage.presets.length} 个方案` : ''}`;
6753
7105
  description = configActionError ?? (configSaveState?.status === 'error' ? configSaveState.error
6754
7106
  : configSaveState?.status === 'saving' ? '正在保存设置…'
6755
7107
  : `${configLayerLabel(route.layer)} · 用户设置${route.layer.context === 'project' ? ' · 当前项目' : ''}`);
6756
- help += ' · Tab 切换 Agent';
7108
+ if (activeConfigLayers.length > 1 && !guidedSetup && !route.view)
7109
+ help += ' · Tab 切换 Agent';
7110
+ if (guidedSetup) {
7111
+ description = guidedBusy ? '正在获取推荐;尚未保存。'
7112
+ : configDraftInputsPending ? '正在读取设置;尚未保存。'
7113
+ : configDraftReferencePending ? referenceContextError ?? '正在读取引用来源;尚未保存。'
7114
+ : configActionError ?? guidedNotice ?? '推荐只填入草稿;确认前不会写入。';
7115
+ help += ' · u 删除可选草稿 · g 预填可选档位';
7116
+ }
6757
7117
  context = configDraftCount > 0 ? `${configDraftCount} 项待保存` : countLabel;
6758
7118
  content = route.view === 'options' ? _jsx(SemanticRows, { actions: actions, focus: focus, kind: "action", compact: policy.mode === 'compact' })
6759
7119
  : route.view === 'values' ? (() => {
6760
7120
  title = '完整设置值与来源';
6761
7121
  description = '显示各保存位置的完整安全值;敏感值不回显。';
6762
- readingText = CONFIG_PROFILE_KEYS.flatMap((profile) => (configLayerPages[profile]?.groups.flatMap((group) => group.fields) ?? []).map((field) => `${field.title} · ${configLayerLabel({ profile })}:${fieldValueText(field, field.draftValue ?? field.value, true, field.configured)}`)).join('\n');
7122
+ readingText = activeConfigLayers.flatMap((profile) => (configLayerPages[profile]?.groups.flatMap((group) => group.fields) ?? []).map((field) => `${field.title} · ${configLayerLabel({ profile })}:${fieldValueText(field, field.draftValue ?? field.value, true, field.configured)}`)).join('\n');
6763
7123
  actions = [{ label: '返回设置', run: back }];
6764
7124
  help = '←→ 或 PgUp/PgDn 阅读 · Esc 返回';
6765
7125
  return _jsxs(Box, { flexDirection: "column", children: [readingPage(readingText, size.columns - 2, Math.max(1, pageActionBudget(4) - 1)), _jsx(SemanticRows, { actions: actions, focus: focus, kind: "action", compact: true })] });
6766
- })() : _jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: tuiTheme.roles.focus, bold: true, children: [route.layer.profile === 'common' ? '◎ 全部 Agent' : `${configLayerLabel(route.layer)} 专用`, " [Tab]"] }), !readonly && configDraftIssues.length > 0 ? _jsx(Callout, { status: "warning", title: "\u6709\u672A\u4FDD\u5B58\u4FEE\u6539\u65E0\u6CD5\u7EE7\u7EED\u4F7F\u7528", description: "\u63D2\u4EF6\u6765\u6E90\u6062\u590D\u540E\uFF0C\u8BBE\u7F6E\u5185\u5BB9\u6216\u53EF\u7528\u4F4D\u7F6E\u5DF2\u53D8\u5316\u3002\u8BF7\u653E\u5F03\u8FD9\u4E9B\u4FEE\u6539\uFF0C\u6216\u8FD4\u56DE\u68C0\u67E5\u63D2\u4EF6\u6765\u6E90\uFF1B\u7CFB\u7EDF\u4E0D\u4F1A\u81EA\u52A8\u4FDD\u5B58\u3002" }) : null, activeTab && visibleConfigTabs.length > 1 ? _jsx(QueryHeader, { width: size.columns - 2, tabs: { label: '分组', items: visibleConfigTabs.map((tab) => ({
7126
+ })() : _jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: tuiTheme.roles.focus, bold: true, children: [route.layer.profile === 'common' ? '◎ 全部 Agent' : `${configLayerLabel(route.layer)} 专用`, activeConfigLayers.length > 1 && !guidedSetup ? ' [Tab]' : ''] }), !readonly && configDraftIssues.length > 0 ? _jsx(Callout, { status: "warning", title: "\u6709\u672A\u4FDD\u5B58\u4FEE\u6539\u65E0\u6CD5\u7EE7\u7EED\u4F7F\u7528", description: "\u63D2\u4EF6\u6765\u6E90\u6062\u590D\u540E\uFF0C\u8BBE\u7F6E\u5185\u5BB9\u6216\u53EF\u7528\u4F4D\u7F6E\u5DF2\u53D8\u5316\u3002\u8BF7\u653E\u5F03\u8FD9\u4E9B\u4FEE\u6539\uFF0C\u6216\u8FD4\u56DE\u68C0\u67E5\u63D2\u4EF6\u6765\u6E90\uFF1B\u7CFB\u7EDF\u4E0D\u4F1A\u81EA\u52A8\u4FDD\u5B58\u3002" }) : null, activeTab && visibleConfigTabs.length > 1 ? _jsx(QueryHeader, { width: size.columns - 2, tabs: { label: '分组', items: visibleConfigTabs.map((tab) => ({
6767
7127
  id: tab.id, label: tab.label, count: tab.count,
6768
7128
  })), currentId: activeTab.id } }) : null, _jsx(SequenceRows, { actions: actions, itemCount: tabActions.length, focus: effectiveConfigFocus, scrollOffset: scrollOffset, columns: size.columns - 2, rowBudget: configRowBudget, configPage: configCardNavigation?.page, compact: policy.mode === 'compact' })] });
6769
7129
  }
6770
7130
  }
6771
7131
  else if (route.name === 'configSave' && plugin) {
6772
- const draftGroups = CONFIG_PROFILE_KEYS.flatMap((scope) => {
7132
+ const draftGroups = activeConfigLayers.flatMap((scope) => {
6773
7133
  const draft = configDrafts[scope];
6774
7134
  const page = configLayerPages[scope];
6775
7135
  return draft && page ? [{ profile: scope, draft, changes: configChanges(page, draft) }] : [];
@@ -6826,10 +7186,18 @@ export function ConsoleAppV4(props) {
6826
7186
  content = _jsxs(Box, { flexDirection: "column", children: [summaryLines.map((line, index) => _jsx(Text, { children: line }, index)), changes.length > visibleChanges.length ? _jsxs(Text, { children: ["\u53E6\u6709 ", changes.length - visibleChanges.length, " \u9879\uFF1B\u5B8C\u6574\u53D8\u5316\u4E2D\u53EF\u8BFB"] }) : null, _jsx(Text, { children: "\u6BCF\u5C42\u72EC\u7ACB\u63D0\u4EA4\uFF1B\u5931\u8D25\u5C42\u4FDD\u7559\u8349\u7A3F" }), _jsx(SemanticRows, { actions: actions, focus: focus, kind: "action", compact: policy.mode === 'compact', offset: configSaveActionViewport.offset, limit: configSaveActionViewport.limit })] });
6827
7187
  }
6828
7188
  }
7189
+ else if ((route.name === 'configFieldEditor' || route.name === 'configObjectPropertyEditor' || route.name === 'configFieldAction')
7190
+ && plugin && (!currentConfigPage || !currentLayerInfo)) {
7191
+ breadcrumb = `${plugin.displayName} / 设置`;
7192
+ title = '正在读取设置字段';
7193
+ help = 'Esc 返回';
7194
+ content = _jsx(ProgressRow, { title: "\u8BFB\u53D6\u8BBE\u7F6E\u5B9A\u4E49", state: "active" });
7195
+ }
6829
7196
  else if (route.name === 'configFieldEditor' && plugin && activeField) {
6830
7197
  breadcrumb = `${plugin.displayName} / 设置 / ${activeField.title}`;
6831
7198
  const scalarReference = 'valueRef' in activeField.definition && activeField.definition.valueRef ? activeField.definition : undefined;
6832
- const showChoices = Boolean(scalarReference) || (activeField.choices?.length ?? 0) > 0 && route.mode !== 'custom';
7199
+ const showChoices = Boolean(scalarReference) || (activeField.choices?.length ?? 0) > 0 && route.mode !== 'custom'
7200
+ && !(activeField.definition.type === 'object' && activeField.definition.suggestions);
6833
7201
  const targetFields = [route.layer.profile].flatMap((profile) => configLayerPages[profile]?.groups.flatMap((group) => group.fields).filter((field) => field.key === activeField.key) ?? []);
6834
7202
  const canSet = targetFields.some(configFieldCanSet);
6835
7203
  const canUnset = !arrayItem && !nestedArray && targetFields.some(configFieldCanUnset);
@@ -6951,6 +7319,57 @@ export function ConsoleAppV4(props) {
6951
7319
  actions = [{ label: '开启', selected: !activeField.sensitive && current === true, run: () => updateDraft(activeField.key, true) }, { label: '关闭', selected: !activeField.sensitive && current === false, run: () => updateDraft(activeField.key, false) }];
6952
7320
  content = _jsx(SemanticRows, { actions: [...actions], focus: focus, kind: "choice", compact: policy.mode === 'compact' });
6953
7321
  }
7322
+ else if (objectSuggestionMenu && objectSuggestionDefinition && objectSuggestions) {
7323
+ const response = compositeSuggestions.response;
7324
+ const dynamicItems = response?.status === 'ok'
7325
+ ? response.items.filter((item) => !('value' in item)) : [];
7326
+ const items = dynamicItems.length ? dynamicItems
7327
+ : response && response.status !== 'not-applicable'
7328
+ ? objectSuggestionFallback(objectSuggestionDefinition, objectSuggestions) : [];
7329
+ const parent = route.suggestionParent === undefined ? undefined
7330
+ : items.find((item) => objectSuggestionGroupKey(item) === route.suggestionParent);
7331
+ title = parent?.children?.title ?? parent?.title ?? objectSuggestions.declaration.title ?? '选择推荐组合';
7332
+ description = response?.message ? safeConfigText(response.message)
7333
+ : !response ? '正在获取动态建议…'
7334
+ : response.status === 'not-applicable' ? '当前选择不支持此项,建议留空。'
7335
+ : response.status !== 'ok' ? '暂时无法获取动态建议,可使用自定义值。'
7336
+ : items.length === 0 ? '没有动态建议,可使用自定义值。' : objectSuggestions.declaration.description;
7337
+ help = '↑↓ 移动 · Enter 使用 · r 刷新建议 · Esc 返回';
7338
+ const sourceLabels = { dynamic: '动态', configured: '已配置', merged: '合并', builtin: '内置' };
7339
+ const select = (patch) => {
7340
+ if (![...Object.keys(patch.set ?? {}), ...patch.unset ?? []].every((key) => objectSuggestions.targets.includes(key))) {
7341
+ setObjectError('建议已不适用于当前属性。请刷新建议。');
7342
+ return;
7343
+ }
7344
+ const next = applyObjectSuggestionPatch(objectSuggestions.draft, patch);
7345
+ const issues = validatePluginConfigValue(objectSuggestionDefinition, next, activeField.key)
7346
+ .filter((issue) => issue.path.property !== undefined && objectSuggestions.targets.includes(issue.path.property));
7347
+ if (issues.length) {
7348
+ setObjectError(issues.slice(0, 2).map(objectIssueText).join(';'));
7349
+ return;
7350
+ }
7351
+ updateObjectDraft(next);
7352
+ if (route.suggestionParent !== undefined)
7353
+ props.controller.back();
7354
+ back();
7355
+ };
7356
+ const itemAction = (item, run) => ({
7357
+ label: `${safeConfigText(item.title)}${item.recommended ? '(推荐)' : ''}${item.children ? ' ▸' : ''}`,
7358
+ description: item.description ? safeConfigText(item.description) : undefined,
7359
+ meta: item.source ? sourceLabels[item.source] : undefined,
7360
+ run,
7361
+ });
7362
+ if (route.suggestionParent === undefined) {
7363
+ actions = [{ label: '自定义(逐项编辑)', run: back }, ...items.map((item) => itemAction(item, () => item.children
7364
+ ? go({ ...route, suggestionParent: objectSuggestionGroupKey(item) }) : select(item)))];
7365
+ }
7366
+ else {
7367
+ actions = parent?.children?.items.map((item) => itemAction({ ...item, source: item.source ?? parent.source }, () => select(mergeObjectSuggestionPatches(parent, item)))) ?? [{ label: '返回建议', run: back }];
7368
+ }
7369
+ if (objectError)
7370
+ description = objectError;
7371
+ content = suggestionRows(actions);
7372
+ }
6954
7373
  else if (route.editor === 'object' && activeField.definition.type === 'object' && activeObjectDraft) {
6955
7374
  const objectDefinition = activeField.definition;
6956
7375
  title = `编辑${activeField.title}`;
@@ -7009,6 +7428,23 @@ export function ConsoleAppV4(props) {
7009
7428
  },
7010
7429
  })),
7011
7430
  ];
7431
+ if (objectSuggestions) {
7432
+ const dependencyKeys = new Set(objectSuggestions.declaration.dependsOn ?? []);
7433
+ const dependencyRows = propertyActions.filter((_action, index) => dependencyKeys.has(fixedEntries[index]?.[0] ?? ''));
7434
+ const remainingRows = propertyActions.filter((_action, index) => !dependencyKeys.has(fixedEntries[index]?.[0] ?? ''));
7435
+ const summary = objectSuggestions.targets.flatMap((key) => Object.hasOwn(activeObjectDraft, key) ? [propertySummary(key, objectSuggestions.properties[key])] : []);
7436
+ const configuredDependency = [...dependencyKeys].some((key) => Object.hasOwn(activeObjectDraft, key));
7437
+ propertyActions.splice(0, propertyActions.length, ...dependencyRows, {
7438
+ label: objectSuggestions.declaration.title ?? '选择推荐组合',
7439
+ description: objectSuggestions.declaration.description,
7440
+ meta: summary.length ? summary.join(' / ') : configuredDependency
7441
+ ? (activeObjectDraft.executor === 'native' ? '宿主默认' : '后端默认') : '未设置',
7442
+ run: () => {
7443
+ setObjectError(undefined);
7444
+ go({ ...route, mode: 'suggestions' });
7445
+ },
7446
+ }, ...remainingRows);
7447
+ }
7012
7448
  const objectOperationActions = [
7013
7449
  ...(objectDefinition.additionalProperties !== false ? [{
7014
7450
  label: '+ 添加键值',
@@ -7053,7 +7489,7 @@ export function ConsoleAppV4(props) {
7053
7489
  : activeField.sensitive ? '当前值不会回显;留空不会自动删除旧值。' : suggestions.notice ?? activeField.description ?? '';
7054
7490
  content = _jsx(InputCard, { focused: true, title: _jsx(InputDisplay, { value: inputValue, sensitive: activeField.sensitive, placeholder: activeField.placeholder, columns: Math.max(8, size.columns - 8) }), description: inputError ?? (activeField.sensitive ? '输入已隐藏。' : activeField.placeholder ?? '按 Enter 使用输入值。'), status: inputError ? 'error' : undefined });
7055
7491
  }
7056
- if (canUnset) {
7492
+ if (canUnset && !objectSuggestionMenu) {
7057
7493
  const unset = { label: '恢复继承', description: '选择要删除覆盖值的位置', run: () => removeDraft(activeField.key) };
7058
7494
  const inputEditor = canSet && !suggestionMenu && !showChoices && (route.editor === 'number' || route.editor === 'string');
7059
7495
  help += ' · Ctrl-R 恢复继承';
@@ -7071,13 +7507,18 @@ export function ConsoleAppV4(props) {
7071
7507
  const propertyTitle = definition && property ? definition.title ?? property : '动态键';
7072
7508
  breadcrumb = `${plugin.displayName} / 设置 / ${activeField.title} / ${propertyTitle}`;
7073
7509
  if (activeVariantPreview) {
7074
- title = '确认分支切换';
7510
+ title = activeVariantPreview.variantSwitch ? '确认分支切换' : '确认关联设置清理';
7075
7511
  description = '确认后仅更新当前对象草稿;完整设置仍需 Review 后保存。';
7076
7512
  const candidateIssues = validatePluginConfigValue(activeField.definition, activeVariantPreview.value, activeField.key);
7077
7513
  readingText = [
7078
7514
  activeVariantPreview.removed.length ? '将移除这些旧值:' : '没有需要移除的旧值。',
7079
- ...activeVariantPreview.removed.map((entry) => `${entry.property} = ${safeConfigText(JSON.stringify(entry.value))}`),
7080
- '切换后的实际配置:', safeConfigText(JSON.stringify(activeVariantPreview.value, null, 2)),
7515
+ ...activeVariantPreview.removed.map((entry) => {
7516
+ const property = activeObjectProperties?.[entry.property];
7517
+ return `${entry.property} = ${activeField.sensitive || !property || property.sensitive || configObjectHasSensitiveChild(property)
7518
+ ? '[redacted]' : safeConfigText(JSON.stringify(entry.value))}`;
7519
+ }),
7520
+ '变更后的实际配置:', safeConfigText(JSON.stringify(activeField.sensitive || configObjectHasSensitiveChild(activeField.definition)
7521
+ ? '[redacted]' : activeVariantPreview.value, null, 2)),
7081
7522
  ...(candidateIssues.length ? ['需要补充或修正:', ...candidateIssues.map(objectIssueText)] : []),
7082
7523
  ].join('\n');
7083
7524
  actions = [{ label: '使用此候选草稿', run: () => {
@@ -7086,7 +7527,7 @@ export function ConsoleAppV4(props) {
7086
7527
  setObjectError(candidateIssues.slice(0, 2).map(objectIssueText).join(';'));
7087
7528
  setObjectVariantPreview(undefined);
7088
7529
  back();
7089
- } }, { label: '取消切换', run: () => { setObjectVariantPreview(undefined); back(); } }];
7530
+ } }, { label: activeVariantPreview.variantSwitch ? '取消切换' : '取消修改', run: () => { setObjectVariantPreview(undefined); back(); } }];
7090
7531
  content = _jsxs(Box, { flexDirection: "column", children: [readingPage(readingText, size.columns - 2, Math.max(1, pageActionBudget(4))), _jsx(SemanticRows, { actions: actions, focus: focus, kind: "action", compact: true })] });
7091
7532
  }
7092
7533
  else if (property !== undefined && definition && 'valueRef' in definition && definition.valueRef
@@ -7134,15 +7575,8 @@ export function ConsoleAppV4(props) {
7134
7575
  label: route.dynamic ? '删除动态键' : '删除属性',
7135
7576
  status: 'error',
7136
7577
  run: () => {
7137
- if (activeField.definition.type === 'object' && activeField.definition.variants?.discriminator === property) {
7138
- if (updateObjectProperty(property, undefined))
7139
- back();
7140
- return;
7141
- }
7142
- const next = { ...activeObjectDraft };
7143
- delete next[property];
7144
- updateObjectDraft(next);
7145
- back();
7578
+ if (updateObjectProperty(property, undefined))
7579
+ back();
7146
7580
  },
7147
7581
  },
7148
7582
  ];
@@ -8060,7 +8494,7 @@ export function ConsoleAppV4(props) {
8060
8494
  else if (entry.id === 'viewSourceChange' && issue.sourceId)
8061
8495
  go({ name: 'sourceTechnical', sourceId: issue.sourceId });
8062
8496
  else if (entry.id === 'openConfig' && issue.pluginId) {
8063
- go({ name: 'configFields', pluginId: issue.pluginId, layer: { profile: 'common' } });
8497
+ openIssueConfig(issue, issue.pluginId);
8064
8498
  }
8065
8499
  else if (entry.id === 'viewDependencies' && issue.pluginId) {
8066
8500
  go({ name: 'pluginDependencies', pluginId: issue.pluginId });
@@ -10372,7 +10806,7 @@ export function ConsoleAppV4(props) {
10372
10806
  }
10373
10807
  return;
10374
10808
  }
10375
- if (flow.stage === 'review' || flow.stage === 'risk' || flow.stage === 'result') {
10809
+ if (flow.stage === 'setup' || flow.stage === 'review' || flow.stage === 'risk' || flow.stage === 'result') {
10376
10810
  if (input.toLowerCase() === 'y' && readingText !== undefined) {
10377
10811
  void copyToClipboard(readingText).then(() => setCopyFeedback({ routeKey, message: '全文已复制' })).catch(() => setCopyFeedback({ routeKey, message: '复制失败,请重试' }));
10378
10812
  return;
@@ -10680,7 +11114,8 @@ export function ConsoleAppV4(props) {
10680
11114
  setChangedObjectDraftKeys([]);
10681
11115
  const discardedSourceDraft = sourceDraft;
10682
11116
  setSourceDraft(undefined);
10683
- setBatchDraft(undefined);
11117
+ if (!guidedSetup)
11118
+ setBatchDraft(undefined);
10684
11119
  if (discardForExit) {
10685
11120
  requestExit({ code: 0, reason: 'user' });
10686
11121
  }
@@ -11056,11 +11491,16 @@ export function ConsoleAppV4(props) {
11056
11491
  setSourceInputError(undefined);
11057
11492
  return;
11058
11493
  }
11059
- if (suggestionMenu && input.toLowerCase() === 'r' && !key.ctrl && !key.meta) {
11060
- suggestions.refresh();
11494
+ if ((suggestionMenu || objectSuggestionMenu) && input.toLowerCase() === 'r' && !key.ctrl && !key.meta) {
11495
+ if (objectSuggestionMenu) {
11496
+ setObjectError(undefined);
11497
+ compositeSuggestions.refresh();
11498
+ }
11499
+ else
11500
+ suggestions.refresh();
11061
11501
  return;
11062
11502
  }
11063
- if (route.name === 'configFieldEditor' && route.mode !== 'choices' && input === 'c'
11503
+ if (route.name === 'configFieldEditor' && route.mode !== 'choices' && route.mode !== 'suggestions' && input === 'c'
11064
11504
  && (route.editor === 'array' || route.editor === 'object')) {
11065
11505
  if (route.editor === 'array')
11066
11506
  commitArray();
@@ -11068,7 +11508,7 @@ export function ConsoleAppV4(props) {
11068
11508
  commitObjectDraft();
11069
11509
  return;
11070
11510
  }
11071
- if (route.name === 'configFieldEditor' && !arrayItem && !nestedArray && activeField && key.ctrl && input.toLowerCase() === 'r') {
11511
+ if (route.name === 'configFieldEditor' && !objectSuggestionMenu && !arrayItem && !nestedArray && activeField && key.ctrl && input.toLowerCase() === 'r') {
11072
11512
  const canUnset = [route.layer.profile].some((profile) => configLayerPages[profile]?.groups.flatMap((group) => group.fields)
11073
11513
  .some((field) => field.key === activeField.key && configFieldCanUnset(field)));
11074
11514
  if (canUnset)
@@ -11297,9 +11737,9 @@ export function ConsoleAppV4(props) {
11297
11737
  // Paste and composed text are data, never multiple background commands.
11298
11738
  if (input.length > 1 && !key.ctrl && !key.meta)
11299
11739
  return;
11300
- if (key.tab && route.name === 'configFields') {
11301
- const index = CONFIG_PROFILE_KEYS.indexOf(route.layer.profile);
11302
- const profile = CONFIG_PROFILE_KEYS[(index + (key.shift ? -1 : 1) + CONFIG_PROFILE_KEYS.length) % CONFIG_PROFILE_KEYS.length];
11740
+ if (key.tab && !guidedSetup && route.name === 'configFields' && !route.view && activeConfigLayers.length > 1) {
11741
+ const index = activeConfigLayers.indexOf(route.layer.profile);
11742
+ const profile = activeConfigLayers[(index + (key.shift ? -1 : 1) + activeConfigLayers.length) % activeConfigLayers.length];
11303
11743
  props.controller.replace({ ...route, layer: { ...route.layer, profile } });
11304
11744
  setFocus(0);
11305
11745
  setScrollOffset(0);
@@ -11432,6 +11872,10 @@ export function ConsoleAppV4(props) {
11432
11872
  }
11433
11873
  else if (globalAction === 'back'
11434
11874
  && (route.name === 'configFieldEditor' || route.name === 'configFieldAction')) {
11875
+ if (route.name === 'configFieldEditor' && route.mode === 'suggestions') {
11876
+ back();
11877
+ return;
11878
+ }
11435
11879
  if (nestedArray && !arrayItem) {
11436
11880
  closeNestedArray();
11437
11881
  return;
@@ -11575,11 +12019,34 @@ export function ConsoleAppV4(props) {
11575
12019
  setFocus(0);
11576
12020
  setScrollOffset(0);
11577
12021
  }
12022
+ else if (route.name === 'configFields' && guidedSetup && input.toLowerCase() === 'g') {
12023
+ runAction(bottomActions.find((action) => action.actionId === 'guided-fill-optional'));
12024
+ }
11578
12025
  else if (route.name === 'configFields' && input.toLowerCase() === 's') {
11579
12026
  runAction(bottomActions[0]);
11580
12027
  }
11581
12028
  else if (route.name === 'configFields' && input.toLowerCase() === 'u') {
11582
- runAction(actions.find((action) => action.actionId === 'config-reset-profile'));
12029
+ const focusedField = currentConfigPage?.groups.flatMap((group) => group.fields)
12030
+ .find((field) => field.key === actions[focus]?.configKey);
12031
+ if (guidedSetup && focusedField && !focusedField.required && configDrafts[route.layer.profile]?.updates[focusedField.key] !== undefined) {
12032
+ guidedTouched.current.add(focusedField.key);
12033
+ setGuidedBadges((badges) => Object.fromEntries(Object.entries(badges).filter(([key]) => key !== focusedField.key)));
12034
+ const previous = configDrafts[route.layer.profile];
12035
+ const updates = { ...previous.updates };
12036
+ delete updates[focusedField.key];
12037
+ const editEvidence = { ...previous.editEvidence };
12038
+ delete editEvidence[focusedField.key];
12039
+ const next = { ...configDrafts, [route.layer.profile]: { ...previous, updates, editEvidence } };
12040
+ if (!Object.keys(updates).length && !previous.removes.length)
12041
+ delete next[route.layer.profile];
12042
+ setConfigDrafts(next);
12043
+ setDirty(Object.keys(next).length + changedObjectDraftKeys.length > 0);
12044
+ }
12045
+ else if (focusedField && !configFieldCanSet(focusedField) && configFieldCanUnset(focusedField)) {
12046
+ removeDraft(focusedField.key);
12047
+ }
12048
+ else
12049
+ runAction(actions.find((action) => action.actionId === 'config-reset-profile'));
11583
12050
  }
11584
12051
  else if (route.name === 'configFields' && !route.view && visibleConfigTabs.length > 1
11585
12052
  && (key.leftArrow || key.rightArrow)) {