@amaster.ai/cli 1.1.69 → 1.1.71
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/README.md
CHANGED
|
@@ -155,7 +155,13 @@ Addon 可在 `addon.json` 中声明安装后的运行配置要求:
|
|
|
155
155
|
|
|
156
156
|
环境变量和 Secret requirement 是应用级共享依赖,不归某一个 Addon 独占。多个 Addon 声明同名且存储类型兼容的 requirement 时会复用同一份 `envMetadata`;展示名称和说明保留应用中已有值,`required` 按逻辑或合并。若同一个 key 被分别声明成 env 和 secret,或核心存储属性不一致,安装会以 `setting_value_conflict` 停止。
|
|
157
157
|
|
|
158
|
-
`settings
|
|
158
|
+
`app.settings.yml` 是应用共享配置文件。Addon 只记录其声明字段的配置贡献,不锁定整个文件。不同 Addon 声明相同的普通字段值时可以共享;声明不兼容值时,只针对该字段返回冲突。环境变量与 Secret 的类型、存储方式等共享要求仍进行兼容检查。
|
|
159
|
+
|
|
160
|
+
升级时,未被用户修改的 Addon 字段更新到新版本;用户修改或删除的字段保留,不因此阻断组件、函数等其他资源升级。用户值已经等于新版本值时直接通过。新版本移除配置时,只恢复未被定制且没有其他 Addon 使用的贡献,并保留用户修改。安装元数据记录原始应用配置、Addon 声明和预期合并值,保证连续升级不会覆盖先前保留的定制;YAML 路径按精确键保存,支持 `envMetadata` 中的 `mqtt.url` 等带点号键。
|
|
161
|
+
|
|
162
|
+
`settings` 成员中的 `rbac.permissions` 按权限字符串去重追加,`rbac.roles` 按 `role.code` 合并;同一角色的 `permissions` 会增量合并,应用已有的角色名称和说明不会被后安装的 Addon 覆盖。升级只清理该 Addon 不再声明的权限贡献,不影响应用原有配置、其他 Addon 的贡献或用户定制的权限范围,也不重新添加用户已删除的权限或角色。其他数组首次安装仍按普通设置整体写入,升级时保留用户修改,不对未知数组自动取并集。
|
|
163
|
+
|
|
164
|
+
安装/升级结果在保留应用定制时返回 `preservedSettings`(例如 `app.settings.yml#auth.loginMethods`);普通输出也列出保留项。调用方应根据这些提示检查新版本的能力要求。旧元数据缺少精确路径时从现有 YAML 键恢复;缺少独立贡献的旧 RBAC 配置采取保守保留策略,避免误删其他 Addon 或应用配置。
|
|
159
165
|
|
|
160
166
|
页面接入方式:
|
|
161
167
|
|
package/dist/cli.cjs
CHANGED
|
@@ -1858,22 +1858,45 @@ async function readYamlDocument(targetPath) {
|
|
|
1858
1858
|
const text = fs.existsSync(targetPath) ? await promises$1.readFile(targetPath, "utf8") : "";
|
|
1859
1859
|
return YAML2__default.default.parseDocument(text);
|
|
1860
1860
|
}
|
|
1861
|
-
function
|
|
1862
|
-
|
|
1861
|
+
function resolveStoredSettingSegments(setting, document, fallback) {
|
|
1862
|
+
if (setting.segments) {
|
|
1863
|
+
return setting.segments;
|
|
1864
|
+
}
|
|
1865
|
+
const find = (value, prefix) => {
|
|
1866
|
+
if (!isPlainObject(value)) {
|
|
1867
|
+
return void 0;
|
|
1868
|
+
}
|
|
1869
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1870
|
+
const segments = prefix.concat(key);
|
|
1871
|
+
const path = segments.join(".");
|
|
1872
|
+
if (path === setting.path) {
|
|
1873
|
+
return segments;
|
|
1874
|
+
}
|
|
1875
|
+
if (setting.path.startsWith(`${path}.`)) {
|
|
1876
|
+
const found = find(child, segments);
|
|
1877
|
+
if (found) {
|
|
1878
|
+
return found;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
return void 0;
|
|
1883
|
+
};
|
|
1884
|
+
return find(document.toJSON(), []) ?? fallback ?? setting.path.split(".");
|
|
1885
|
+
}
|
|
1886
|
+
function findIncompatibleSettingsOwner(metas, addonName, setting, document) {
|
|
1863
1887
|
for (const meta of metas) {
|
|
1864
|
-
if (
|
|
1888
|
+
if (meta.name === addonName) {
|
|
1865
1889
|
continue;
|
|
1866
1890
|
}
|
|
1867
1891
|
for (const member of meta.members) {
|
|
1868
|
-
for (const
|
|
1869
|
-
if (
|
|
1870
|
-
|
|
1892
|
+
for (const previous of member.settings?.paths ?? []) {
|
|
1893
|
+
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)) {
|
|
1894
|
+
return meta.name;
|
|
1871
1895
|
}
|
|
1872
|
-
ownership.set(`${item.targetPath}#${item.path}`, meta.name);
|
|
1873
1896
|
}
|
|
1874
1897
|
}
|
|
1875
1898
|
}
|
|
1876
|
-
return
|
|
1899
|
+
return void 0;
|
|
1877
1900
|
}
|
|
1878
1901
|
function listPlannedSettingPaths(settings) {
|
|
1879
1902
|
return settings.flatMap(
|
|
@@ -1908,6 +1931,69 @@ function cloneSettingsValue(value) {
|
|
|
1908
1931
|
function settingsValuesEqual(left, right) {
|
|
1909
1932
|
return stableJsonStringify(left) === stableJsonStringify(right);
|
|
1910
1933
|
}
|
|
1934
|
+
function storedSettingReference(setting, current) {
|
|
1935
|
+
if ("appliedValue" in setting) {
|
|
1936
|
+
return cloneSettingsValue(setting.appliedValue);
|
|
1937
|
+
}
|
|
1938
|
+
if (setting.mergeStrategy && setting.managedValue !== void 0) {
|
|
1939
|
+
return mergePlannedSettingValue(setting.previousValue, {
|
|
1940
|
+
path: setting.path,
|
|
1941
|
+
segments: setting.segments ?? setting.path.split("."),
|
|
1942
|
+
value: setting.managedValue,
|
|
1943
|
+
mergeStrategy: setting.mergeStrategy,
|
|
1944
|
+
mergeKey: setting.mergeKey
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
return sha256Value(current) === setting.sha256 ? cloneSettingsValue(current) : void 0;
|
|
1948
|
+
}
|
|
1949
|
+
function mergeSettingsUpgrade(current, previous, next, mergeStrategy, mergeKey = "code") {
|
|
1950
|
+
if (settingsValuesEqual(current, previous)) {
|
|
1951
|
+
return cloneSettingsValue(next);
|
|
1952
|
+
}
|
|
1953
|
+
if (settingsValuesEqual(current, next) || settingsValuesEqual(previous, next)) {
|
|
1954
|
+
return cloneSettingsValue(current);
|
|
1955
|
+
}
|
|
1956
|
+
if (isPlainObject(current) && isPlainObject(next) && (previous === void 0 || isPlainObject(previous))) {
|
|
1957
|
+
const old = previous ?? {};
|
|
1958
|
+
const merged = {};
|
|
1959
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(current), ...Object.keys(old), ...Object.keys(next)])) {
|
|
1960
|
+
const value = mergeSettingsUpgrade(current[key], old[key], next[key]);
|
|
1961
|
+
if (value !== void 0) {
|
|
1962
|
+
merged[key] = value;
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
return merged;
|
|
1966
|
+
}
|
|
1967
|
+
if (Array.isArray(current) && Array.isArray(next) && (previous === void 0 || Array.isArray(previous))) {
|
|
1968
|
+
const old = previous ?? [];
|
|
1969
|
+
if (mergeStrategy === "append-unique") {
|
|
1970
|
+
const merged = current.filter(
|
|
1971
|
+
(item) => !old.some((value) => settingsValuesEqual(item, value)) || next.some((value) => settingsValuesEqual(item, value))
|
|
1972
|
+
);
|
|
1973
|
+
for (const item of next) {
|
|
1974
|
+
if (!old.some((value) => settingsValuesEqual(item, value)) && !merged.some((value) => settingsValuesEqual(item, value))) {
|
|
1975
|
+
merged.push(cloneSettingsValue(item));
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
return merged;
|
|
1979
|
+
}
|
|
1980
|
+
if (mergeStrategy === "merge-by-key") {
|
|
1981
|
+
const byKey = (items) => new Map(items.filter(isPlainObject).map((item) => [item[mergeKey], item]));
|
|
1982
|
+
const currentItems = byKey(current);
|
|
1983
|
+
const oldItems = byKey(old);
|
|
1984
|
+
const nextItems = byKey(next);
|
|
1985
|
+
const merged = [];
|
|
1986
|
+
for (const key of /* @__PURE__ */ new Set([...currentItems.keys(), ...nextItems.keys()])) {
|
|
1987
|
+
const value = mergeSettingsUpgrade(currentItems.get(key), oldItems.get(key), nextItems.get(key));
|
|
1988
|
+
if (value !== void 0) {
|
|
1989
|
+
merged.push(value);
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
return merged;
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
return cloneSettingsValue(current);
|
|
1996
|
+
}
|
|
1911
1997
|
function isComposableSettingsPath(path) {
|
|
1912
1998
|
return path === "rbac.permissions" || path === "rbac.roles" || path.startsWith("envMetadata.");
|
|
1913
1999
|
}
|
|
@@ -1989,98 +2075,9 @@ function mergePlannedSettingValue(current, settingPath) {
|
|
|
1989
2075
|
return cloneSettingsValue(settingPath.value);
|
|
1990
2076
|
}
|
|
1991
2077
|
}
|
|
1992
|
-
function settingsValueContains(current, expected) {
|
|
1993
|
-
if (Array.isArray(expected)) {
|
|
1994
|
-
return Array.isArray(current) && expected.every(
|
|
1995
|
-
(item) => current.some((candidate) => settingsValueContains(candidate, item))
|
|
1996
|
-
);
|
|
1997
|
-
}
|
|
1998
|
-
if (isPlainObject(expected)) {
|
|
1999
|
-
return isPlainObject(current) && Object.entries(expected).every(
|
|
2000
|
-
([key, value]) => key in current && settingsValueContains(current[key], value)
|
|
2001
|
-
);
|
|
2002
|
-
}
|
|
2003
|
-
return settingsValuesEqual(current, expected);
|
|
2004
|
-
}
|
|
2005
|
-
function keyedArrayContributionPresent(current, contribution, previousValue, mergeKey) {
|
|
2006
|
-
if (!Array.isArray(current) || !Array.isArray(contribution)) {
|
|
2007
|
-
return false;
|
|
2008
|
-
}
|
|
2009
|
-
const previous = Array.isArray(previousValue) ? previousValue : [];
|
|
2010
|
-
for (const contributedItem of contribution) {
|
|
2011
|
-
if (!isPlainObject(contributedItem) || contributedItem[mergeKey] === void 0) {
|
|
2012
|
-
return false;
|
|
2013
|
-
}
|
|
2014
|
-
const currentItem = current.find(
|
|
2015
|
-
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
2016
|
-
);
|
|
2017
|
-
if (!isPlainObject(currentItem)) {
|
|
2018
|
-
return false;
|
|
2019
|
-
}
|
|
2020
|
-
const previousItem = previous.find(
|
|
2021
|
-
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
2022
|
-
);
|
|
2023
|
-
if (!isPlainObject(previousItem)) {
|
|
2024
|
-
if (!settingsValueContains(currentItem, contributedItem)) {
|
|
2025
|
-
return false;
|
|
2026
|
-
}
|
|
2027
|
-
continue;
|
|
2028
|
-
}
|
|
2029
|
-
for (const [field, value] of Object.entries(contributedItem)) {
|
|
2030
|
-
if (field === mergeKey) {
|
|
2031
|
-
continue;
|
|
2032
|
-
}
|
|
2033
|
-
if (isPlainObject(value)) {
|
|
2034
|
-
if (!settingsValueContains(currentItem[field], value)) {
|
|
2035
|
-
return false;
|
|
2036
|
-
}
|
|
2037
|
-
} else if (!(field in previousItem) && !settingsValuesEqual(currentItem[field], value)) {
|
|
2038
|
-
return false;
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
}
|
|
2042
|
-
return true;
|
|
2043
|
-
}
|
|
2044
|
-
function managedSettingContributionPresent(current, settingPath) {
|
|
2045
|
-
switch (settingPath.mergeStrategy) {
|
|
2046
|
-
case "append-unique":
|
|
2047
|
-
return settingsValueContains(current, settingPath.managedValue);
|
|
2048
|
-
case "merge-by-key":
|
|
2049
|
-
return keyedArrayContributionPresent(
|
|
2050
|
-
current,
|
|
2051
|
-
settingPath.managedValue,
|
|
2052
|
-
settingPath.previousValue,
|
|
2053
|
-
settingPath.mergeKey ?? "code"
|
|
2054
|
-
);
|
|
2055
|
-
case "shared-requirement":
|
|
2056
|
-
return true;
|
|
2057
|
-
default:
|
|
2058
|
-
return sha256Value(current) === settingPath.sha256;
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
function plannedSettingContributionPresent(current, settingPath, previousValue) {
|
|
2062
|
-
switch (settingPath.mergeStrategy) {
|
|
2063
|
-
case "append-unique":
|
|
2064
|
-
return settingsValueContains(current, settingPath.value);
|
|
2065
|
-
case "merge-by-key":
|
|
2066
|
-
return keyedArrayContributionPresent(
|
|
2067
|
-
current,
|
|
2068
|
-
settingPath.value,
|
|
2069
|
-
previousValue,
|
|
2070
|
-
settingPath.mergeKey ?? "code"
|
|
2071
|
-
);
|
|
2072
|
-
case "shared-requirement":
|
|
2073
|
-
return sharedRequirementValuesCompatible(settingPath.path, current, settingPath.value);
|
|
2074
|
-
default:
|
|
2075
|
-
return settingsValuesEqual(current, settingPath.value);
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
2078
|
function sharedRequirementValuesCompatible(path, current, incoming) {
|
|
2079
2079
|
const field = path.split(".").at(-1);
|
|
2080
|
-
if (current === void 0 || field
|
|
2081
|
-
return true;
|
|
2082
|
-
}
|
|
2083
|
-
if (field === "category" || field === "label" || field === "description") {
|
|
2080
|
+
if (current === void 0 || !["type", "storage", "sensitive", "envVar"].includes(field ?? "")) {
|
|
2084
2081
|
return true;
|
|
2085
2082
|
}
|
|
2086
2083
|
return settingsValuesEqual(current, incoming);
|
|
@@ -2131,27 +2128,66 @@ function attachAppliedSettings(members, appliedSettings) {
|
|
|
2131
2128
|
};
|
|
2132
2129
|
});
|
|
2133
2130
|
}
|
|
2134
|
-
async function applyPlannedSettings(targetDir, settings) {
|
|
2131
|
+
async function applyPlannedSettings(targetDir, settings, previousMeta, existingMetas) {
|
|
2135
2132
|
const written = /* @__PURE__ */ new Set();
|
|
2136
2133
|
const appliedSettings = [];
|
|
2134
|
+
const preservedSettings = [];
|
|
2137
2135
|
for (const item of settings) {
|
|
2138
2136
|
const targetPath = ensurePathInsideTarget(targetDir, item.targetPath);
|
|
2139
2137
|
const document = await readYamlDocument(targetPath);
|
|
2140
2138
|
const pathMetas = [];
|
|
2141
2139
|
for (const settingPath of item.paths) {
|
|
2142
|
-
const
|
|
2143
|
-
const
|
|
2144
|
-
const
|
|
2145
|
-
|
|
2140
|
+
const currentExists = document.hasIn(settingPath.segments);
|
|
2141
|
+
const current = currentExists ? getPlainYamlValue(document, settingPath.segments) : void 0;
|
|
2142
|
+
const previous = previousMeta?.members.flatMap((member) => member.settings?.paths ?? []).find(
|
|
2143
|
+
(path) => path.targetPath === item.targetPath && settingsValuesEqual(resolveStoredSettingSegments(path, document, path.path === settingPath.path ? settingPath.segments : void 0), settingPath.segments)
|
|
2144
|
+
);
|
|
2145
|
+
const shared = !settingPath.mergeStrategy ? existingMetas.filter((meta) => meta.name !== previousMeta?.name).flatMap(
|
|
2146
|
+
(meta) => meta.members.flatMap((member) => member.settings?.paths ?? [])
|
|
2147
|
+
).find(
|
|
2148
|
+
(path) => !path.mergeStrategy && path.targetPath === item.targetPath && settingsValuesEqual(resolveStoredSettingSegments(path, document), settingPath.segments)
|
|
2149
|
+
) : void 0;
|
|
2150
|
+
const baseline = previous ?? shared;
|
|
2151
|
+
let reference = current;
|
|
2152
|
+
if (previous?.mergeStrategy && previous.mergeStrategy !== "shared-requirement") {
|
|
2153
|
+
reference = removeManagedSettingContribution(
|
|
2154
|
+
storedSettingReference(previous, current),
|
|
2155
|
+
previous,
|
|
2156
|
+
listOtherManagedSettingValues(existingMetas, previousMeta.name, item.targetPath, previous.path, previous.mergeStrategy, settingPath.segments)
|
|
2157
|
+
);
|
|
2158
|
+
}
|
|
2159
|
+
const appliedValue = mergePlannedSettingValue(reference, settingPath);
|
|
2160
|
+
let nextValue = appliedValue;
|
|
2161
|
+
if (!settingPath.mergeStrategy && (baseline && sha256Value(current) !== baseline.sha256 || previousMeta && !baseline && currentExists)) {
|
|
2162
|
+
nextValue = current;
|
|
2163
|
+
} else if (previous && settingPath.mergeStrategy && settingPath.mergeStrategy !== "shared-requirement") {
|
|
2164
|
+
nextValue = mergeSettingsUpgrade(
|
|
2165
|
+
current,
|
|
2166
|
+
storedSettingReference(previous, current),
|
|
2167
|
+
appliedValue,
|
|
2168
|
+
settingPath.mergeStrategy,
|
|
2169
|
+
settingPath.mergeKey
|
|
2170
|
+
);
|
|
2171
|
+
}
|
|
2172
|
+
if (nextValue === void 0) {
|
|
2173
|
+
document.deleteIn(settingPath.segments);
|
|
2174
|
+
} else {
|
|
2175
|
+
document.setIn(settingPath.segments, nextValue);
|
|
2176
|
+
}
|
|
2177
|
+
if (!settingsValuesEqual(nextValue, appliedValue) || settingPath.mergeStrategy === "shared-requirement" && currentExists && !settingsValuesEqual(nextValue, settingPath.value)) {
|
|
2178
|
+
preservedSettings.push(`${item.targetPath}#${settingPath.path}`);
|
|
2179
|
+
}
|
|
2146
2180
|
pathMetas.push({
|
|
2147
2181
|
targetPath: item.targetPath,
|
|
2148
2182
|
path: settingPath.path,
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2183
|
+
segments: settingPath.segments,
|
|
2184
|
+
sha256: sha256Value(settingPath.mergeStrategy ? settingPath.value : appliedValue),
|
|
2185
|
+
previousValueExists: baseline?.previousValueExists ?? currentExists,
|
|
2186
|
+
previousValue: baseline ? baseline.previousValue : current,
|
|
2152
2187
|
mergeStrategy: settingPath.mergeStrategy,
|
|
2153
2188
|
mergeKey: settingPath.mergeKey,
|
|
2154
|
-
managedValue:
|
|
2189
|
+
managedValue: cloneSettingsValue(settingPath.value),
|
|
2190
|
+
appliedValue
|
|
2155
2191
|
});
|
|
2156
2192
|
}
|
|
2157
2193
|
await ensureParentDirectory(targetPath);
|
|
@@ -2165,10 +2201,11 @@ async function applyPlannedSettings(targetDir, settings) {
|
|
|
2165
2201
|
}
|
|
2166
2202
|
return {
|
|
2167
2203
|
writtenFiles: [...written],
|
|
2168
|
-
appliedSettings
|
|
2204
|
+
appliedSettings,
|
|
2205
|
+
preservedSettings
|
|
2169
2206
|
};
|
|
2170
2207
|
}
|
|
2171
|
-
function listOtherManagedSettingValues(metas, excludeAddonName, targetPath, path, mergeStrategy) {
|
|
2208
|
+
function listOtherManagedSettingValues(metas, excludeAddonName, targetPath, path, mergeStrategy, segments) {
|
|
2172
2209
|
const values = [];
|
|
2173
2210
|
for (const meta of metas) {
|
|
2174
2211
|
if (meta.name === excludeAddonName) {
|
|
@@ -2176,7 +2213,7 @@ function listOtherManagedSettingValues(metas, excludeAddonName, targetPath, path
|
|
|
2176
2213
|
}
|
|
2177
2214
|
for (const member of meta.members) {
|
|
2178
2215
|
for (const settingPath of member.settings?.paths ?? []) {
|
|
2179
|
-
if (settingPath.targetPath === targetPath && settingPath.path === path && settingPath.mergeStrategy === mergeStrategy && settingPath.managedValue !== void 0) {
|
|
2216
|
+
if (settingPath.targetPath === targetPath && settingPath.path === path && (!segments || !settingPath.segments || settingsValuesEqual(segments, settingPath.segments)) && settingPath.mergeStrategy === mergeStrategy && settingPath.managedValue !== void 0) {
|
|
2180
2217
|
values.push(settingPath.managedValue);
|
|
2181
2218
|
}
|
|
2182
2219
|
}
|
|
@@ -2287,13 +2324,12 @@ function removeManagedSettingContribution(current, settingPath, otherManagedValu
|
|
|
2287
2324
|
}
|
|
2288
2325
|
async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings, existingMetas) {
|
|
2289
2326
|
if (!previousMeta) {
|
|
2290
|
-
return [];
|
|
2327
|
+
return { writtenFiles: [], preservedSettings: [] };
|
|
2291
2328
|
}
|
|
2292
|
-
const
|
|
2293
|
-
listPlannedSettingPaths(nextSettings).map((item) => `${item.targetPath}#${item.path}`)
|
|
2294
|
-
);
|
|
2329
|
+
const plannedPaths = listPlannedSettingPaths(nextSettings);
|
|
2295
2330
|
const documents = /* @__PURE__ */ new Map();
|
|
2296
2331
|
const written = /* @__PURE__ */ new Set();
|
|
2332
|
+
const preservedSettings = [];
|
|
2297
2333
|
const getDocument = async (targetPath) => {
|
|
2298
2334
|
const cached = documents.get(targetPath);
|
|
2299
2335
|
if (cached) {
|
|
@@ -2305,33 +2341,53 @@ async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings, ex
|
|
|
2305
2341
|
};
|
|
2306
2342
|
for (const member of previousMeta.members) {
|
|
2307
2343
|
for (const settingPath of member.settings?.paths ?? []) {
|
|
2308
|
-
|
|
2344
|
+
const document = await getDocument(settingPath.targetPath);
|
|
2345
|
+
const segments = resolveStoredSettingSegments(
|
|
2346
|
+
settingPath,
|
|
2347
|
+
document,
|
|
2348
|
+
plannedPaths.find((item) => item.targetPath === settingPath.targetPath && item.path === settingPath.path)?.segments
|
|
2349
|
+
);
|
|
2350
|
+
if (plannedPaths.some(
|
|
2351
|
+
(item) => item.targetPath === settingPath.targetPath && settingsValuesEqual(item.segments, segments)
|
|
2352
|
+
)) {
|
|
2309
2353
|
continue;
|
|
2310
2354
|
}
|
|
2311
|
-
if (!settingPath.mergeStrategy && isComposableSettingsPath(settingPath.path)) {
|
|
2355
|
+
if (!settingPath.mergeStrategy && settingPath.managedValue === void 0 && isComposableSettingsPath(settingPath.path)) {
|
|
2312
2356
|
continue;
|
|
2313
2357
|
}
|
|
2314
|
-
const
|
|
2315
|
-
const
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
)
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2358
|
+
const current = document.hasIn(segments) ? getPlainYamlValue(document, segments) : void 0;
|
|
2359
|
+
const otherManagedValues = listOtherManagedSettingValues(
|
|
2360
|
+
existingMetas,
|
|
2361
|
+
previousMeta.name,
|
|
2362
|
+
settingPath.targetPath,
|
|
2363
|
+
settingPath.path,
|
|
2364
|
+
settingPath.mergeStrategy,
|
|
2365
|
+
segments
|
|
2366
|
+
);
|
|
2367
|
+
const sharedByAnotherAddon = existingMetas.some(
|
|
2368
|
+
(meta) => meta.name !== previousMeta.name && meta.members.some((member2) => member2.settings?.paths.some(
|
|
2369
|
+
(other) => other.targetPath === settingPath.targetPath && settingsValuesEqual(resolveStoredSettingSegments(other, document), segments)
|
|
2370
|
+
))
|
|
2371
|
+
);
|
|
2372
|
+
if (!settingPath.mergeStrategy && sharedByAnotherAddon) {
|
|
2373
|
+
continue;
|
|
2374
|
+
}
|
|
2375
|
+
const reference = storedSettingReference(settingPath, current);
|
|
2376
|
+
const restored = settingPath.mergeStrategy ? mergeSettingsUpgrade(
|
|
2377
|
+
current,
|
|
2378
|
+
reference,
|
|
2379
|
+
removeManagedSettingContribution(reference, settingPath, otherManagedValues),
|
|
2380
|
+
settingPath.mergeStrategy,
|
|
2381
|
+
settingPath.mergeKey
|
|
2382
|
+
) : sha256Value(current) === settingPath.sha256 ? removeManagedSettingContribution(current, settingPath, otherManagedValues) : current;
|
|
2383
|
+
const expected = removeManagedSettingContribution(reference, settingPath, otherManagedValues);
|
|
2384
|
+
if (!settingsValuesEqual(restored, expected)) {
|
|
2385
|
+
preservedSettings.push(`${settingPath.targetPath}#${settingPath.path}`);
|
|
2386
|
+
}
|
|
2387
|
+
if (restored === void 0) {
|
|
2334
2388
|
document.deleteIn(segments);
|
|
2389
|
+
} else {
|
|
2390
|
+
document.setIn(segments, restored);
|
|
2335
2391
|
}
|
|
2336
2392
|
written.add(settingPath.targetPath);
|
|
2337
2393
|
}
|
|
@@ -2342,7 +2398,7 @@ async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings, ex
|
|
|
2342
2398
|
await promises$1.writeFile(ensurePathInsideTarget(targetDir, targetPath), document.toString());
|
|
2343
2399
|
}
|
|
2344
2400
|
}
|
|
2345
|
-
return [...written];
|
|
2401
|
+
return { writtenFiles: [...written], preservedSettings };
|
|
2346
2402
|
}
|
|
2347
2403
|
async function removeObsoleteFiles(targetDir, previousMeta, nextPaths) {
|
|
2348
2404
|
const removed = [];
|
|
@@ -2417,7 +2473,6 @@ async function installPackageDependencies(targetDir) {
|
|
|
2417
2473
|
}
|
|
2418
2474
|
async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
2419
2475
|
const ownership = buildOwnershipMap(existingMetas);
|
|
2420
|
-
const settingsOwnership = buildSettingsOwnershipMap(existingMetas);
|
|
2421
2476
|
const conflicts = [];
|
|
2422
2477
|
const packageJson = await readPackageJson(targetDir);
|
|
2423
2478
|
const settingsDocuments = /* @__PURE__ */ new Map();
|
|
@@ -2503,7 +2558,7 @@ async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
|
2503
2558
|
continue;
|
|
2504
2559
|
}
|
|
2505
2560
|
}
|
|
2506
|
-
const owner =
|
|
2561
|
+
const owner = findIncompatibleSettingsOwner(existingMetas, plan.manifest.name, item, document);
|
|
2507
2562
|
if (!item.mergeStrategy && owner && owner !== plan.manifest.name) {
|
|
2508
2563
|
conflicts.push({
|
|
2509
2564
|
kind: "owned_by_other_addon",
|
|
@@ -2533,12 +2588,9 @@ async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
|
2533
2588
|
}
|
|
2534
2589
|
async function validateUpgradeConflicts(targetDir, plan, existingMetas, previousMeta) {
|
|
2535
2590
|
const ownership = buildOwnershipMap(existingMetas, previousMeta.name);
|
|
2536
|
-
const settingsOwnership = buildSettingsOwnershipMap(existingMetas, previousMeta.name);
|
|
2537
2591
|
const previousFilesByPath = new Map(previousMeta.files.map((file) => [file.path, file]));
|
|
2538
2592
|
const nextPaths = new Set(plan.files.map((file) => file.targetPath));
|
|
2539
2593
|
const plannedSettings = listPlannedSettingPaths(plan.settings);
|
|
2540
|
-
const nextSettingKeys = new Set(plannedSettings.map((item) => `${item.targetPath}#${item.path}`));
|
|
2541
|
-
const plannedSettingsByKey = new Map(plannedSettings.map((item) => [`${item.targetPath}#${item.path}`, item]));
|
|
2542
2594
|
const conflicts = [];
|
|
2543
2595
|
const packageJson = await readPackageJson(targetDir);
|
|
2544
2596
|
const previousNpmByName = buildNpmDependencyMap(previousMeta.npm ?? {});
|
|
@@ -2632,35 +2684,6 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
|
|
|
2632
2684
|
settingsDocuments.set(targetPath, document);
|
|
2633
2685
|
return document;
|
|
2634
2686
|
};
|
|
2635
|
-
for (const member of previousMeta.members) {
|
|
2636
|
-
for (const settingPath of member.settings?.paths ?? []) {
|
|
2637
|
-
const document = await getSettingsDocument(settingPath.targetPath);
|
|
2638
|
-
const segments = settingPath.path.split(".");
|
|
2639
|
-
const currentValue = document.hasIn(segments) ? getPlainYamlValue(document, segments) : void 0;
|
|
2640
|
-
const actualSha256 = sha256Value(currentValue);
|
|
2641
|
-
const settingKey = `${settingPath.targetPath}#${settingPath.path}`;
|
|
2642
|
-
const isStillManaged = nextSettingKeys.has(settingKey);
|
|
2643
|
-
const nextSetting = plannedSettingsByKey.get(settingKey);
|
|
2644
|
-
const contributionPresent = settingPath.mergeStrategy ? managedSettingContributionPresent(currentValue, settingPath) : nextSetting?.mergeStrategy ? plannedSettingContributionPresent(currentValue, nextSetting, settingPath.previousValue) : actualSha256 === settingPath.sha256;
|
|
2645
|
-
if (contributionPresent) {
|
|
2646
|
-
continue;
|
|
2647
|
-
}
|
|
2648
|
-
conflicts.push({
|
|
2649
|
-
kind: isStillManaged ? "managed_file_modified" : "obsolete_file_modified",
|
|
2650
|
-
path: settingKey,
|
|
2651
|
-
sourcePath: member.sourcePath,
|
|
2652
|
-
memberName: member.name,
|
|
2653
|
-
memberType: "settings",
|
|
2654
|
-
expectedSha256: settingPath.sha256,
|
|
2655
|
-
actualSha256,
|
|
2656
|
-
settingPath: settingPath.path,
|
|
2657
|
-
currentValue,
|
|
2658
|
-
nextValue: nextSetting?.value,
|
|
2659
|
-
previousValue: settingPath.previousValue,
|
|
2660
|
-
message: isStillManaged ? `managed setting modified locally: ${settingKey}` : `setting changed locally and would be restored: ${settingKey}`
|
|
2661
|
-
});
|
|
2662
|
-
}
|
|
2663
|
-
}
|
|
2664
2687
|
for (const item of plannedSettings) {
|
|
2665
2688
|
const document = await getSettingsDocument(item.targetPath);
|
|
2666
2689
|
const currentValue = document.hasIn(item.segments) ? getPlainYamlValue(document, item.segments) : void 0;
|
|
@@ -2678,7 +2701,32 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
|
|
|
2678
2701
|
});
|
|
2679
2702
|
continue;
|
|
2680
2703
|
}
|
|
2681
|
-
|
|
2704
|
+
if (item.mergeStrategy === "merge-by-key") {
|
|
2705
|
+
const otherContributions = listOtherManagedSettingValues(
|
|
2706
|
+
existingMetas,
|
|
2707
|
+
previousMeta.name,
|
|
2708
|
+
item.targetPath,
|
|
2709
|
+
item.path,
|
|
2710
|
+
item.mergeStrategy,
|
|
2711
|
+
item.segments
|
|
2712
|
+
);
|
|
2713
|
+
const conflict = otherContributions.map((value) => findMergeByKeyConflict(value, item.value, item.mergeKey ?? "code")).find((value) => value !== null);
|
|
2714
|
+
if (conflict) {
|
|
2715
|
+
conflicts.push({
|
|
2716
|
+
kind: "setting_value_conflict",
|
|
2717
|
+
path: `${item.targetPath}#${item.path}`,
|
|
2718
|
+
sourcePath: item.sourceRelativePath,
|
|
2719
|
+
memberName: item.memberName,
|
|
2720
|
+
memberType: "settings",
|
|
2721
|
+
settingPath: item.path,
|
|
2722
|
+
currentValue: conflict.currentValue,
|
|
2723
|
+
nextValue: conflict.nextValue,
|
|
2724
|
+
message: `${item.targetPath}#${item.path} conflicts with another addon's keyed setting contribution`
|
|
2725
|
+
});
|
|
2726
|
+
continue;
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
const owner = findIncompatibleSettingsOwner(existingMetas, plan.manifest.name, item, document);
|
|
2682
2730
|
if (!item.mergeStrategy && owner) {
|
|
2683
2731
|
conflicts.push({
|
|
2684
2732
|
kind: "owned_by_other_addon",
|
|
@@ -2748,7 +2796,7 @@ async function materializeAddon(options) {
|
|
|
2748
2796
|
}
|
|
2749
2797
|
const workflowDatasetBinding = await prepareWorkflowDatasetBinding(options, plan);
|
|
2750
2798
|
const removedFiles = previousMeta ? await removeObsoleteFiles(targetDir, previousMeta, new Set(plan.files.map((file) => file.targetPath))) : [];
|
|
2751
|
-
const
|
|
2799
|
+
const restoredSettings = await restoreObsoleteSettings(
|
|
2752
2800
|
targetDir,
|
|
2753
2801
|
previousMeta,
|
|
2754
2802
|
plan.settings,
|
|
@@ -2757,7 +2805,8 @@ async function materializeAddon(options) {
|
|
|
2757
2805
|
const npm = resolveInstallNpm(plan.manifest);
|
|
2758
2806
|
const packageJsonFiles = await applyNpmDependencies(targetDir, npm);
|
|
2759
2807
|
await writePlannedFiles(targetDir, plan.files, workflowDatasetBinding?.contentByTargetPath);
|
|
2760
|
-
const settingsResult = await applyPlannedSettings(targetDir, plan.settings);
|
|
2808
|
+
const settingsResult = await applyPlannedSettings(targetDir, plan.settings, previousMeta, existingMetas);
|
|
2809
|
+
const preservedSettings = [.../* @__PURE__ */ new Set([...restoredSettings.preservedSettings, ...settingsResult.preservedSettings])];
|
|
2761
2810
|
const promptContent = options.promptContent?.trim() || void 0;
|
|
2762
2811
|
const promptFiles = await writeAddonPromptFile(targetDir, plan.manifest.name, promptContent);
|
|
2763
2812
|
const installedFiles = [];
|
|
@@ -2791,14 +2840,20 @@ async function materializeAddon(options) {
|
|
|
2791
2840
|
npm,
|
|
2792
2841
|
promptContent
|
|
2793
2842
|
});
|
|
2843
|
+
if (preservedSettings.length) {
|
|
2844
|
+
llmGuidance.instructions.push(
|
|
2845
|
+
"app.settings.yml is shared application configuration. Local settings were preserved during this upgrade; review preservedSettings against the Addon's requirements before running it."
|
|
2846
|
+
);
|
|
2847
|
+
}
|
|
2794
2848
|
return {
|
|
2795
2849
|
meta,
|
|
2796
|
-
writtenFiles: installedFiles.map((file) => file.path).concat(promptFiles.writtenFiles, packageJsonFiles,
|
|
2850
|
+
writtenFiles: installedFiles.map((file) => file.path).concat(promptFiles.writtenFiles, packageJsonFiles, restoredSettings.writtenFiles, settingsResult.writtenFiles),
|
|
2797
2851
|
removedFiles: removedFiles.concat(promptFiles.removedFiles),
|
|
2798
2852
|
requirements,
|
|
2799
2853
|
missingRequirements: buildMissingRequirements(requirements),
|
|
2800
2854
|
npm,
|
|
2801
2855
|
llmGuidance,
|
|
2856
|
+
preservedSettings: preservedSettings.length ? preservedSettings : void 0,
|
|
2802
2857
|
workflowDatasetBinding: workflowDatasetBinding ? { boundFiles: workflowDatasetBinding.boundFiles } : void 0
|
|
2803
2858
|
};
|
|
2804
2859
|
}
|
|
@@ -4525,6 +4580,7 @@ function renderAddonInstallResult(result, operation, options) {
|
|
|
4525
4580
|
applicationType: result.meta.applicationType
|
|
4526
4581
|
},
|
|
4527
4582
|
llmGuidance: result.llmGuidance,
|
|
4583
|
+
...result.preservedSettings?.length ? { preservedSettings: result.preservedSettings } : {},
|
|
4528
4584
|
...result.workflowDatasetBinding ? { workflowDatasetBinding: result.workflowDatasetBinding } : {}
|
|
4529
4585
|
};
|
|
4530
4586
|
if (options.json) {
|
|
@@ -4539,6 +4595,9 @@ function renderAddonInstallResult(result, operation, options) {
|
|
|
4539
4595
|
if (result.removedFiles.length) {
|
|
4540
4596
|
lines.push(`Removed files: ${result.removedFiles.length}`);
|
|
4541
4597
|
}
|
|
4598
|
+
if (result.preservedSettings?.length) {
|
|
4599
|
+
lines.push(`Preserved application settings: ${result.preservedSettings.join(", ")}`);
|
|
4600
|
+
}
|
|
4542
4601
|
if (result.workflowDatasetBinding?.boundFiles.length) {
|
|
4543
4602
|
lines.push(`Bound encrypted Workflow dataset IDs: ${result.workflowDatasetBinding.boundFiles.join(", ")}`);
|
|
4544
4603
|
}
|