@lmzhen/dsh-evolution-commands 0.39.2 → 0.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +75 -51
  2. package/package.json +6 -6
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
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, MAINTAINER_PRESET_ID, MAX_TIMER_DELAY_MS, PARAM_EXPOSURE, PARAM_GROUP_LABELS, PARAM_NAMESPACES, PLATFORM_LINE, REVIEWER_PRESET_ID, absentHostServices, appendEvolutionEvent, applyNamespaceMigration, asRecord, assertSkillsRootAliasRetired, atomicWriteFiles, authorityFrom, buildExtractPlanFromLibrary, buildLearnPrompt, canonicalWriteId, clampedNumber, classifyNamespaceMigration, classifySessionEvent, createSubagentChannel, elapsedSince, errorText, eventsFile, evolutionHome, evolutionRoot, hostSurface, isDeprecatedParamId, isPresent, isRecord, isUnknown, liveBool, newRunRegistry, newSkillLibrary, ownerDecisionText, paramSettingsId, partitionVersions, planNamespaceMigration, policyStageLimits, probeMtime, probeText, proposalFromPlan, registerOwnerSettings, reportsSweepLockTarget, resolveParamId, resolveRootConfig, scopedPackageName, scopedProbeReport, sweepReports, transactIo, unwrapLive, writeProposalReport } from "@lmzhen/dsh-evolution-core";
2
+ import { DEFAULT_SKILL_LIMITS, DIAGNOSTICS_FACT_KEYS, DIAGNOSTICS_RUNTIME_KEYS, DIAGNOSTICS_VIEW_SCHEMA_VERSION, EVOLUTION_PRESET_IDS, MAINTAINER_PRESET_ID, MAX_TIMER_DELAY_MS, PARAM_EXPOSURE, PARAM_GROUP_LABELS, PARAM_NAMESPACES, PLATFORM_LINE, REVIEWER_PRESET_ID, absentHostServices, appendEvolutionEvent, applyNamespaceMigration, asRecord, assertSkillsRootAliasRetired, atomicWriteFiles, authorityFrom, buildExtractPlanFromLibrary, buildLearnPrompt, canonicalWriteId, clampedNumber, classifyNamespaceMigration, classifySessionEvent, createSubagentChannel, elapsedSince, errorText, eventsFile, evolutionHome, evolutionRoot, hostSurface, isDeprecatedParamId, isPresent, isRecord, isUnknown, liveBool, mutationLockFrom, newRunRegistry, newSkillLibrary, ownerDecisionText, paramSettingsId, partitionVersions, planNamespaceMigration, policyStageLimits, probeMtime, probeText, proposalFromPlan, readProposalReport, registerOwnerSettings, reportsSweepLockTarget, resolveParamId, resolveRootConfig, 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";
@@ -2608,30 +2608,34 @@ async function syncRuns(registry) {
2608
2608
  };
2609
2609
  }
2610
2610
  }
2611
- async function writeMaintainReport(io, record, warn, evolutionHomePath) {
2611
+ async function writeMaintainReport(io, record, warn, evolutionHomePath, fence) {
2612
2612
  const dir = join(evolutionHomePath, "reports");
2613
2613
  const path = join(dir, `maintain-${record.runId}.json`);
2614
2614
  let written = true;
2615
- try {
2616
- await io.writeText(path, JSON.stringify(record, null, 2));
2617
- await io.writeText(join(dir, `maintain-${record.runId}.md`), record.text.trim() === "" ? `Maintenance run ${record.runId}: ${record.failure ?? "no plan"}\n` : record.text);
2618
- } catch (error) {
2619
- written = false;
2620
- warn(`evolution-commands: could not write the report for run ${record.runId} (${error instanceof Error ? error.message : String(error)}) — that run will answer "no result"`);
2621
- }
2622
- await transactIo(io, reportsSweepLockTarget(), async () => {
2623
- await sweepReports({
2624
- io,
2625
- dir,
2626
- buckets: [{
2627
- prefix: "maintain-",
2628
- keep: 20
2629
- }],
2630
- owner: "evolution-commands",
2631
- warn
2615
+ const body = async () => {
2616
+ try {
2617
+ await io.writeText(path, JSON.stringify(record, null, 2));
2618
+ await io.writeText(join(dir, `maintain-${record.runId}.md`), record.text.trim() === "" ? `Maintenance run ${record.runId}: ${record.failure ?? "no plan"}\n` : record.text);
2619
+ } catch (error) {
2620
+ written = false;
2621
+ warn(`evolution-commands: could not write the report for run ${record.runId} (${error instanceof Error ? error.message : String(error)}) — that run will answer "no result"`);
2622
+ }
2623
+ await transactIo(io, reportsSweepLockTarget(), async () => {
2624
+ await sweepReports({
2625
+ io,
2626
+ dir,
2627
+ buckets: [{
2628
+ prefix: "maintain-",
2629
+ keep: 20
2630
+ }],
2631
+ owner: "evolution-commands",
2632
+ warn
2633
+ });
2634
+ return null;
2632
2635
  });
2633
- return null;
2634
- });
2636
+ };
2637
+ if (fence !== void 0) await fence.run(body);
2638
+ else await body();
2635
2639
  return written ? path : void 0;
2636
2640
  }
2637
2641
  /** Three-state read of a run's result: present, missing, or unreadable (never collapsed). */
@@ -2676,7 +2680,8 @@ function apply(ctx, rawConfig = {}) {
2676
2680
  home: evolutionHome(),
2677
2681
  warn: (message) => {
2678
2682
  ctx.logger.warn(message);
2679
- }
2683
+ },
2684
+ ...ctx.get("evolutionMutationAuthority")?.homeFence === void 0 ? {} : { fence: ctx.get("evolutionMutationAuthority").homeFence }
2680
2685
  });
2681
2686
  runs = registry;
2682
2687
  registry.load().then((loaded) => {
@@ -3004,7 +3009,8 @@ function apply(ctx, rawConfig = {}) {
3004
3009
  const library = newSkillLibrary({
3005
3010
  authority: authorityFrom({ origin: "foreground" }),
3006
3011
  config: { root: skillsRootValue },
3007
- io: ioRegistry.provider()
3012
+ io: ioRegistry.provider(),
3013
+ ...mutationLockFrom(ctx) === void 0 ? {} : { mutationLock: mutationLockFrom(ctx) }
3008
3014
  });
3009
3015
  const enrichment = await buildEnrichment(ctx, library);
3010
3016
  const readFailures = [];
@@ -3057,7 +3063,8 @@ function apply(ctx, rawConfig = {}) {
3057
3063
  const library = newSkillLibrary({
3058
3064
  authority: authorityFrom({ origin: "foreground" }),
3059
3065
  config: { root: skillsRootValue },
3060
- io: ioRegistry.provider()
3066
+ io: ioRegistry.provider(),
3067
+ ...mutationLockFrom(ctx) === void 0 ? {} : { mutationLock: mutationLockFrom(ctx) }
3061
3068
  });
3062
3069
  const enrichment = await buildEnrichment(ctx, library);
3063
3070
  const outcome = await runMaintain({
@@ -3094,7 +3101,7 @@ function apply(ctx, rawConfig = {}) {
3094
3101
  text: outcome.text ?? ""
3095
3102
  }, (message) => {
3096
3103
  ctx.logger.warn(message);
3097
- }, runHome);
3104
+ }, runHome, ctx.get("evolutionMutationAuthority")?.homeFence);
3098
3105
  if (resultRef !== void 0) {
3099
3106
  if (!isPresent(await probeMtime(ioRegistry.provider(), resultRef))) {
3100
3107
  await registry.settle(handle.id, {
@@ -3347,20 +3354,48 @@ function apply(ctx, rawConfig = {}) {
3347
3354
  }
3348
3355
  if (input.startsWith("extract ")) {
3349
3356
  const extractParsed = parseSubcommand(rawInputTrimmed);
3350
- if (isParseFailure(extractParsed) || extractParsed.name !== "extract") return err("用法:/evolution extract <source> <target> \"<heading>\" [--start <line>] [--end <line>] [--owner-covers]");
3357
+ if (isParseFailure(extractParsed) || extractParsed.name !== "extract") return err("用法:/evolution extract <source> <target> \"<heading>\" [--start <line>] [--end <line>] [--owner-covers] 或 --proposal <id>");
3351
3358
  const source = extractParsed.positionals[0] ?? "";
3352
- const target = extractParsed.positionals[1] ?? "";
3353
- const heading = extractParsed.positionals[2] ?? "";
3354
- if (source === "" || target === "" || heading === "") return err("用法:/evolution extract <source> <target> \"<heading>\" [--start <line>] [--end <line>]");
3355
- const startFlag = extractParsed.flags.get("start");
3356
- const endFlag = extractParsed.flags.get("end");
3359
+ const proposalFlag = extractParsed.flags.get("proposal");
3360
+ const ioRegistry = ctx.get("evolutionIo");
3361
+ if (!ioRegistry) return err("未挂载 evolution-io 注册表:无法执行 extract。");
3362
+ let target = extractParsed.positionals[1] ?? "";
3363
+ let heading = extractParsed.positionals[2] ?? "";
3364
+ let start;
3365
+ let end;
3366
+ let extractItems = [];
3367
+ let proposalOutcome;
3368
+ if (typeof proposalFlag === "string") {
3369
+ if (source === "") return err("用法:/evolution extract <source> --proposal <id>");
3370
+ const proposal = await readProposalReport(ioRegistry.provider(), proposalFlag);
3371
+ if (proposal === null) return err("找不到 extract proposal:" + proposalFlag);
3372
+ if (proposal.outcome === "keep") return err("该 proposal 的结论是 keep,没有可应用提取。");
3373
+ if (proposal.owner.mode !== "covered" || proposal.owner.name === void 0) return err("该 proposal 未覆盖 owner(owner-gap),不能应用。");
3374
+ target = proposal.owner.name;
3375
+ heading = proposal.parts[0]?.heading ?? "";
3376
+ proposalOutcome = proposal.outcome === "extract" || proposal.outcome === "mixed" ? proposal.outcome : void 0;
3377
+ extractItems = proposal.parts.map((part) => ({
3378
+ heading: part.heading,
3379
+ ...part.anchor.start === void 0 ? {} : { start: part.anchor.start },
3380
+ ...part.anchor.end === void 0 ? {} : { end: part.anchor.end },
3381
+ to_skill: target
3382
+ }));
3383
+ } else {
3384
+ if (source === "" || target === "" || heading === "") return err("用法:/evolution extract <source> <target> \"<heading>\" [--start <line>] [--end <line>]");
3385
+ const startFlag = extractParsed.flags.get("start");
3386
+ const endFlag = extractParsed.flags.get("end");
3387
+ start = typeof startFlag === "string" ? startFlag : void 0;
3388
+ end = typeof endFlag === "string" ? endFlag : void 0;
3389
+ extractItems = [{
3390
+ heading,
3391
+ ...start === void 0 ? {} : { start },
3392
+ ...end === void 0 ? {} : { end },
3393
+ to_skill: target
3394
+ }];
3395
+ }
3357
3396
  const ownerCovers = extractParsed.flags.has("owner-covers");
3358
3397
  const outcomeFlag = extractParsed.flags.get("outcome");
3359
3398
  if (outcomeFlag !== void 0 && outcomeFlag !== "extract" && outcomeFlag !== "mixed") return err("--outcome 只能是 extract 或 mixed。");
3360
- const start = typeof startFlag === "string" ? startFlag : void 0;
3361
- const end = typeof endFlag === "string" ? endFlag : void 0;
3362
- const ioRegistry = ctx.get("evolutionIo");
3363
- if (!ioRegistry) return err("未挂载 evolution-io 注册表:无法执行 extract。");
3364
3399
  const library = newSkillLibrary({
3365
3400
  authority: authorityFrom({ origin: "foreground" }),
3366
3401
  config: { root: skillsRootValue },
@@ -3374,13 +3409,8 @@ function apply(ctx, rawConfig = {}) {
3374
3409
  });
3375
3410
  const built = await buildExtractPlanFromLibrary(library, {
3376
3411
  source,
3377
- items: [{
3378
- heading,
3379
- ...start === void 0 ? {} : { start },
3380
- ...end === void 0 ? {} : { end },
3381
- to_skill: target
3382
- }],
3383
- ...outcomeFlag === void 0 ? {} : { outcome: outcomeFlag },
3412
+ items: extractItems,
3413
+ ...outcomeFlag === void 0 ? proposalOutcome === void 0 ? {} : { outcome: proposalOutcome } : { outcome: outcomeFlag },
3384
3414
  ...ownerCovers ? { ownerCovers: true } : {}
3385
3415
  });
3386
3416
  if (!built.ok) return err(built.message);
@@ -3388,9 +3418,8 @@ function apply(ctx, rawConfig = {}) {
3388
3418
  const warnings = built.warnings === void 0 || built.warnings.length === 0 ? "" : "\n" + built.warnings.join("\n");
3389
3419
  if (!extractParsed.flags.has("apply")) {
3390
3420
  const proposal = proposalFromPlan(plan, { runId: "cli-" + Date.now().toString(36) });
3391
- const io = ctx.get("evolutionIo")?.provider();
3392
- if (io !== void 0) await writeProposalReport(io, proposal).catch(() => {});
3393
- return ok("提取计划(未写入;默认 plan,--apply 才写):" + plan.parts.map((part) => "## " + part.heading).join(", ") + " -> " + target + "\n提取判定:outcome=" + plan.outcome + ";target=" + target + ";owner=" + ownerDecisionText(plan.owner) + warnings);
3421
+ const proposalPath = await writeProposalReport(ioRegistry.provider(), proposal).catch(() => {});
3422
+ return ok("提取计划(未写入;默认 plan,--apply 才写):" + plan.parts.map((part) => "## " + part.heading).join(", ") + " -> " + target + "\n提取判定:outcome=" + plan.outcome + ";target=" + target + ";owner=" + ownerDecisionText(plan.owner) + warnings + "\nproposal_id: " + proposal.id + (proposalPath === void 0 ? "" : "(已写入 reports)"));
3394
3423
  }
3395
3424
  if (approval) {
3396
3425
  const session = invocationAgent?.session;
@@ -3405,12 +3434,7 @@ function apply(ctx, rawConfig = {}) {
3405
3434
  operation: {
3406
3435
  action: "extract",
3407
3436
  name: source,
3408
- extract: [{
3409
- heading,
3410
- ...start === void 0 ? {} : { start },
3411
- ...end === void 0 ? {} : { end },
3412
- to_skill: target
3413
- }]
3437
+ extract: extractItems
3414
3438
  },
3415
3439
  origin: "foreground",
3416
3440
  libraryOrigin: "foreground"
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.39.2",
4
+ "version": "0.40.1",
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.39.2",
31
- "@lmzhen/dsh-evolution-core": "^0.39.2",
32
- "@lmzhen/dsh-evolution-maintenance": "^0.39.2",
33
- "@lmzhen/dsh-evolution-state-storage": "^0.39.2"
30
+ "@lmzhen/dsh-evolution-approval": "^0.40.1",
31
+ "@lmzhen/dsh-evolution-core": "^0.40.1",
32
+ "@lmzhen/dsh-evolution-maintenance": "^0.40.1",
33
+ "@lmzhen/dsh-evolution-state-storage": "^0.40.1"
34
34
  },
35
35
  "optionalDependencies": {
36
- "@lmzhen/dsh-evolution-agent-preset": "^0.39.2"
36
+ "@lmzhen/dsh-evolution-agent-preset": "^0.40.1"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@deepseek-ai/cordis": "^4.0.5",