@lmzhen/dsh-evolution-core 0.46.0 → 0.48.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.
Files changed (101) hide show
  1. package/lib/authority-plugin.js +1 -1
  2. package/lib/composition/index.js +3 -3
  3. package/lib/{composition-Da8NfRI7.js → composition-Cqjbho0t.js} +1 -1
  4. package/lib/{ensure-C5Mo1dbB.js → ensure-CAjLGd9f.js} +1 -2
  5. package/lib/http-routes.js +21 -96
  6. package/lib/index.js +47 -246
  7. package/lib/{io-AmUf4lVY.js → io-GxghO3Ip.js} +30 -70
  8. package/lib/io-node.js +1 -1
  9. package/lib/io-registry.js +1 -35
  10. package/lib/{mutation-authority-DeJ_Wz14.js → mutation-authority-l57R626O.js} +17 -15
  11. package/lib/{mutations-DwvbjRHF.js → mutations-DQXddSJd.js} +1 -1
  12. package/lib/{numeric-DLeLvvGb.js → numeric-D8js3sqC.js} +1 -5
  13. package/lib/platform/index.js +1 -1
  14. package/lib/{platform-CFA12Jam.js → platform-Cc9cNt5j.js} +4 -28
  15. package/lib/policy.js +1 -1
  16. package/lib/runtime/plugin.js +21 -43
  17. package/lib/{session-projection-EB7mUOlJ.js → session-projection-DSXnUNZG.js} +3 -21
  18. package/lib/{skill-health-D1pZGk5V.js → skill-health-DP8z9TPf.js} +4 -25
  19. package/lib/{skill-history-CjypdYqv.js → skill-history-CxrDE3Rb.js} +54 -102
  20. package/lib/skills.js +166 -184
  21. package/lib/subagent/index.js +4 -10
  22. package/lib/types/authority.d.ts +2 -0
  23. package/lib/types/authority.js +5 -0
  24. package/lib/types/composition/preset-ids.d.ts +0 -1
  25. package/lib/types/composition/preset-ids.js +0 -1
  26. package/lib/types/constants.d.ts +0 -4
  27. package/lib/types/constants.js +0 -4
  28. package/lib/types/contract.d.ts +0 -5
  29. package/lib/types/curator.d.ts +0 -1
  30. package/lib/types/curator.js +0 -1
  31. package/lib/types/document-body.d.ts +0 -12
  32. package/lib/types/document-body.js +0 -14
  33. package/lib/types/health-baseline.d.ts +0 -13
  34. package/lib/types/health-baseline.js +0 -20
  35. package/lib/types/home-fence.d.ts +2 -0
  36. package/lib/types/home-fence.js +11 -1
  37. package/lib/types/http-routes.d.ts +9 -4
  38. package/lib/types/http-routes.js +36 -116
  39. package/lib/types/index.d.ts +0 -3
  40. package/lib/types/index.js +0 -3
  41. package/lib/types/io-registry.d.ts +0 -16
  42. package/lib/types/io-registry.js +0 -27
  43. package/lib/types/io.d.ts +6 -54
  44. package/lib/types/io.js +35 -65
  45. package/lib/types/journal-protocol.d.ts +0 -15
  46. package/lib/types/journal-protocol.js +1 -19
  47. package/lib/types/lease-store.d.ts +1 -1
  48. package/lib/types/lease-store.js +4 -15
  49. package/lib/types/live.d.ts +0 -12
  50. package/lib/types/live.js +0 -18
  51. package/lib/types/memory-store.d.ts +0 -1
  52. package/lib/types/memory-store.js +13 -6
  53. package/lib/types/mutation-authority.js +5 -0
  54. package/lib/types/mutation-unit.d.ts +1 -1
  55. package/lib/types/mutation-unit.js +14 -31
  56. package/lib/types/params.d.ts +11 -29
  57. package/lib/types/params.js +13 -60
  58. package/lib/types/platform/llm.d.ts +2 -3
  59. package/lib/types/platform/llm.js +3 -10
  60. package/lib/types/platform/projections.d.ts +4 -5
  61. package/lib/types/platform/projections.js +4 -18
  62. package/lib/types/probe.d.ts +0 -3
  63. package/lib/types/probe.js +0 -7
  64. package/lib/types/run-registry.js +10 -12
  65. package/lib/types/runtime/llm.js +2 -2
  66. package/lib/types/runtime/platform.d.ts +7 -11
  67. package/lib/types/runtime/platform.js +13 -19
  68. package/lib/types/runtime/plugin.d.ts +1 -1
  69. package/lib/types/runtime/plugin.js +6 -4
  70. package/lib/types/runtime/projections.js +1 -2
  71. package/lib/types/session-fold.d.ts +0 -8
  72. package/lib/types/session-fold.js +0 -5
  73. package/lib/types/session-projection.js +2 -2
  74. package/lib/types/skill-discovery.d.ts +0 -2
  75. package/lib/types/skill-discovery.js +1 -2
  76. package/lib/types/skill-health.d.ts +29 -1
  77. package/lib/types/skill-history.d.ts +0 -24
  78. package/lib/types/skill-history.js +0 -41
  79. package/lib/types/skill-lint.d.ts +0 -3
  80. package/lib/types/skill-lint.js +0 -12
  81. package/lib/types/skill-store.d.ts +6 -0
  82. package/lib/types/skill-store.js +130 -142
  83. package/lib/types/subagent/readiness.d.ts +0 -1
  84. package/lib/types/subagent/readiness.js +2 -8
  85. package/lib/types/tool-dispatch.d.ts +1 -16
  86. package/lib/types/tool-dispatch.js +0 -18
  87. package/lib/types/unit-journal.d.ts +1 -1
  88. package/lib/types/unit-journal.js +20 -15
  89. package/lib/types/unit-storage.d.ts +1 -1
  90. package/lib/types/unit-storage.js +5 -16
  91. package/lib/types/write-inventory.d.ts +0 -4
  92. package/lib/types/write-inventory.js +0 -9
  93. package/lib/types/write-kernel.d.ts +3 -4
  94. package/lib/types/write-kernel.js +13 -25
  95. package/lib/write.js +2 -2
  96. package/package.json +1 -1
  97. package/persisted-write-inventory.json +72 -9
  98. package/lib/types/fold-untrusted.d.ts +0 -35
  99. package/lib/types/fold-untrusted.js +0 -44
  100. package/lib/types/unit-recovery.d.ts +0 -5
  101. package/lib/types/unit-recovery.js +0 -12
package/lib/skills.js CHANGED
@@ -1,10 +1,10 @@
1
- import { C as probeUnknown, S as probeText, _ as probeAbsent, a as nodeEvolutionIo, b as probePresent, f as isAbsent, h as isUnknown, m as isPresent, r as isCommittedWarning, s as transactIo, v as probeList, x as probeReason, y as probeMtime } from "./io-AmUf4lVY.js";
2
- import { l as evolutionRoot, n as mutationLockFrom } from "./mutation-authority-DeJ_Wz14.js";
3
- import { q as resolveCitations } from "./session-projection-EB7mUOlJ.js";
4
- import { X as SKILL_NAME_RE, Z as SUPPORT_DIRS, a as DEFAULT_SKILL_LIMITS, c as policyStageLimits, d as CONTENT_SPLIT_HINT, i as DEFAULT_REFERENCE_REWRITE_POLICY, n as DEFAULT_ARCHIVE_RETENTION_POLICY, o as DEFAULT_SUPPORT_FILE_CHAR_POLICY, q as PROTECTED_BUILTIN_SKILLS, r as DEFAULT_CITATION_POLICY, s as POLICY_STAGE_DEFAULTS } from "./numeric-DLeLvvGb.js";
5
- import { At as normalizeFrontmatter, Bt as describeReferenceRewrite, D as appendEvolutionEvent, Dt as exceedsContentLimit, Et as ensureSkillFrontmatter, F as RULES, Ft as validateFrontmatter, Gt as isUnreadWrite, Ht as planRehoming, I as countReferenceFiles, It as yamlPlainScalarNeedsQuotes, Kt as sessionReadSkillNames, L as diffFindings, Mt as relatedSkillNames, Nt as shrinksOverLimit, O as eventsFile, Ot as frontmatterBlock, Pt as skillMdOnDisk, R as lintSkill, Rt as supportRefs, S as trimPatternBoundaries, Tt as authoringFeedback, Ut as READ_REQUIRED_ACTIONS, Vt as planReferenceRewrite, Wt as filterUnreadSkillOps, Xt as authorityFrom, a as lintBody, bt as selectSections, ct as loadUsage, gt as usageFile, h as scanContentThreats, i as assessStructureHealth, it as getRecord, jt as parseFrontmatter, kt as frontmatterCatalogInvalid, l as isReviewChannelSession, mt as suppressedFile, n as HEALTH_STAMP_RE, o as currentReviewContext, qt as sessionReadSupportFiles, r as MIN_STAMP_BODY_CHARS, t as DEFAULT_HEALTH_THRESHOLDS, ut as mutateUsage, v as makeSerialQueue, x as fuzzyPatch, yt as projectExtractBodies, zt as applyReferenceRewrite } from "./skill-health-D1pZGk5V.js";
6
- import { i as loadMutations, o as recordMutation, r as contentHash } from "./mutations-DwvbjRHF.js";
7
- import { A as unitJournalPort, C as readHistoryIndex, D as versionSummaryPrompt, E as versionActionKind, O as versionTarget, S as partitionVersions, T as textDiffFacts, _ as loadVersions, a as RETENTION_FEEDBACK_MIN_CHARS, b as orderVersions, c as VERSION_SUMMARY_MAX_CHARS, d as elapsedSince, et as MutationUnit, f as entryTarget, g as loadVersionContent, h as latestVersionAt, i as RETENTION_FEEDBACK_KEEP_RATIO, j as unitSnapshotPort, k as pruneTreeChangeUnits, l as blobPath, m as historyRoot, n as HISTORY_DIR, o as TEXT_DIFF_MAX_CHARS, p as historyIndexFile, r as HISTORY_INDEX_VERSION, s as TEXT_DIFF_MAX_LINES, t as BASELINE_ACTION, tt as fileMutationLock, u as contentRetentionFeedback, v as nextHistoryIndex, w as recordVersions, x as parseHistoryIndex, y as normalizeVersionSummary } from "./skill-history-CjypdYqv.js";
1
+ import { _ as probeMtime, b as probeText, c as transactIo, d as isAbsent, g as probeList, h as probeAbsent, i as isCommittedWarning, m as isUnknown, o as nodeEvolutionIo, p as isPresent, t as TransactionNotInvokedError, v as probePresent, x as probeUnknown, y as probeReason } from "./io-GxghO3Ip.js";
2
+ import { l as evolutionRoot, n as mutationLockFrom } from "./mutation-authority-l57R626O.js";
3
+ import { G as resolveCitations } from "./session-projection-DSXnUNZG.js";
4
+ import { K as SKILL_NAME_RE, U as PROTECTED_BUILTIN_SKILLS, a as DEFAULT_SKILL_LIMITS, c as policyStageLimits, d as CONTENT_SPLIT_HINT, i as DEFAULT_REFERENCE_REWRITE_POLICY, n as DEFAULT_ARCHIVE_RETENTION_POLICY, o as DEFAULT_SUPPORT_FILE_CHAR_POLICY, q as SUPPORT_DIRS, r as DEFAULT_CITATION_POLICY, s as POLICY_STAGE_DEFAULTS } from "./numeric-D8js3sqC.js";
5
+ import { At as relatedSkillNames, Bt as planRehoming, Ct as authoringFeedback, D as appendEvolutionEvent, Dt as frontmatterCatalogInvalid, Et as frontmatterBlock, F as RULES, Gt as sessionReadSupportFiles, Ht as filterUnreadSkillOps, I as diffFindings, It as supportRefs, Jt as authorityFrom, L as lintSkill, Lt as applyReferenceRewrite, Mt as skillMdOnDisk, Nt as validateFrontmatter, O as eventsFile, Ot as normalizeFrontmatter, Pt as yamlPlainScalarNeedsQuotes, Rt as describeReferenceRewrite, S as trimPatternBoundaries, Tt as exceedsContentLimit, Ut as isUnreadWrite, Vt as READ_REQUIRED_ACTIONS, Wt as sessionReadSkillNames, a as lintBody, h as scanContentThreats, ht as usageFile, i as assessStructureHealth, jt as shrinksOverLimit, kt as parseFrontmatter, l as isReviewChannelSession, lt as mutateUsage, n as HEALTH_STAMP_RE, o as currentReviewContext, pt as suppressedFile, r as MIN_STAMP_BODY_CHARS, rt as getRecord, st as loadUsage, t as DEFAULT_HEALTH_THRESHOLDS, v as makeSerialQueue, vt as projectExtractBodies, wt as ensureSkillFrontmatter, x as fuzzyPatch, yt as selectSections, zt as planReferenceRewrite } from "./skill-health-DP8z9TPf.js";
6
+ import { i as loadMutations, o as recordMutation, r as contentHash } from "./mutations-DQXddSJd.js";
7
+ import { C as textDiffFacts, D as unitJournalPort, E as pruneTreeChangeUnits, O as unitSnapshotPort, Q as fileMutationLock, S as recordVersions, T as versionTarget, Z as MutationUnit, _ as nextHistoryIndex, a as RETENTION_FEEDBACK_MIN_CHARS, b as partitionVersions, c as blobPath, d as entryTarget, f as historyIndexFile, g as loadVersions, h as loadVersionContent, i as RETENTION_FEEDBACK_KEEP_RATIO, l as contentRetentionFeedback, m as latestVersionAt, n as HISTORY_DIR, o as TEXT_DIFF_MAX_CHARS, p as historyRoot, r as HISTORY_INDEX_VERSION, s as TEXT_DIFF_MAX_LINES, t as BASELINE_ACTION, u as elapsedSince, v as orderVersions, w as versionActionKind, x as readHistoryIndex, y as parseHistoryIndex } from "./skill-history-CxrDE3Rb.js";
8
8
  import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
9
9
  //#region lib/types/skill-row-cells.js
10
10
  /**
@@ -759,10 +759,7 @@ var SkillLibrary = class {
759
759
  this.authority = authority;
760
760
  this.mutationLock = mutationLock;
761
761
  this.fence = fence;
762
- this.transact = transact ?? (io.transact ? (ioLike, path, task) => {
763
- const t = ioLike.transact;
764
- return t ? t(path, task) : transactIo(ioLike, path, task);
765
- } : void 0);
762
+ this.transact = transact ?? (io.transact ? transactIo : void 0);
766
763
  this.serial = serialForRoot(this.root);
767
764
  this.model = new SkillModel({
768
765
  list: async (query) => await this.list(query),
@@ -807,6 +804,56 @@ var SkillLibrary = class {
807
804
  await lease.release();
808
805
  }
809
806
  }
807
+ /** The one MutationUnit constructor: storage ports are fixed here, callers pass the rest. */
808
+ commitUnit(options) {
809
+ return new MutationUnit({
810
+ io: this.io,
811
+ journal: unitJournalPort(this.io, dirname(this.root)),
812
+ snapshots: unitSnapshotPort(this.io, dirname(this.root)),
813
+ ...options
814
+ });
815
+ }
816
+ /** The one frontmatter pipeline for create/update/patch; patch keeps its cap checks outside. */
817
+ prepareBody(content, name, current, mode) {
818
+ const validation = validateFrontmatter(content, name, this.limits, current ?? void 0);
819
+ if (validation) return {
820
+ ok: false,
821
+ message: validation,
822
+ validation: true
823
+ };
824
+ const norm = normalizeFrontmatter(content);
825
+ if (norm.issues.length > 0) {
826
+ const issue = norm.issues[0];
827
+ return {
828
+ ok: false,
829
+ message: mode === "skill" ? `技能「${name}」的 frontmatter 无法自动修复:${issue}:请用双引号包住取值后重试。` : `frontmatter 无法自动修复(${issue})。`,
830
+ validation: false
831
+ };
832
+ }
833
+ const body = norm.changed ? norm.content : content;
834
+ if (norm.changed) {
835
+ const revalidated = validateFrontmatter(body, name, this.limits, current ?? void 0);
836
+ if (revalidated) return {
837
+ ok: false,
838
+ message: revalidated,
839
+ validation: false
840
+ };
841
+ }
842
+ if (mode === "skill") {
843
+ const threat = this.contentThreatBlock(body);
844
+ if (threat) return {
845
+ ok: false,
846
+ message: threat,
847
+ validation: false
848
+ };
849
+ }
850
+ return {
851
+ ok: true,
852
+ body,
853
+ onDisk: body.trimEnd() + "\n",
854
+ norm
855
+ };
856
+ }
810
857
  lockPort() {
811
858
  if (this.mutationLock !== void 0) return this.mutationLock;
812
859
  if (process.env["VITEST"] === "true" || process.env["NODE_ENV"] === "test") return fileMutationLock(this.io, this.root);
@@ -827,16 +874,13 @@ var SkillLibrary = class {
827
874
  /** Recover every prepared tree-change snapshot in the shared unit store. */
828
875
  async recoverPreparedUnits() {
829
876
  const home = dirname(this.root);
830
- const results = await new MutationUnit({
831
- io: this.io,
877
+ const results = await this.commitUnit({
832
878
  limits: {
833
879
  maxSkillFileBytes: this.limits.maxSkillFileBytes,
834
880
  maxSkillContentChars: this.limits.maxSkillContentChars
835
881
  },
836
882
  serial: this.serial,
837
- lock: this.lockPort(),
838
- journal: unitJournalPort(this.io, home),
839
- snapshots: unitSnapshotPort(this.io, home)
883
+ lock: this.lockPort()
840
884
  }).recoverPrepared();
841
885
  await pruneTreeChangeUnits(this.io, home).catch(() => {});
842
886
  return results;
@@ -1292,7 +1336,7 @@ var SkillLibrary = class {
1292
1336
  }
1293
1337
  }
1294
1338
  /** S2: mechanical hard-cap event; failure must not change the refusal. */
1295
- async recordHardCapHit(name, bodyChars, source, supportFiles = null) {
1339
+ async recordHardCapHit(name, bodyChars, source, supportFiles = null, fenceHeld = false) {
1296
1340
  try {
1297
1341
  await appendEvolutionEvent(this.io, eventsFile(dirname(this.root)), {
1298
1342
  type: "hard-cap",
@@ -1301,7 +1345,7 @@ var SkillLibrary = class {
1301
1345
  supportFiles,
1302
1346
  restructureRounds: 0,
1303
1347
  source
1304
- }, void 0, this.fence);
1348
+ }, void 0, fenceHeld ? void 0 : this.fence);
1305
1349
  } catch (error) {
1306
1350
  console.warn("skill-store: hard-cap event not recorded for \"" + name + "\": " + (error instanceof Error ? error.message : String(error)));
1307
1351
  }
@@ -1313,7 +1357,8 @@ var SkillLibrary = class {
1313
1357
  * mutation ledger that points at it. The history failure is not silent — a deployment whose
1314
1358
  * history stopped growing is a degradation worth seeing once (the ledger keeps hashes either
1315
1359
  * way). */
1316
- async audit(skillName, action, before, after, summary, path, unitId, unitHead, origin) {
1360
+ async audit(skillName, action, before, after, summary, path, unitId, unitHead, origin, fenceHeld = false) {
1361
+ const fence = fenceHeld ? void 0 : this.fence;
1317
1362
  const at = (/* @__PURE__ */ new Date()).toISOString();
1318
1363
  let versions = null;
1319
1364
  try {
@@ -1328,7 +1373,7 @@ var SkillLibrary = class {
1328
1373
  ...unitId === void 0 ? {} : { unitId },
1329
1374
  ...unitHead === void 0 ? {} : { unitHead }
1330
1375
  };
1331
- versions = await recordVersions(this.root, this.io, input, keep, this.fence);
1376
+ versions = await recordVersions(this.root, this.io, input, keep, fence);
1332
1377
  } catch (error) {
1333
1378
  if (!this.historyWarned) {
1334
1379
  this.historyWarned = true;
@@ -1358,7 +1403,7 @@ var SkillLibrary = class {
1358
1403
  summary: summary + healthNote + danglingNote,
1359
1404
  at,
1360
1405
  ...origin === void 0 ? {} : { origin }
1361
- }, void 0, this.fence);
1406
+ }, void 0, fence);
1362
1407
  } catch {}
1363
1408
  }
1364
1409
  /** Recent mutation audit records (read-only inspection surface). */
@@ -1508,40 +1553,23 @@ var SkillLibrary = class {
1508
1553
  async create(name, content, origin = this.authority.origin, options = {}) {
1509
1554
  await this.ensureRecovered();
1510
1555
  const normalized = name.trim();
1511
- return await this.serial(() => this.withMutationLock(() => this.createCore(normalized, content, origin, options)));
1556
+ return await this.serial(() => this.withMutationLock(() => this.createCore(normalized, content, origin, options, true)));
1512
1557
  }
1513
- async createCore(normalized, content, origin, options = {}) {
1558
+ async createCore(normalized, content, origin, options = {}, fenceHeld = false) {
1514
1559
  const bad = this.badName(normalized);
1515
1560
  if (bad) return {
1516
1561
  ok: false,
1517
1562
  message: bad
1518
1563
  };
1519
- const validation = validateFrontmatter(content, normalized, this.limits);
1520
- if (validation) {
1521
- if (exceedsContentLimit(content, this.limits.maxSkillContentChars)) await this.recordHardCapHit(normalized, content.length, "create");
1564
+ const prepared = this.prepareBody(content, normalized, null, "skill");
1565
+ if (!prepared.ok) {
1566
+ if (prepared.validation && exceedsContentLimit(content, this.limits.maxSkillContentChars)) await this.recordHardCapHit(normalized, content.length, "create", null, fenceHeld);
1522
1567
  return {
1523
1568
  ok: false,
1524
- message: validation
1569
+ message: prepared.message
1525
1570
  };
1526
1571
  }
1527
- const norm = normalizeFrontmatter(content);
1528
- if (norm.issues.length > 0) return {
1529
- ok: false,
1530
- message: `技能「${normalized}」的 frontmatter 无法自动修复:${norm.issues[0]}:请用双引号包住取值后重试。`
1531
- };
1532
- const finalContent = norm.changed ? norm.content : content;
1533
- if (norm.changed) {
1534
- const revalidated = validateFrontmatter(finalContent, normalized, this.limits);
1535
- if (revalidated) return {
1536
- ok: false,
1537
- message: revalidated
1538
- };
1539
- }
1540
- const threat = this.contentThreatBlock(finalContent);
1541
- if (threat) return {
1542
- ok: false,
1543
- message: threat
1544
- };
1572
+ const { onDisk, norm } = prepared;
1545
1573
  const dir = this.dirOf(normalized);
1546
1574
  if (await this.io.exists(join(dir, "SKILL.md"))) return {
1547
1575
  ok: false,
@@ -1566,17 +1594,13 @@ var SkillLibrary = class {
1566
1594
  ok: false,
1567
1595
  message: `技能「${normalized}」受保护(${protection})。`
1568
1596
  };
1569
- const onDisk = finalContent.trimEnd() + "\n";
1570
1597
  const createPath = join(dir, "SKILL.md");
1571
- const result = await new MutationUnit({
1572
- io: this.io,
1598
+ const result = await this.commitUnit({
1573
1599
  limits: {
1574
1600
  maxSkillFileBytes: Number.MAX_SAFE_INTEGER,
1575
1601
  maxSkillContentChars: Number.MAX_SAFE_INTEGER
1576
1602
  },
1577
1603
  nested: true,
1578
- journal: unitJournalPort(this.io, dirname(this.root)),
1579
- snapshots: unitSnapshotPort(this.io, dirname(this.root)),
1580
1604
  transactGuard: false,
1581
1605
  hooks: { undone: async () => {
1582
1606
  await this.io.remove(markerPath(dir, "hermes-managed")).catch(() => {});
@@ -1630,7 +1654,7 @@ var SkillLibrary = class {
1630
1654
  };
1631
1655
  }
1632
1656
  }
1633
- await this.audit(normalized, "create", null, onDisk, "created", void 0, result.unitId, options.unitHead);
1657
+ await this.audit(normalized, "create", null, onDisk, "created", void 0, result.unitId, options.unitHead, void 0, fenceHeld);
1634
1658
  this.notifyMutation({
1635
1659
  action: "create",
1636
1660
  name: normalized,
@@ -1665,32 +1689,14 @@ var SkillLibrary = class {
1665
1689
  const limitProbe = await probeText(this.io, path);
1666
1690
  if (isUnknown(limitProbe)) console.warn(`skill-store: could not re-read ${path} for the shrink exemption (${limitProbe.reason}); validating without it — an over-limit repair is refused, not accepted`);
1667
1691
  const currentForLimit = isPresent(limitProbe) ? limitProbe.value : null;
1668
- const validation = validateFrontmatter(content, name, this.limits, currentForLimit);
1669
- if (validation) {
1670
- if (exceedsContentLimit(content, this.limits.maxSkillContentChars)) await this.recordHardCapHit(name, content.length, "update");
1692
+ const prepared = this.prepareBody(content, name, currentForLimit, "skill");
1693
+ if (!prepared.ok) {
1694
+ if (prepared.validation && exceedsContentLimit(content, this.limits.maxSkillContentChars)) await this.recordHardCapHit(name, content.length, "update");
1671
1695
  return {
1672
1696
  ok: false,
1673
- message: validation
1674
- };
1675
- }
1676
- const norm = normalizeFrontmatter(content);
1677
- if (norm.issues.length > 0) return {
1678
- ok: false,
1679
- message: `技能「${name}」的 frontmatter 无法自动修复:${norm.issues[0]}:请用双引号包住取值后重试。`
1680
- };
1681
- const finalContent = norm.changed ? norm.content : content;
1682
- if (norm.changed) {
1683
- const revalidated = validateFrontmatter(finalContent, name, this.limits, currentForLimit);
1684
- if (revalidated) return {
1685
- ok: false,
1686
- message: revalidated
1697
+ message: prepared.message
1687
1698
  };
1688
1699
  }
1689
- const threat = this.contentThreatBlock(finalContent);
1690
- if (threat) return {
1691
- ok: false,
1692
- message: threat
1693
- };
1694
1700
  let current;
1695
1701
  try {
1696
1702
  current = await this.io.readText(path);
@@ -1706,27 +1712,24 @@ var SkillLibrary = class {
1706
1712
  message: `技能「${name}」不存在。`
1707
1713
  };
1708
1714
  }
1709
- if (finalContent.trimEnd() === current.trimEnd()) return {
1715
+ if (prepared.body.trimEnd() === current.trimEnd()) return {
1710
1716
  ok: true,
1711
1717
  message: `技能「${name}」未变更:提供的内容与当前文件一致,未写入。`,
1712
1718
  noop: true,
1713
1719
  path: dir
1714
1720
  };
1715
- const onDisk = finalContent.trimEnd() + "\n";
1716
- const result = await new MutationUnit({
1717
- io: this.io,
1721
+ const onDisk = prepared.onDisk;
1722
+ const result = await this.commitUnit({
1718
1723
  limits: {
1719
1724
  maxSkillFileBytes: Number.MAX_SAFE_INTEGER,
1720
1725
  maxSkillContentChars: Number.MAX_SAFE_INTEGER
1721
1726
  },
1722
1727
  lock: this.lockPort(),
1723
- journal: unitJournalPort(this.io, dirname(this.root)),
1724
- snapshots: unitSnapshotPort(this.io, dirname(this.root)),
1725
1728
  ...this.transact === void 0 ? {} : { transact: this.transact },
1726
1729
  hooks: { committed: async (event) => {
1727
1730
  const op = event.ops[0];
1728
1731
  if (op === void 0) return;
1729
- await this.audit(name, "update", op.before, op.after, "updated", void 0, event.unitId, { sources: [{ skill: name }] }, origin);
1732
+ await this.audit(name, "update", op.before, op.after, "updated", void 0, event.unitId, { sources: [{ skill: name }] }, origin, true);
1730
1733
  this.notifyMutation({
1731
1734
  action: "update",
1732
1735
  name,
@@ -1755,7 +1758,7 @@ var SkillLibrary = class {
1755
1758
  });
1756
1759
  if (!result.ok) {
1757
1760
  const messages = result.errors.map((error) => error.message);
1758
- if (messages.some((message) => message.includes("mutation-lock-transact-not-run") || message.includes("did not invoke the task"))) return {
1761
+ if (result.errors.some((error) => error.code === "transact-not-invoked")) return {
1759
1762
  ok: false,
1760
1763
  message: "内部错误:写事务没有调用任务;未执行任何写入"
1761
1764
  };
@@ -1775,7 +1778,7 @@ var SkillLibrary = class {
1775
1778
  ok: true,
1776
1779
  message: `技能「${name}」已更新。${warning}${retention === null ? "" : "\n" + retention}`,
1777
1780
  path: dir,
1778
- ...norm.changed ? { normalizedFrontmatterFields: norm.fields } : {}
1781
+ ...prepared.norm.changed ? { normalizedFrontmatterFields: prepared.norm.fields } : {}
1779
1782
  };
1780
1783
  }
1781
1784
  async patch(rawName, oldString, newString, filePath = "", replaceAll = false, origin = this.authority.origin) {
@@ -1847,34 +1850,16 @@ var SkillLibrary = class {
1847
1850
  let writeContent = patched;
1848
1851
  let normalizedFields;
1849
1852
  if (target === skillMd) {
1850
- const validation = validateFrontmatter(patched, name, this.limits, md);
1851
- if (validation) return {
1852
- result: {
1853
- ok: false,
1854
- message: `补丁被拒绝:${validation}`
1855
- },
1856
- write: null
1857
- };
1858
- const norm = normalizeFrontmatter(patched);
1859
- if (norm.issues.length > 0) return {
1853
+ const prepared = this.prepareBody(patched, name, md, "patch");
1854
+ if (!prepared.ok) return {
1860
1855
  result: {
1861
1856
  ok: false,
1862
- message: `补丁被拒绝:frontmatter 无法自动修复(${norm.issues[0]})。`
1857
+ message: `补丁被拒绝:${prepared.message}`
1863
1858
  },
1864
1859
  write: null
1865
1860
  };
1866
- if (norm.changed) {
1867
- writeContent = norm.content;
1868
- normalizedFields = norm.fields;
1869
- const revalidated = validateFrontmatter(writeContent, name, this.limits, md);
1870
- if (revalidated) return {
1871
- result: {
1872
- ok: false,
1873
- message: `补丁被拒绝:${revalidated}`
1874
- },
1875
- write: null
1876
- };
1877
- }
1861
+ writeContent = prepared.body;
1862
+ if (prepared.norm.changed) normalizedFields = prepared.norm.fields;
1878
1863
  }
1879
1864
  if (Buffer.byteLength(writeContent, "utf8") > this.limits.maxSkillFileBytes && target !== skillMd) return {
1880
1865
  result: {
@@ -1968,18 +1953,15 @@ var SkillLibrary = class {
1968
1953
  return outcome.result;
1969
1954
  }
1970
1955
  const onDisk = outcome.write;
1971
- const result = await new MutationUnit({
1972
- io: this.io,
1956
+ const result = await this.commitUnit({
1973
1957
  limits: {
1974
1958
  maxSkillFileBytes: Number.MAX_SAFE_INTEGER,
1975
1959
  maxSkillContentChars: Number.MAX_SAFE_INTEGER
1976
1960
  },
1977
1961
  lock: this.lockPort(),
1978
- journal: unitJournalPort(this.io, dirname(this.root)),
1979
- snapshots: unitSnapshotPort(this.io, dirname(this.root)),
1980
1962
  ...this.transact === void 0 ? {} : { transact: this.transact },
1981
1963
  hooks: { committed: async (event) => {
1982
- await this.audit(name, "patch", outcome.audit?.before ?? current, event.ops[0]?.after ?? onDisk, outcome.audit?.summary ?? `patched ${patchLabel}`, filePath === "" ? void 0 : filePath, event.unitId, { sources: [{ skill: name }] }, origin);
1964
+ await this.audit(name, "patch", outcome.audit?.before ?? current, event.ops[0]?.after ?? onDisk, outcome.audit?.summary ?? `patched ${patchLabel}`, filePath === "" ? void 0 : filePath, event.unitId, { sources: [{ skill: name }] }, origin, true);
1983
1965
  this.notifyMutation({
1984
1966
  action: "patch",
1985
1967
  name,
@@ -2008,7 +1990,7 @@ var SkillLibrary = class {
2008
1990
  });
2009
1991
  if (!result.ok) {
2010
1992
  const messages = result.errors.map((error) => error.message);
2011
- if (messages.some((message) => message.includes("mutation-lock-transact-not-run") || message.includes("did not invoke the task"))) return {
1993
+ if (result.errors.some((error) => error.code === "transact-not-invoked")) return {
2012
1994
  ok: false,
2013
1995
  message: "内部错误:写事务没有调用任务;未执行任何写入"
2014
1996
  };
@@ -2101,6 +2083,9 @@ var SkillLibrary = class {
2101
2083
  } catch {}
2102
2084
  }
2103
2085
  async archive(rawName, options = {}, origin = this.authority.origin) {
2086
+ return await this.archiveCore(rawName, options, origin, false);
2087
+ }
2088
+ async archiveCore(rawName, options, origin, fenceHeld) {
2104
2089
  const name = rawName.trim();
2105
2090
  const badName = this.badName(name, { allowReserved: true });
2106
2091
  if (badName) return {
@@ -2167,7 +2152,7 @@ var SkillLibrary = class {
2167
2152
  try {
2168
2153
  await this.io.writeText(join(dest, ".archive-name"), `${name}\n`);
2169
2154
  } catch {}
2170
- await this.audit(name, "archive", md, null, reason, void 0, options.unitId, options.unitHead, origin);
2155
+ await this.audit(name, "archive", md, null, reason, void 0, options.unitId, options.unitHead, origin, fenceHeld);
2171
2156
  this.notifyMutation({
2172
2157
  action: "archive",
2173
2158
  name,
@@ -2217,6 +2202,8 @@ var SkillLibrary = class {
2217
2202
  };
2218
2203
  const limits = plan.limits ?? this.limits;
2219
2204
  const run = async () => {
2205
+ const fenceHeld = plan.nested === true;
2206
+ const archive = (name, archiveOptions) => fenceHeld ? this.archiveCore(name, archiveOptions, plan.origin, true) : this.archive(name, archiveOptions, plan.origin);
2220
2207
  const dir = this.dirOf(target);
2221
2208
  const targetPath = join(dir, "SKILL.md");
2222
2209
  if (!plan.targetExists && await this.io.exists(dir)) return {
@@ -2355,7 +2342,7 @@ var SkillLibrary = class {
2355
2342
  const rollbackSources = async () => {
2356
2343
  const stuck = [];
2357
2344
  for (const source of [...archived].reverse()) try {
2358
- if (!(await this.restoreFromArchive(source, plan.origin)).ok) stuck.push(source);
2345
+ if (!(fenceHeld ? await this.restoreFromArchiveCore(source, plan.origin, true) : await this.restoreFromArchive(source, plan.origin)).ok) stuck.push(source);
2359
2346
  } catch {
2360
2347
  stuck.push(source);
2361
2348
  }
@@ -2447,12 +2434,12 @@ var SkillLibrary = class {
2447
2434
  message: "tree fence lost before source archive; recovery required"
2448
2435
  };
2449
2436
  await plan.onPhase?.("source-archiving", { source });
2450
- const archivedResult = await this.archive(source, {
2437
+ const archivedResult = await archive(source, {
2451
2438
  absorbedInto: target,
2452
2439
  unitId,
2453
2440
  unitHead: { skill: target },
2454
2441
  reason: `Merged into ${target}`
2455
- }, plan.origin);
2442
+ });
2456
2443
  if (!archivedResult.ok) {
2457
2444
  const stuck = await rollbackSources();
2458
2445
  stuck.push(...await rollbackTarget());
@@ -2481,23 +2468,23 @@ var SkillLibrary = class {
2481
2468
  unitId,
2482
2469
  unitHead,
2483
2470
  managed: true
2484
- });
2471
+ }, fenceHeld);
2485
2472
  if (!created.ok) return {
2486
2473
  ok: false,
2487
2474
  message: created.message
2488
2475
  };
2489
2476
  await plan.onPhase?.("target-applied");
2490
2477
  await plan.onPhase?.("target-written");
2491
- if (plan.signal?.aborted) return rollbackMessage("cancelled before sources archived", (await this.archive(target, { reason: "merge cancelled" }, plan.origin)).ok ? [] : [target]);
2478
+ if (plan.signal?.aborted) return rollbackMessage("cancelled before sources archived", (await archive(target, { reason: "merge cancelled" })).ok ? [] : [target]);
2492
2479
  for (const source of sources) {
2493
2480
  if (plan.signal?.aborted) {
2494
2481
  const stuck = await rollbackSources();
2495
- if (!(await this.archive(target, { reason: "merge cancelled" }, plan.origin)).ok) stuck.push(target);
2482
+ if (!(await archive(target, { reason: "merge cancelled" })).ok) stuck.push(target);
2496
2483
  return rollbackMessage("cancelled before next source archive", stuck);
2497
2484
  }
2498
2485
  if (await this.io.readText(join(this.dirOf(source), "SKILL.md")) !== sourceBodies.get(source)) {
2499
2486
  const stuck = await rollbackSources();
2500
- if (!(await this.archive(target, { reason: "merge rolled back" }, plan.origin)).ok) stuck.push(target);
2487
+ if (!(await archive(target, { reason: "merge rolled back" })).ok) stuck.push(target);
2501
2488
  return rollbackMessage(`来源技能「${source}」在归档前被改过`, stuck);
2502
2489
  }
2503
2490
  if (plan.assertFence !== void 0 && !await plan.assertFence()) return {
@@ -2505,15 +2492,15 @@ var SkillLibrary = class {
2505
2492
  message: "tree fence lost before source archive; recovery required"
2506
2493
  };
2507
2494
  await plan.onPhase?.("source-archiving", { source });
2508
- const result = await this.archive(source, {
2495
+ const result = await archive(source, {
2509
2496
  absorbedInto: target,
2510
2497
  unitId,
2511
2498
  unitHead: { skill: target },
2512
2499
  reason: `Merged into ${target}`
2513
- }, plan.origin);
2500
+ });
2514
2501
  if (!result.ok) {
2515
2502
  const stuck = await rollbackSources();
2516
- if (!(await this.archive(target, { reason: "merge rolled back" }, plan.origin)).ok) stuck.push(target);
2503
+ if (!(await archive(target, { reason: "merge rolled back" })).ok) stuck.push(target);
2517
2504
  return rollbackMessage(result.message, stuck);
2518
2505
  }
2519
2506
  archived.push(source);
@@ -2543,7 +2530,7 @@ var SkillLibrary = class {
2543
2530
  });
2544
2531
  if (!result.ok) {
2545
2532
  const stuck = await rollbackSources();
2546
- if (!(await this.archive(target, { reason: "merge rolled back" }, plan.origin)).ok) stuck.push(target);
2533
+ if (!(await archive(target, { reason: "merge rolled back" })).ok) stuck.push(target);
2547
2534
  return rollbackMessage(result.message, stuck);
2548
2535
  }
2549
2536
  }
@@ -2964,31 +2951,26 @@ var SkillLibrary = class {
2964
2951
  ...write.expected === void 0 ? {} : { expected: write.expected },
2965
2952
  skill: name
2966
2953
  }));
2967
- const hooks = { committed: async (event) => {
2968
- let headPlaced = false;
2969
- for (const op of event.ops) {
2970
- const rel = relative(dir, op.target).split(String.fromCharCode(92)).join("/");
2971
- await this.audit(name, "restructure", op.before, op.after, summary, rel === "SKILL.md" ? void 0 : rel, event.unitId, headPlaced ? void 0 : this.unitHeadForOps(event.ops, [name]), origin);
2972
- headPlaced = true;
2973
- }
2974
- this.notifyMutation({
2975
- action: "restructure",
2976
- name,
2977
- skillDir: dir
2978
- });
2979
- } };
2980
- const home = dirname(this.root);
2981
- const result = await new MutationUnit({
2982
- io: this.io,
2954
+ const result = await this.commitUnit({
2983
2955
  limits: {
2984
2956
  maxSkillFileBytes: this.limits.maxSkillFileBytes,
2985
2957
  maxSkillContentChars: this.limits.maxSkillContentChars
2986
2958
  },
2987
2959
  serial: this.serial,
2988
2960
  lock: this.lockPort(),
2989
- journal: unitJournalPort(this.io, home),
2990
- snapshots: unitSnapshotPort(this.io, home),
2991
- hooks,
2961
+ hooks: { committed: async (event) => {
2962
+ let headPlaced = false;
2963
+ for (const op of event.ops) {
2964
+ const rel = relative(dir, op.target).split(String.fromCharCode(92)).join("/");
2965
+ await this.audit(name, "restructure", op.before, op.after, summary, rel === "SKILL.md" ? void 0 : rel, event.unitId, headPlaced ? void 0 : this.unitHeadForOps(event.ops, [name]), origin, true);
2966
+ headPlaced = true;
2967
+ }
2968
+ this.notifyMutation({
2969
+ action: "restructure",
2970
+ name,
2971
+ skillDir: dir
2972
+ });
2973
+ } },
2992
2974
  validateWrite: (op) => op.kind === "write" ? this.contentThreatBlock(op.content) : null
2993
2975
  }).apply({
2994
2976
  name,
@@ -3162,35 +3144,30 @@ var SkillLibrary = class {
3162
3144
  }
3163
3145
  const summary = "extract " + plan.parts.map((part) => part.heading).join(", ") + " from " + source + " to " + target;
3164
3146
  const roots = [source, target];
3165
- const hooks = { committed: async (event) => {
3166
- const provenance = /* @__PURE__ */ new Map();
3167
- for (const move of [...plan.support.shared, ...plan.support.external]) provenance.set(join(targetDir, ...move.to.split("/")), move.provenance);
3168
- const head = this.unitHeadForOps(event.ops, roots, provenance);
3169
- let headPlaced = false;
3170
- for (const op of event.ops) {
3171
- if (op.skill === void 0) continue;
3172
- const rel = relative(this.dirOf(op.skill), op.target).split(String.fromCharCode(92)).join("/");
3173
- await this.audit(op.skill, "extract", op.before, op.after, summary, rel === "SKILL.md" ? void 0 : rel, event.unitId, headPlaced ? void 0 : head, origin);
3174
- headPlaced = true;
3175
- }
3176
- for (const name of roots) this.notifyMutation({
3177
- action: "extract",
3178
- name,
3179
- skillDir: this.dirOf(name)
3180
- });
3181
- } };
3182
- const home = dirname(this.root);
3183
- const result = await new MutationUnit({
3184
- io: this.io,
3147
+ const result = await this.commitUnit({
3185
3148
  limits: {
3186
3149
  maxSkillFileBytes: this.limits.maxSkillFileBytes,
3187
3150
  maxSkillContentChars: this.limits.maxSkillContentChars
3188
3151
  },
3189
3152
  serial: this.serial,
3190
3153
  lock: this.lockPort(),
3191
- journal: unitJournalPort(this.io, home),
3192
- snapshots: unitSnapshotPort(this.io, home),
3193
- hooks,
3154
+ hooks: { committed: async (event) => {
3155
+ const provenance = /* @__PURE__ */ new Map();
3156
+ for (const move of [...plan.support.shared, ...plan.support.external]) provenance.set(join(targetDir, ...move.to.split("/")), move.provenance);
3157
+ const head = this.unitHeadForOps(event.ops, roots, provenance);
3158
+ let headPlaced = false;
3159
+ for (const op of event.ops) {
3160
+ if (op.skill === void 0) continue;
3161
+ const rel = relative(this.dirOf(op.skill), op.target).split(String.fromCharCode(92)).join("/");
3162
+ await this.audit(op.skill, "extract", op.before, op.after, summary, rel === "SKILL.md" ? void 0 : rel, event.unitId, headPlaced ? void 0 : head, origin, true);
3163
+ headPlaced = true;
3164
+ }
3165
+ for (const name of roots) this.notifyMutation({
3166
+ action: "extract",
3167
+ name,
3168
+ skillDir: this.dirOf(name)
3169
+ });
3170
+ } },
3194
3171
  validateWrite: (op) => op.kind === "write" ? this.contentThreatBlock(op.content) : null
3195
3172
  }).apply({
3196
3173
  name: source,
@@ -3234,7 +3211,7 @@ var SkillLibrary = class {
3234
3211
  message: badName
3235
3212
  };
3236
3213
  const dir = this.dirOf(name);
3237
- if (!await this.io.readText(join(dir, "SKILL.md"))) return {
3214
+ if (await this.io.readText(join(dir, "SKILL.md")) === null) return {
3238
3215
  ok: false,
3239
3216
  message: "技能「" + name + "」不存在。"
3240
3217
  };
@@ -3316,12 +3293,9 @@ var SkillLibrary = class {
3316
3293
  });
3317
3294
  }
3318
3295
  const unitId = plan.unitId ?? "u-" + Date.now().toString(36) + "-" + (nextUnitSeq += 1).toString(36);
3319
- const applied = await new MutationUnit({
3320
- io: this.io,
3296
+ const applied = await this.commitUnit({
3321
3297
  limits: this.limits,
3322
3298
  ...plan.nested === true ? { nested: true } : { lock: this.lockPort() },
3323
- journal: unitJournalPort(this.io, dirname(this.root)),
3324
- snapshots: unitSnapshotPort(this.io, dirname(this.root)),
3325
3299
  ...this.transact === void 0 ? {} : { transact: this.transact },
3326
3300
  now: () => Date.now()
3327
3301
  }).apply({
@@ -3364,7 +3338,7 @@ var SkillLibrary = class {
3364
3338
  for (let index = 0; index < landing.length; index += 1) {
3365
3339
  const entry = landing[index];
3366
3340
  if (entry === void 0) continue;
3367
- await this.audit(entry.skill, plan.auditAction, entry.previous, entry.kind === "delete" ? null : entry.content, plan.auditSummary, entry.rel === "SKILL.md" ? void 0 : entry.rel, unitId, index === 0 ? plan.unitHead ?? defaultHead : void 0, plan.origin);
3341
+ await this.audit(entry.skill, plan.auditAction, entry.previous, entry.kind === "delete" ? null : entry.content, plan.auditSummary, entry.rel === "SKILL.md" ? void 0 : entry.rel, unitId, index === 0 ? plan.unitHead ?? defaultHead : void 0, plan.origin, plan.nested === true);
3368
3342
  affected.add(entry.skill);
3369
3343
  }
3370
3344
  for (const skill of affected) {
@@ -3389,6 +3363,9 @@ var SkillLibrary = class {
3389
3363
  * path back. The `.archive-reason` marker is dropped on restore.
3390
3364
  */
3391
3365
  async restoreFromArchive(rawName, origin = this.authority.origin) {
3366
+ return await this.restoreFromArchiveCore(rawName, origin, false);
3367
+ }
3368
+ async restoreFromArchiveCore(rawName, origin, fenceHeld) {
3392
3369
  const name = rawName.trim();
3393
3370
  const bad = this.badName(name, { allowReserved: true });
3394
3371
  if (bad) return {
@@ -3476,7 +3453,7 @@ var SkillLibrary = class {
3476
3453
  for (const marker of [".archive-reason", ".archive-name"]) if (await this.io.exists(join(dest, marker))) await this.io.remove(join(dest, marker));
3477
3454
  const restoredProbe = await probeText(this.io, join(dest, "SKILL.md"));
3478
3455
  if (isUnknown(restoredProbe)) console.warn(`evolution-skill-store: the restored SKILL.md of "${name}" could not be read back (${restoredProbe.reason}); the restore is recorded without after-bytes`);
3479
- await this.audit(name, "restore", null, isPresent(restoredProbe) ? restoredProbe.value : null, `restored from ${source}`, void 0, void 0, void 0, origin);
3456
+ await this.audit(name, "restore", null, isPresent(restoredProbe) ? restoredProbe.value : null, `restored from ${source}`, void 0, void 0, void 0, origin, fenceHeld);
3480
3457
  this.notifyMutation({
3481
3458
  action: "restore",
3482
3459
  name,
@@ -3544,21 +3521,18 @@ var SkillLibrary = class {
3544
3521
  noop: true,
3545
3522
  path: target
3546
3523
  };
3547
- const result = await new MutationUnit({
3548
- io: this.io,
3524
+ const result = await this.commitUnit({
3549
3525
  limits: {
3550
3526
  maxSkillFileBytes: Number.MAX_SAFE_INTEGER,
3551
3527
  maxSkillContentChars: Number.MAX_SAFE_INTEGER
3552
3528
  },
3553
3529
  serial: this.serial,
3554
3530
  lock: this.lockPort(),
3555
- journal: unitJournalPort(this.io, dirname(this.root)),
3556
- snapshots: unitSnapshotPort(this.io, dirname(this.root)),
3557
3531
  ...this.transact === void 0 ? {} : { transact: this.transact },
3558
3532
  hooks: { committed: async (event) => {
3559
3533
  const op = event.ops[0];
3560
3534
  if (op === void 0) return;
3561
- await this.audit(name, "write_file", op.before, op.after, `wrote ${filePath}`, filePath, event.unitId, void 0, origin);
3535
+ await this.audit(name, "write_file", op.before, op.after, `wrote ${filePath}`, filePath, event.unitId, void 0, origin, true);
3562
3536
  this.notifyMutation({
3563
3537
  action: "write_file",
3564
3538
  name,
@@ -3641,12 +3615,20 @@ var SkillLibrary = class {
3641
3615
  let lockedBefore = before;
3642
3616
  if (verdict === "match" && this.transact) {
3643
3617
  const ran = { done: false };
3644
- await this.transact(this.io, target, (current) => {
3645
- ran.done = true;
3646
- verdict = anchorVerdict(anchor, current);
3647
- if (verdict === "match" && current !== null) lockedBefore = current;
3648
- return verdict === "match" ? null : current;
3649
- });
3618
+ try {
3619
+ await this.transact(this.io, target, (current) => {
3620
+ ran.done = true;
3621
+ verdict = anchorVerdict(anchor, current);
3622
+ if (verdict === "match" && current !== null) lockedBefore = current;
3623
+ return verdict === "match" ? null : current;
3624
+ });
3625
+ } catch (error) {
3626
+ if (error instanceof TransactionNotInvokedError) return {
3627
+ ok: false,
3628
+ message: "内部错误:删除事务没有调用任务;没有删除任何东西"
3629
+ };
3630
+ throw error;
3631
+ }
3650
3632
  if (!ran.done) return {
3651
3633
  ok: false,
3652
3634
  message: "内部错误:删除事务没有调用任务;没有删除任何东西"
@@ -4067,4 +4049,4 @@ function newSkillLibrary(options) {
4067
4049
  } : void 0, transact, [...threatExemptLabels ?? []], authority, options.mutationLock ?? mutationLockFrom(ctx), options.fence ?? ctx?.get?.("evolutionMutationAuthority")?.homeFence);
4068
4050
  }
4069
4051
  //#endregion
4070
- export { BASELINE_ACTION, DEFAULT_ARCHIVE_RETENTION_POLICY, DEFAULT_CITATION_POLICY, DEFAULT_HEALTH_THRESHOLDS, DEFAULT_REFERENCE_REWRITE_POLICY, DEFAULT_SKILL_LIMITS, DEFAULT_SUPPORT_FILE_CHAR_POLICY, HEALTH_STAMP_RE, HISTORY_DIR, HISTORY_INDEX_VERSION, MAX_RESTRUCTURE_MOVES, MIN_STAMP_BODY_CHARS, POLICY_STAGE_DEFAULTS, READ_REQUIRED_ACTIONS, RESTRUCTURE_TARGET_RE, RETENTION_FEEDBACK_KEEP_RATIO, RETENTION_FEEDBACK_MIN_CHARS, RULES, SNAPSHOT_EXTRA_NAME_RE, SkillLibrary, SkillModel, TEXT_DIFF_MAX_CHARS, TEXT_DIFF_MAX_LINES, VERSION_SUMMARY_MAX_CHARS, ageCopyKey, anchorVerdict, assertSkillsRootAliasRetired, assessStructureHealth, authoringFeedback, blobPath, contentRetentionFeedback, countReferenceFiles, diffFindings, elapsedSince, ensureSkillFrontmatter, entryTarget, exceedsContentLimit, filterUnreadSkillOps, frontmatterBlock, frontmatterCatalogInvalid, historyIndexFile, historyRoot, isUnreadWrite, latestVersionAt, lintBody, lintSkill, loadVersionContent, loadVersions, markerEntryName, newSkillLibrary, nextHistoryIndex, normalizeFrontmatter, normalizeVersionSummary, orderVersions, parseFrontmatter, parseHistoryIndex, partitionVersions, policyStageLimits, readHistoryIndex, recordVersions, relatedSkillNames, resolveExecOrigins, resolveOrigins, resolveRootConfig, resolveSkillsRoot, revisionAnchor, revisionAnchorOf, revisionFingerprint, revisionSupportDigest, sessionReadSkillNames, sessionReadSupportFiles, shrinksOverLimit, skillMdOnDisk, skillRowCells, skillStateKey, skillsRoot, textDiffFacts, validateFrontmatter, validateRestructureTarget, validateSupportPath, versionActionKind, versionRowCells, versionSummaryPrompt, versionTarget, yamlPlainScalarNeedsQuotes };
4052
+ export { BASELINE_ACTION, DEFAULT_ARCHIVE_RETENTION_POLICY, DEFAULT_CITATION_POLICY, DEFAULT_HEALTH_THRESHOLDS, DEFAULT_REFERENCE_REWRITE_POLICY, DEFAULT_SKILL_LIMITS, DEFAULT_SUPPORT_FILE_CHAR_POLICY, HEALTH_STAMP_RE, HISTORY_DIR, HISTORY_INDEX_VERSION, MAX_RESTRUCTURE_MOVES, MIN_STAMP_BODY_CHARS, POLICY_STAGE_DEFAULTS, READ_REQUIRED_ACTIONS, RESTRUCTURE_TARGET_RE, RETENTION_FEEDBACK_KEEP_RATIO, RETENTION_FEEDBACK_MIN_CHARS, RULES, SNAPSHOT_EXTRA_NAME_RE, SkillLibrary, SkillModel, TEXT_DIFF_MAX_CHARS, TEXT_DIFF_MAX_LINES, ageCopyKey, anchorVerdict, assertSkillsRootAliasRetired, assessStructureHealth, authoringFeedback, blobPath, contentRetentionFeedback, diffFindings, elapsedSince, ensureSkillFrontmatter, entryTarget, exceedsContentLimit, filterUnreadSkillOps, frontmatterBlock, frontmatterCatalogInvalid, historyIndexFile, historyRoot, isUnreadWrite, latestVersionAt, lintBody, lintSkill, loadVersionContent, loadVersions, markerEntryName, newSkillLibrary, nextHistoryIndex, normalizeFrontmatter, orderVersions, parseFrontmatter, parseHistoryIndex, partitionVersions, policyStageLimits, readHistoryIndex, recordVersions, relatedSkillNames, resolveExecOrigins, resolveOrigins, resolveRootConfig, resolveSkillsRoot, revisionAnchor, revisionAnchorOf, revisionFingerprint, revisionSupportDigest, sessionReadSkillNames, sessionReadSupportFiles, shrinksOverLimit, skillMdOnDisk, skillRowCells, skillStateKey, skillsRoot, textDiffFacts, validateFrontmatter, validateRestructureTarget, validateSupportPath, versionActionKind, versionRowCells, versionTarget, yamlPlainScalarNeedsQuotes };