@amaster.ai/cli 1.1.69 → 1.1.70
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.
- package/README.md +7 -1
- package/dist/cli.cjs +234 -175
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +234 -175
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1831,22 +1831,45 @@ async function readYamlDocument(targetPath) {
|
|
|
1831
1831
|
const text = existsSync(targetPath) ? await readFile(targetPath, "utf8") : "";
|
|
1832
1832
|
return YAML2.parseDocument(text);
|
|
1833
1833
|
}
|
|
1834
|
-
function
|
|
1835
|
-
|
|
1834
|
+
function resolveStoredSettingSegments(setting, document, fallback) {
|
|
1835
|
+
if (setting.segments) {
|
|
1836
|
+
return setting.segments;
|
|
1837
|
+
}
|
|
1838
|
+
const find = (value, prefix) => {
|
|
1839
|
+
if (!isPlainObject(value)) {
|
|
1840
|
+
return void 0;
|
|
1841
|
+
}
|
|
1842
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1843
|
+
const segments = prefix.concat(key);
|
|
1844
|
+
const path = segments.join(".");
|
|
1845
|
+
if (path === setting.path) {
|
|
1846
|
+
return segments;
|
|
1847
|
+
}
|
|
1848
|
+
if (setting.path.startsWith(`${path}.`)) {
|
|
1849
|
+
const found = find(child, segments);
|
|
1850
|
+
if (found) {
|
|
1851
|
+
return found;
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
return void 0;
|
|
1856
|
+
};
|
|
1857
|
+
return find(document.toJSON(), []) ?? fallback ?? setting.path.split(".");
|
|
1858
|
+
}
|
|
1859
|
+
function findIncompatibleSettingsOwner(metas, addonName, setting, document) {
|
|
1836
1860
|
for (const meta of metas) {
|
|
1837
|
-
if (
|
|
1861
|
+
if (meta.name === addonName) {
|
|
1838
1862
|
continue;
|
|
1839
1863
|
}
|
|
1840
1864
|
for (const member of meta.members) {
|
|
1841
|
-
for (const
|
|
1842
|
-
if (
|
|
1843
|
-
|
|
1865
|
+
for (const previous of member.settings?.paths ?? []) {
|
|
1866
|
+
if (previous.targetPath === setting.targetPath && !previous.mergeStrategy && settingsValuesEqual(resolveStoredSettingSegments(previous, document, previous.path === setting.path ? setting.segments : void 0), setting.segments) && previous.sha256 !== sha256Value(setting.value)) {
|
|
1867
|
+
return meta.name;
|
|
1844
1868
|
}
|
|
1845
|
-
ownership.set(`${item.targetPath}#${item.path}`, meta.name);
|
|
1846
1869
|
}
|
|
1847
1870
|
}
|
|
1848
1871
|
}
|
|
1849
|
-
return
|
|
1872
|
+
return void 0;
|
|
1850
1873
|
}
|
|
1851
1874
|
function listPlannedSettingPaths(settings) {
|
|
1852
1875
|
return settings.flatMap(
|
|
@@ -1881,6 +1904,69 @@ function cloneSettingsValue(value) {
|
|
|
1881
1904
|
function settingsValuesEqual(left, right) {
|
|
1882
1905
|
return stableJsonStringify(left) === stableJsonStringify(right);
|
|
1883
1906
|
}
|
|
1907
|
+
function storedSettingReference(setting, current) {
|
|
1908
|
+
if ("appliedValue" in setting) {
|
|
1909
|
+
return cloneSettingsValue(setting.appliedValue);
|
|
1910
|
+
}
|
|
1911
|
+
if (setting.mergeStrategy && setting.managedValue !== void 0) {
|
|
1912
|
+
return mergePlannedSettingValue(setting.previousValue, {
|
|
1913
|
+
path: setting.path,
|
|
1914
|
+
segments: setting.segments ?? setting.path.split("."),
|
|
1915
|
+
value: setting.managedValue,
|
|
1916
|
+
mergeStrategy: setting.mergeStrategy,
|
|
1917
|
+
mergeKey: setting.mergeKey
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
return sha256Value(current) === setting.sha256 ? cloneSettingsValue(current) : void 0;
|
|
1921
|
+
}
|
|
1922
|
+
function mergeSettingsUpgrade(current, previous, next, mergeStrategy, mergeKey = "code") {
|
|
1923
|
+
if (settingsValuesEqual(current, previous)) {
|
|
1924
|
+
return cloneSettingsValue(next);
|
|
1925
|
+
}
|
|
1926
|
+
if (settingsValuesEqual(current, next) || settingsValuesEqual(previous, next)) {
|
|
1927
|
+
return cloneSettingsValue(current);
|
|
1928
|
+
}
|
|
1929
|
+
if (isPlainObject(current) && isPlainObject(next) && (previous === void 0 || isPlainObject(previous))) {
|
|
1930
|
+
const old = previous ?? {};
|
|
1931
|
+
const merged = {};
|
|
1932
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(current), ...Object.keys(old), ...Object.keys(next)])) {
|
|
1933
|
+
const value = mergeSettingsUpgrade(current[key], old[key], next[key]);
|
|
1934
|
+
if (value !== void 0) {
|
|
1935
|
+
merged[key] = value;
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
return merged;
|
|
1939
|
+
}
|
|
1940
|
+
if (Array.isArray(current) && Array.isArray(next) && (previous === void 0 || Array.isArray(previous))) {
|
|
1941
|
+
const old = previous ?? [];
|
|
1942
|
+
if (mergeStrategy === "append-unique") {
|
|
1943
|
+
const merged = current.filter(
|
|
1944
|
+
(item) => !old.some((value) => settingsValuesEqual(item, value)) || next.some((value) => settingsValuesEqual(item, value))
|
|
1945
|
+
);
|
|
1946
|
+
for (const item of next) {
|
|
1947
|
+
if (!old.some((value) => settingsValuesEqual(item, value)) && !merged.some((value) => settingsValuesEqual(item, value))) {
|
|
1948
|
+
merged.push(cloneSettingsValue(item));
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
return merged;
|
|
1952
|
+
}
|
|
1953
|
+
if (mergeStrategy === "merge-by-key") {
|
|
1954
|
+
const byKey = (items) => new Map(items.filter(isPlainObject).map((item) => [item[mergeKey], item]));
|
|
1955
|
+
const currentItems = byKey(current);
|
|
1956
|
+
const oldItems = byKey(old);
|
|
1957
|
+
const nextItems = byKey(next);
|
|
1958
|
+
const merged = [];
|
|
1959
|
+
for (const key of /* @__PURE__ */ new Set([...currentItems.keys(), ...nextItems.keys()])) {
|
|
1960
|
+
const value = mergeSettingsUpgrade(currentItems.get(key), oldItems.get(key), nextItems.get(key));
|
|
1961
|
+
if (value !== void 0) {
|
|
1962
|
+
merged.push(value);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
return merged;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
return cloneSettingsValue(current);
|
|
1969
|
+
}
|
|
1884
1970
|
function isComposableSettingsPath(path) {
|
|
1885
1971
|
return path === "rbac.permissions" || path === "rbac.roles" || path.startsWith("envMetadata.");
|
|
1886
1972
|
}
|
|
@@ -1962,98 +2048,9 @@ function mergePlannedSettingValue(current, settingPath) {
|
|
|
1962
2048
|
return cloneSettingsValue(settingPath.value);
|
|
1963
2049
|
}
|
|
1964
2050
|
}
|
|
1965
|
-
function settingsValueContains(current, expected) {
|
|
1966
|
-
if (Array.isArray(expected)) {
|
|
1967
|
-
return Array.isArray(current) && expected.every(
|
|
1968
|
-
(item) => current.some((candidate) => settingsValueContains(candidate, item))
|
|
1969
|
-
);
|
|
1970
|
-
}
|
|
1971
|
-
if (isPlainObject(expected)) {
|
|
1972
|
-
return isPlainObject(current) && Object.entries(expected).every(
|
|
1973
|
-
([key, value]) => key in current && settingsValueContains(current[key], value)
|
|
1974
|
-
);
|
|
1975
|
-
}
|
|
1976
|
-
return settingsValuesEqual(current, expected);
|
|
1977
|
-
}
|
|
1978
|
-
function keyedArrayContributionPresent(current, contribution, previousValue, mergeKey) {
|
|
1979
|
-
if (!Array.isArray(current) || !Array.isArray(contribution)) {
|
|
1980
|
-
return false;
|
|
1981
|
-
}
|
|
1982
|
-
const previous = Array.isArray(previousValue) ? previousValue : [];
|
|
1983
|
-
for (const contributedItem of contribution) {
|
|
1984
|
-
if (!isPlainObject(contributedItem) || contributedItem[mergeKey] === void 0) {
|
|
1985
|
-
return false;
|
|
1986
|
-
}
|
|
1987
|
-
const currentItem = current.find(
|
|
1988
|
-
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
1989
|
-
);
|
|
1990
|
-
if (!isPlainObject(currentItem)) {
|
|
1991
|
-
return false;
|
|
1992
|
-
}
|
|
1993
|
-
const previousItem = previous.find(
|
|
1994
|
-
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
1995
|
-
);
|
|
1996
|
-
if (!isPlainObject(previousItem)) {
|
|
1997
|
-
if (!settingsValueContains(currentItem, contributedItem)) {
|
|
1998
|
-
return false;
|
|
1999
|
-
}
|
|
2000
|
-
continue;
|
|
2001
|
-
}
|
|
2002
|
-
for (const [field, value] of Object.entries(contributedItem)) {
|
|
2003
|
-
if (field === mergeKey) {
|
|
2004
|
-
continue;
|
|
2005
|
-
}
|
|
2006
|
-
if (isPlainObject(value)) {
|
|
2007
|
-
if (!settingsValueContains(currentItem[field], value)) {
|
|
2008
|
-
return false;
|
|
2009
|
-
}
|
|
2010
|
-
} else if (!(field in previousItem) && !settingsValuesEqual(currentItem[field], value)) {
|
|
2011
|
-
return false;
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
return true;
|
|
2016
|
-
}
|
|
2017
|
-
function managedSettingContributionPresent(current, settingPath) {
|
|
2018
|
-
switch (settingPath.mergeStrategy) {
|
|
2019
|
-
case "append-unique":
|
|
2020
|
-
return settingsValueContains(current, settingPath.managedValue);
|
|
2021
|
-
case "merge-by-key":
|
|
2022
|
-
return keyedArrayContributionPresent(
|
|
2023
|
-
current,
|
|
2024
|
-
settingPath.managedValue,
|
|
2025
|
-
settingPath.previousValue,
|
|
2026
|
-
settingPath.mergeKey ?? "code"
|
|
2027
|
-
);
|
|
2028
|
-
case "shared-requirement":
|
|
2029
|
-
return true;
|
|
2030
|
-
default:
|
|
2031
|
-
return sha256Value(current) === settingPath.sha256;
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
function plannedSettingContributionPresent(current, settingPath, previousValue) {
|
|
2035
|
-
switch (settingPath.mergeStrategy) {
|
|
2036
|
-
case "append-unique":
|
|
2037
|
-
return settingsValueContains(current, settingPath.value);
|
|
2038
|
-
case "merge-by-key":
|
|
2039
|
-
return keyedArrayContributionPresent(
|
|
2040
|
-
current,
|
|
2041
|
-
settingPath.value,
|
|
2042
|
-
previousValue,
|
|
2043
|
-
settingPath.mergeKey ?? "code"
|
|
2044
|
-
);
|
|
2045
|
-
case "shared-requirement":
|
|
2046
|
-
return sharedRequirementValuesCompatible(settingPath.path, current, settingPath.value);
|
|
2047
|
-
default:
|
|
2048
|
-
return settingsValuesEqual(current, settingPath.value);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
2051
|
function sharedRequirementValuesCompatible(path, current, incoming) {
|
|
2052
2052
|
const field = path.split(".").at(-1);
|
|
2053
|
-
if (current === void 0 || field
|
|
2054
|
-
return true;
|
|
2055
|
-
}
|
|
2056
|
-
if (field === "category" || field === "label" || field === "description") {
|
|
2053
|
+
if (current === void 0 || !["type", "storage", "sensitive", "envVar"].includes(field ?? "")) {
|
|
2057
2054
|
return true;
|
|
2058
2055
|
}
|
|
2059
2056
|
return settingsValuesEqual(current, incoming);
|
|
@@ -2104,27 +2101,66 @@ function attachAppliedSettings(members, appliedSettings) {
|
|
|
2104
2101
|
};
|
|
2105
2102
|
});
|
|
2106
2103
|
}
|
|
2107
|
-
async function applyPlannedSettings(targetDir, settings) {
|
|
2104
|
+
async function applyPlannedSettings(targetDir, settings, previousMeta, existingMetas) {
|
|
2108
2105
|
const written = /* @__PURE__ */ new Set();
|
|
2109
2106
|
const appliedSettings = [];
|
|
2107
|
+
const preservedSettings = [];
|
|
2110
2108
|
for (const item of settings) {
|
|
2111
2109
|
const targetPath = ensurePathInsideTarget(targetDir, item.targetPath);
|
|
2112
2110
|
const document = await readYamlDocument(targetPath);
|
|
2113
2111
|
const pathMetas = [];
|
|
2114
2112
|
for (const settingPath of item.paths) {
|
|
2115
|
-
const
|
|
2116
|
-
const
|
|
2117
|
-
const
|
|
2118
|
-
|
|
2113
|
+
const currentExists = document.hasIn(settingPath.segments);
|
|
2114
|
+
const current = currentExists ? getPlainYamlValue(document, settingPath.segments) : void 0;
|
|
2115
|
+
const previous = previousMeta?.members.flatMap((member) => member.settings?.paths ?? []).find(
|
|
2116
|
+
(path) => path.targetPath === item.targetPath && settingsValuesEqual(resolveStoredSettingSegments(path, document, path.path === settingPath.path ? settingPath.segments : void 0), settingPath.segments)
|
|
2117
|
+
);
|
|
2118
|
+
const shared = !settingPath.mergeStrategy ? existingMetas.filter((meta) => meta.name !== previousMeta?.name).flatMap(
|
|
2119
|
+
(meta) => meta.members.flatMap((member) => member.settings?.paths ?? [])
|
|
2120
|
+
).find(
|
|
2121
|
+
(path) => !path.mergeStrategy && path.targetPath === item.targetPath && settingsValuesEqual(resolveStoredSettingSegments(path, document), settingPath.segments)
|
|
2122
|
+
) : void 0;
|
|
2123
|
+
const baseline = previous ?? shared;
|
|
2124
|
+
let reference = current;
|
|
2125
|
+
if (previous?.mergeStrategy && previous.mergeStrategy !== "shared-requirement") {
|
|
2126
|
+
reference = removeManagedSettingContribution(
|
|
2127
|
+
storedSettingReference(previous, current),
|
|
2128
|
+
previous,
|
|
2129
|
+
listOtherManagedSettingValues(existingMetas, previousMeta.name, item.targetPath, previous.path, previous.mergeStrategy, settingPath.segments)
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
const appliedValue = mergePlannedSettingValue(reference, settingPath);
|
|
2133
|
+
let nextValue = appliedValue;
|
|
2134
|
+
if (!settingPath.mergeStrategy && (baseline && sha256Value(current) !== baseline.sha256 || previousMeta && !baseline && currentExists)) {
|
|
2135
|
+
nextValue = current;
|
|
2136
|
+
} else if (previous && settingPath.mergeStrategy && settingPath.mergeStrategy !== "shared-requirement") {
|
|
2137
|
+
nextValue = mergeSettingsUpgrade(
|
|
2138
|
+
current,
|
|
2139
|
+
storedSettingReference(previous, current),
|
|
2140
|
+
appliedValue,
|
|
2141
|
+
settingPath.mergeStrategy,
|
|
2142
|
+
settingPath.mergeKey
|
|
2143
|
+
);
|
|
2144
|
+
}
|
|
2145
|
+
if (nextValue === void 0) {
|
|
2146
|
+
document.deleteIn(settingPath.segments);
|
|
2147
|
+
} else {
|
|
2148
|
+
document.setIn(settingPath.segments, nextValue);
|
|
2149
|
+
}
|
|
2150
|
+
if (!settingsValuesEqual(nextValue, appliedValue) || settingPath.mergeStrategy === "shared-requirement" && currentExists && !settingsValuesEqual(nextValue, settingPath.value)) {
|
|
2151
|
+
preservedSettings.push(`${item.targetPath}#${settingPath.path}`);
|
|
2152
|
+
}
|
|
2119
2153
|
pathMetas.push({
|
|
2120
2154
|
targetPath: item.targetPath,
|
|
2121
2155
|
path: settingPath.path,
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2156
|
+
segments: settingPath.segments,
|
|
2157
|
+
sha256: sha256Value(settingPath.mergeStrategy ? settingPath.value : appliedValue),
|
|
2158
|
+
previousValueExists: baseline?.previousValueExists ?? currentExists,
|
|
2159
|
+
previousValue: baseline ? baseline.previousValue : current,
|
|
2125
2160
|
mergeStrategy: settingPath.mergeStrategy,
|
|
2126
2161
|
mergeKey: settingPath.mergeKey,
|
|
2127
|
-
managedValue:
|
|
2162
|
+
managedValue: cloneSettingsValue(settingPath.value),
|
|
2163
|
+
appliedValue
|
|
2128
2164
|
});
|
|
2129
2165
|
}
|
|
2130
2166
|
await ensureParentDirectory(targetPath);
|
|
@@ -2138,10 +2174,11 @@ async function applyPlannedSettings(targetDir, settings) {
|
|
|
2138
2174
|
}
|
|
2139
2175
|
return {
|
|
2140
2176
|
writtenFiles: [...written],
|
|
2141
|
-
appliedSettings
|
|
2177
|
+
appliedSettings,
|
|
2178
|
+
preservedSettings
|
|
2142
2179
|
};
|
|
2143
2180
|
}
|
|
2144
|
-
function listOtherManagedSettingValues(metas, excludeAddonName, targetPath, path, mergeStrategy) {
|
|
2181
|
+
function listOtherManagedSettingValues(metas, excludeAddonName, targetPath, path, mergeStrategy, segments) {
|
|
2145
2182
|
const values = [];
|
|
2146
2183
|
for (const meta of metas) {
|
|
2147
2184
|
if (meta.name === excludeAddonName) {
|
|
@@ -2149,7 +2186,7 @@ function listOtherManagedSettingValues(metas, excludeAddonName, targetPath, path
|
|
|
2149
2186
|
}
|
|
2150
2187
|
for (const member of meta.members) {
|
|
2151
2188
|
for (const settingPath of member.settings?.paths ?? []) {
|
|
2152
|
-
if (settingPath.targetPath === targetPath && settingPath.path === path && settingPath.mergeStrategy === mergeStrategy && settingPath.managedValue !== void 0) {
|
|
2189
|
+
if (settingPath.targetPath === targetPath && settingPath.path === path && (!segments || !settingPath.segments || settingsValuesEqual(segments, settingPath.segments)) && settingPath.mergeStrategy === mergeStrategy && settingPath.managedValue !== void 0) {
|
|
2153
2190
|
values.push(settingPath.managedValue);
|
|
2154
2191
|
}
|
|
2155
2192
|
}
|
|
@@ -2260,13 +2297,12 @@ function removeManagedSettingContribution(current, settingPath, otherManagedValu
|
|
|
2260
2297
|
}
|
|
2261
2298
|
async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings, existingMetas) {
|
|
2262
2299
|
if (!previousMeta) {
|
|
2263
|
-
return [];
|
|
2300
|
+
return { writtenFiles: [], preservedSettings: [] };
|
|
2264
2301
|
}
|
|
2265
|
-
const
|
|
2266
|
-
listPlannedSettingPaths(nextSettings).map((item) => `${item.targetPath}#${item.path}`)
|
|
2267
|
-
);
|
|
2302
|
+
const plannedPaths = listPlannedSettingPaths(nextSettings);
|
|
2268
2303
|
const documents = /* @__PURE__ */ new Map();
|
|
2269
2304
|
const written = /* @__PURE__ */ new Set();
|
|
2305
|
+
const preservedSettings = [];
|
|
2270
2306
|
const getDocument = async (targetPath) => {
|
|
2271
2307
|
const cached = documents.get(targetPath);
|
|
2272
2308
|
if (cached) {
|
|
@@ -2278,33 +2314,53 @@ async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings, ex
|
|
|
2278
2314
|
};
|
|
2279
2315
|
for (const member of previousMeta.members) {
|
|
2280
2316
|
for (const settingPath of member.settings?.paths ?? []) {
|
|
2281
|
-
|
|
2317
|
+
const document = await getDocument(settingPath.targetPath);
|
|
2318
|
+
const segments = resolveStoredSettingSegments(
|
|
2319
|
+
settingPath,
|
|
2320
|
+
document,
|
|
2321
|
+
plannedPaths.find((item) => item.targetPath === settingPath.targetPath && item.path === settingPath.path)?.segments
|
|
2322
|
+
);
|
|
2323
|
+
if (plannedPaths.some(
|
|
2324
|
+
(item) => item.targetPath === settingPath.targetPath && settingsValuesEqual(item.segments, segments)
|
|
2325
|
+
)) {
|
|
2282
2326
|
continue;
|
|
2283
2327
|
}
|
|
2284
|
-
if (!settingPath.mergeStrategy && isComposableSettingsPath(settingPath.path)) {
|
|
2328
|
+
if (!settingPath.mergeStrategy && settingPath.managedValue === void 0 && isComposableSettingsPath(settingPath.path)) {
|
|
2285
2329
|
continue;
|
|
2286
2330
|
}
|
|
2287
|
-
const
|
|
2288
|
-
const
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
)
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2331
|
+
const current = document.hasIn(segments) ? getPlainYamlValue(document, segments) : void 0;
|
|
2332
|
+
const otherManagedValues = listOtherManagedSettingValues(
|
|
2333
|
+
existingMetas,
|
|
2334
|
+
previousMeta.name,
|
|
2335
|
+
settingPath.targetPath,
|
|
2336
|
+
settingPath.path,
|
|
2337
|
+
settingPath.mergeStrategy,
|
|
2338
|
+
segments
|
|
2339
|
+
);
|
|
2340
|
+
const sharedByAnotherAddon = existingMetas.some(
|
|
2341
|
+
(meta) => meta.name !== previousMeta.name && meta.members.some((member2) => member2.settings?.paths.some(
|
|
2342
|
+
(other) => other.targetPath === settingPath.targetPath && settingsValuesEqual(resolveStoredSettingSegments(other, document), segments)
|
|
2343
|
+
))
|
|
2344
|
+
);
|
|
2345
|
+
if (!settingPath.mergeStrategy && sharedByAnotherAddon) {
|
|
2346
|
+
continue;
|
|
2347
|
+
}
|
|
2348
|
+
const reference = storedSettingReference(settingPath, current);
|
|
2349
|
+
const restored = settingPath.mergeStrategy ? mergeSettingsUpgrade(
|
|
2350
|
+
current,
|
|
2351
|
+
reference,
|
|
2352
|
+
removeManagedSettingContribution(reference, settingPath, otherManagedValues),
|
|
2353
|
+
settingPath.mergeStrategy,
|
|
2354
|
+
settingPath.mergeKey
|
|
2355
|
+
) : sha256Value(current) === settingPath.sha256 ? removeManagedSettingContribution(current, settingPath, otherManagedValues) : current;
|
|
2356
|
+
const expected = removeManagedSettingContribution(reference, settingPath, otherManagedValues);
|
|
2357
|
+
if (!settingsValuesEqual(restored, expected)) {
|
|
2358
|
+
preservedSettings.push(`${settingPath.targetPath}#${settingPath.path}`);
|
|
2359
|
+
}
|
|
2360
|
+
if (restored === void 0) {
|
|
2307
2361
|
document.deleteIn(segments);
|
|
2362
|
+
} else {
|
|
2363
|
+
document.setIn(segments, restored);
|
|
2308
2364
|
}
|
|
2309
2365
|
written.add(settingPath.targetPath);
|
|
2310
2366
|
}
|
|
@@ -2315,7 +2371,7 @@ async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings, ex
|
|
|
2315
2371
|
await writeFile(ensurePathInsideTarget(targetDir, targetPath), document.toString());
|
|
2316
2372
|
}
|
|
2317
2373
|
}
|
|
2318
|
-
return [...written];
|
|
2374
|
+
return { writtenFiles: [...written], preservedSettings };
|
|
2319
2375
|
}
|
|
2320
2376
|
async function removeObsoleteFiles(targetDir, previousMeta, nextPaths) {
|
|
2321
2377
|
const removed = [];
|
|
@@ -2390,7 +2446,6 @@ async function installPackageDependencies(targetDir) {
|
|
|
2390
2446
|
}
|
|
2391
2447
|
async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
2392
2448
|
const ownership = buildOwnershipMap(existingMetas);
|
|
2393
|
-
const settingsOwnership = buildSettingsOwnershipMap(existingMetas);
|
|
2394
2449
|
const conflicts = [];
|
|
2395
2450
|
const packageJson = await readPackageJson(targetDir);
|
|
2396
2451
|
const settingsDocuments = /* @__PURE__ */ new Map();
|
|
@@ -2476,7 +2531,7 @@ async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
|
2476
2531
|
continue;
|
|
2477
2532
|
}
|
|
2478
2533
|
}
|
|
2479
|
-
const owner =
|
|
2534
|
+
const owner = findIncompatibleSettingsOwner(existingMetas, plan.manifest.name, item, document);
|
|
2480
2535
|
if (!item.mergeStrategy && owner && owner !== plan.manifest.name) {
|
|
2481
2536
|
conflicts.push({
|
|
2482
2537
|
kind: "owned_by_other_addon",
|
|
@@ -2506,12 +2561,9 @@ async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
|
2506
2561
|
}
|
|
2507
2562
|
async function validateUpgradeConflicts(targetDir, plan, existingMetas, previousMeta) {
|
|
2508
2563
|
const ownership = buildOwnershipMap(existingMetas, previousMeta.name);
|
|
2509
|
-
const settingsOwnership = buildSettingsOwnershipMap(existingMetas, previousMeta.name);
|
|
2510
2564
|
const previousFilesByPath = new Map(previousMeta.files.map((file) => [file.path, file]));
|
|
2511
2565
|
const nextPaths = new Set(plan.files.map((file) => file.targetPath));
|
|
2512
2566
|
const plannedSettings = listPlannedSettingPaths(plan.settings);
|
|
2513
|
-
const nextSettingKeys = new Set(plannedSettings.map((item) => `${item.targetPath}#${item.path}`));
|
|
2514
|
-
const plannedSettingsByKey = new Map(plannedSettings.map((item) => [`${item.targetPath}#${item.path}`, item]));
|
|
2515
2567
|
const conflicts = [];
|
|
2516
2568
|
const packageJson = await readPackageJson(targetDir);
|
|
2517
2569
|
const previousNpmByName = buildNpmDependencyMap(previousMeta.npm ?? {});
|
|
@@ -2605,35 +2657,6 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
|
|
|
2605
2657
|
settingsDocuments.set(targetPath, document);
|
|
2606
2658
|
return document;
|
|
2607
2659
|
};
|
|
2608
|
-
for (const member of previousMeta.members) {
|
|
2609
|
-
for (const settingPath of member.settings?.paths ?? []) {
|
|
2610
|
-
const document = await getSettingsDocument(settingPath.targetPath);
|
|
2611
|
-
const segments = settingPath.path.split(".");
|
|
2612
|
-
const currentValue = document.hasIn(segments) ? getPlainYamlValue(document, segments) : void 0;
|
|
2613
|
-
const actualSha256 = sha256Value(currentValue);
|
|
2614
|
-
const settingKey = `${settingPath.targetPath}#${settingPath.path}`;
|
|
2615
|
-
const isStillManaged = nextSettingKeys.has(settingKey);
|
|
2616
|
-
const nextSetting = plannedSettingsByKey.get(settingKey);
|
|
2617
|
-
const contributionPresent = settingPath.mergeStrategy ? managedSettingContributionPresent(currentValue, settingPath) : nextSetting?.mergeStrategy ? plannedSettingContributionPresent(currentValue, nextSetting, settingPath.previousValue) : actualSha256 === settingPath.sha256;
|
|
2618
|
-
if (contributionPresent) {
|
|
2619
|
-
continue;
|
|
2620
|
-
}
|
|
2621
|
-
conflicts.push({
|
|
2622
|
-
kind: isStillManaged ? "managed_file_modified" : "obsolete_file_modified",
|
|
2623
|
-
path: settingKey,
|
|
2624
|
-
sourcePath: member.sourcePath,
|
|
2625
|
-
memberName: member.name,
|
|
2626
|
-
memberType: "settings",
|
|
2627
|
-
expectedSha256: settingPath.sha256,
|
|
2628
|
-
actualSha256,
|
|
2629
|
-
settingPath: settingPath.path,
|
|
2630
|
-
currentValue,
|
|
2631
|
-
nextValue: nextSetting?.value,
|
|
2632
|
-
previousValue: settingPath.previousValue,
|
|
2633
|
-
message: isStillManaged ? `managed setting modified locally: ${settingKey}` : `setting changed locally and would be restored: ${settingKey}`
|
|
2634
|
-
});
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
2660
|
for (const item of plannedSettings) {
|
|
2638
2661
|
const document = await getSettingsDocument(item.targetPath);
|
|
2639
2662
|
const currentValue = document.hasIn(item.segments) ? getPlainYamlValue(document, item.segments) : void 0;
|
|
@@ -2651,7 +2674,32 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
|
|
|
2651
2674
|
});
|
|
2652
2675
|
continue;
|
|
2653
2676
|
}
|
|
2654
|
-
|
|
2677
|
+
if (item.mergeStrategy === "merge-by-key") {
|
|
2678
|
+
const otherContributions = listOtherManagedSettingValues(
|
|
2679
|
+
existingMetas,
|
|
2680
|
+
previousMeta.name,
|
|
2681
|
+
item.targetPath,
|
|
2682
|
+
item.path,
|
|
2683
|
+
item.mergeStrategy,
|
|
2684
|
+
item.segments
|
|
2685
|
+
);
|
|
2686
|
+
const conflict = otherContributions.map((value) => findMergeByKeyConflict(value, item.value, item.mergeKey ?? "code")).find((value) => value !== null);
|
|
2687
|
+
if (conflict) {
|
|
2688
|
+
conflicts.push({
|
|
2689
|
+
kind: "setting_value_conflict",
|
|
2690
|
+
path: `${item.targetPath}#${item.path}`,
|
|
2691
|
+
sourcePath: item.sourceRelativePath,
|
|
2692
|
+
memberName: item.memberName,
|
|
2693
|
+
memberType: "settings",
|
|
2694
|
+
settingPath: item.path,
|
|
2695
|
+
currentValue: conflict.currentValue,
|
|
2696
|
+
nextValue: conflict.nextValue,
|
|
2697
|
+
message: `${item.targetPath}#${item.path} conflicts with another addon's keyed setting contribution`
|
|
2698
|
+
});
|
|
2699
|
+
continue;
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
const owner = findIncompatibleSettingsOwner(existingMetas, plan.manifest.name, item, document);
|
|
2655
2703
|
if (!item.mergeStrategy && owner) {
|
|
2656
2704
|
conflicts.push({
|
|
2657
2705
|
kind: "owned_by_other_addon",
|
|
@@ -2721,7 +2769,7 @@ async function materializeAddon(options) {
|
|
|
2721
2769
|
}
|
|
2722
2770
|
const workflowDatasetBinding = await prepareWorkflowDatasetBinding(options, plan);
|
|
2723
2771
|
const removedFiles = previousMeta ? await removeObsoleteFiles(targetDir, previousMeta, new Set(plan.files.map((file) => file.targetPath))) : [];
|
|
2724
|
-
const
|
|
2772
|
+
const restoredSettings = await restoreObsoleteSettings(
|
|
2725
2773
|
targetDir,
|
|
2726
2774
|
previousMeta,
|
|
2727
2775
|
plan.settings,
|
|
@@ -2730,7 +2778,8 @@ async function materializeAddon(options) {
|
|
|
2730
2778
|
const npm = resolveInstallNpm(plan.manifest);
|
|
2731
2779
|
const packageJsonFiles = await applyNpmDependencies(targetDir, npm);
|
|
2732
2780
|
await writePlannedFiles(targetDir, plan.files, workflowDatasetBinding?.contentByTargetPath);
|
|
2733
|
-
const settingsResult = await applyPlannedSettings(targetDir, plan.settings);
|
|
2781
|
+
const settingsResult = await applyPlannedSettings(targetDir, plan.settings, previousMeta, existingMetas);
|
|
2782
|
+
const preservedSettings = [.../* @__PURE__ */ new Set([...restoredSettings.preservedSettings, ...settingsResult.preservedSettings])];
|
|
2734
2783
|
const promptContent = options.promptContent?.trim() || void 0;
|
|
2735
2784
|
const promptFiles = await writeAddonPromptFile(targetDir, plan.manifest.name, promptContent);
|
|
2736
2785
|
const installedFiles = [];
|
|
@@ -2764,14 +2813,20 @@ async function materializeAddon(options) {
|
|
|
2764
2813
|
npm,
|
|
2765
2814
|
promptContent
|
|
2766
2815
|
});
|
|
2816
|
+
if (preservedSettings.length) {
|
|
2817
|
+
llmGuidance.instructions.push(
|
|
2818
|
+
"app.settings.yml is shared application configuration. Local settings were preserved during this upgrade; review preservedSettings against the Addon's requirements before running it."
|
|
2819
|
+
);
|
|
2820
|
+
}
|
|
2767
2821
|
return {
|
|
2768
2822
|
meta,
|
|
2769
|
-
writtenFiles: installedFiles.map((file) => file.path).concat(promptFiles.writtenFiles, packageJsonFiles,
|
|
2823
|
+
writtenFiles: installedFiles.map((file) => file.path).concat(promptFiles.writtenFiles, packageJsonFiles, restoredSettings.writtenFiles, settingsResult.writtenFiles),
|
|
2770
2824
|
removedFiles: removedFiles.concat(promptFiles.removedFiles),
|
|
2771
2825
|
requirements,
|
|
2772
2826
|
missingRequirements: buildMissingRequirements(requirements),
|
|
2773
2827
|
npm,
|
|
2774
2828
|
llmGuidance,
|
|
2829
|
+
preservedSettings: preservedSettings.length ? preservedSettings : void 0,
|
|
2775
2830
|
workflowDatasetBinding: workflowDatasetBinding ? { boundFiles: workflowDatasetBinding.boundFiles } : void 0
|
|
2776
2831
|
};
|
|
2777
2832
|
}
|
|
@@ -4498,6 +4553,7 @@ function renderAddonInstallResult(result, operation, options) {
|
|
|
4498
4553
|
applicationType: result.meta.applicationType
|
|
4499
4554
|
},
|
|
4500
4555
|
llmGuidance: result.llmGuidance,
|
|
4556
|
+
...result.preservedSettings?.length ? { preservedSettings: result.preservedSettings } : {},
|
|
4501
4557
|
...result.workflowDatasetBinding ? { workflowDatasetBinding: result.workflowDatasetBinding } : {}
|
|
4502
4558
|
};
|
|
4503
4559
|
if (options.json) {
|
|
@@ -4512,6 +4568,9 @@ function renderAddonInstallResult(result, operation, options) {
|
|
|
4512
4568
|
if (result.removedFiles.length) {
|
|
4513
4569
|
lines.push(`Removed files: ${result.removedFiles.length}`);
|
|
4514
4570
|
}
|
|
4571
|
+
if (result.preservedSettings?.length) {
|
|
4572
|
+
lines.push(`Preserved application settings: ${result.preservedSettings.join(", ")}`);
|
|
4573
|
+
}
|
|
4515
4574
|
if (result.workflowDatasetBinding?.boundFiles.length) {
|
|
4516
4575
|
lines.push(`Bound encrypted Workflow dataset IDs: ${result.workflowDatasetBinding.boundFiles.join(", ")}`);
|
|
4517
4576
|
}
|