dsh-desktop-kit 2.23.1 → 2.23.17
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/CHANGELOG.md +35 -0
- package/README.md +255 -245
- package/client.js +130 -8
- package/docs/AGENT-HARNESS.md +9 -0
- package/docs/TEST-2.23.2.md +23 -0
- package/index.js +2 -0
- package/package.json +3 -3
- package/plugins/dsh-agent-extensions/README.md +5 -0
- package/plugins/dsh-agent-extensions/client.js +129 -7
- package/plugins/dsh-agent-extensions/index.js +24 -5
- package/plugins/dsh-agent-extensions/lib/agents.js +26 -3
- package/plugins/dsh-agent-extensions/lib/api.js +55 -1
- package/plugins/dsh-agent-extensions/lib/board.js +8 -2
- package/plugins/dsh-agent-extensions/lib/findings.js +67 -0
- package/plugins/dsh-agent-extensions/lib/project.js +2 -0
- package/plugins/dsh-agent-extensions/lib/routing.js +72 -0
- package/plugins/dsh-agent-extensions/lib/scaffold.js +120 -21
- package/plugins/dsh-agent-extensions/lib/settings.js +94 -0
- package/plugins/dsh-agent-extensions/lib/swarm.js +10 -5
- package/plugins/dsh-mcp-manager/README.md +10 -0
- package/plugins/dsh-mcp-manager/index.js +62 -2
- package/plugins/dsh-mcp-manager/lib/bootstrap.js +94 -0
- package/plugins/dsh-mcp-manager/lib/catalog.js +128 -0
- package/plugins/dsh-research-ledger/README.md +48 -0
- package/plugins/dsh-research-ledger/cordis.patch.yml +3 -0
- package/plugins/dsh-research-ledger/index.js +145 -0
- package/plugins/dsh-research-ledger/lib/ledger.js +346 -0
- package/plugins/dsh-research-ledger/package.json +25 -0
- package/plugins/dsh-skill-autopilot/index.js +65 -13
- package/skills/manifest.json +8 -8
- package/skills/research-first/SKILL.md +1 -0
- package/skills-baseline.json +480 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evidence ledger: every external claim gets a source, date and verification
|
|
3
|
+
* state. It is deliberately local and plain JSON; the model records claims via
|
|
4
|
+
* the `research_ledger` tool, and a validator flags missing/stale/contested
|
|
5
|
+
* evidence before the final answer.
|
|
6
|
+
*/
|
|
7
|
+
import crypto from "node:crypto";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
export const LEDGER_VERSION = 1;
|
|
12
|
+
export const MAX_CLAIMS = 300;
|
|
13
|
+
export const STALE_DAYS = 365;
|
|
14
|
+
export const MAX_TEXT = 2000;
|
|
15
|
+
export const FRESHNESS_DAYS = { day: 2, week: 14, month: 60, year: 365, any: 0 };
|
|
16
|
+
const STOPWORDS = new Set(["the", "and", "for", "with", "from", "that", "this", "как", "что", "для", "или", "при", "это", "его", "она", "они", "чтобы", "какие", "какой", "чем", "про", "над", "под", "без", "если"]);
|
|
17
|
+
|
|
18
|
+
export function projectRoot(cwd = process.cwd()) {
|
|
19
|
+
let current = path.resolve(cwd);
|
|
20
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
21
|
+
if (fs.existsSync(path.join(current, ".dsh"))) return current;
|
|
22
|
+
const parent = path.dirname(current);
|
|
23
|
+
if (parent === current) break;
|
|
24
|
+
current = parent;
|
|
25
|
+
}
|
|
26
|
+
return path.resolve(cwd);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function ledgerPath(root) {
|
|
30
|
+
return path.join(projectRoot(root), ".dsh", "research", "ledger.json");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function emptyLedger(root) {
|
|
34
|
+
const now = new Date().toISOString();
|
|
35
|
+
return { schema: LEDGER_VERSION, root: projectRoot(root), createdAt: now, updatedAt: now, claims: [] };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function readLedger(root) {
|
|
39
|
+
const file = ledgerPath(root);
|
|
40
|
+
try {
|
|
41
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
42
|
+
if (!parsed || !Array.isArray(parsed.claims)) return emptyLedger(root);
|
|
43
|
+
return { ...emptyLedger(root), ...parsed, claims: parsed.claims.slice(-MAX_CLAIMS) };
|
|
44
|
+
} catch {
|
|
45
|
+
return emptyLedger(root);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function writeLedger(root, ledger) {
|
|
50
|
+
const file = ledgerPath(root);
|
|
51
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
52
|
+
const next = { ...ledger, schema: LEDGER_VERSION, root: projectRoot(root), updatedAt: new Date().toISOString() };
|
|
53
|
+
const temporary = `${file}.tmp`;
|
|
54
|
+
fs.writeFileSync(temporary, `${JSON.stringify(next, null, 2)}\n`, "utf8");
|
|
55
|
+
fs.renameSync(temporary, file);
|
|
56
|
+
return next;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isPublicHttpUrl(value) {
|
|
60
|
+
let url;
|
|
61
|
+
try {
|
|
62
|
+
url = new URL(String(value ?? "").trim());
|
|
63
|
+
} catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return false;
|
|
67
|
+
if (url.username || url.password) return false;
|
|
68
|
+
const host = url.hostname.toLowerCase();
|
|
69
|
+
if (host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local")) return false;
|
|
70
|
+
if (host === "0.0.0.0" || host === "::1" || host === "[::1]") return false;
|
|
71
|
+
if (/^\d{1,3}(?:\.\d{1,3}){3}$/u.test(host)) {
|
|
72
|
+
const octets = host.split(".").map(Number);
|
|
73
|
+
if (octets[0] === 10 || octets[0] === 127 || (octets[0] === 169 && octets[1] === 254)) return false;
|
|
74
|
+
if (octets[0] === 172 && octets[1] >= 16 && octets[1] <= 31) return false;
|
|
75
|
+
if (octets[0] === 192 && octets[1] === 168) return false;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function text(value, max = MAX_TEXT) {
|
|
81
|
+
return String(value ?? "").trim().replace(/\s+/gu, " ").slice(0, max);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function isoDate(value) {
|
|
85
|
+
if (!value) return "";
|
|
86
|
+
const date = new Date(value);
|
|
87
|
+
return Number.isNaN(date.getTime()) ? "" : date.toISOString().slice(0, 10);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function makeId(claim, url) {
|
|
91
|
+
return `cl-${crypto.createHash("sha256").update(`${claim}\n${url}`).digest("hex").slice(0, 10)}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function normalizeClaim(input) {
|
|
95
|
+
const claim = text(input?.claim);
|
|
96
|
+
const url = text(input?.url, 1000);
|
|
97
|
+
if (claim.length < 8) throw new Error("claim должен быть содержательным (>= 8 символов)");
|
|
98
|
+
if (!isPublicHttpUrl(url)) throw new Error("url должен быть публичным http(s) адресом");
|
|
99
|
+
const confidence = ["low", "medium", "high"].includes(input?.confidence) ? input.confidence : "medium";
|
|
100
|
+
return {
|
|
101
|
+
id: makeId(claim, url),
|
|
102
|
+
claim,
|
|
103
|
+
url,
|
|
104
|
+
sourceDate: isoDate(input?.sourceDate),
|
|
105
|
+
quote: text(input?.quote, 1200),
|
|
106
|
+
topic: text(input?.topic, 120).toLowerCase() || "",
|
|
107
|
+
confidence,
|
|
108
|
+
contested: input?.contested === true,
|
|
109
|
+
tags: Array.isArray(input?.tags) ? [...new Set(input.tags.map((tag) => text(tag, 40)).filter(Boolean))].slice(0, 10) : [],
|
|
110
|
+
verified: null,
|
|
111
|
+
createdAt: new Date().toISOString(),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function addClaim(root, input) {
|
|
116
|
+
const ledger = readLedger(root);
|
|
117
|
+
const claim = normalizeClaim(input);
|
|
118
|
+
const duplicate = ledger.claims.find((item) => item.id === claim.id);
|
|
119
|
+
if (duplicate) return { ledger, claim: duplicate, duplicate: true };
|
|
120
|
+
if (ledger.claims.length >= MAX_CLAIMS) ledger.claims.shift();
|
|
121
|
+
ledger.claims.push(claim);
|
|
122
|
+
return { ledger: writeLedger(root, ledger), claim, duplicate: false };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export async function verifyClaim(claim, timeoutMs = 8000) {
|
|
126
|
+
if (!isPublicHttpUrl(claim.url)) {
|
|
127
|
+
return { ok: false, status: 0, finalUrl: "", error: "unsafe or invalid URL", checkedAt: new Date().toISOString() };
|
|
128
|
+
}
|
|
129
|
+
const controller = new AbortController();
|
|
130
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
131
|
+
try {
|
|
132
|
+
const response = await fetch(claim.url, {
|
|
133
|
+
method: "GET",
|
|
134
|
+
redirect: "follow",
|
|
135
|
+
signal: controller.signal,
|
|
136
|
+
headers: { "user-agent": "dsh-research-ledger/1.0", accept: "text/html,application/xhtml+xml,application/json;q=0.8,*/*;q=0.5" },
|
|
137
|
+
});
|
|
138
|
+
try { await response.body?.cancel(); } catch { /* body already consumed */ }
|
|
139
|
+
return {
|
|
140
|
+
ok: response.ok,
|
|
141
|
+
status: response.status,
|
|
142
|
+
finalUrl: response.url || claim.url,
|
|
143
|
+
error: response.ok ? "" : `HTTP ${response.status}`,
|
|
144
|
+
checkedAt: new Date().toISOString(),
|
|
145
|
+
};
|
|
146
|
+
} catch (error) {
|
|
147
|
+
return {
|
|
148
|
+
ok: false,
|
|
149
|
+
status: 0,
|
|
150
|
+
finalUrl: claim.url,
|
|
151
|
+
error: error instanceof Error ? error.message : String(error),
|
|
152
|
+
checkedAt: new Date().toISOString(),
|
|
153
|
+
};
|
|
154
|
+
} finally {
|
|
155
|
+
clearTimeout(timer);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export async function verifyClaims(root, id = "", options = {}) {
|
|
160
|
+
const ledger = readLedger(root);
|
|
161
|
+
const target = id ? ledger.claims.filter((claim) => claim.id === id || claim.id.startsWith(id)) : ledger.claims;
|
|
162
|
+
const force = options.force === true;
|
|
163
|
+
const ttlHours = Math.max(1, Number(options.ttlHours) || 168);
|
|
164
|
+
let checked = 0;
|
|
165
|
+
let skipped = 0;
|
|
166
|
+
for (const claim of target) {
|
|
167
|
+
const ageHours = claim.verified?.checkedAt ? (Date.now() - Date.parse(claim.verified.checkedAt)) / 3_600_000 : Infinity;
|
|
168
|
+
if (!force && ageHours < ttlHours) {
|
|
169
|
+
skipped += 1;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
claim.verified = await verifyClaim(claim);
|
|
173
|
+
checked += 1;
|
|
174
|
+
}
|
|
175
|
+
return { ledger: writeLedger(root, ledger), checked, skipped };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function planPath(root) {
|
|
179
|
+
return path.join(projectRoot(root), ".dsh", "research", "plan.json");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function buildResearchPlan(question, options = {}) {
|
|
183
|
+
const clean = text(question, 1200);
|
|
184
|
+
if (clean.length < 8) throw new Error("question должен быть содержательным (>= 8 символов)");
|
|
185
|
+
const freshness = String(options.freshness ?? "month").toLowerCase();
|
|
186
|
+
if (!Object.hasOwn(FRESHNESS_DAYS, freshness)) throw new Error("freshness: day|week|month|year|any");
|
|
187
|
+
const domains = (Array.isArray(options.domains) ? options.domains : []).map((domain) => text(domain, 120).replace(/^https?:\/\//u, "").replace(/\/.*$/u, "")).filter(Boolean).slice(0, 4);
|
|
188
|
+
const keywords = [...new Set(clean.toLowerCase().split(/[^\p{L}\p{N}+#._-]+/u).filter((word) => word.length >= 3 && !STOPWORDS.has(word)))].slice(0, 12);
|
|
189
|
+
const keywordText = keywords.join(" ") || clean;
|
|
190
|
+
const year = new Date().getUTCFullYear();
|
|
191
|
+
const queries = [...new Set([
|
|
192
|
+
clean,
|
|
193
|
+
`${keywordText} official documentation`,
|
|
194
|
+
`${keywordText} ${year}`,
|
|
195
|
+
`${keywordText} changelog release notes`,
|
|
196
|
+
`site:github.com ${keywordText}`,
|
|
197
|
+
...domains.map((domain) => `site:${domain} ${keywordText}`),
|
|
198
|
+
].map((query) => text(query, 240)).filter(Boolean))].slice(0, 8);
|
|
199
|
+
const subquestions = clean.split(/[?;]\s*/u).map((part) => part.trim()).filter((part) => part.length > 3).slice(0, 4);
|
|
200
|
+
const days = FRESHNESS_DAYS[freshness];
|
|
201
|
+
const queryNodes = (subquestions.length > 0 ? subquestions : [clean]).map((question, index) => ({
|
|
202
|
+
id: `q${index + 1}`,
|
|
203
|
+
question,
|
|
204
|
+
status: "pending",
|
|
205
|
+
evidence: "",
|
|
206
|
+
dependsOn: [],
|
|
207
|
+
}));
|
|
208
|
+
const verifyNode = {
|
|
209
|
+
id: "verify",
|
|
210
|
+
question: "Проверить ссылки, даты, цитаты и противоречия",
|
|
211
|
+
status: "pending",
|
|
212
|
+
evidence: "",
|
|
213
|
+
dependsOn: queryNodes.map((node) => node.id),
|
|
214
|
+
};
|
|
215
|
+
const synthesizeNode = {
|
|
216
|
+
id: "synthesize",
|
|
217
|
+
question: "Свести verified claims в PASS/FAIL и unknowns",
|
|
218
|
+
status: "pending",
|
|
219
|
+
evidence: "",
|
|
220
|
+
dependsOn: [verifyNode.id],
|
|
221
|
+
};
|
|
222
|
+
const dagNodes = [...queryNodes, verifyNode, synthesizeNode];
|
|
223
|
+
const dagEdges = dagNodes.flatMap((node) => node.dependsOn.map((from) => ({ from, to: node.id })));
|
|
224
|
+
return {
|
|
225
|
+
schema: 1,
|
|
226
|
+
question: clean,
|
|
227
|
+
keywords,
|
|
228
|
+
subquestions: subquestions.length > 0 ? subquestions : [clean],
|
|
229
|
+
queries,
|
|
230
|
+
domains,
|
|
231
|
+
freshness,
|
|
232
|
+
freshnessDays: days,
|
|
233
|
+
dag: { nodes: dagNodes, edges: dagEdges },
|
|
234
|
+
sourcePriority: [
|
|
235
|
+
"official documentation / specification / changelog",
|
|
236
|
+
"primary source (paper, RFC, law, data)",
|
|
237
|
+
"maintainer GitHub / engineering write-up",
|
|
238
|
+
"community summary (only as opinion)",
|
|
239
|
+
],
|
|
240
|
+
checklist: [
|
|
241
|
+
"2+ independent sources for each contested claim",
|
|
242
|
+
"publication date + URL for every external fact",
|
|
243
|
+
`freshness: ${freshness} (${days ? `${days} days` : "no automatic expiry"})`,
|
|
244
|
+
"quote what exactly supports the claim",
|
|
245
|
+
"contradictions: mark contested in research_ledger",
|
|
246
|
+
"verify links before the final answer",
|
|
247
|
+
],
|
|
248
|
+
createdAt: new Date().toISOString(),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function writeResearchPlan(root, plan) {
|
|
253
|
+
const file = planPath(root);
|
|
254
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
255
|
+
fs.writeFileSync(file, `${JSON.stringify(plan, null, 2)}\n`, "utf8");
|
|
256
|
+
return file;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function readResearchPlan(root) {
|
|
260
|
+
try {
|
|
261
|
+
return JSON.parse(fs.readFileSync(planPath(root), "utf8"));
|
|
262
|
+
} catch {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function updatePlanProgress(root, nodeId, { status = "done", evidence = "" } = {}) {
|
|
268
|
+
if (!["pending", "in_progress", "done", "blocked"].includes(status)) throw new Error("plan status: pending|in_progress|done|blocked");
|
|
269
|
+
const plan = readResearchPlan(root);
|
|
270
|
+
if (!plan || !plan.dag || !Array.isArray(plan.dag.nodes)) throw new Error("plan не найден; сначала research_ledger action=plan");
|
|
271
|
+
const node = plan.dag.nodes.find((item) => item.id === String(nodeId));
|
|
272
|
+
if (!node) throw new Error(`plan node не найден: ${nodeId}`);
|
|
273
|
+
node.status = status;
|
|
274
|
+
node.evidence = text(evidence, 1200);
|
|
275
|
+
node.updatedAt = new Date().toISOString();
|
|
276
|
+
writeResearchPlan(root, plan);
|
|
277
|
+
const blocked = plan.dag.nodes.filter((item) => item.status !== "done");
|
|
278
|
+
return { plan, node, remaining: blocked.length };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function planText(plan) {
|
|
282
|
+
return [
|
|
283
|
+
`Вопрос: ${plan.question}`,
|
|
284
|
+
`Freshness: ${plan.freshness}${plan.freshnessDays ? ` (${plan.freshnessDays} дней)` : ""}`,
|
|
285
|
+
"Запросы:",
|
|
286
|
+
...plan.queries.map((query) => `- ${query}`),
|
|
287
|
+
"DAG:",
|
|
288
|
+
...(plan.dag?.nodes ?? []).map((node) => `- ${node.id} [${node.status}] ${node.question}${node.dependsOn.length ? ` ← ${node.dependsOn.join(", ")}` : ""}`),
|
|
289
|
+
"Источники:",
|
|
290
|
+
...plan.sourcePriority.map((source) => `- ${source}`),
|
|
291
|
+
"Чек-лист:",
|
|
292
|
+
...plan.checklist.map((item) => `- ${item}`),
|
|
293
|
+
].join("\n");
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function summarize(ledger, now = Date.now()) {
|
|
297
|
+
const claims = Array.isArray(ledger.claims) ? ledger.claims : [];
|
|
298
|
+
const byTopic = new Map();
|
|
299
|
+
for (const claim of claims) {
|
|
300
|
+
const key = claim.topic || claim.id;
|
|
301
|
+
if (!byTopic.has(key)) byTopic.set(key, new Set());
|
|
302
|
+
byTopic.get(key).add(claim.url);
|
|
303
|
+
}
|
|
304
|
+
const stale = [];
|
|
305
|
+
const noDate = [];
|
|
306
|
+
const unreachable = [];
|
|
307
|
+
const singleSource = [];
|
|
308
|
+
const contested = [];
|
|
309
|
+
for (const claim of claims) {
|
|
310
|
+
const age = claim.sourceDate ? (now - Date.parse(claim.sourceDate)) / 86_400_000 : Infinity;
|
|
311
|
+
if (!claim.sourceDate) noDate.push(claim.id);
|
|
312
|
+
else if (age > STALE_DAYS) stale.push(claim.id);
|
|
313
|
+
if (claim.verified && !claim.verified.ok) unreachable.push(claim.id);
|
|
314
|
+
const key = claim.topic || claim.id;
|
|
315
|
+
if ((byTopic.get(key)?.size ?? 0) < 2) singleSource.push(claim.id);
|
|
316
|
+
if (claim.contested) contested.push(claim.id);
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
total: claims.length,
|
|
320
|
+
verified: claims.filter((claim) => claim.verified?.ok).length,
|
|
321
|
+
unverified: claims.filter((claim) => !claim.verified).length,
|
|
322
|
+
stale,
|
|
323
|
+
noDate,
|
|
324
|
+
unreachable,
|
|
325
|
+
singleSource,
|
|
326
|
+
contested,
|
|
327
|
+
missingQuote: claims.filter((claim) => !claim.quote).map((claim) => claim.id),
|
|
328
|
+
warnings: [
|
|
329
|
+
noDate.length ? `${noDate.length} claim(s) без даты источника` : "",
|
|
330
|
+
stale.length ? `${stale.length} claim(s) старше ${STALE_DAYS} дней` : "",
|
|
331
|
+
unreachable.length ? `${unreachable.length} недоступных источник(ов)` : "",
|
|
332
|
+
singleSource.length ? `${singleSource.length} claim(s) с одним источником` : "",
|
|
333
|
+
contested.length ? `${contested.length} спорных claim(s)` : "",
|
|
334
|
+
claims.some((claim) => !claim.verified) ? "часть claim(s) не проверена" : "",
|
|
335
|
+
].filter(Boolean),
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function ledgerText(ledger, limit = 30) {
|
|
340
|
+
const claims = ledger.claims.slice(-limit).reverse();
|
|
341
|
+
if (claims.length === 0) return "Ledger пуст. Записывайте внешние утверждения через research_ledger action=record.";
|
|
342
|
+
return claims.map((claim) => {
|
|
343
|
+
const status = claim.verified ? (claim.verified.ok ? "✓" : "✗") : "?";
|
|
344
|
+
return `${status} ${claim.id} · ${claim.claim}\n ${claim.url}${claim.sourceDate ? ` · ${claim.sourceDate}` : ""}${claim.topic ? ` · ${claim.topic}` : ""}${claim.contested ? " · CONTESTED" : ""}`;
|
|
345
|
+
}).join("\n");
|
|
346
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-research-ledger",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Evidence ledger for DSH web research: claims, public sources, dates, link verification, stale/single-source/contested warnings, with a prompt summary.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./lib": "./lib/ledger.js",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"lib/**",
|
|
16
|
+
"cordis.patch.yml",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"dsh": {
|
|
20
|
+
"manifestVersion": 1,
|
|
21
|
+
"bundle": {
|
|
22
|
+
"patch": "./cordis.patch.yml"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -26,11 +26,26 @@ const SKILL_CACHE_MS = 60_000;
|
|
|
26
26
|
const AUTO_LOAD_MAX_BYTES = 4200;
|
|
27
27
|
const AUTO_LOAD_MAX_SKILLS = 2;
|
|
28
28
|
const PROJECT_RULES_MAX_BYTES = 2500;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
function readKitSettings() {
|
|
30
|
+
try {
|
|
31
|
+
const home = process.env.DSH_HOME || path.join(os.homedir(), ".dsh");
|
|
32
|
+
return JSON.parse(fs.readFileSync(path.join(home, "kit.settings.json"), "utf8"));
|
|
33
|
+
} catch {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function qualityContractText() {
|
|
39
|
+
const full = [
|
|
40
|
+
"<quality-contract>",
|
|
41
|
+
"Работай как топовый агент: 1) ПЕРЕД любой задачей — короткий web_search/web_fetch по лучшим мировым практикам и референсам; даже локальную задачу проверь на более качественный современный подход; 2) дай 2+ независимых источника, дату и ссылки; 3) для рекомендаций предложи 2–3 конкретных референса/варианта и объясни выбор; 4) внешние claims — research_ledger, проверка ссылок и дат перед выводами; 5) UI: до правок — wow-design/ui-craft, после — browser_qa audit 390/768/1440, исправь overflow, console errors и markup (alt, labels, duplicate id, heading order), приложи скриншоты; 6) код — repo_map/checkpoint/план/тесты; 7) не заявляй «готово» без проверки; если проверить нельзя — скажи честно.",
|
|
42
|
+
"</quality-contract>",
|
|
43
|
+
].join("\n");
|
|
44
|
+
if (readKitSettings().researchFirst === false) {
|
|
45
|
+
return full.replace("1) ПЕРЕД любой задачей — короткий web_search/web_fetch по лучшим мировым практикам и референсам; даже локальную задачу проверь на более качественный современный подход; 2) дай 2+ независимых источника, дату и ссылки; 3) для рекомендаций предложи 2–3 конкретных референса/варианта и объясни выбор; 4) внешние claims — research_ledger, проверка ссылок и дат перед выводами;", "1) внешние факты — web_search/web_fetch, 2+ источника со ссылками и датами; 2) для рекомендаций — 2–3 варианта с обоснованием;");
|
|
46
|
+
}
|
|
47
|
+
return full;
|
|
48
|
+
}
|
|
34
49
|
let skillMetaCache = { at: 0, map: new Map() };
|
|
35
50
|
|
|
36
51
|
/* ------------------------------------------------------------------ */
|
|
@@ -286,11 +301,44 @@ function loadAutoSkills(names) {
|
|
|
286
301
|
}
|
|
287
302
|
|
|
288
303
|
/**
|
|
289
|
-
* Project rules: <cwd>/.dsh/rules/*.md.
|
|
290
|
-
* `paths`
|
|
291
|
-
*
|
|
304
|
+
* Project rules: <cwd>/.dsh/rules/*.md.
|
|
305
|
+
* Rules without `paths` or with `always: true` apply to every prompt.
|
|
306
|
+
* Rules with `paths:` load only when the user message mentions a matching
|
|
307
|
+
* file path; globs support `**`, `*`, `?` and basename matches.
|
|
292
308
|
*/
|
|
293
|
-
function
|
|
309
|
+
function extractRulePaths(text) {
|
|
310
|
+
const source = String(text ?? "").replace(/\\/gu, "/");
|
|
311
|
+
const matches = new Set();
|
|
312
|
+
for (const match of source.matchAll(/(?:\.{0,2}\/)?(?:[\w@.-]+\/)+[\w@.-]+\.[A-Za-z0-9]{1,8}/gu)) matches.add(match[0].replace(/^\.\//u, ""));
|
|
313
|
+
for (const match of source.matchAll(/\b[\w@.-]+\.(?:tsx?|jsx?|mjs|cjs|css|scss|html|json|md|py|go|rs|php|vue|svelte|yml|yaml)\b/gu)) matches.add(match[0]);
|
|
314
|
+
return [...matches];
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function globToRegExp(glob) {
|
|
318
|
+
const escaped = glob
|
|
319
|
+
.replace(/[.+^${}()|[\]\\]/gu, "\\$&")
|
|
320
|
+
.replace(/\*\*/gu, "\u0000")
|
|
321
|
+
.replace(/\*/gu, "[^/]*")
|
|
322
|
+
.replace(/\?/gu, "[^/]")
|
|
323
|
+
.replace(/\u0000/gu, ".*");
|
|
324
|
+
return new RegExp(`^${escaped}$`, "u");
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function ruleMatches(rulePaths, candidates) {
|
|
328
|
+
if (rulePaths.length === 0) return true;
|
|
329
|
+
for (const rulePath of rulePaths) {
|
|
330
|
+
const normalized = rulePath.replace(/\\/gu, "/").replace(/^\.\//u, "");
|
|
331
|
+
const regex = globToRegExp(normalized);
|
|
332
|
+
if (rulePath.includes("/")) {
|
|
333
|
+
if (candidates.some((candidate) => regex.test(candidate))) return true;
|
|
334
|
+
} else if (candidates.some((candidate) => regex.test(candidate) || regex.test(candidate.split("/").pop() ?? ""))) {
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function loadProjectRules(session, messageText = "") {
|
|
294
342
|
const cwd = typeof session?.header?.cwd === "string" ? session.header.cwd : "";
|
|
295
343
|
if (cwd.length === 0) return "";
|
|
296
344
|
const directory = path.join(cwd, ".dsh", "rules");
|
|
@@ -300,6 +348,7 @@ function loadProjectRules(session) {
|
|
|
300
348
|
} catch {
|
|
301
349
|
return "";
|
|
302
350
|
}
|
|
351
|
+
const candidates = extractRulePaths(messageText);
|
|
303
352
|
const blocks = [];
|
|
304
353
|
let used = 0;
|
|
305
354
|
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
@@ -307,9 +356,12 @@ function loadProjectRules(session) {
|
|
|
307
356
|
const text = fs.readFileSync(path.join(directory, entry.name), "utf8");
|
|
308
357
|
const front = text.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/u);
|
|
309
358
|
const metadata = front ? front[1] : "";
|
|
310
|
-
const hasPaths = /^paths\s*:/mu.test(metadata);
|
|
311
359
|
const always = /^always:\s*true\s*$/mu.test(metadata);
|
|
312
|
-
|
|
360
|
+
const pathsLine = metadata.match(/^paths:\s*(.+)$/mu);
|
|
361
|
+
const rulePaths = pathsLine
|
|
362
|
+
? pathsLine[1].replace(/^\[|\]$/gu, "").split(",").map((item) => item.trim().replace(/^"|"$/gu, "")).filter(Boolean)
|
|
363
|
+
: [];
|
|
364
|
+
if (!always && rulePaths.length > 0 && !ruleMatches(rulePaths, candidates)) continue;
|
|
313
365
|
const body = (front ? text.slice(front[0].length) : text).trim();
|
|
314
366
|
if (body.length === 0) continue;
|
|
315
367
|
const remaining = PROJECT_RULES_MAX_BYTES - used;
|
|
@@ -550,8 +602,8 @@ export function apply(ctx) {
|
|
|
550
602
|
const hint = route.skills.length > 0 ? renderHint(route) : "";
|
|
551
603
|
const autoSkills = loadAutoSkills(route.allSkills ?? []);
|
|
552
604
|
const autoBlock = autoSkills.length > 0 ? `<auto-skills>\n${autoSkills.join("\n")}\n</auto-skills>` : "";
|
|
553
|
-
const rules = loadProjectRules(session);
|
|
554
|
-
const value = [
|
|
605
|
+
const rules = loadProjectRules(session, message.text);
|
|
606
|
+
const value = [qualityContractText(), rules, autoBlock, hint].filter((part) => part.length > 0).join("\n");
|
|
555
607
|
if (route.skills.length === 0) return value;
|
|
556
608
|
const now = Date.now();
|
|
557
609
|
lastHintAt = now;
|
package/skills/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
|
-
"kitVersion": "2.
|
|
4
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"kitVersion": "2.23.17",
|
|
4
|
+
"generatedAt": "2026-11-12T18:27:10.256Z",
|
|
5
5
|
"skills": {
|
|
6
6
|
"code-review-checklist": {
|
|
7
7
|
"hash": "e665bf72cfbfb77948a3cd6df6ebced38777f9aff543d7b9c80b2ced8cccc662",
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
"bytes": 13078
|
|
75
75
|
},
|
|
76
76
|
"research-first": {
|
|
77
|
-
"hash": "
|
|
77
|
+
"hash": "ea5e3684d20529fca65a233044e914ba5b7be56a3d93ce283d8632e87904c23e",
|
|
78
78
|
"files": 2,
|
|
79
|
-
"bytes":
|
|
79
|
+
"bytes": 4495
|
|
80
80
|
},
|
|
81
81
|
"security-review": {
|
|
82
82
|
"hash": "8665b2c469de8e83aca670021d5c335fa8c9b93b8dc6bb866759e6062b1abde4",
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
"bytes": 4257
|
|
85
85
|
},
|
|
86
86
|
"seo": {
|
|
87
|
-
"hash": "
|
|
87
|
+
"hash": "4e2a6a3c960fa51edbdac0467d41ea023be37a50afb67b03c0474f33adfb6fc6",
|
|
88
88
|
"files": 29,
|
|
89
|
-
"bytes":
|
|
89
|
+
"bytes": 386399
|
|
90
90
|
},
|
|
91
91
|
"service-desk-conventions": {
|
|
92
92
|
"hash": "22ae6c29b7debb0154d183bc732795b67557aeaa0ac906d7b038134aea8ba39a",
|
|
@@ -149,9 +149,9 @@
|
|
|
149
149
|
"bytes": 14150
|
|
150
150
|
},
|
|
151
151
|
"wow-design": {
|
|
152
|
-
"hash": "
|
|
152
|
+
"hash": "bba0d65db46c89d971eed43e7cd934f59752c062795a4e0d3d345d7313640e48",
|
|
153
153
|
"files": 52,
|
|
154
|
-
"bytes":
|
|
154
|
+
"bytes": 918621
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -19,6 +19,7 @@ autoLoad: true
|
|
|
19
19
|
## 2. Протокол (до реализации)
|
|
20
20
|
1. **2–4 запроса**: русский + английский, официальные термины, `site:` для docs.
|
|
21
21
|
2. **2–3 независимых источника**, приоритет: официальная документация → первоисточник/paper → крупный инженерный блог. Маркетинг — только как мнение.
|
|
22
|
+
3. В DSH начни с `research_ledger action=plan` — он даёт multi-query, freshness и checklist; затем записывай claim через `action=record` и проверяй ссылки `action=verify`.
|
|
22
23
|
3. **Открой ключевые страницы** (`web_fetch`), не ограничивайся сниппетами.
|
|
23
24
|
4. Зафиксируй: дата поиска, версия/дата источника, расхождения.
|
|
24
25
|
5. Сделай **матрицу вариантов**: 2–3 подхода, плюсы, минусы, риски, стоимость, рекомендация. Для мелкой задачи — 3 строки, не эссе.
|