@lynn123411/dsh-matt-plus 0.0.0-stage → 0.13.8
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/README.md +192 -2
- package/assets/icon.svg +7 -0
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/preview.svg +27 -0
- package/docs/preview.zh.svg +27 -0
- package/lib/client.js +1161 -0
- package/lib/client.js.map +7 -0
- package/lib/index.js +587 -0
- package/lib/index.js.map +7 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +76 -4
- package/skills/LICENSE +21 -0
- package/skills/code-review/SKILL.md +91 -0
- package/skills/grilling/SKILL.md +16 -0
- package/skills/implement-spec/SKILL.md +52 -0
- package/skills/retro/SESSION-EVIDENCE.md +27 -0
- package/skills/retro/SKILL.md +44 -0
- package/skills/retro/agents/openai.yaml +5 -0
- package/skills/retro/session-index.mjs +193 -0
- package/skills/retro/session-index.test.mjs +80 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { ToolArgsError, defineTool } from "@deepseek-ai/dsh-tools";
|
|
3
|
+
|
|
4
|
+
// src/config.ts
|
|
5
|
+
import z from "@deepseek-ai/schemastery";
|
|
6
|
+
|
|
7
|
+
// src/grilling-settings.ts
|
|
8
|
+
var GRILLING_FIELD = "grillingEnhanced";
|
|
9
|
+
var GRILLING_FIELDS = [GRILLING_FIELD, "formTool", "grillingSkill"];
|
|
10
|
+
function grillingEnabled(value) {
|
|
11
|
+
const enhanced = value[GRILLING_FIELD];
|
|
12
|
+
return typeof enhanced === "boolean" ? enhanced : value.formTool !== false && value.grillingSkill !== false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/config.ts
|
|
16
|
+
var PLUGIN_NAME = "dsh-matt-plus";
|
|
17
|
+
var Config = z.object({
|
|
18
|
+
grillingEnhanced: z.boolean().volatile(),
|
|
19
|
+
formTool: z.boolean().volatile(),
|
|
20
|
+
grillingSkill: z.boolean().volatile()
|
|
21
|
+
});
|
|
22
|
+
var FIELDS = GRILLING_FIELDS;
|
|
23
|
+
function assertKnownConfig(config) {
|
|
24
|
+
if (config === void 0 || config === null) return;
|
|
25
|
+
if (typeof config !== "object" || Array.isArray(config)) {
|
|
26
|
+
throw new TypeError(PLUGIN_NAME + ": config must be an object");
|
|
27
|
+
}
|
|
28
|
+
const unknown = Object.keys(config).filter((key) => !FIELDS.includes(key));
|
|
29
|
+
if (unknown.length === 0) return;
|
|
30
|
+
throw new TypeError(PLUGIN_NAME + ": unknown config key(s) " + unknown.map((key) => JSON.stringify(key)).join(", ") + "; this row takes " + FIELDS.join(" and "));
|
|
31
|
+
}
|
|
32
|
+
function configOn(config) {
|
|
33
|
+
return grillingEnabled(Object.fromEntries(GRILLING_FIELDS.map((key) => [key, config?.[key]?.get?.()])));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/recommendation.js
|
|
37
|
+
var MARKER = "recommended|\u63A8\u8350";
|
|
38
|
+
var BRACKETED_MARKER = `[\uFF08(\u3010\\[]\\s*(?:${MARKER})\\s*[\uFF09)\u3011\\]]`;
|
|
39
|
+
var SEPARATOR = "\uFF1B;\uFF0C,\u3001:\uFF1A\\-\u2014";
|
|
40
|
+
var TRAILING_PUNCTUATION = "\u3002.\uFF01!\uFF1F?\uFF1B;\uFF0C,\u3001~\uFF5E\\s";
|
|
41
|
+
var BRACKETED_SUFFIX = new RegExp(`[\\s]*[${SEPARATOR}]?\\s*${BRACKETED_MARKER}[${TRAILING_PUNCTUATION}]*$`, "i");
|
|
42
|
+
var BARE_SUFFIX = new RegExp(`[\\s]*[${SEPARATOR}]\\s*(?:${MARKER})[${TRAILING_PUNCTUATION}]*$`, "i");
|
|
43
|
+
function normalizeOption(option) {
|
|
44
|
+
const record = typeof option === "object" && option !== null && !Array.isArray(option) ? (
|
|
45
|
+
/** @type {Record<string, unknown>} */
|
|
46
|
+
option
|
|
47
|
+
) : {};
|
|
48
|
+
const label = stripRecommendationMarker(record.label);
|
|
49
|
+
const description = readExplanation(record.description);
|
|
50
|
+
return {
|
|
51
|
+
label: typeof label.text === "string" ? label.text : "",
|
|
52
|
+
recommended: label.found,
|
|
53
|
+
...description === void 0 ? {} : { description }
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function readExplanation(value) {
|
|
57
|
+
if (typeof value !== "string") return void 0;
|
|
58
|
+
const text = value.trim();
|
|
59
|
+
return text === "" ? void 0 : text;
|
|
60
|
+
}
|
|
61
|
+
function stripRecommendationMarker(text) {
|
|
62
|
+
if (typeof text !== "string") return { text, found: false };
|
|
63
|
+
let remaining = text;
|
|
64
|
+
let found = false;
|
|
65
|
+
for (; ; ) {
|
|
66
|
+
const match = BRACKETED_SUFFIX.exec(remaining) ?? BARE_SUFFIX.exec(remaining);
|
|
67
|
+
if (match === null) break;
|
|
68
|
+
found = true;
|
|
69
|
+
remaining = remaining.slice(0, match.index).replace(/\s+$/, "");
|
|
70
|
+
}
|
|
71
|
+
return { text: remaining, found };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/answer-block.ts
|
|
75
|
+
var IMPORT_BLOCK_END = "\u3010/\u62F7\u95EE\u4F5C\u7B54\u3011";
|
|
76
|
+
var formIdEncoder = new TextEncoder();
|
|
77
|
+
var FNV64_OFFSET_BASIS = 0xcbf29ce484222325n;
|
|
78
|
+
var FNV64_PRIME = 0x100000001b3n;
|
|
79
|
+
function shortFormId(callId) {
|
|
80
|
+
const text = typeof callId === "string" ? callId : "";
|
|
81
|
+
const compact = text.replace(/:ptc:/g, "").replace(/[^0-9a-z]/gi, "").toLowerCase();
|
|
82
|
+
return compact.length >= 4 ? compact.slice(-4) : compact.padStart(4, "0");
|
|
83
|
+
}
|
|
84
|
+
function importBlockStart(callId) {
|
|
85
|
+
let hash = FNV64_OFFSET_BASIS;
|
|
86
|
+
for (const byte of formIdEncoder.encode(String(callId))) {
|
|
87
|
+
hash = BigInt.asUintN(64, (hash ^ BigInt(byte)) * FNV64_PRIME);
|
|
88
|
+
}
|
|
89
|
+
return `\u3010\u62F7\u95EE\u4F5C\u7B54 #${hash.toString(36).padStart(13, "0")}\u3011`;
|
|
90
|
+
}
|
|
91
|
+
function versionTwoHeader(callId) {
|
|
92
|
+
return `\u3010\u62F7\u95EE\u4F5C\u7B54 v2:${encodeURIComponent(String(callId))}\u3011`;
|
|
93
|
+
}
|
|
94
|
+
function* importBlocks(text) {
|
|
95
|
+
let opening;
|
|
96
|
+
for (const match of text.matchAll(/(?:^|\n)(【(?:拷问作答(?: [^】\r\n]+)?|\/拷问作答)】)(?=\r?\n|$)/g)) {
|
|
97
|
+
const header = match[1];
|
|
98
|
+
const end = match.index + match[0].length;
|
|
99
|
+
const start = end - header.length;
|
|
100
|
+
if (header !== IMPORT_BLOCK_END) {
|
|
101
|
+
opening = { header, start, bodyStart: end };
|
|
102
|
+
} else if (opening !== void 0) {
|
|
103
|
+
yield { ...opening, bodyEnd: start, end };
|
|
104
|
+
opening = void 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function findImportBlock(draft, callId, format = "compatible") {
|
|
109
|
+
const firstHeader = format === "legacy" ? `\u3010\u62F7\u95EE\u4F5C\u7B54 ${shortFormId(callId)}\u3011` : importBlockStart(callId);
|
|
110
|
+
const fallbackHeader = format === "compatible" ? versionTwoHeader(callId) : void 0;
|
|
111
|
+
let fallback;
|
|
112
|
+
for (const block of importBlocks(draft)) {
|
|
113
|
+
if (block.header === firstHeader) return block;
|
|
114
|
+
if (block.header === fallbackHeader && fallback === void 0) fallback = block;
|
|
115
|
+
}
|
|
116
|
+
return fallback;
|
|
117
|
+
}
|
|
118
|
+
function importBlockBody(draft, callId, format = "compatible") {
|
|
119
|
+
if (typeof draft !== "string") return void 0;
|
|
120
|
+
const block = findImportBlock(draft, callId, format);
|
|
121
|
+
if (block === void 0) return void 0;
|
|
122
|
+
return draft.slice(block.bodyStart, block.bodyEnd).replace(/^\r?\n/, "").replace(/\r?\n$/, "");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/form-model.js
|
|
126
|
+
var TOOL_NAME = "grilling_form";
|
|
127
|
+
var GATE_KEY = "grillingFormPending";
|
|
128
|
+
var QUESTION_TYPES = ["single", "multi", "free"];
|
|
129
|
+
function isRecord(value) {
|
|
130
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
131
|
+
}
|
|
132
|
+
function parseJson(text) {
|
|
133
|
+
if (typeof text !== "string" || text === "") return void 0;
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(text);
|
|
136
|
+
} catch {
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function isBlank(value) {
|
|
141
|
+
return typeof value !== "string" || value.trim() === "";
|
|
142
|
+
}
|
|
143
|
+
function readQuestionType(question) {
|
|
144
|
+
return QUESTION_TYPES.find((candidate) => question.type === candidate);
|
|
145
|
+
}
|
|
146
|
+
function drawnType(question, options) {
|
|
147
|
+
if (options.length === 0) return "free";
|
|
148
|
+
return readQuestionType(question) === "single" ? "single" : "multi";
|
|
149
|
+
}
|
|
150
|
+
function readOptions(options) {
|
|
151
|
+
if (!Array.isArray(options)) return [];
|
|
152
|
+
return options.filter(isRecord).map((option) => normalizeOption(option));
|
|
153
|
+
}
|
|
154
|
+
function readRound(args) {
|
|
155
|
+
const parsed = isRecord(args) ? args : parseJson(args);
|
|
156
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.questions) || parsed.questions.length === 0) {
|
|
157
|
+
return { questions: [], replace: false };
|
|
158
|
+
}
|
|
159
|
+
const questions = [];
|
|
160
|
+
for (const [index, question] of parsed.questions.entries()) {
|
|
161
|
+
if (!isRecord(question)) return { questions: [], replace: false };
|
|
162
|
+
const options = readOptions(question.options);
|
|
163
|
+
const detail = readExplanation(question.detail);
|
|
164
|
+
questions.push({
|
|
165
|
+
id: String(index + 1),
|
|
166
|
+
number: index + 1,
|
|
167
|
+
question: typeof question.question === "string" ? question.question : "",
|
|
168
|
+
...detail === void 0 ? {} : { detail },
|
|
169
|
+
type: drawnType(question, options),
|
|
170
|
+
options
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return { questions, replace: parsed.replace === true };
|
|
174
|
+
}
|
|
175
|
+
function readQuestions(args) {
|
|
176
|
+
return readRound(args).questions;
|
|
177
|
+
}
|
|
178
|
+
function validateRound(questions) {
|
|
179
|
+
const violations = [];
|
|
180
|
+
if (!Array.isArray(questions)) return violations;
|
|
181
|
+
questions.forEach((question, questionIndex) => {
|
|
182
|
+
if (!isRecord(question)) return;
|
|
183
|
+
const where = `Question ${questionIndex + 1}`;
|
|
184
|
+
if (isBlank(question.question)) {
|
|
185
|
+
violations.push(`${where} has an empty question text; write the question itself in question`);
|
|
186
|
+
}
|
|
187
|
+
const optionList = Array.isArray(question.options) ? question.options : [];
|
|
188
|
+
const seenLabels = /* @__PURE__ */ new Set();
|
|
189
|
+
optionList.forEach((option, optionIndex) => {
|
|
190
|
+
const normalized = normalizeOption(option);
|
|
191
|
+
if (isBlank(normalized.label)) {
|
|
192
|
+
violations.push(`${where}, option ${optionIndex + 1} has an empty label; every option needs a label the user can read and pick`);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (seenLabels.has(normalized.label)) {
|
|
196
|
+
violations.push(`${where} has two options that render with the same label ${JSON.stringify(normalized.label)}; the form identifies a choice by its label, so make them differ`);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
seenLabels.add(normalized.label);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
return violations;
|
|
203
|
+
}
|
|
204
|
+
function readResult(resultText) {
|
|
205
|
+
const parsed = parseJson(resultText);
|
|
206
|
+
if (!isRecord(parsed) || typeof parsed.ok !== "boolean") return void 0;
|
|
207
|
+
return { shown: parsed.ok, message: typeof parsed.message === "string" ? parsed.message : void 0 };
|
|
208
|
+
}
|
|
209
|
+
function firstText(content) {
|
|
210
|
+
if (!Array.isArray(content)) return void 0;
|
|
211
|
+
const text = content.find((block) => isRecord(block) && block.type === "text");
|
|
212
|
+
return isRecord(text) && typeof text.text === "string" ? text.text : void 0;
|
|
213
|
+
}
|
|
214
|
+
function initialFormGate() {
|
|
215
|
+
return { call: null, pending: null, seen: [] };
|
|
216
|
+
}
|
|
217
|
+
function foldFormGate(state, event) {
|
|
218
|
+
if (!isRecord(event) || typeof event.type !== "string") return state;
|
|
219
|
+
const data = isRecord(event.data) ? event.data : {};
|
|
220
|
+
if (event.type === "tool/call" || event.type === "tool/ptc-dispatch-start") {
|
|
221
|
+
if (data.name !== TOOL_NAME) return state;
|
|
222
|
+
const questions = readQuestions(data.arguments);
|
|
223
|
+
if (questions.length === 0) return state;
|
|
224
|
+
return {
|
|
225
|
+
...state,
|
|
226
|
+
call: {
|
|
227
|
+
callId: String((event.type === "tool/call" ? data.callId : data.subCallId) ?? ""),
|
|
228
|
+
questions: questions.map((question) => question.question),
|
|
229
|
+
seq: typeof event.seq === "number" ? event.seq : -1
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
if (event.type === "tool/result") {
|
|
234
|
+
const message = isRecord(data.message) ? data.message : void 0;
|
|
235
|
+
if (message === void 0) return state;
|
|
236
|
+
return settleFormGate(state, String(message.toolCallId), firstText(message.content));
|
|
237
|
+
}
|
|
238
|
+
if (event.type === "tool/ptc-dispatch") {
|
|
239
|
+
return settleFormGate(state, String(data.subCallId ?? ""), firstText(data.content));
|
|
240
|
+
}
|
|
241
|
+
if (event.type === "user/message") {
|
|
242
|
+
const pending = state.pending;
|
|
243
|
+
if (pending === null) return state;
|
|
244
|
+
const legacyUnique = state.seen.filter((id) => shortFormId(id) === shortFormId(pending.callId)).length === 1;
|
|
245
|
+
return importBlockBody(messageText(data), pending.callId) === void 0 && (!legacyUnique || importBlockBody(messageText(data), pending.callId, "legacy") === void 0) ? state : { ...state, pending: null };
|
|
246
|
+
}
|
|
247
|
+
return state;
|
|
248
|
+
}
|
|
249
|
+
function settleFormGate(state, callId, resultText) {
|
|
250
|
+
const call = state.call;
|
|
251
|
+
if (call === null || callId !== call.callId) return state;
|
|
252
|
+
const result = readResult(resultText);
|
|
253
|
+
return result !== void 0 && result.shown ? { ...state, call: null, pending: call, seen: [.../* @__PURE__ */ new Set([...state.seen, call.callId])] } : { ...state, call: null };
|
|
254
|
+
}
|
|
255
|
+
function messageText(node) {
|
|
256
|
+
const content = isRecord(node) && Array.isArray(node.content) ? node.content : [];
|
|
257
|
+
return content.filter((block) => isRecord(block) && block.type === "text" && typeof block.text === "string").map((block) => (
|
|
258
|
+
/** @type {string} */
|
|
259
|
+
isRecord(block) ? block.text : ""
|
|
260
|
+
)).join("\n");
|
|
261
|
+
}
|
|
262
|
+
function isFormCall(value) {
|
|
263
|
+
return isRecord(value) && typeof value.callId === "string" && Array.isArray(value.questions) && value.questions.every((question) => typeof question === "string") && typeof value.seq === "number";
|
|
264
|
+
}
|
|
265
|
+
function normalizeGate(value) {
|
|
266
|
+
if (!isRecord(value)) return initialFormGate();
|
|
267
|
+
return {
|
|
268
|
+
call: isFormCall(value.call) ? value.call : null,
|
|
269
|
+
pending: isFormCall(value.pending) ? value.pending : null,
|
|
270
|
+
seen: Array.isArray(value.seen) ? value.seen.filter((id) => typeof id === "string") : []
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function pendingFormOf(state) {
|
|
274
|
+
return isRecord(state) && isFormCall(state.pending) ? state.pending : null;
|
|
275
|
+
}
|
|
276
|
+
var FORM_GATE_UNIT = {
|
|
277
|
+
key: GATE_KEY,
|
|
278
|
+
stateVersion: 5,
|
|
279
|
+
stateSchema: { parse: (value) => normalizeGate(value) },
|
|
280
|
+
init: () => initialFormGate(),
|
|
281
|
+
apply: (state, event) => foldFormGate(state, event)
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// src/skill-provider.js
|
|
285
|
+
import { readFileSync } from "node:fs";
|
|
286
|
+
import { join, resolve } from "node:path";
|
|
287
|
+
import { fileURLToPath } from "node:url";
|
|
288
|
+
|
|
289
|
+
// src/skill-markdown.ts
|
|
290
|
+
import { parse as parseYaml } from "yaml";
|
|
291
|
+
var SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
292
|
+
function readBoolean(value, filePath, key) {
|
|
293
|
+
if (value === void 0 || typeof value === "boolean") return value;
|
|
294
|
+
if (value === 1 || value === 0) return value === 1;
|
|
295
|
+
if (typeof value === "string") {
|
|
296
|
+
const normalized = value.toLowerCase();
|
|
297
|
+
if (["true", "yes", "on", "1"].includes(normalized)) return true;
|
|
298
|
+
if (["false", "no", "off", "0"].includes(normalized)) return false;
|
|
299
|
+
}
|
|
300
|
+
throw new TypeError(filePath + ': frontmatter field "' + key + '" must be a boolean');
|
|
301
|
+
}
|
|
302
|
+
function isMapping(value) {
|
|
303
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
304
|
+
}
|
|
305
|
+
function parseSkillMarkdown(raw, filePath) {
|
|
306
|
+
const text = typeof raw === "string" ? raw : "";
|
|
307
|
+
const lines = text.split("\n");
|
|
308
|
+
if ((lines[0] ?? "").replace(/\r$/, "") !== "---") {
|
|
309
|
+
throw new TypeError(filePath + ": missing YAML frontmatter");
|
|
310
|
+
}
|
|
311
|
+
let closing = -1;
|
|
312
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
313
|
+
if (lines[index].replace(/\r$/, "") === "---") {
|
|
314
|
+
closing = index;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (closing === -1) throw new TypeError(filePath + ": unterminated YAML frontmatter");
|
|
319
|
+
let fields;
|
|
320
|
+
try {
|
|
321
|
+
fields = parseYaml(lines.slice(1, closing).join("\n") + "\n");
|
|
322
|
+
} catch (error) {
|
|
323
|
+
throw new TypeError(`${filePath}: invalid YAML frontmatter: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
324
|
+
}
|
|
325
|
+
if (!isMapping(fields)) throw new TypeError(filePath + ": YAML frontmatter must be a mapping");
|
|
326
|
+
const { name: name2, description } = fields;
|
|
327
|
+
if (typeof name2 !== "string" || !SKILL_NAME.test(name2)) {
|
|
328
|
+
throw new TypeError(filePath + ": frontmatter requires a kebab-case name");
|
|
329
|
+
}
|
|
330
|
+
if (typeof description !== "string" || description === "") {
|
|
331
|
+
throw new TypeError(filePath + ": frontmatter requires a description");
|
|
332
|
+
}
|
|
333
|
+
const disableModelInvocation = readBoolean(fields["disable-model-invocation"], filePath, "disable-model-invocation");
|
|
334
|
+
const userInvocable = readBoolean(fields["user-invocable"], filePath, "user-invocable");
|
|
335
|
+
return {
|
|
336
|
+
name: name2,
|
|
337
|
+
description,
|
|
338
|
+
invocation: {
|
|
339
|
+
modelInvocable: disableModelInvocation !== true,
|
|
340
|
+
userInvocable: userInvocable !== false
|
|
341
|
+
},
|
|
342
|
+
content: lines.slice(closing + 1).join("\n").trim()
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/skill-provider.js
|
|
347
|
+
var SKILL_PROVIDER_NAME = "dsh-matt-plus";
|
|
348
|
+
var SKILL_RANK = 0;
|
|
349
|
+
var SKILL_SOURCE = "plugin";
|
|
350
|
+
var SKILL_NAMES = ["grilling", "implement-spec", "code-review", "retro"];
|
|
351
|
+
function loadSkills(baseUrl = new URL("../skills/", import.meta.url), names = SKILL_NAMES) {
|
|
352
|
+
const directory = resolve(fileURLToPath(baseUrl));
|
|
353
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
354
|
+
for (const name2 of names) {
|
|
355
|
+
const skillDirectory = join(directory, name2);
|
|
356
|
+
const path = join(skillDirectory, "SKILL.md");
|
|
357
|
+
const parsed = parseSkillMarkdown(readFileSync(path, "utf8"), path);
|
|
358
|
+
if (parsed.name !== name2) {
|
|
359
|
+
throw new TypeError(path + ': frontmatter name "' + parsed.name + '" does not match its directory');
|
|
360
|
+
}
|
|
361
|
+
definitions.set(name2, {
|
|
362
|
+
name: parsed.name,
|
|
363
|
+
description: parsed.description,
|
|
364
|
+
invocation: parsed.invocation,
|
|
365
|
+
source: SKILL_SOURCE,
|
|
366
|
+
provider: SKILL_PROVIDER_NAME,
|
|
367
|
+
resourceBase: { kind: "directory", path: skillDirectory },
|
|
368
|
+
path,
|
|
369
|
+
content: parsed.content
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return definitions;
|
|
373
|
+
}
|
|
374
|
+
function createSkillProvider(definitions) {
|
|
375
|
+
return {
|
|
376
|
+
name: SKILL_PROVIDER_NAME,
|
|
377
|
+
async list() {
|
|
378
|
+
return [...definitions.values()].map(({ content, ...summary }) => ({
|
|
379
|
+
...summary,
|
|
380
|
+
rank: SKILL_RANK,
|
|
381
|
+
locator: summary.name
|
|
382
|
+
}));
|
|
383
|
+
},
|
|
384
|
+
async get(candidate) {
|
|
385
|
+
return typeof candidate.locator === "string" ? definitions.get(candidate.locator) : void 0;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// src/index.ts
|
|
391
|
+
var name = PLUGIN_NAME;
|
|
392
|
+
var inject = ["tools"];
|
|
393
|
+
var GRILLING_SKILL = "grilling";
|
|
394
|
+
var SHOWN_MESSAGE = `The form with this round's questions is now shown in the conversation and this turn has ended. The user has not answered yet: they answer in their own composer, and their answers arrive later as their next user message, one block per round \u2014 a line with just the question number ("1.") and then one "- " line per chosen option or typed text. Do not wait for it, do not treat this as an answer, and do not write the questions in prose as well.`;
|
|
395
|
+
function touches(paths, field) {
|
|
396
|
+
return paths.some((path) => path[0] === field);
|
|
397
|
+
}
|
|
398
|
+
function gateMessage(pending) {
|
|
399
|
+
const asked = pending.questions.map((question, index) => index + 1 + ". " + question).join(" ");
|
|
400
|
+
return "An earlier form is still waiting for the user's answer, so this round was not shown. It asked: " + asked + " If these questions replace it, call again with replace: true \u2014 the earlier form turns read-only. If they are additional, stop now and ask them after the user has answered; do not write them as prose.";
|
|
401
|
+
}
|
|
402
|
+
function agentSkillProvider(config) {
|
|
403
|
+
const definitions = createSkillProvider(loadSkills());
|
|
404
|
+
const available = (skill) => skill !== GRILLING_SKILL || configOn(config);
|
|
405
|
+
return {
|
|
406
|
+
name: definitions.name,
|
|
407
|
+
async list(options) {
|
|
408
|
+
const listed = await definitions.list(options);
|
|
409
|
+
const candidates = Array.isArray(listed) ? listed : listed.candidates;
|
|
410
|
+
return candidates.filter((candidate) => available(candidate.name));
|
|
411
|
+
},
|
|
412
|
+
async get(candidate, options) {
|
|
413
|
+
if (!available(candidate.name)) return void 0;
|
|
414
|
+
return definitions.get(candidate, options);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function formTool(pendingForm) {
|
|
419
|
+
return defineTool({
|
|
420
|
+
name: TOOL_NAME,
|
|
421
|
+
description: "Put this round's questions to the user as a form, then end your turn. Make it the round's only tool call. If new information changes questions already shown and unanswered, call again with replace: true instead of waiting for the user to fill them.",
|
|
422
|
+
parameters: {
|
|
423
|
+
questions: {
|
|
424
|
+
type: "array",
|
|
425
|
+
required: true,
|
|
426
|
+
description: "This round's questions, in order.",
|
|
427
|
+
items: {
|
|
428
|
+
type: "object",
|
|
429
|
+
additionalProperties: true,
|
|
430
|
+
properties: {
|
|
431
|
+
question: {
|
|
432
|
+
type: "string",
|
|
433
|
+
required: true,
|
|
434
|
+
description: "The specific question to ask the user."
|
|
435
|
+
},
|
|
436
|
+
detail: {
|
|
437
|
+
type: "string",
|
|
438
|
+
description: "Explain the background of the question."
|
|
439
|
+
},
|
|
440
|
+
type: {
|
|
441
|
+
type: "string",
|
|
442
|
+
enum: [...QUESTION_TYPES],
|
|
443
|
+
description: "How the question is answered: single, multi, or free."
|
|
444
|
+
},
|
|
445
|
+
options: {
|
|
446
|
+
type: "array",
|
|
447
|
+
description: 'Optional choices to show the user. If you recommend one, put it first and append "(Recommended)" to that label.',
|
|
448
|
+
items: {
|
|
449
|
+
type: "object",
|
|
450
|
+
additionalProperties: true,
|
|
451
|
+
properties: {
|
|
452
|
+
label: {
|
|
453
|
+
type: "string",
|
|
454
|
+
required: true,
|
|
455
|
+
description: "Short user-facing option label."
|
|
456
|
+
},
|
|
457
|
+
description: {
|
|
458
|
+
type: "string",
|
|
459
|
+
description: "Explaining the tradeoff or impact."
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
replace: {
|
|
468
|
+
type: "boolean",
|
|
469
|
+
description: "Whether this round replaces the earlier unanswered form."
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
output: {
|
|
473
|
+
schema: {
|
|
474
|
+
type: "object",
|
|
475
|
+
additionalProperties: false,
|
|
476
|
+
properties: {
|
|
477
|
+
ok: {
|
|
478
|
+
type: "boolean",
|
|
479
|
+
description: "Whether the form was shown."
|
|
480
|
+
},
|
|
481
|
+
message: {
|
|
482
|
+
type: "string",
|
|
483
|
+
description: "What happened."
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
render: (_args, value) => [{ type: "text", text: JSON.stringify(value) }]
|
|
488
|
+
},
|
|
489
|
+
async execute(args, exec) {
|
|
490
|
+
const violations = validateRound(args.questions);
|
|
491
|
+
if (violations.length > 0) throw new ToolArgsError(violations);
|
|
492
|
+
const pending = pendingForm(exec);
|
|
493
|
+
if (pending !== null && args.replace !== true) return { ok: false, message: gateMessage(pending) };
|
|
494
|
+
exec.concludeTurn();
|
|
495
|
+
return { ok: true, message: SHOWN_MESSAGE };
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
async function apply(ctx, config) {
|
|
500
|
+
assertKnownConfig(config);
|
|
501
|
+
let gateHandle;
|
|
502
|
+
const binding = ctx.inject(["sessionProjections"], async (scoped) => {
|
|
503
|
+
const projections = scoped.get("sessionProjections");
|
|
504
|
+
gateHandle = await projections.register(FORM_GATE_UNIT);
|
|
505
|
+
return () => {
|
|
506
|
+
gateHandle = void 0;
|
|
507
|
+
};
|
|
508
|
+
});
|
|
509
|
+
ctx.inject(["skills"], (scoped) => {
|
|
510
|
+
const skills = scoped.get("skills");
|
|
511
|
+
return skills.registerProvider(() => createSkillProvider(loadSkills(void 0, ["retro"])));
|
|
512
|
+
});
|
|
513
|
+
ctx.inject(["settings"], (scoped) => {
|
|
514
|
+
const settings = scoped.get("settings");
|
|
515
|
+
scoped.effect(() => settings.configure({ auto: false }, ctx.fiber), PLUGIN_NAME + ": settings page policy");
|
|
516
|
+
});
|
|
517
|
+
const agentSkillDisposers = /* @__PURE__ */ new Map();
|
|
518
|
+
const skillControls = /* @__PURE__ */ new Set();
|
|
519
|
+
const registerAgentSkills = (agent) => {
|
|
520
|
+
if (agentSkillDisposers.has(agent)) return;
|
|
521
|
+
const skills = agent.ctx.get("skills");
|
|
522
|
+
if (skills === void 0) return;
|
|
523
|
+
let control;
|
|
524
|
+
const dispose = skills.registerProvider((registration) => {
|
|
525
|
+
control = registration;
|
|
526
|
+
return agentSkillProvider(config);
|
|
527
|
+
});
|
|
528
|
+
if (control !== void 0) skillControls.add(control);
|
|
529
|
+
agentSkillDisposers.set(agent, () => {
|
|
530
|
+
if (control !== void 0) skillControls.delete(control);
|
|
531
|
+
dispose();
|
|
532
|
+
});
|
|
533
|
+
};
|
|
534
|
+
const unregisterAgentSkills = (agent) => {
|
|
535
|
+
const dispose = agentSkillDisposers.get(agent);
|
|
536
|
+
if (dispose !== void 0) dispose();
|
|
537
|
+
};
|
|
538
|
+
const onAgentEvent = ctx.on;
|
|
539
|
+
onAgentEvent("agent/created", ({ agent }) => {
|
|
540
|
+
registerAgentSkills(agent);
|
|
541
|
+
});
|
|
542
|
+
onAgentEvent("agent/disposed", ({ agent }) => {
|
|
543
|
+
unregisterAgentSkills(agent);
|
|
544
|
+
});
|
|
545
|
+
const agents = ctx.get("agents");
|
|
546
|
+
if (agents !== void 0) for (const agent of agents.list()) registerAgentSkills(agent);
|
|
547
|
+
ctx.effect(() => () => {
|
|
548
|
+
for (const dispose of [...agentSkillDisposers.values()]) dispose();
|
|
549
|
+
agentSkillDisposers.clear();
|
|
550
|
+
skillControls.clear();
|
|
551
|
+
});
|
|
552
|
+
if (ctx.get("sessionProjections") !== void 0) await binding;
|
|
553
|
+
const pendingForm = (exec) => {
|
|
554
|
+
const session = exec.agent === void 0 ? void 0 : exec.agent.session;
|
|
555
|
+
if (session === void 0 || gateHandle === void 0) return null;
|
|
556
|
+
return pendingFormOf(gateHandle.stateOf(session));
|
|
557
|
+
};
|
|
558
|
+
let disposeFormTool;
|
|
559
|
+
const syncFormTool = () => {
|
|
560
|
+
if (!configOn(config)) {
|
|
561
|
+
if (disposeFormTool === void 0) return;
|
|
562
|
+
disposeFormTool();
|
|
563
|
+
disposeFormTool = void 0;
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (disposeFormTool !== void 0) return;
|
|
567
|
+
disposeFormTool = ctx.tools.register(formTool(pendingForm));
|
|
568
|
+
};
|
|
569
|
+
ctx.effect(() => () => {
|
|
570
|
+
if (disposeFormTool === void 0) return;
|
|
571
|
+
disposeFormTool();
|
|
572
|
+
disposeFormTool = void 0;
|
|
573
|
+
});
|
|
574
|
+
syncFormTool();
|
|
575
|
+
ctx.on("loader/volatile-update", (paths) => {
|
|
576
|
+
if (!GRILLING_FIELDS.some((field) => touches(paths, field))) return;
|
|
577
|
+
syncFormTool();
|
|
578
|
+
for (const control of skillControls) control.invalidate();
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
export {
|
|
582
|
+
Config,
|
|
583
|
+
apply,
|
|
584
|
+
inject,
|
|
585
|
+
name
|
|
586
|
+
};
|
|
587
|
+
//# sourceMappingURL=index.js.map
|