@lmzhen/dsh-evolution-commands 0.41.0 → 0.43.0
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/lib/index.js +9 -295
- package/lib/types/doctor.d.ts +0 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/parse.d.ts +1 -1
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { DEFAULT_SKILL_LIMITS, DIAGNOSTICS_FACT_KEYS, DIAGNOSTICS_RUNTIME_KEYS, DIAGNOSTICS_VIEW_SCHEMA_VERSION, EVOLUTION_PRESET_IDS, HOST_LOCALES, MAINTAINER_PRESET_ID, MAX_TIMER_DELAY_MS, PARAM_EXPOSURE, PARAM_GROUP_LABELS, PARAM_NAMESPACES, PLATFORM_LINE, REVIEWER_PRESET_ID, absentHostServices, appendEvolutionEvent, applyNamespaceMigration, asRecord,
|
|
2
|
+
import { DEFAULT_SKILL_LIMITS, DIAGNOSTICS_FACT_KEYS, DIAGNOSTICS_RUNTIME_KEYS, DIAGNOSTICS_VIEW_SCHEMA_VERSION, EVOLUTION_PRESET_IDS, HOST_LOCALES, MAINTAINER_PRESET_ID, MAX_TIMER_DELAY_MS, PARAM_EXPOSURE, PARAM_GROUP_LABELS, PARAM_NAMESPACES, PLATFORM_LINE, REVIEWER_PRESET_ID, absentHostServices, appendEvolutionEvent, applyNamespaceMigration, asRecord, atomicWriteFiles, authorityFrom, buildExtractPlanFromLibrary, buildLearnPrompt, clampedNumber, classifyNamespaceMigration, classifySessionEvent, createSubagentChannel, errorText, errorTextIn, eventsFile, evolutionHome, evolutionRoot, hostSurface, isDeprecatedParamId, isPresent, isRecord, isUnknown, liveBool, mutationLockFrom, newRunRegistry, ownerDecisionText, paramSettingsId, planNamespaceMigration, policyStageLimits, probeMtime, probeText, proposalFromPlan, readProposalReport, registerOwnerSettings, reportsSweepLockTarget, resolveParamId, scopedPackageName, scopedProbeReport, sweepReports, transactIo, unwrapLive, writeProposalReport } from "@lmzhen/dsh-evolution-core";
|
|
3
3
|
import { HOST_ROUTES, json, methodNotAllowed, registerHostRoutes } from "@lmzhen/dsh-evolution-core/http-routes";
|
|
4
4
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import z from "@deepseek-ai/schemastery";
|
|
8
8
|
import { effectiveSessionPolicy } from "@lmzhen/dsh-evolution-approval";
|
|
9
|
-
import { createUserMessage } from "@
|
|
10
|
-
import {
|
|
9
|
+
import { createUserMessage } from "@lmzhen/dsh-evolution-core/platform";
|
|
10
|
+
import { assertSkillsRootAliasRetired, elapsedSince, newSkillLibrary, partitionVersions, resolveRootConfig } from "@lmzhen/dsh-evolution-core/skills";
|
|
11
11
|
import { buildEnrichment, buildMaintainFacts, enrichmentSnapshotOptions, runMaintain, snapshotFromLibrary } from "@lmzhen/dsh-evolution-maintenance";
|
|
12
|
+
import { composePresetEntry, presetRowBlock, presetRowBody, presetRowId, resolveBasePresetPatch } from "@lmzhen/dsh-evolution-core/composition";
|
|
12
13
|
import { processScopeViolations } from "@lmzhen/dsh-evolution-state-storage";
|
|
13
14
|
//#region lib/types/command-fallback.js
|
|
14
15
|
/**
|
|
@@ -1768,38 +1769,6 @@ function readTextOrEmpty(path) {
|
|
|
1768
1769
|
function profilePatchText(profileDir) {
|
|
1769
1770
|
return readTextOrEmpty(join(profileDir, PROFILE_PATCH_FILENAME));
|
|
1770
1771
|
}
|
|
1771
|
-
/** Where the preset-install exclusion must look: THIS plane only, or an explicit refusal.
|
|
1772
|
-
*
|
|
1773
|
-
* The write path does NOT scan the home: the mounted profile is the whole question (its started
|
|
1774
|
-
* bundles plus the ones its own manifest declares — either can double-mount), and a question that
|
|
1775
|
-
* cannot be answered still REFUSES. That is what makes a leftover profile from the other plane
|
|
1776
|
-
* harmless here: it is not this plane's profile, so it is never consulted.
|
|
1777
|
-
* @param mounted - the mounted profile, or undefined outside a profile (a bare library mount).
|
|
1778
|
-
* @returns the profile to judge with its bundle rows, or the reason a refusal is mandatory.
|
|
1779
|
-
*/
|
|
1780
|
-
function installExclusionTarget(mounted) {
|
|
1781
|
-
if (mounted === void 0 || mounted.dir === "") return {
|
|
1782
|
-
kind: "undecidable",
|
|
1783
|
-
reason: "本进程没有挂载 profile,因此无法在这里回答双挂载问题"
|
|
1784
|
-
};
|
|
1785
|
-
let manifestFailure;
|
|
1786
|
-
const declared = profileBundles(mounted.dir, (error) => {
|
|
1787
|
-
manifestFailure = error;
|
|
1788
|
-
});
|
|
1789
|
-
const manifestCode = manifestFailure?.code;
|
|
1790
|
-
if (manifestFailure !== void 0 && manifestCode !== "ENOENT") return {
|
|
1791
|
-
kind: "undecidable",
|
|
1792
|
-
reason: "读不出已挂载 profile 的清单"
|
|
1793
|
-
};
|
|
1794
|
-
return {
|
|
1795
|
-
kind: "mounted",
|
|
1796
|
-
profile: {
|
|
1797
|
-
profile: mounted.profile,
|
|
1798
|
-
dir: mounted.dir
|
|
1799
|
-
},
|
|
1800
|
-
bundles: [...mounted.bundles, ...declared]
|
|
1801
|
-
};
|
|
1802
|
-
}
|
|
1803
1772
|
//#endregion
|
|
1804
1773
|
//#region lib/types/doctor.js
|
|
1805
1774
|
/**
|
|
@@ -1971,17 +1940,6 @@ function collectEvolutionBundles(home, onReadError) {
|
|
|
1971
1940
|
}
|
|
1972
1941
|
return bundles;
|
|
1973
1942
|
}
|
|
1974
|
-
const SESSION_QUERY_MODES = new Set([
|
|
1975
|
-
"startup",
|
|
1976
|
-
"first-search",
|
|
1977
|
-
"never"
|
|
1978
|
-
]);
|
|
1979
|
-
function envIssues() {
|
|
1980
|
-
const issues = [];
|
|
1981
|
-
const query = process.env.DSH_EVOLUTION_SESSION_QUERY;
|
|
1982
|
-
if (query && !SESSION_QUERY_MODES.has(query)) issues.push(`DSH_EVOLUTION_SESSION_QUERY="${query}" is not one of startup|first-search|never — the patch normalizes it to 'startup' silently; set it to a listed mode.`);
|
|
1983
|
-
return issues;
|
|
1984
|
-
}
|
|
1985
1943
|
/** G3-② (B2): the family delta container. An optionalDependency of this
|
|
1986
1944
|
* package, so resolution may legitimately fail; every failure degrades to
|
|
1987
1945
|
* "unknown" — the doctor never throws.
|
|
@@ -1993,7 +1951,7 @@ const AGENT_PRESET_PACKAGE = scopedPackageName("dsh-evolution-agent-preset", imp
|
|
|
1993
1951
|
* @returns the file path, or null when the package is not installed. */
|
|
1994
1952
|
function resolveAgentPresetAsset(asset) {
|
|
1995
1953
|
try {
|
|
1996
|
-
return
|
|
1954
|
+
return createRequire(import.meta.url).resolve(`${AGENT_PRESET_PACKAGE}/${asset}`);
|
|
1997
1955
|
} catch {
|
|
1998
1956
|
return null;
|
|
1999
1957
|
}
|
|
@@ -2005,7 +1963,7 @@ function resolveAgentPresetAsset(asset) {
|
|
|
2005
1963
|
* (minimal) as a double-mount participant.
|
|
2006
1964
|
* @param path - resolved bases.json.
|
|
2007
1965
|
* @returns the rows, or null when the table is unreadable or malformed. */
|
|
2008
|
-
function readAgentPresetBases
|
|
1966
|
+
function readAgentPresetBases(path) {
|
|
2009
1967
|
try {
|
|
2010
1968
|
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
2011
1969
|
if (!Array.isArray(parsed.bases)) return null;
|
|
@@ -2077,7 +2035,7 @@ function baseInstallable(base, servicePresent) {
|
|
|
2077
2035
|
*/
|
|
2078
2036
|
function installedLayeredPresetIds(home) {
|
|
2079
2037
|
const basesPath = resolveAgentPresetAsset("bases.json");
|
|
2080
|
-
const bases = basesPath === null ? null : readAgentPresetBases
|
|
2038
|
+
const bases = basesPath === null ? null : readAgentPresetBases(basesPath);
|
|
2081
2039
|
const ids = /* @__PURE__ */ new Set();
|
|
2082
2040
|
for (const text of userPatchTexts(home)) {
|
|
2083
2041
|
if (text === "") continue;
|
|
@@ -2108,7 +2066,7 @@ function installedLayeredPresetIds(home) {
|
|
|
2108
2066
|
function probePresetFreshness(home, servicePresent) {
|
|
2109
2067
|
const basesPath = resolveAgentPresetAsset("bases.json");
|
|
2110
2068
|
const deltaPath = resolveAgentPresetAsset("agent.cordis.yml");
|
|
2111
|
-
const bases = basesPath === null ? null : readAgentPresetBases
|
|
2069
|
+
const bases = basesPath === null ? null : readAgentPresetBases(basesPath);
|
|
2112
2070
|
let delta = null;
|
|
2113
2071
|
let deltaFailure = `${AGENT_PRESET_PACKAGE}/agent.cordis.yml could not be resolved — is the family agent-preset package installed?`;
|
|
2114
2072
|
if (deltaPath !== null) try {
|
|
@@ -2321,8 +2279,6 @@ async function diagnose(ctx, options = {}) {
|
|
|
2321
2279
|
else if (installForm === "none") actions.push("Install the default full bundle: dsh plugin --profile web add @lmzhen/dsh-evolution-all");
|
|
2322
2280
|
else if (installForm === "preset-only") actions.push(`The Evolution preset row is installed but no profile mounts an evolution bundle — re-add @lmzhen/dsh-evolution-host for the layered layout (do NOT add all on top of the preset: that double-mounts the model rows), or drop the row (${layeredArtifactLabel}) from the profile patch if the layered layout is no longer wanted.`);
|
|
2323
2281
|
else if (installForm === "layered") actions.push("Variant form (session opt-in): model tools follow the Evolution preset, and a session on a platform original preset carries no family rows; add @lmzhen/dsh-evolution-all instead if every session should have them.");
|
|
2324
|
-
const env = envIssues();
|
|
2325
|
-
if (env.length > 0) actions.push("Fix the DSH_EVOLUTION_* variable listed above.");
|
|
2326
2282
|
if (capabilityAbsence.length > 0) actions.push(`The family probes ${capabilityAbsence.length} platform capability/ies this deployment does not mount (${capabilityAbsence.map((entry) => entry.service).join(", ")}) — mount the rows that carry the ones you need; the features they gate are listed above.`);
|
|
2327
2283
|
if (processScopeIssues.length > 0) actions.push(`The mounted IO backend does not back every cross-process medium claim: ${processScopeIssues.join("; ")} — mount a provider that declares processScope 'cross-process', or treat this home as single-process (no concurrent writers).`);
|
|
2328
2284
|
if (services.review && !services.curator) actions.push("Curator service is not mounted — automatic curation is off; verify the host/all bundle row set is complete.");
|
|
@@ -2353,7 +2309,6 @@ async function diagnose(ctx, options = {}) {
|
|
|
2353
2309
|
bundles,
|
|
2354
2310
|
foreignProfiles: homeProfiles(home).filter(({ profile, dir }) => mounted === void 0 || profile !== mounted.profile && dir !== mounted.dir).map(({ profile }) => profile),
|
|
2355
2311
|
conflicts,
|
|
2356
|
-
envIssues: env,
|
|
2357
2312
|
budgetIssues,
|
|
2358
2313
|
paramIssues,
|
|
2359
2314
|
queryIssues,
|
|
@@ -2560,7 +2515,6 @@ function renderDoctorText(report, locale = "zh") {
|
|
|
2560
2515
|
if (report.presetIssues.length > 0) extras.push("agent presets:", ...report.presetIssues.map((line) => ` ! ${line}`));
|
|
2561
2516
|
if (report.foreignProfiles.length > 0) extras.push("profiles-foreign: " + report.foreignProfiles.join(", ") + " — not part of this plane: /evolution preset install ignores them, while the bundles (all profiles) line above counts them");
|
|
2562
2517
|
if (report.conflicts.length > 0) extras.push("conflicts:", ...report.conflicts.map((line) => ` ! ${line}`));
|
|
2563
|
-
if (report.envIssues.length > 0) extras.push("env:", ...report.envIssues.map((line) => ` ! ${line}`));
|
|
2564
2518
|
if (report.budgetIssues.length > 0) extras.push("memory budget:", ...report.budgetIssues.map((line) => ` ! ${line}`));
|
|
2565
2519
|
if (report.paramIssues.length > 0) extras.push("parameters:", ...report.paramIssues.map((line) => ` ! ${line}`));
|
|
2566
2520
|
if (report.queryIssues.length > 0) extras.push("session search:", ...report.queryIssues.map((line) => ` ! ${line}`));
|
|
@@ -2739,32 +2693,6 @@ function renderParamRows(rows, options) {
|
|
|
2739
2693
|
].join("\n");
|
|
2740
2694
|
}
|
|
2741
2695
|
/**
|
|
2742
|
-
* Parse one command-line value into what the settings document stores: JSON
|
|
2743
|
-
* when it parses (numbers, booleans, quoted strings, arrays, objects), the raw
|
|
2744
|
-
* text otherwise, so a bare word like `enforce` stays a word.
|
|
2745
|
-
* @param raw - the text typed after the parameter id.
|
|
2746
|
-
* @returns the value to write.
|
|
2747
|
-
*/
|
|
2748
|
-
function parseParamValue(raw) {
|
|
2749
|
-
const text = raw.trim();
|
|
2750
|
-
try {
|
|
2751
|
-
return JSON.parse(text);
|
|
2752
|
-
} catch {
|
|
2753
|
-
return text;
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
/**
|
|
2757
|
-
* Render the write result: the value move, then where it landed and when it
|
|
2758
|
-
* takes effect (the two things a caller cannot infer from the command line).
|
|
2759
|
-
* @param write - the accepted write.
|
|
2760
|
-
* @returns the command text.
|
|
2761
|
-
*/
|
|
2762
|
-
function renderPolicySet(write) {
|
|
2763
|
-
const timing = write.applies === "live" ? "takes effect at the next use (live)" : "takes effect after a host restart (restart)";
|
|
2764
|
-
const origin = write.wasOverridden ? "replacing your earlier override" : "now a user override (the deployment value stays underneath)";
|
|
2765
|
-
return [`${write.id}: ${renderValue(write.before)} → ${renderValue(write.after)}`, `namespace ${write.namespace}; applies ${write.applies} — ${timing}; ${origin}`].join("\n");
|
|
2766
|
-
}
|
|
2767
|
-
/**
|
|
2768
2696
|
* Render the rows as JSON for scripts (same fields, no formatting).
|
|
2769
2697
|
* @param rows - rows from {@link paramSurfaceRows}.
|
|
2770
2698
|
* @returns a JSON document with a `params` array.
|
|
@@ -2927,26 +2855,11 @@ const COMMAND_ENTRIES = [
|
|
|
2927
2855
|
usage: "maintain cancel [<id>]",
|
|
2928
2856
|
summary: "停掉在飞的那次维护扫描(省略 id 仅当最新一条是本进程在跑的那次)"
|
|
2929
2857
|
},
|
|
2930
|
-
{
|
|
2931
|
-
readonly: false,
|
|
2932
|
-
usage: "migrate",
|
|
2933
|
-
summary: "把旧设置文档里家族的旧分区迁进现在的行(幂等;已迁移过就报「已一致」)"
|
|
2934
|
-
},
|
|
2935
|
-
{
|
|
2936
|
-
readonly: false,
|
|
2937
|
-
usage: "policy set <id> <value> [--expect <revision>]",
|
|
2938
|
-
summary: "通过设置服务写入一个你可改的参数 (仅 E3;E1/E2 仍留在 cordis.yml)"
|
|
2939
|
-
},
|
|
2940
2858
|
{
|
|
2941
2859
|
readonly: true,
|
|
2942
2860
|
usage: "params [--group <name>] [--json]",
|
|
2943
2861
|
summary: "列出全部参数:分组、档位、生效时机、来源与当前值(--json 便于脚本处理)"
|
|
2944
2862
|
},
|
|
2945
|
-
{
|
|
2946
|
-
readonly: false,
|
|
2947
|
-
usage: "preset install [--base <name>[,<name>...]]",
|
|
2948
|
-
summary: "把自进化 Agent 预设**行**写进当前 profile 的 patch 层(`profiles/<p>/cordis.patch.yml`;bases 来自 agent 包的 bases.json)"
|
|
2949
|
-
},
|
|
2950
2863
|
{
|
|
2951
2864
|
readonly: false,
|
|
2952
2865
|
usage: "restructure <name> \"<heading>\" <to_file> [--plan <runId>]",
|
|
@@ -2987,7 +2900,7 @@ function renderHelpText(locale = "zh") {
|
|
|
2987
2900
|
*
|
|
2988
2901
|
* This parser is order- and `=`-tolerant, matches the subcommand name case-insensitively, keeps a flag
|
|
2989
2902
|
* VALUE's case intact (the domain layer is the one that validates it), and answers a SYNTAX failure when a
|
|
2990
|
-
* declared value flag is left without its value (F-3: `
|
|
2903
|
+
* declared value flag is left without its value (F-3: `extract --start 3` must not read
|
|
2991
2904
|
* `--expect 3` as the value).
|
|
2992
2905
|
*
|
|
2993
2906
|
* @module @lmzhen/dsh-evolution-commands/parse
|
|
@@ -2999,8 +2912,6 @@ function renderHelpText(locale = "zh") {
|
|
|
2999
2912
|
*/
|
|
3000
2913
|
const VALUE_FLAGS = [
|
|
3001
2914
|
"group",
|
|
3002
|
-
"expect",
|
|
3003
|
-
"base",
|
|
3004
2915
|
"to",
|
|
3005
2916
|
"timeout",
|
|
3006
2917
|
"plan",
|
|
@@ -4028,76 +3939,6 @@ function apply(ctx, rawConfig = {}) {
|
|
|
4028
3939
|
return ok(woke ? `已把运行 ${record.id} 交给模型 —— 报告:${reportDigestPath(record)}。它会读取该文件并执行其中的行动项。` : `已把运行 ${record.id} 交给模型并排队 —— 本宿主没有唤醒通道,因此会在你下一条消息时被读取。`);
|
|
4029
3940
|
}
|
|
4030
3941
|
if (/^maintain\b/.test(input)) return err("未知的 maintain 参数:应为 `maintain`、`maintain --timeout <ms>` / `maintain --timeout=<ms>`、`maintain status [<id>]`、`maintain report [<id>]`、`maintain handoff [<id>]` 或 `maintain cancel [<id>]`。实际收到:" + input);
|
|
4031
|
-
const presetParsed = parseSubcommand(input);
|
|
4032
|
-
const presetInstall = isParseFailure(presetParsed) || presetParsed.name !== "preset" ? null : presetParsed.positionals[0] === "install" && presetParsed.positionals.length === 1 && [...presetParsed.flags.keys()].every((flag) => flagsOf("preset install").includes("--" + flag)) ? presetParsed : false;
|
|
4033
|
-
if (presetInstall !== null && presetInstall !== false) {
|
|
4034
|
-
{
|
|
4035
|
-
const mounted = presetProfileTarget(ctx);
|
|
4036
|
-
const exclusion = installExclusionTarget(mounted === void 0 ? void 0 : {
|
|
4037
|
-
profile: mounted.profile,
|
|
4038
|
-
dir: mounted.profileDir,
|
|
4039
|
-
bundles: mounted.bundles
|
|
4040
|
-
});
|
|
4041
|
-
if (exclusion.kind === "undecidable") return err(`拒绝安装分层 Evolution 预设:${exclusion.reason}:all/preset 双重挂载检查无法执行。请解决该 profile 的访问权限后重试,或改用分层安装器——它会在安装前就执行同一套排除检查。`);
|
|
4042
|
-
const installedBundles = exclusion.bundles;
|
|
4043
|
-
const allBundle = installedBundles.find((name) => name === "dsh-evolution-all" || name.endsWith("/dsh-evolution-all"));
|
|
4044
|
-
const presetBundle = installedBundles.find((name) => name === "dsh-evolution-preset" || name.endsWith("/dsh-evolution-preset"));
|
|
4045
|
-
if (allBundle || presetBundle) return err(`拒绝安装分层 Evolution 预设:本 profile 里已安装「${allBundle ?? presetBundle}」:它的模型行(tool-memory / tool-skill-manage / tool-session-query / skill-catalog)会与预设的重复挂载,profile 启动时会直接报错。只保留一个:安装分层预设前先移除 ${allBundle ? "evolution-all bundle" : "evolution-preset bundle"}(见 /evolution doctor)。`);
|
|
4046
|
-
}
|
|
4047
|
-
try {
|
|
4048
|
-
const source = resolveAgentPresetDir(import.meta.url);
|
|
4049
|
-
const table = readAgentPresetBases(source);
|
|
4050
|
-
const baseFlag = presetInstall.flags.get("base");
|
|
4051
|
-
const requestedRaw = typeof baseFlag === "string" ? baseFlag : table.defaultBase;
|
|
4052
|
-
const requested = [...new Set(requestedRaw.split(",").map((part) => part.trim()).filter((part) => part !== ""))];
|
|
4053
|
-
if (requested.length === 0) return err(`没有指定 agent-preset 基名:${join(source, "bases.json")} 里列出的是 ${table.entries.map((entry) => entry.name).join(", ")}`);
|
|
4054
|
-
const selected = [];
|
|
4055
|
-
for (const name of requested) {
|
|
4056
|
-
const entry = table.entries.find((candidate) => candidate.name === name);
|
|
4057
|
-
if (entry === void 0) return err(`未知的 agent-preset 基名「${name}」:${join(source, "bases.json")} 里列出的是 ${table.entries.map((candidate) => candidate.name).join(", ")}`);
|
|
4058
|
-
selected.push(entry);
|
|
4059
|
-
}
|
|
4060
|
-
const deltaPath = join(source, "agent.cordis.yml");
|
|
4061
|
-
if (!existsSync(deltaPath)) return err(`预设文件在 ${source} 里缺失:是否装了 dsh-evolution-agent-preset 包?`);
|
|
4062
|
-
const profile = presetProfileTarget(ctx);
|
|
4063
|
-
if (profile === void 0) return err("本进程没有挂载任何 profile,因此没有可写入预设行的 profile 补丁:请在由 `dsh --profile <name>` 启动的会话里执行该命令。");
|
|
4064
|
-
const delta = readFileSync(deltaPath, "utf8");
|
|
4065
|
-
const hmr = ctx.get("hmr");
|
|
4066
|
-
const commit = () => {
|
|
4067
|
-
const current = existsSync(profile.patchPath) ? readFileSync(profile.patchPath, "utf8") : "";
|
|
4068
|
-
let merged = current;
|
|
4069
|
-
const written = [];
|
|
4070
|
-
for (const base of selected) {
|
|
4071
|
-
const refusal = baseRefusalReason(base, (name) => ctx.get(name) !== void 0);
|
|
4072
|
-
if (refusal !== void 0) return err(refusal);
|
|
4073
|
-
const basePatch = resolvePresetBasePatch(base.name, profile);
|
|
4074
|
-
const rowId = presetRowId(base.id);
|
|
4075
|
-
const entryText = composePresetEntry(readFileSync(basePatch, "utf8"), delta, {
|
|
4076
|
-
rowId,
|
|
4077
|
-
id: base.id,
|
|
4078
|
-
name: base.display.name,
|
|
4079
|
-
description: base.display.description,
|
|
4080
|
-
order: base.display.order
|
|
4081
|
-
});
|
|
4082
|
-
const next = mergePresetRow(merged, entryText, rowId);
|
|
4083
|
-
written.push(next === merged ? `${base.name} → ${profile.patchPath} (already current)` : `${base.name} → ${rowId} in ${profile.patchPath}`);
|
|
4084
|
-
merged = next;
|
|
4085
|
-
}
|
|
4086
|
-
if (merged !== current) atomicWriteFiles(dirname(profile.patchPath), [{
|
|
4087
|
-
name: PROFILE_PATCH_FILENAME$1,
|
|
4088
|
-
content: presetPatchText(merged)
|
|
4089
|
-
}], void 0, (message) => {
|
|
4090
|
-
ctx.logger.warn(message);
|
|
4091
|
-
});
|
|
4092
|
-
return ok(`已写入 evolution agent preset 行(${written.join("; ")})。重启会话切换器后即可选中它。`);
|
|
4093
|
-
};
|
|
4094
|
-
const runExclusive = hmr?.runExclusive;
|
|
4095
|
-
if (runExclusive === void 0) return commit();
|
|
4096
|
-
return await runExclusive.call(hmr, commit);
|
|
4097
|
-
} catch (error) {
|
|
4098
|
-
return err(`预设安装失败:${error instanceof Error ? error.message : String(error)}`);
|
|
4099
|
-
}
|
|
4100
|
-
}
|
|
4101
3942
|
if (input.startsWith("extract ")) {
|
|
4102
3943
|
const extractParsed = parseSubcommand(rawInputTrimmed);
|
|
4103
3944
|
if (isParseFailure(extractParsed) || extractParsed.name !== "extract") return err("用法:/evolution extract <source> <target> \"<heading>\" [--start <line>] [--end <line>] [--owner-covers] 或 --proposal <id>");
|
|
@@ -4289,87 +4130,6 @@ function apply(ctx, rawConfig = {}) {
|
|
|
4289
4130
|
if (paramsParsed.flags.get("json") === true) return ok(renderParamJson(selected));
|
|
4290
4131
|
return ok(renderParamRows(selected, { providerMounted: provider !== void 0 }));
|
|
4291
4132
|
}
|
|
4292
|
-
const policyParsed = parseSubcommand(input);
|
|
4293
|
-
if (isParseFailure(policyParsed) && policyParsed.name === "policy" && policyParsed.kind === "missing-value") return err("/evolution policy set 需要在 --" + (policyParsed.flag ?? "") + ";用法:policy set <id> <value> [--expect <revision>]");
|
|
4294
|
-
if (!isParseFailure(policyParsed) && policyParsed.name === "policy" && policyParsed.positionals[0] === "set") {
|
|
4295
|
-
const provider = ctx.get("settings");
|
|
4296
|
-
if (provider?.update === void 0 || provider.describe === void 0) return err(hostError("e-311-no-settings-service-is"));
|
|
4297
|
-
const rawId = policyParsed.positionals[1] ?? "";
|
|
4298
|
-
const rawValue = policyParsed.positionals[2] ?? "";
|
|
4299
|
-
let id;
|
|
4300
|
-
try {
|
|
4301
|
-
id = canonicalWriteId(rawId);
|
|
4302
|
-
} catch (error) {
|
|
4303
|
-
return err(hostError("e-312-error-instanceof-Error-error", { a1: error instanceof Error ? error.message : String(error) }));
|
|
4304
|
-
}
|
|
4305
|
-
const entry = PARAM_EXPOSURE.find((candidate) => candidate.id === id);
|
|
4306
|
-
if (entry === void 0) return err(hostError("e-313-unknown-parameter-id-evolution", { a1: id }));
|
|
4307
|
-
if (entry.tier !== "E3") return err(hostError("e-314-id-is-a-deployment", {
|
|
4308
|
-
a1: id,
|
|
4309
|
-
a2: entry.tier,
|
|
4310
|
-
a3: entry.owner
|
|
4311
|
-
}));
|
|
4312
|
-
const namespace = paramSettingsId(entry.owner);
|
|
4313
|
-
if (namespace === void 0) return err(hostError("e-315-id-has-no-user", {
|
|
4314
|
-
a1: id,
|
|
4315
|
-
a2: entry.owner
|
|
4316
|
-
}));
|
|
4317
|
-
let descriptor;
|
|
4318
|
-
try {
|
|
4319
|
-
descriptor = provider.describe({ redactSecrets: false }).find((candidate) => candidate.ns === namespace);
|
|
4320
|
-
} catch (error) {
|
|
4321
|
-
return err(hostError("e-307-the-settings-service-could-2", { a1: error instanceof Error ? error.message : String(error) }));
|
|
4322
|
-
}
|
|
4323
|
-
if (descriptor === void 0) return err(hostError("e-316-namespace-namespace-is-not", {
|
|
4324
|
-
a1: namespace,
|
|
4325
|
-
a2: entry.owner
|
|
4326
|
-
}));
|
|
4327
|
-
const current = descriptor.value;
|
|
4328
|
-
const resolved = typeof current === "object" && current !== null ? current : void 0;
|
|
4329
|
-
const expectFlag = policyParsed.flags.get("expect");
|
|
4330
|
-
const expectedRaw = typeof expectFlag === "string" ? expectFlag : void 0;
|
|
4331
|
-
const expected = expectedRaw === void 0 ? descriptor.revision : Number(expectedRaw);
|
|
4332
|
-
if (expectedRaw !== void 0 && descriptor.revision !== void 0 && Number(expectedRaw) !== descriptor.revision) return err(hostError("e-309-revision-conflict-you-sent", {
|
|
4333
|
-
a1: expectedRaw,
|
|
4334
|
-
a2: descriptor.revision
|
|
4335
|
-
}));
|
|
4336
|
-
const value = parseParamValue(rawValue);
|
|
4337
|
-
const floorId = entry.relation?.atLeast;
|
|
4338
|
-
if (floorId !== void 0 && typeof value === "number") {
|
|
4339
|
-
const sibling = resolved?.[floorId];
|
|
4340
|
-
const floor = typeof sibling === "number" ? sibling : NaN;
|
|
4341
|
-
if (Number.isFinite(floor) && value < floor) return err(hostError("e-322-a-parameter-would-break-a", {
|
|
4342
|
-
a1: id,
|
|
4343
|
-
a2: String(floor),
|
|
4344
|
-
a3: String(value)
|
|
4345
|
-
}));
|
|
4346
|
-
}
|
|
4347
|
-
try {
|
|
4348
|
-
await provider.update(namespace, { [id]: value }, expected);
|
|
4349
|
-
} catch (error) {
|
|
4350
|
-
const code = error?.code;
|
|
4351
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
4352
|
-
if (code === "SETTINGS_CONFLICT") return err(hostError("e-309-revision-conflict-message-Re", { a1: message }));
|
|
4353
|
-
return err(hostError("e-310-the-settings-service-refused", { a1: message }));
|
|
4354
|
-
}
|
|
4355
|
-
return ok(renderPolicySet({
|
|
4356
|
-
id,
|
|
4357
|
-
namespace,
|
|
4358
|
-
applies: entry.applies,
|
|
4359
|
-
before: descriptor.user?.[id] ?? resolved?.[id],
|
|
4360
|
-
after: value,
|
|
4361
|
-
wasOverridden: descriptor.user !== void 0 && Object.hasOwn(descriptor.user, id)
|
|
4362
|
-
}));
|
|
4363
|
-
}
|
|
4364
|
-
if (input === "migrate") {
|
|
4365
|
-
const attempt = await migrateFromContext(ctx);
|
|
4366
|
-
if (!attempt.ok) {
|
|
4367
|
-
if (attempt.problem === "settings") return err(hostError("e-311-no-settings-service-is"));
|
|
4368
|
-
if (attempt.problem === "home") return err(hostError("e-320-the-profile-home-is-not"));
|
|
4369
|
-
return err(hostError("e-321-no-io-provider-is"));
|
|
4370
|
-
}
|
|
4371
|
-
return ok(renderNamespaceMigration(attempt.outcome));
|
|
4372
|
-
}
|
|
4373
4133
|
if (input === "doctor" || input === "doctor --json") {
|
|
4374
4134
|
const mountedForDoctor = presetProfileTarget(ctx);
|
|
4375
4135
|
const mounted = mountedForDoctor === void 0 ? {} : { mounted: {
|
|
@@ -4467,52 +4227,6 @@ function apply(ctx, rawConfig = {}) {
|
|
|
4467
4227
|
* each of them is what kept this path on `standard` while the installer knew
|
|
4468
4228
|
* `ptc` too. Fails loud: a missing table is an incomplete install, never a
|
|
4469
4229
|
* silent fallback to the default base. */
|
|
4470
|
-
function readAgentPresetBases(source) {
|
|
4471
|
-
const path = join(source, "bases.json");
|
|
4472
|
-
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
4473
|
-
if (!Array.isArray(parsed.bases) || parsed.bases.length === 0) throw new Error(`${path} carries no bases[]`);
|
|
4474
|
-
const entries = parsed.bases.map((raw) => {
|
|
4475
|
-
const entry = raw;
|
|
4476
|
-
if (typeof entry.name !== "string" || typeof entry.id !== "string") throw new Error(`${path} entry ${JSON.stringify(raw)} needs name/id strings`);
|
|
4477
|
-
const display = entry.display;
|
|
4478
|
-
if (display === null || typeof display !== "object" || typeof display.name !== "string" || display.name === "" || typeof display.description !== "string" || display.description === "" || typeof display.order !== "number" || !Number.isInteger(display.order)) throw new Error(`${path} entry "${entry.name}" needs display { name, description, order }`);
|
|
4479
|
-
const requires = entry.requires;
|
|
4480
|
-
if (requires !== void 0 && (requires === null || typeof requires !== "object" || typeof requires.service !== "string")) throw new Error(`${path} entry "${entry.name}" needs requires.service as a string`);
|
|
4481
|
-
if (entry.unsupported !== void 0 && (typeof entry.unsupported !== "string" || entry.unsupported === "")) throw new Error(`${path} entry "${entry.name}" needs unsupported as a non-empty reason string`);
|
|
4482
|
-
return {
|
|
4483
|
-
name: entry.name,
|
|
4484
|
-
id: entry.id,
|
|
4485
|
-
display: {
|
|
4486
|
-
name: display.name,
|
|
4487
|
-
description: display.description,
|
|
4488
|
-
order: display.order
|
|
4489
|
-
},
|
|
4490
|
-
...requires === void 0 ? {} : { requires: { service: requires.service } },
|
|
4491
|
-
...entry.unsupported === void 0 ? {} : { unsupported: entry.unsupported }
|
|
4492
|
-
};
|
|
4493
|
-
});
|
|
4494
|
-
const declared = parsed.default;
|
|
4495
|
-
if (typeof declared !== "string" || !entries.some((entry) => entry.name === declared)) throw new Error(`${path} default ${JSON.stringify(declared)} is not one of ${entries.map((entry) => entry.name).join(", ")}`);
|
|
4496
|
-
return {
|
|
4497
|
-
defaultBase: declared,
|
|
4498
|
-
entries
|
|
4499
|
-
};
|
|
4500
|
-
}
|
|
4501
|
-
function resolveAgentPresetDir(importMetaUrl) {
|
|
4502
|
-
const overlayCandidate = join(dirname(fileURLToPath(importMetaUrl)), "..", "..", "evolution-agent");
|
|
4503
|
-
if (existsSync(join(overlayCandidate, "agent.cordis.yml")) && existsSync(join(overlayCandidate, "bases.json"))) return overlayCandidate;
|
|
4504
|
-
try {
|
|
4505
|
-
const agentPresetPackage = scopedPackageName("dsh-evolution-agent-preset", importMetaUrl);
|
|
4506
|
-
return dirname(createRequire(importMetaUrl).resolve(agentPresetPackage + "/package.json"));
|
|
4507
|
-
} catch {
|
|
4508
|
-
return overlayCandidate;
|
|
4509
|
-
}
|
|
4510
|
-
}
|
|
4511
|
-
/** F-328: render staged args for `pending --detail`, truncated to 500 chars.
|
|
4512
|
-
* args may be non-JSON (a tool produced garbage), so the render is fail-safe.
|
|
4513
|
-
* V4-19: a truncation is marked with `…(truncated N chars)` so the operator is
|
|
4514
|
-
* never silently shown a partial JSON payload that could even split an escape
|
|
4515
|
-
* sequence — the marker makes the cut explicit rather than looking complete. */
|
|
4516
4230
|
function safeStagedArgs(args) {
|
|
4517
4231
|
try {
|
|
4518
4232
|
const json = JSON.stringify(args);
|
package/lib/types/doctor.d.ts
CHANGED
|
@@ -94,7 +94,6 @@ export interface DoctorReport {
|
|
|
94
94
|
* list is what makes that difference visible instead of mysterious. */
|
|
95
95
|
foreignProfiles: string[];
|
|
96
96
|
conflicts: string[];
|
|
97
|
-
envIssues: string[];
|
|
98
97
|
/** S4/P-1+P-2 (platform gap, family mitigation): the session-query corpus
|
|
99
98
|
* listing failed — reported verbatim, with the isolation recipe. Empty when the
|
|
100
99
|
* service is absent or answering. */
|
package/lib/types/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { Context, Volatile } from '@deepseek-ai/cordis';
|
|
6
6
|
import z from '@deepseek-ai/schemastery';
|
|
7
|
-
import type { ContextFormed } from '@
|
|
7
|
+
import type { ContextFormed } from '@lmzhen/dsh-evolution-core/platform';
|
|
8
8
|
declare module '@deepseek-ai/dsh-llm' {
|
|
9
9
|
interface MessageSourceMap {
|
|
10
10
|
'evolution-commands': {
|
package/lib/types/parse.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* This parser is order- and `=`-tolerant, matches the subcommand name case-insensitively, keeps a flag
|
|
10
10
|
* VALUE's case intact (the domain layer is the one that validates it), and answers a SYNTAX failure when a
|
|
11
|
-
* declared value flag is left without its value (F-3: `
|
|
11
|
+
* declared value flag is left without its value (F-3: `extract --start 3` must not read
|
|
12
12
|
* `--expect 3` as the value).
|
|
13
13
|
*
|
|
14
14
|
* @module @lmzhen/dsh-evolution-commands/parse
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-commands",
|
|
3
3
|
"description": "Human commands for the evolution family (/evolution pending|curator|maintain|doctor) (community build)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.43.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@deepseek-ai/schemastery": "^3.18.5",
|
|
30
|
-
"@lmzhen/dsh-evolution-approval": "^0.
|
|
31
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
32
|
-
"@lmzhen/dsh-evolution-maintenance": "^0.
|
|
33
|
-
"@lmzhen/dsh-evolution-state-storage": "^0.
|
|
30
|
+
"@lmzhen/dsh-evolution-approval": "^0.43.0",
|
|
31
|
+
"@lmzhen/dsh-evolution-core": "^0.43.0",
|
|
32
|
+
"@lmzhen/dsh-evolution-maintenance": "^0.43.0",
|
|
33
|
+
"@lmzhen/dsh-evolution-state-storage": "^0.43.0"
|
|
34
34
|
},
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@lmzhen/dsh-evolution-agent-preset": "^0.
|
|
36
|
+
"@lmzhen/dsh-evolution-agent-preset": "^0.43.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@deepseek-ai/cordis": "^4.0.5",
|