@lmzhen/dsh-evolution-core 0.49.0 → 0.51.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/authority-plugin.js +2 -1
- package/lib/citations-CZKTUGQF.js +198 -0
- package/lib/composition/index.js +3 -3
- package/lib/{composition-Cqjbho0t.js → composition-CtNbVHq3.js} +1 -1
- package/lib/connection-DAJy7Xjm.js +28 -0
- package/lib/{ensure-CAjLGd9f.js → ensure-BLmEW0Ju.js} +25 -7
- package/lib/errors.js +2 -0
- package/lib/extract-plan-D6o__2Kf.js +271 -0
- package/lib/extract.js +240 -0
- package/lib/http-routes.js +27 -7
- package/lib/index.js +100 -811
- package/lib/{numeric-D8js3sqC.js → limits-C9jfvxBl.js} +1 -43
- package/lib/{mutation-authority-l57R626O.js → mutation-authority-DQfpXs1O.js} +2 -54
- package/lib/numeric-Dc53KQoe.js +43 -0
- package/lib/platform/index.js +4 -3
- package/lib/platform-DyHnHUmQ.js +251 -0
- package/lib/policy.js +3 -2
- package/lib/quality-DpAS0rd9.js +554 -0
- package/lib/restrictor.js +1 -1
- package/lib/result.js +33 -0
- package/lib/runtime/plugin.js +97 -43
- package/lib/{session-projection-DSXnUNZG.js → session-projection-ByNxQi9O.js} +2 -198
- package/lib/skill-health-BQCM4N8z.js +1419 -0
- package/lib/{skill-history-CxrDE3Rb.js → skill-history-CZp8vhyL.js} +46 -2
- package/lib/skills.js +140 -20
- package/lib/state-store-Jpa-iYIZ.js +54 -0
- package/lib/subagent/index.js +214 -176
- package/lib/{tools-DzcNFex2.js → tools-BrUswg8v.js} +3 -1
- package/lib/types/composition/ensure.js +21 -7
- package/lib/types/composition/preset-ids.d.ts +2 -1
- package/lib/types/composition/preset-ids.js +7 -1
- package/lib/types/events.d.ts +3 -0
- package/lib/types/extract-plan.d.ts +2 -0
- package/lib/types/extract.d.ts +12 -0
- package/lib/types/extract.js +12 -0
- package/lib/types/http-routes.js +32 -9
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -3
- package/lib/types/opt-in.js +4 -3
- package/lib/types/params.js +2 -1
- package/lib/types/platform/agents.d.ts +32 -0
- package/lib/types/platform/agents.js +26 -0
- package/lib/types/platform/commands.d.ts +14 -0
- package/lib/types/platform/commands.js +9 -0
- package/lib/types/platform/connection.d.ts +26 -0
- package/lib/types/platform/connection.js +27 -0
- package/lib/types/platform/index.d.ts +26 -0
- package/lib/types/platform/index.js +13 -0
- package/lib/types/platform/llm.d.ts +3 -1
- package/lib/types/platform/llm.js +1 -0
- package/lib/types/platform/platformView.d.ts +21 -0
- package/lib/types/platform/platformView.js +29 -0
- package/lib/types/platform/profileContext.d.ts +16 -0
- package/lib/types/platform/profileContext.js +14 -0
- package/lib/types/platform/sessionQuery.d.ts +14 -0
- package/lib/types/platform/sessionQuery.js +9 -0
- package/lib/types/platform/settings.d.ts +22 -0
- package/lib/types/platform/settings.js +14 -0
- package/lib/types/platform/skills.d.ts +16 -0
- package/lib/types/platform/skills.js +9 -0
- package/lib/types/platform/storageDomain.d.ts +13 -0
- package/lib/types/platform/storageDomain.js +9 -0
- package/lib/types/platform/subagents.d.ts +25 -0
- package/lib/types/platform/subagents.js +17 -0
- package/lib/types/platform/systemPrompt.d.ts +16 -0
- package/lib/types/platform/systemPrompt.js +13 -0
- package/lib/types/platform/tools.d.ts +4 -0
- package/lib/types/platform/tools.js +2 -0
- package/lib/types/platform/userQuestions.d.ts +33 -0
- package/lib/types/platform/userQuestions.js +9 -0
- package/lib/types/platform/workingDirectory.d.ts +14 -0
- package/lib/types/platform/workingDirectory.js +9 -0
- package/lib/types/platform-line.generated.d.ts +5 -5
- package/lib/types/platform-line.generated.js +5 -5
- package/lib/types/platform-services.js +4 -0
- package/lib/types/prompts.d.ts +9 -8
- package/lib/types/prompts.js +20 -1
- package/lib/types/result.d.ts +35 -0
- package/lib/types/result.js +25 -0
- package/lib/types/review-context.d.ts +8 -0
- package/lib/types/review-context.js +11 -0
- package/lib/types/run-registry.d.ts +2 -1
- package/lib/types/run-registry.js +37 -7
- package/lib/types/runtime/llm.d.ts +2 -2
- package/lib/types/runtime/llm.js +5 -8
- package/lib/types/runtime/platform.d.ts +37 -4
- package/lib/types/runtime/platform.js +40 -5
- package/lib/types/runtime/projections.d.ts +9 -4
- package/lib/types/runtime/projections.js +64 -28
- package/lib/types/section-selection.js +5 -0
- package/lib/types/skill-history.d.ts +29 -3
- package/lib/types/skill-history.js +30 -0
- package/lib/types/skill-store.d.ts +32 -4
- package/lib/types/skill-store.js +109 -15
- package/lib/types/subagent/channel.d.ts +1 -3
- package/lib/types/subagent/channel.js +2 -332
- package/lib/types/subagent/index.d.ts +2 -0
- package/lib/types/subagent/index.js +2 -0
- package/lib/types/subagent/kernel.d.ts +4 -0
- package/lib/types/subagent/kernel.js +234 -0
- package/lib/types/subagent/readiness.js +5 -7
- package/lib/types/subagent/run.d.ts +53 -0
- package/lib/types/subagent/run.js +125 -0
- package/lib/types/subagent/types.d.ts +3 -3
- package/lib/types/write-gates.js +11 -1
- package/lib/usage-B5a90TKv.js +1257 -0
- package/lib/write.js +1 -1
- package/package.json +37 -25
- package/lib/platform-Cc9cNt5j.js +0 -111
- package/lib/skill-health-DP8z9TPf.js +0 -2923
|
@@ -1299,6 +1299,46 @@ const HISTORY_INDEX_VERSION = 1;
|
|
|
1299
1299
|
/** The action label for a predecessor the index had never seen (content found on disk before this
|
|
1300
1300
|
* feature existed, or a hand-edited tree): it says "this is what was there", not what wrote it. */
|
|
1301
1301
|
const BASELINE_ACTION = "baseline";
|
|
1302
|
+
/** Default hard cap for a change summary, counted in Unicode code points. */
|
|
1303
|
+
const DEFAULT_SKILL_WRITE_SUMMARY_CHARS = 50;
|
|
1304
|
+
/** Count a summary the same way the write gate does (code points, not UTF-16 units). */
|
|
1305
|
+
function summaryChars(text) {
|
|
1306
|
+
return [...text].length;
|
|
1307
|
+
}
|
|
1308
|
+
/** Normalize a model-supplied summary: single line, trimmed, non-empty, within the hard cap. */
|
|
1309
|
+
function normalizeChangeSummary(value, cap = 50) {
|
|
1310
|
+
if (typeof value !== "string") return {
|
|
1311
|
+
ok: false,
|
|
1312
|
+
reason: "missing",
|
|
1313
|
+
length: 0
|
|
1314
|
+
};
|
|
1315
|
+
const text = value.replace(/\s+/g, " ").trim();
|
|
1316
|
+
if (text === "") return {
|
|
1317
|
+
ok: false,
|
|
1318
|
+
reason: "missing",
|
|
1319
|
+
length: 0
|
|
1320
|
+
};
|
|
1321
|
+
if (value.includes("\n") || value.includes("\r")) return {
|
|
1322
|
+
ok: false,
|
|
1323
|
+
reason: "multiline",
|
|
1324
|
+
length: summaryChars(text)
|
|
1325
|
+
};
|
|
1326
|
+
const length = summaryChars(text);
|
|
1327
|
+
return length <= cap ? {
|
|
1328
|
+
ok: true,
|
|
1329
|
+
text
|
|
1330
|
+
} : {
|
|
1331
|
+
ok: false,
|
|
1332
|
+
reason: "length",
|
|
1333
|
+
length
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
/** Clip a host-generated summary to the same hard cap; host facts are not rejected. */
|
|
1337
|
+
function clipChangeSummary(text, cap = 50) {
|
|
1338
|
+
const line = text.replace(/\s+/g, " ").trim();
|
|
1339
|
+
const chars = [...line];
|
|
1340
|
+
return chars.length <= cap ? line : chars.slice(0, Math.max(1, cap - 1)).join("") + "…";
|
|
1341
|
+
}
|
|
1302
1342
|
/** The root-level history directory. */
|
|
1303
1343
|
function historyRoot(root) {
|
|
1304
1344
|
return join(root, HISTORY_DIR);
|
|
@@ -1450,6 +1490,7 @@ function readVersionEntry(entry) {
|
|
|
1450
1490
|
if (typeof candidate.action !== "string") return null;
|
|
1451
1491
|
if (typeof candidate.chars !== "number") return null;
|
|
1452
1492
|
const summary = typeof candidate.summary === "string" && candidate.summary !== "" ? candidate.summary : void 0;
|
|
1493
|
+
const summarySource = candidate.summarySource === "model" || candidate.summarySource === "host" || candidate.summarySource === "fallback" ? candidate.summarySource : void 0;
|
|
1453
1494
|
const path = typeof candidate.path === "string" && candidate.path !== "" ? candidate.path : void 0;
|
|
1454
1495
|
const unitId = typeof candidate.unitId === "string" && candidate.unitId !== "" ? candidate.unitId : void 0;
|
|
1455
1496
|
const removed = candidate.removed === true ? true : void 0;
|
|
@@ -1461,6 +1502,7 @@ function readVersionEntry(entry) {
|
|
|
1461
1502
|
hash: candidate.hash,
|
|
1462
1503
|
chars: candidate.chars,
|
|
1463
1504
|
...summary === void 0 ? {} : { summary },
|
|
1505
|
+
...summarySource === void 0 ? {} : { summarySource },
|
|
1464
1506
|
...path === void 0 ? {} : { path },
|
|
1465
1507
|
...unitId === void 0 ? {} : { unitId },
|
|
1466
1508
|
...removed === void 0 ? {} : { removed },
|
|
@@ -1551,6 +1593,7 @@ function nextHistoryIndex(versions, input, keep) {
|
|
|
1551
1593
|
chars: input.after?.length ?? 0,
|
|
1552
1594
|
...pathField,
|
|
1553
1595
|
...input.summary === void 0 ? {} : { summary: input.summary },
|
|
1596
|
+
...input.summarySource === void 0 ? {} : { summarySource: input.summarySource },
|
|
1554
1597
|
...beforeHash === null ? {} : { beforeHash }
|
|
1555
1598
|
});
|
|
1556
1599
|
}
|
|
@@ -1566,7 +1609,8 @@ function nextHistoryIndex(versions, input, keep) {
|
|
|
1566
1609
|
...pathField,
|
|
1567
1610
|
...input.unitId === void 0 ? {} : { unitId: input.unitId },
|
|
1568
1611
|
...input.unitHead === void 0 ? {} : { unitHead: input.unitHead },
|
|
1569
|
-
...input.summary === void 0 ? {} : { summary: input.summary }
|
|
1612
|
+
...input.summary === void 0 ? {} : { summary: input.summary },
|
|
1613
|
+
...input.summarySource === void 0 ? {} : { summarySource: input.summarySource }
|
|
1570
1614
|
});
|
|
1571
1615
|
}
|
|
1572
1616
|
const budget = clampKeep(keep);
|
|
@@ -1862,4 +1906,4 @@ function elapsedSince(at, nowMs) {
|
|
|
1862
1906
|
};
|
|
1863
1907
|
}
|
|
1864
1908
|
//#endregion
|
|
1865
|
-
export {
|
|
1909
|
+
export { writeUnitReceipt as $, pruneTreeChangeUnits as A, UNIT_STORAGE_SCHEMA_VERSION as B, partitionVersions as C, textDiffFacts as D, summaryChars as E, assertUnitJournalTransition as F, unitEvidencePath as G, readUnitIndex as H, readUnitJournal as I, unitSnapshotPath as J, unitIndexPath as K, unitJournalPath as L, unitSnapshotPort as M, UNIT_JOURNAL_PHASES as N, versionActionKind as O, UNIT_JOURNAL_SCHEMA_VERSION as P, writeUnitEvidence as Q, unitJournalPhaseRank as R, parseHistoryIndex as S, recordVersions as T, readUnitReceipt as U, readUnitEvidence as V, readUnitSnapshot as W, unitStorageKey as X, unitSnapshotsDir as Y, upsertUnitIndex as Z, loadVersionContent as _, RETENTION_FEEDBACK_KEEP_RATIO as a, normalizeChangeSummary as b, TEXT_DIFF_MAX_LINES as c, contentRetentionFeedback as d, writeUnitSnapshot as et, elapsedSince as f, latestVersionAt as g, historyRoot as h, HISTORY_INDEX_VERSION as i, WriteKernel as it, unitJournalPort as j, versionTarget as k, blobPath as l, historyIndexFile as m, DEFAULT_SKILL_WRITE_SUMMARY_CHARS as n, fileMutationLock as nt, RETENTION_FEEDBACK_MIN_CHARS as o, entryTarget as p, unitReceiptPath as q, HISTORY_DIR as r, validateMutationRequest as rt, TEXT_DIFF_MAX_CHARS as s, BASELINE_ACTION as t, MutationUnit as tt, clipChangeSummary as u, loadVersions as v, readHistoryIndex as w, orderVersions as x, nextHistoryIndex as y, writeUnitJournal as z };
|
package/lib/skills.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
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 {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { n as mutationLockFrom } from "./mutation-authority-DQfpXs1O.js";
|
|
3
|
+
import { o as resolveCitations } from "./citations-CZKTUGQF.js";
|
|
4
|
+
import { G as SKILL_NAME_RE, H as PROTECTED_BUILTIN_SKILLS, K as SUPPORT_DIRS, a as DEFAULT_SUPPORT_FILE_CHAR_POLICY, i as DEFAULT_SKILL_LIMITS, n as DEFAULT_CITATION_POLICY, o as POLICY_STAGE_DEFAULTS, r as DEFAULT_REFERENCE_REWRITE_POLICY, s as policyStageLimits, t as DEFAULT_ARCHIVE_RETENTION_POLICY, u as CONTENT_SPLIT_HINT } from "./limits-C9jfvxBl.js";
|
|
5
|
+
import { C as trimPatternBoundaries, I as RULES, J as filterUnreadSkillOps, L as diffFindings, O as appendEvolutionEvent, R as lintSkill, S as fuzzyPatch, X as sessionReadSkillNames, Y as isUnreadWrite, Z as sessionReadSupportFiles, a as lintBody, et as authorityFrom, g as scanContentThreats, i as assessStructureHealth, k as eventsFile, n as HEALTH_STAMP_RE, o as currentReviewContext, q as READ_REQUIRED_ACTIONS, r as MIN_STAMP_BODY_CHARS, t as DEFAULT_HEALTH_THRESHOLDS, u as isReviewChannelSession, y as makeSerialQueue } from "./skill-health-BQCM4N8z.js";
|
|
6
|
+
import { A as authoringFeedback, B as validateFrontmatter, E as selectSections, F as normalizeFrontmatter, G as describeReferenceRewrite, I as parseFrontmatter, K as planReferenceRewrite, L as relatedSkillNames, M as exceedsContentLimit, N as frontmatterBlock, P as frontmatterCatalogInvalid, R as shrinksOverLimit, S as suppressedFile, U as supportRefs, V as yamlPlainScalarNeedsQuotes, W as applyReferenceRewrite, f as getRecord, g as loadUsage, j as ensureSkillFrontmatter, q as planRehoming, v as mutateUsage, w as usageFile, z as skillMdOnDisk } from "./usage-B5a90TKv.js";
|
|
7
|
+
import { n as evolutionRoot } from "./state-store-Jpa-iYIZ.js";
|
|
6
8
|
import { i as loadMutations, o as recordMutation, r as contentHash } from "./mutations-DQXddSJd.js";
|
|
7
|
-
import { C as
|
|
9
|
+
import { A as pruneTreeChangeUnits, C as partitionVersions, D as textDiffFacts, E as summaryChars, M as unitSnapshotPort, O as versionActionKind, S as parseHistoryIndex, T as recordVersions, _ as loadVersionContent, a as RETENTION_FEEDBACK_KEEP_RATIO, b as normalizeChangeSummary, c as TEXT_DIFF_MAX_LINES, d as contentRetentionFeedback, f as elapsedSince, g as latestVersionAt, h as historyRoot, i as HISTORY_INDEX_VERSION, j as unitJournalPort, k as versionTarget, l as blobPath, m as historyIndexFile, n as DEFAULT_SKILL_WRITE_SUMMARY_CHARS, nt as fileMutationLock, o as RETENTION_FEEDBACK_MIN_CHARS, p as entryTarget, r as HISTORY_DIR, s as TEXT_DIFF_MAX_CHARS, t as BASELINE_ACTION, tt as MutationUnit, u as clipChangeSummary, v as loadVersions, w as readHistoryIndex, x as orderVersions, y as nextHistoryIndex } from "./skill-history-CZp8vhyL.js";
|
|
10
|
+
import { n as projectExtractBodies } from "./extract-plan-D6o__2Kf.js";
|
|
8
11
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
9
12
|
//#region lib/types/skill-row-cells.js
|
|
10
13
|
/**
|
|
@@ -663,7 +666,11 @@ function validateSupportPath(filePath) {
|
|
|
663
666
|
return null;
|
|
664
667
|
}
|
|
665
668
|
function planRestructureSections(body, moves) {
|
|
666
|
-
const selection = selectSections(body, moves.map((move) => ({
|
|
669
|
+
const selection = selectSections(body, moves.map((move) => ({
|
|
670
|
+
heading: move.heading,
|
|
671
|
+
...move.start === void 0 ? {} : { start: move.start },
|
|
672
|
+
...move.end === void 0 ? {} : { end: move.end }
|
|
673
|
+
})));
|
|
667
674
|
if (!selection.ok) return { error: selection.message };
|
|
668
675
|
const lines = body.split("\n");
|
|
669
676
|
const spans = selection.sections.map((section) => {
|
|
@@ -791,7 +798,9 @@ var SkillLibrary = class {
|
|
|
791
798
|
...provenance.get(op.target) === void 0 ? {} : { provenance: provenance.get(op.target) }
|
|
792
799
|
});
|
|
793
800
|
}
|
|
801
|
+
const runId = currentReviewContext()?.runId;
|
|
794
802
|
return {
|
|
803
|
+
...runId === void 0 ? {} : { runId },
|
|
795
804
|
moves,
|
|
796
805
|
sources: roots.map((skill) => ({ skill }))
|
|
797
806
|
};
|
|
@@ -1350,6 +1359,18 @@ var SkillLibrary = class {
|
|
|
1350
1359
|
console.warn("skill-store: hard-cap event not recorded for \"" + name + "\": " + (error instanceof Error ? error.message : String(error)));
|
|
1351
1360
|
}
|
|
1352
1361
|
}
|
|
1362
|
+
/** Host fallback for the user-facing change summary when the writer did not supply one. */
|
|
1363
|
+
hostChangeSummary(action, before, after, path, machine) {
|
|
1364
|
+
const target = path ?? "SKILL.md";
|
|
1365
|
+
let text = machine;
|
|
1366
|
+
if (action === "update" || action === "edit") text = `updated ${target} (${before?.length ?? 0} → ${after?.length ?? 0})`;
|
|
1367
|
+
else if (action === "create") text = `created ${target} (${after?.length ?? 0})`;
|
|
1368
|
+
else if (action === "patch") text = machine.trim() === "" || machine === "patched" ? `patched ${target}` : machine;
|
|
1369
|
+
return {
|
|
1370
|
+
text: clipChangeSummary(text, 50),
|
|
1371
|
+
source: "host"
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1353
1374
|
/** Best-effort audit trail entry; never blocks the mutation.
|
|
1354
1375
|
*
|
|
1355
1376
|
* Two independent best-effort writes run here, because either one failing must not cost the
|
|
@@ -1357,9 +1378,16 @@ var SkillLibrary = class {
|
|
|
1357
1378
|
* mutation ledger that points at it. The history failure is not silent — a deployment whose
|
|
1358
1379
|
* history stopped growing is a degradation worth seeing once (the ledger keeps hashes either
|
|
1359
1380
|
* way). */
|
|
1360
|
-
async audit(skillName, action, before, after, summary, path, unitId, unitHead, origin, fenceHeld = false) {
|
|
1381
|
+
async audit(skillName, action, before, after, summary, path, unitId, unitHead, origin, fenceHeld = false, change) {
|
|
1361
1382
|
const fence = fenceHeld ? void 0 : this.fence;
|
|
1362
1383
|
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
1384
|
+
const finalSummary = change === void 0 ? this.hostChangeSummary(action, before, after, path, summary) : (() => {
|
|
1385
|
+
const normalized = normalizeChangeSummary(change.text, 50);
|
|
1386
|
+
return normalized.ok ? {
|
|
1387
|
+
text: normalized.text,
|
|
1388
|
+
source: change.source
|
|
1389
|
+
} : this.hostChangeSummary(action, before, after, path, summary);
|
|
1390
|
+
})();
|
|
1363
1391
|
let versions = null;
|
|
1364
1392
|
try {
|
|
1365
1393
|
const keep = this.limits.versionKeep ?? 20;
|
|
@@ -1371,7 +1399,9 @@ var SkillLibrary = class {
|
|
|
1371
1399
|
at,
|
|
1372
1400
|
...path === void 0 ? {} : { path },
|
|
1373
1401
|
...unitId === void 0 ? {} : { unitId },
|
|
1374
|
-
...unitHead === void 0 ? {} : { unitHead }
|
|
1402
|
+
...unitHead === void 0 ? {} : { unitHead },
|
|
1403
|
+
summary: finalSummary.text,
|
|
1404
|
+
summarySource: finalSummary.source
|
|
1375
1405
|
};
|
|
1376
1406
|
versions = await recordVersions(this.root, this.io, input, keep, fence);
|
|
1377
1407
|
} catch (error) {
|
|
@@ -1786,6 +1816,88 @@ var SkillLibrary = class {
|
|
|
1786
1816
|
const name = rawName.trim();
|
|
1787
1817
|
return await this.serial(() => this.patchCore(name, oldString, newString, filePath, replaceAll, origin));
|
|
1788
1818
|
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Replace ONE section's content (or one exact sub-block) in place. Keeps the
|
|
1821
|
+
* H2 heading line for whole-section edits, so a model can compress one
|
|
1822
|
+
* section at a time without re-sending the body. No content-conservation
|
|
1823
|
+
* gate: the version history is the rollback, and existing structural
|
|
1824
|
+
* validation still applies through {@link update}.
|
|
1825
|
+
* @param rawName - skill name.
|
|
1826
|
+
* @param edit - section selector plus replacement text.
|
|
1827
|
+
* @param origin - write face.
|
|
1828
|
+
* @returns the normalized result, with before/after body sizes.
|
|
1829
|
+
*/
|
|
1830
|
+
async patchSection(rawName, edit, origin = this.authority.origin) {
|
|
1831
|
+
await this.ensureRecovered();
|
|
1832
|
+
return await this.patchSectionCore(rawName.trim(), edit, origin);
|
|
1833
|
+
}
|
|
1834
|
+
async patchSectionCore(name, edit, origin) {
|
|
1835
|
+
const badName = this.badName(name);
|
|
1836
|
+
if (badName) return {
|
|
1837
|
+
ok: false,
|
|
1838
|
+
message: badName
|
|
1839
|
+
};
|
|
1840
|
+
if (typeof edit.heading !== "string" || edit.heading.trim() === "") return {
|
|
1841
|
+
ok: false,
|
|
1842
|
+
message: "章节改写需要非空 heading。"
|
|
1843
|
+
};
|
|
1844
|
+
const dir = this.dirOf(name);
|
|
1845
|
+
const path = join(dir, "SKILL.md");
|
|
1846
|
+
let md;
|
|
1847
|
+
try {
|
|
1848
|
+
md = await this.io.readText(path);
|
|
1849
|
+
} catch (error) {
|
|
1850
|
+
return unreadableTarget(name, error);
|
|
1851
|
+
}
|
|
1852
|
+
if (md === null) return {
|
|
1853
|
+
ok: false,
|
|
1854
|
+
message: `技能「${name}」不存在。`
|
|
1855
|
+
};
|
|
1856
|
+
const block = frontmatterBlock(md);
|
|
1857
|
+
if (!block) return {
|
|
1858
|
+
ok: false,
|
|
1859
|
+
message: "SKILL.md 没有有效的 frontmatter;拒绝章节改写。"
|
|
1860
|
+
};
|
|
1861
|
+
const header = block.lines.slice(0, block.end + 1).join("\n");
|
|
1862
|
+
const body = md.slice(header.length).replace(/\r\n/g, "\n");
|
|
1863
|
+
const selection = selectSections(body, [{
|
|
1864
|
+
heading: edit.heading,
|
|
1865
|
+
...edit.start === void 0 ? {} : { start: edit.start },
|
|
1866
|
+
...edit.end === void 0 ? {} : { end: edit.end }
|
|
1867
|
+
}]);
|
|
1868
|
+
if (!selection.ok) return {
|
|
1869
|
+
ok: false,
|
|
1870
|
+
message: `章节改写被拒绝:${selection.message}`
|
|
1871
|
+
};
|
|
1872
|
+
const section = selection.sections[0];
|
|
1873
|
+
if (section === void 0) return {
|
|
1874
|
+
ok: false,
|
|
1875
|
+
message: "章节改写被拒绝:没有匹配的章节。"
|
|
1876
|
+
};
|
|
1877
|
+
const lines = body.split("\n");
|
|
1878
|
+
const start = section.anchorStart === void 0 ? section.start + 1 : section.start;
|
|
1879
|
+
const end = section.end;
|
|
1880
|
+
const replacement = edit.content === "" ? [] : edit.content.replace(/\r\n/g, "\n").split("\n");
|
|
1881
|
+
const next = `${header}${[
|
|
1882
|
+
...lines.slice(0, start),
|
|
1883
|
+
...replacement,
|
|
1884
|
+
...lines.slice(end)
|
|
1885
|
+
].join("\n")}`;
|
|
1886
|
+
const finalMd = block.nl === "\r\n" ? next.replace(/\n/g, "\r\n") : next;
|
|
1887
|
+
if (finalMd.trimEnd() === md.trimEnd()) return {
|
|
1888
|
+
ok: true,
|
|
1889
|
+
message: `技能「${name}」未变更:章节内容一致,未写入。`,
|
|
1890
|
+
noop: true,
|
|
1891
|
+
path: dir
|
|
1892
|
+
};
|
|
1893
|
+
const result = await this.update(name, finalMd, origin, { sha256: contentHash(md) });
|
|
1894
|
+
if (!result.ok) return result;
|
|
1895
|
+
return {
|
|
1896
|
+
ok: true,
|
|
1897
|
+
message: `已更新「${name}」的「${edit.heading}」章节(正文 ${md.length} → ${finalMd.length} 字符)。`,
|
|
1898
|
+
path: dir
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1789
1901
|
async patchCore(name, oldString, newString, filePath, replaceAll, origin) {
|
|
1790
1902
|
const badName = this.badName(name);
|
|
1791
1903
|
if (badName) return {
|
|
@@ -2082,10 +2194,10 @@ var SkillLibrary = class {
|
|
|
2082
2194
|
});
|
|
2083
2195
|
} catch {}
|
|
2084
2196
|
}
|
|
2085
|
-
async archive(rawName, options = {}, origin = this.authority.origin) {
|
|
2086
|
-
return await this.archiveCore(rawName, options, origin, false);
|
|
2197
|
+
async archive(rawName, options = {}, origin = this.authority.origin, change) {
|
|
2198
|
+
return await this.archiveCore(rawName, options, origin, false, change);
|
|
2087
2199
|
}
|
|
2088
|
-
async archiveCore(rawName, options, origin, fenceHeld) {
|
|
2200
|
+
async archiveCore(rawName, options, origin, fenceHeld, change) {
|
|
2089
2201
|
const name = rawName.trim();
|
|
2090
2202
|
const badName = this.badName(name, { allowReserved: true });
|
|
2091
2203
|
if (badName) return {
|
|
@@ -2152,7 +2264,7 @@ var SkillLibrary = class {
|
|
|
2152
2264
|
try {
|
|
2153
2265
|
await this.io.writeText(join(dest, ".archive-name"), `${name}\n`);
|
|
2154
2266
|
} catch {}
|
|
2155
|
-
await this.audit(name, "archive", md, null, reason, void 0, options.unitId, options.unitHead, origin, fenceHeld);
|
|
2267
|
+
await this.audit(name, "archive", md, null, reason, void 0, options.unitId, options.unitHead, origin, fenceHeld, change);
|
|
2156
2268
|
this.notifyMutation({
|
|
2157
2269
|
action: "archive",
|
|
2158
2270
|
name,
|
|
@@ -2832,12 +2944,12 @@ var SkillLibrary = class {
|
|
|
2832
2944
|
* support-directory links is refused (those links' files stay behind in the
|
|
2833
2945
|
* same package; the moved text belongs in references/ beside them).
|
|
2834
2946
|
*/
|
|
2835
|
-
async restructure(rawName, moves, origin = this.authority.origin) {
|
|
2947
|
+
async restructure(rawName, moves, origin = this.authority.origin, change) {
|
|
2836
2948
|
const name = rawName.trim();
|
|
2837
2949
|
await this.ensureRecovered();
|
|
2838
|
-
return await this.restructureCore(name, moves, origin);
|
|
2950
|
+
return await this.restructureCore(name, moves, origin, change);
|
|
2839
2951
|
}
|
|
2840
|
-
async restructureCore(name, moves, origin) {
|
|
2952
|
+
async restructureCore(name, moves, origin, change) {
|
|
2841
2953
|
const badName = this.badName(name);
|
|
2842
2954
|
if (badName) return {
|
|
2843
2955
|
ok: false,
|
|
@@ -2861,6 +2973,14 @@ var SkillLibrary = class {
|
|
|
2861
2973
|
ok: false,
|
|
2862
2974
|
message: "每次重构搬移都需要非空的 heading。"
|
|
2863
2975
|
};
|
|
2976
|
+
if (move.start === void 0 !== (move.end === void 0)) return {
|
|
2977
|
+
ok: false,
|
|
2978
|
+
message: "子块搬移必须同时提供 start 和 end。"
|
|
2979
|
+
};
|
|
2980
|
+
if (move.start !== void 0 && (typeof move.start !== "string" || typeof move.end !== "string" || !move.start.trim() || !move.end.trim())) return {
|
|
2981
|
+
ok: false,
|
|
2982
|
+
message: "子块搬移的 start/end 必须是匹配行的非空文本。"
|
|
2983
|
+
};
|
|
2864
2984
|
const targetIssue = validateRestructureTarget(move.toFile);
|
|
2865
2985
|
if (targetIssue) return {
|
|
2866
2986
|
ok: false,
|
|
@@ -2962,7 +3082,7 @@ var SkillLibrary = class {
|
|
|
2962
3082
|
let headPlaced = false;
|
|
2963
3083
|
for (const op of event.ops) {
|
|
2964
3084
|
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);
|
|
3085
|
+
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, change);
|
|
2966
3086
|
headPlaced = true;
|
|
2967
3087
|
}
|
|
2968
3088
|
this.notifyMutation({
|
|
@@ -2991,7 +3111,7 @@ var SkillLibrary = class {
|
|
|
2991
3111
|
};
|
|
2992
3112
|
return {
|
|
2993
3113
|
ok: true,
|
|
2994
|
-
message: `已重构「${name}」:把 ${plan.sections.length} 个章节搬到 references
|
|
3114
|
+
message: `已重构「${name}」:把 ${plan.sections.length} 个章节搬到 references/(正文 ${md.length} → ${finalMd.length} 字符)。`,
|
|
2995
3115
|
path: dir
|
|
2996
3116
|
};
|
|
2997
3117
|
}
|
|
@@ -3010,7 +3130,7 @@ var SkillLibrary = class {
|
|
|
3010
3130
|
* @param origin - write face recorded in the audit ledger.
|
|
3011
3131
|
* @returns the kernel result; a refusal writes nothing.
|
|
3012
3132
|
*/
|
|
3013
|
-
async extract(plan, origin = this.authority.origin) {
|
|
3133
|
+
async extract(plan, origin = this.authority.origin, change) {
|
|
3014
3134
|
await this.ensureRecovered();
|
|
3015
3135
|
if (plan.outcome === "owner-gap" || plan.owner.mode !== "covered") return {
|
|
3016
3136
|
ok: false,
|
|
@@ -3159,7 +3279,7 @@ var SkillLibrary = class {
|
|
|
3159
3279
|
for (const op of event.ops) {
|
|
3160
3280
|
if (op.skill === void 0) continue;
|
|
3161
3281
|
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);
|
|
3282
|
+
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, change);
|
|
3163
3283
|
headPlaced = true;
|
|
3164
3284
|
}
|
|
3165
3285
|
for (const name of roots) this.notifyMutation({
|
|
@@ -4049,4 +4169,4 @@ function newSkillLibrary(options) {
|
|
|
4049
4169
|
} : void 0, transact, [...threatExemptLabels ?? []], authority, options.mutationLock ?? mutationLockFrom(ctx), options.fence ?? ctx?.get?.("evolutionMutationAuthority")?.homeFence);
|
|
4050
4170
|
}
|
|
4051
4171
|
//#endregion
|
|
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 };
|
|
4172
|
+
export { BASELINE_ACTION, DEFAULT_ARCHIVE_RETENTION_POLICY, DEFAULT_CITATION_POLICY, DEFAULT_HEALTH_THRESHOLDS, DEFAULT_REFERENCE_REWRITE_POLICY, DEFAULT_SKILL_LIMITS, DEFAULT_SKILL_WRITE_SUMMARY_CHARS, 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, clipChangeSummary, contentRetentionFeedback, diffFindings, elapsedSince, ensureSkillFrontmatter, entryTarget, exceedsContentLimit, filterUnreadSkillOps, frontmatterBlock, frontmatterCatalogInvalid, historyIndexFile, historyRoot, isUnreadWrite, latestVersionAt, lintBody, lintSkill, loadVersionContent, loadVersions, markerEntryName, newSkillLibrary, nextHistoryIndex, normalizeChangeSummary, normalizeFrontmatter, orderVersions, parseFrontmatter, parseHistoryIndex, partitionVersions, policyStageLimits, readHistoryIndex, recordVersions, relatedSkillNames, resolveExecOrigins, resolveOrigins, resolveRootConfig, resolveSkillsRoot, revisionAnchor, revisionAnchorOf, revisionFingerprint, revisionSupportDigest, sessionReadSkillNames, sessionReadSupportFiles, shrinksOverLimit, skillMdOnDisk, skillRowCells, skillStateKey, skillsRoot, summaryChars, textDiffFacts, validateFrontmatter, validateRestructureTarget, validateSupportPath, versionActionKind, versionRowCells, versionTarget, yamlPlainScalarNeedsQuotes };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { join, resolve } from "node:path";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
//#region lib/types/state-store.js
|
|
4
|
+
/**
|
|
5
|
+
* Evolution home path helpers: the DSH root and `$DSH_HOME/evolution` for
|
|
6
|
+
* plugin-owned sidecar state (reports, activity store, feedback file,
|
|
7
|
+
* state-domain data).
|
|
8
|
+
*
|
|
9
|
+
* C-10: PATH HELPERS ONLY — despite the file name there is no store
|
|
10
|
+
* here. Durable evolution state lives in the state stack (evolution-state over
|
|
11
|
+
* evolution-state-domain); skills and memories live in skill-store.ts
|
|
12
|
+
* / memory-store.ts. The file name is kept deliberately: renaming it would
|
|
13
|
+
* touch every family import for zero behavior change, and the audit records
|
|
14
|
+
* the mismatch as known naming debt.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* DSH home root: `$DSH_HOME` or `~/.dsh`. Single source of the empty-string
|
|
18
|
+
* fallback — an EMPTY or WHITESPACE-ONLY DSH_HOME resolves to the default
|
|
19
|
+
* home, never to a CWD-relative path (0.3.19 W1.3, 0.3.22 F-207);
|
|
20
|
+
* V8-06 (0.3.47) extends the guard to whitespace.
|
|
21
|
+
* C-11 correction (S2.2, PLAN 2026-09-16): upstream `resolveDshHome`
|
|
22
|
+
* (util/home-paths) uses `trim()` ONLY as the ADOPTION test and then uses the
|
|
23
|
+
* RAW env value — the earlier "same trimmed source" form returned the trimmed
|
|
24
|
+
* text, so `DSH_HOME=" /x "` produced `/x` where upstream produced the literal
|
|
25
|
+
* padded path. The value semantics now match upstream line for line:
|
|
26
|
+
* `const selected = configured ?? (fromEnv !== undefined &&
|
|
27
|
+
* fromEnv.trim().length > 0 ? fromEnv : defaultDshHome())`.
|
|
28
|
+
* OPT-27 (2026-09, plan D5 — accepted): the v10-era "no `~` expansion, no
|
|
29
|
+
* resolve" divergence from upstream `resolveDshHome` is RETIRED. It became
|
|
30
|
+
* load-bearing when the skill-catalog shadow made "same tree as the upstream
|
|
31
|
+
* `USER_DSH_RANK` provider" a hard contract: upstream watches the EXPANDED
|
|
32
|
+
* absolute `<home>/skills` while this value fed a literal `~/x` (a directory
|
|
33
|
+
* named `~` under the host CWD) or a CWD-relative path — split-brain skill
|
|
34
|
+
* trees, preset installs the platform never reads, doctor probes of a
|
|
35
|
+
* directory nothing serves.
|
|
36
|
+
* S2.2 (PLAN 2026-09-16), final correction: the result is ALWAYS
|
|
37
|
+
* `resolve(expandHomePath(selected))` — the earlier form returned an
|
|
38
|
+
* already-absolute value VERBATIM, so a trailing slash or `..` segment
|
|
39
|
+
* landed unnormalized while upstream normalizes every value. Relative
|
|
40
|
+
* `DSH_HOME` values change landing spot; a CLEAN absolute home stays
|
|
41
|
+
* byte-identical (resolve is a no-op on it).
|
|
42
|
+
*/
|
|
43
|
+
function evolutionRoot(env = process.env) {
|
|
44
|
+
const fromEnv = env.DSH_HOME;
|
|
45
|
+
const selected = fromEnv !== void 0 && fromEnv.trim().length > 0 ? fromEnv : join(homedir(), ".dsh");
|
|
46
|
+
return resolve(selected === "~" ? homedir() : selected.startsWith("~/") || selected.startsWith("~\\") ? join(homedir(), selected.slice(2)) : selected);
|
|
47
|
+
}
|
|
48
|
+
/** Evolution home path helper: `$DSH_HOME/evolution` for plugin-owned sidecar
|
|
49
|
+
* state (reports, activity store, feedback file, state-domain data). */
|
|
50
|
+
function evolutionHome(env = process.env) {
|
|
51
|
+
return join(evolutionRoot(env), "evolution");
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { evolutionRoot as n, evolutionHome as t };
|