@lmzhen/dsh-evolution-core 0.49.0 → 0.50.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 +2 -2
- package/lib/{composition-Cqjbho0t.js → composition-DA8XPfMc.js} +1 -1
- package/lib/connection-DAJy7Xjm.js +28 -0
- package/lib/{ensure-CAjLGd9f.js → ensure-Bx4ksgJk.js} +15 -5
- package/lib/errors.js +2 -0
- package/lib/extract-plan-Bru3c9ec.js +271 -0
- package/lib/extract.js +240 -0
- package/lib/http-routes.js +27 -7
- package/lib/index.js +41 -800
- 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-WAU6YatF.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-Bl-MdXZ4.js +1409 -0
- package/lib/skills.js +7 -4
- 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/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 +3 -0
- package/lib/types/result.d.ts +35 -0
- package/lib/types/result.js +25 -0
- 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/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 +2 -2
- package/lib/usage-DdjIBAkm.js +1252 -0
- package/package.json +37 -25
- package/lib/platform-Cc9cNt5j.js +0 -111
- package/lib/skill-health-DP8z9TPf.js +0 -2923
package/lib/extract.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { p as isPresent } from "./io-GxghO3Ip.js";
|
|
2
|
+
import { i as DEFAULT_SKILL_LIMITS } from "./limits-C9jfvxBl.js";
|
|
3
|
+
import { I as parseFrontmatter } from "./usage-DdjIBAkm.js";
|
|
4
|
+
import { C as EXTRACT_PROMPT_VERSION, S as EXTRACT_PROMPT_V1, T as ownerCandidatesFromSummaries, _ as readProposalReport, b as proposalFromPlan, d as nearDuplicateSummaries, m as readExternalSupport, v as readProposalReports, w as findOwnerCandidate, x as EXTRACT_PROMPT_HASH, y as writeProposalReport } from "./quality-WAU6YatF.js";
|
|
5
|
+
import { r as contentHash } from "./mutations-DQXddSJd.js";
|
|
6
|
+
import { n as projectExtractBodies, t as planExtract } from "./extract-plan-Bru3c9ec.js";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
//#region lib/types/extract-request.js
|
|
9
|
+
/** The one human-readable owner decision shared by tool and CLI. */
|
|
10
|
+
function ownerDecisionText(owner) {
|
|
11
|
+
return owner.mode === "covered" ? "covered by " + (owner.name ?? "unknown") : "owner-gap, neededOwner=" + (owner.neededOwner ?? "unknown");
|
|
12
|
+
}
|
|
13
|
+
/** Build the one extract plan both the tool and CLI consume. */
|
|
14
|
+
async function buildExtractPlanFromLibrary(library, input) {
|
|
15
|
+
const source = input.source.trim();
|
|
16
|
+
const raw = input.items;
|
|
17
|
+
if (source === "" || raw.length === 0) return {
|
|
18
|
+
ok: false,
|
|
19
|
+
message: "extract 需要 name 与至少一个 extract 项。"
|
|
20
|
+
};
|
|
21
|
+
const requests = [];
|
|
22
|
+
let target = "";
|
|
23
|
+
for (const item of raw) {
|
|
24
|
+
if (item === null || typeof item !== "object") return {
|
|
25
|
+
ok: false,
|
|
26
|
+
message: "extract 的每一项都必须是对象。"
|
|
27
|
+
};
|
|
28
|
+
const heading = typeof item.heading === "string" ? item.heading.trim().replace(/^#+\s*/, "") : "";
|
|
29
|
+
const toSkill = typeof item.to_skill === "string" ? item.to_skill.trim() : "";
|
|
30
|
+
if (heading === "" || toSkill === "") return {
|
|
31
|
+
ok: false,
|
|
32
|
+
message: "extract 的每一项都需要 heading 与 to_skill。"
|
|
33
|
+
};
|
|
34
|
+
if (target === "") target = toSkill;
|
|
35
|
+
if (target !== toSkill) return {
|
|
36
|
+
ok: false,
|
|
37
|
+
message: "一次 extract 只能有一个 to_skill;多目标请分多次调用。"
|
|
38
|
+
};
|
|
39
|
+
const toHeading = typeof item.to_heading === "string" ? item.to_heading.trim().replace(/^#+\s*/, "") : void 0;
|
|
40
|
+
if (toHeading !== void 0 && toHeading !== heading) return {
|
|
41
|
+
ok: false,
|
|
42
|
+
message: "to_heading 暂不支持改名;G3 要求 heading 与 to_heading 相同。"
|
|
43
|
+
};
|
|
44
|
+
requests.push({
|
|
45
|
+
heading,
|
|
46
|
+
...typeof item.start === "string" ? { start: item.start } : {},
|
|
47
|
+
...typeof item.end === "string" ? { end: item.end } : {}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const sourceMd = await library.read(source);
|
|
51
|
+
if (sourceMd === null) return {
|
|
52
|
+
ok: false,
|
|
53
|
+
message: "技能「" + source + "」不存在。"
|
|
54
|
+
};
|
|
55
|
+
if (source === target) return {
|
|
56
|
+
ok: false,
|
|
57
|
+
message: "source 与 target 不能相同。"
|
|
58
|
+
};
|
|
59
|
+
const summaries = await library.model.list({
|
|
60
|
+
withContent: true,
|
|
61
|
+
withFrontmatter: true
|
|
62
|
+
});
|
|
63
|
+
const lookup = ownerCandidatesFromSummaries(source, summaries);
|
|
64
|
+
const candidateNames = lookup.candidates.map((candidate) => candidate.name);
|
|
65
|
+
const candidateHint = candidateNames.length === 0 ? "当前没有可用 owner candidate(描述为空或被排除)。" : "候选 owner:" + candidateNames.slice(0, 8).join("、") + (candidateNames.length > 8 ? " 等" : "") + "。";
|
|
66
|
+
const targetMd = await library.read(target);
|
|
67
|
+
if (targetMd === null) {
|
|
68
|
+
const parsed = parseFrontmatter(sourceMd);
|
|
69
|
+
if (parsed === null) return {
|
|
70
|
+
ok: false,
|
|
71
|
+
message: "技能「" + source + "」没有可读取的正文。"
|
|
72
|
+
};
|
|
73
|
+
const sourceProbe = await library.listSupportFiles(source);
|
|
74
|
+
if (!isPresent(sourceProbe)) return {
|
|
75
|
+
ok: false,
|
|
76
|
+
message: "支撑文件列表不可读;拒绝在不确定的闭包上提取。"
|
|
77
|
+
};
|
|
78
|
+
const external = await readExternalSupport(parsed.body, join(library.root, source), dirname(library.root), []);
|
|
79
|
+
if (!external.ok) return {
|
|
80
|
+
ok: false,
|
|
81
|
+
message: external.message
|
|
82
|
+
};
|
|
83
|
+
const plan = planExtract({
|
|
84
|
+
body: parsed.body,
|
|
85
|
+
sourceName: source,
|
|
86
|
+
targetName: target,
|
|
87
|
+
targetExists: false,
|
|
88
|
+
outcome: "owner-gap",
|
|
89
|
+
owner: {
|
|
90
|
+
mode: "owner-gap",
|
|
91
|
+
neededOwner: target,
|
|
92
|
+
triggerCovers: true,
|
|
93
|
+
outcomeCovers: false,
|
|
94
|
+
reason: "target missing; no auto create"
|
|
95
|
+
},
|
|
96
|
+
requests,
|
|
97
|
+
sourceFiles: sourceProbe.value,
|
|
98
|
+
targetFiles: [],
|
|
99
|
+
external: external.files
|
|
100
|
+
});
|
|
101
|
+
if (!plan.ok) return {
|
|
102
|
+
ok: false,
|
|
103
|
+
message: plan.message + candidateHint
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
ok: true,
|
|
107
|
+
plan: plan.plan,
|
|
108
|
+
candidates: lookup.candidates
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (targetMd.length > DEFAULT_SKILL_LIMITS.maxSkillContentChars) return {
|
|
112
|
+
ok: false,
|
|
113
|
+
message: "目标技能「" + target + "」已超过 " + DEFAULT_SKILL_LIMITS.maxSkillContentChars + " 字符,拒绝继续提取。"
|
|
114
|
+
};
|
|
115
|
+
const candidate = findOwnerCandidate(lookup, target);
|
|
116
|
+
if (candidate === void 0) return {
|
|
117
|
+
ok: false,
|
|
118
|
+
message: "目标「" + target + "」不是可用的 owner candidate(描述为空或已排除);owner-gap,不自动 create。" + candidateHint
|
|
119
|
+
};
|
|
120
|
+
if (!candidate.managed) return {
|
|
121
|
+
ok: false,
|
|
122
|
+
message: "目标「" + target + "」不是家族 managed 技能;拒绝把可复用部分写进不受管目录。"
|
|
123
|
+
};
|
|
124
|
+
if (input.ownerCovers !== true) {
|
|
125
|
+
const parsed = parseFrontmatter(sourceMd);
|
|
126
|
+
if (parsed === null) return {
|
|
127
|
+
ok: false,
|
|
128
|
+
message: "技能「" + source + "」没有可读取的正文。"
|
|
129
|
+
};
|
|
130
|
+
const sourceProbe = await library.listSupportFiles(source);
|
|
131
|
+
if (!isPresent(sourceProbe)) return {
|
|
132
|
+
ok: false,
|
|
133
|
+
message: "支撑文件列表不可读;拒绝在不确定的闭包上提取。"
|
|
134
|
+
};
|
|
135
|
+
const external = await readExternalSupport(parsed.body, join(library.root, source), dirname(library.root), []);
|
|
136
|
+
if (!external.ok) return {
|
|
137
|
+
ok: false,
|
|
138
|
+
message: external.message
|
|
139
|
+
};
|
|
140
|
+
const plan = planExtract({
|
|
141
|
+
body: parsed.body,
|
|
142
|
+
sourceName: source,
|
|
143
|
+
targetName: target,
|
|
144
|
+
targetExists: true,
|
|
145
|
+
outcome: "owner-gap",
|
|
146
|
+
owner: {
|
|
147
|
+
mode: "owner-gap",
|
|
148
|
+
neededOwner: target,
|
|
149
|
+
triggerCovers: false,
|
|
150
|
+
outcomeCovers: false,
|
|
151
|
+
reason: "agent judged the target does not cover this part"
|
|
152
|
+
},
|
|
153
|
+
requests,
|
|
154
|
+
sourceFiles: sourceProbe.value,
|
|
155
|
+
targetFiles: [],
|
|
156
|
+
external: external.files
|
|
157
|
+
});
|
|
158
|
+
if (!plan.ok) return {
|
|
159
|
+
ok: false,
|
|
160
|
+
message: plan.message + candidateHint
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
ok: true,
|
|
164
|
+
plan: plan.plan,
|
|
165
|
+
candidates: lookup.candidates
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const overlaps = nearDuplicateSummaries({
|
|
169
|
+
candidate: {
|
|
170
|
+
name: target,
|
|
171
|
+
description: candidate.description
|
|
172
|
+
},
|
|
173
|
+
existing: summaries.filter((summary) => summary.name !== source && summary.name !== target)
|
|
174
|
+
});
|
|
175
|
+
const overlapWarnings = overlaps.length === 0 ? [] : ["目标「" + target + "」描述与邻技能重叠:" + overlaps.map((match) => match.name + " (" + match.score.toFixed(2) + ")").join("、") + ";请确认 owner 覆盖,提取仍可继续。"];
|
|
176
|
+
if (candidate.protectionUnknown || candidate.protectedBy !== null) return {
|
|
177
|
+
ok: false,
|
|
178
|
+
message: "目标「" + target + "」受保护(" + (candidate.protectedBy ?? "未知") + "),拒绝提取。"
|
|
179
|
+
};
|
|
180
|
+
const parsed = parseFrontmatter(sourceMd);
|
|
181
|
+
if (parsed === null) return {
|
|
182
|
+
ok: false,
|
|
183
|
+
message: "技能「" + source + "」没有可读取的正文。"
|
|
184
|
+
};
|
|
185
|
+
const sourceProbe = await library.listSupportFiles(source);
|
|
186
|
+
const targetProbe = await library.listSupportFiles(target);
|
|
187
|
+
if (!isPresent(sourceProbe) || !isPresent(targetProbe)) return {
|
|
188
|
+
ok: false,
|
|
189
|
+
message: "支撑文件列表不可读;拒绝在不确定的闭包上提取。"
|
|
190
|
+
};
|
|
191
|
+
const external = await readExternalSupport(parsed.body, join(library.root, source), dirname(library.root), targetProbe.value);
|
|
192
|
+
if (!external.ok) return {
|
|
193
|
+
ok: false,
|
|
194
|
+
message: external.message
|
|
195
|
+
};
|
|
196
|
+
if (input.outcome !== void 0 && input.outcome !== "extract" && input.outcome !== "mixed") return {
|
|
197
|
+
ok: false,
|
|
198
|
+
message: "outcome 只能是 extract 或 mixed;owner-gap 由缺失 target 的路径自动决定。"
|
|
199
|
+
};
|
|
200
|
+
const outcome = input.outcome ?? "extract";
|
|
201
|
+
const plan = planExtract({
|
|
202
|
+
body: parsed.body,
|
|
203
|
+
sourceName: source,
|
|
204
|
+
targetName: target,
|
|
205
|
+
targetExists: true,
|
|
206
|
+
outcome,
|
|
207
|
+
owner: {
|
|
208
|
+
mode: "covered",
|
|
209
|
+
name: target,
|
|
210
|
+
triggerCovers: true,
|
|
211
|
+
outcomeCovers: true,
|
|
212
|
+
reason: "explicit target"
|
|
213
|
+
},
|
|
214
|
+
requests,
|
|
215
|
+
sourceFiles: sourceProbe.value,
|
|
216
|
+
targetFiles: targetProbe.value,
|
|
217
|
+
external: external.files,
|
|
218
|
+
anchors: {
|
|
219
|
+
sourceMdSha256: contentHash(sourceMd),
|
|
220
|
+
targetMdSha256: contentHash(targetMd)
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
if (!plan.ok) return {
|
|
224
|
+
ok: false,
|
|
225
|
+
message: plan.message
|
|
226
|
+
};
|
|
227
|
+
const projectedChars = targetMd.length + plan.plan.parts.reduce((sum, part) => sum + part.movedText.length + 2, 0);
|
|
228
|
+
if (projectedChars > DEFAULT_SKILL_LIMITS.maxSkillContentChars) return {
|
|
229
|
+
ok: false,
|
|
230
|
+
message: "目标「" + target + "」投影后约 " + projectedChars + " 字符,超过 " + DEFAULT_SKILL_LIMITS.maxSkillContentChars + " 上限;拒绝提取。"
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
ok: true,
|
|
234
|
+
plan: plan.plan,
|
|
235
|
+
candidates: lookup.candidates,
|
|
236
|
+
...overlapWarnings.length === 0 ? {} : { warnings: overlapWarnings }
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
export { EXTRACT_PROMPT_HASH, EXTRACT_PROMPT_V1, EXTRACT_PROMPT_VERSION, buildExtractPlanFromLibrary, ownerCandidatesFromSummaries, ownerDecisionText, planExtract, projectExtractBodies, proposalFromPlan, readExternalSupport, readProposalReport, readProposalReports, writeProposalReport };
|
package/lib/http-routes.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { n as isRecord } from "./guards-3f02mnf2.js";
|
|
2
|
+
import { t as connectionPort } from "./connection-DAJy7Xjm.js";
|
|
2
3
|
//#region lib/types/http-routes.js
|
|
3
4
|
/**
|
|
4
5
|
* The Host data-plane contract + Fetch-shaped helpers every family route surface shares (W1/W6).
|
|
@@ -58,16 +59,27 @@ const HOST_ROUTES = {
|
|
|
58
59
|
},
|
|
59
60
|
diagnostics: { view: "/api/dsh-evolution/diagnostics" }
|
|
60
61
|
};
|
|
62
|
+
/** Resolve through the port; only a context with NO platform service falls back to its direct service (legacy tests/fakes). */
|
|
63
|
+
function connectionFor(ctx) {
|
|
64
|
+
const port = ctx.get("evolutionPlatform")?.ports?.connection ?? connectionPort(ctx);
|
|
65
|
+
if (port !== void 0) return port;
|
|
66
|
+
const raw = ctx.connection;
|
|
67
|
+
if (raw?.fetch?.register === void 0) return void 0;
|
|
68
|
+
return {
|
|
69
|
+
allowsRemoteAuthorities: raw.allowsRemoteAuthorities === true,
|
|
70
|
+
register: (route) => raw.fetch.register(route)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
61
73
|
function hostSurface(ctx) {
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
74
|
+
const port = connectionFor(ctx);
|
|
75
|
+
if (port === void 0) return {
|
|
64
76
|
available: false,
|
|
65
77
|
code: "E-325",
|
|
66
78
|
reason: "connection-missing"
|
|
67
79
|
};
|
|
68
80
|
return {
|
|
69
81
|
available: true,
|
|
70
|
-
allowsRemoteAuthorities:
|
|
82
|
+
allowsRemoteAuthorities: port.allowsRemoteAuthorities
|
|
71
83
|
};
|
|
72
84
|
}
|
|
73
85
|
/**
|
|
@@ -83,7 +95,7 @@ function registerHostRoutes(owner, build) {
|
|
|
83
95
|
const injecting = owner;
|
|
84
96
|
if (typeof injecting.inject !== "function") throw new Error("host routes require a context that owns inject()");
|
|
85
97
|
injecting.inject(["connection"], (scope) => {
|
|
86
|
-
const connection = scope
|
|
98
|
+
const connection = connectionFor(scope);
|
|
87
99
|
const routes = build({
|
|
88
100
|
channel: "connection.fetch",
|
|
89
101
|
principal: "owner",
|
|
@@ -92,12 +104,20 @@ function registerHostRoutes(owner, build) {
|
|
|
92
104
|
for (const route of routes) if (!route.path.startsWith("/api/dsh-evolution/")) throw new Error("host route path must carry the /api/dsh-evolution/ prefix: " + route.path);
|
|
93
105
|
const effect = scope.effect;
|
|
94
106
|
if (typeof effect !== "function") throw new Error("connection scope has no effect() to own the registration");
|
|
95
|
-
if (connection
|
|
96
|
-
const register = connection.
|
|
107
|
+
if (connection === void 0) throw new Error("connection.fetch.register() is required to register family host routes (platform >= 0.2.2-rc.1); no fallback admission path exists");
|
|
108
|
+
const register = connection.register.bind(connection);
|
|
97
109
|
effect.call(scope, () => {
|
|
98
110
|
const disposers = [];
|
|
99
111
|
try {
|
|
100
|
-
for (const route of routes)
|
|
112
|
+
for (const route of routes) {
|
|
113
|
+
const outcome = connection.tryRegister?.(route);
|
|
114
|
+
if (outcome === void 0) {
|
|
115
|
+
disposers.push(register(route));
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (!outcome.ok) throw new Error(outcome.error.message);
|
|
119
|
+
disposers.push(outcome.value);
|
|
120
|
+
}
|
|
101
121
|
} catch (error) {
|
|
102
122
|
for (const dispose of disposers) try {
|
|
103
123
|
dispose();
|