@y1x1n/dsh-prompt-optimizer 0.3.16 → 0.6.4

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/prompt.js CHANGED
@@ -4,8 +4,8 @@ var MARKERS = {
4
4
  optimized: "<<<OPTIMIZED>>>",
5
5
  end: "<<<END>>>"
6
6
  };
7
- var ROLE_FULL_ZH = "\u4F60\u662F\u4E00\u4F4D\u8D44\u6DF1\u63D0\u793A\u8BCD\u5DE5\u7A0B\u4E13\u5BB6\u3002\u7528\u6237\u4F1A\u7ED9\u4F60\u4E00\u6BB5\u300C\u63D0\u793A\u8BCD\u8349\u7A3F\u300D,\u4F60\u8981\u5B8C\u6210\u4E24\u4EF6\u4E8B:\u8BCA\u65AD\u5206\u6790 + \u4F18\u5316\u6539\u5199\u3002";
8
- var ROLE_FULL_EN = 'You are a senior prompt engineering expert. Given a "prompt draft" from the user, do two things: diagnose it, then rewrite an optimized version.';
7
+ var ROLE_FULL_ZH = "\u4F60\u662F\u4E00\u4F4D\u8D44\u6DF1\u63D0\u793A\u8BCD\u5DE5\u7A0B\u4E13\u5BB6\u3002\u7528\u6237\u4F1A\u7ED9\u4F60\u4E00\u6BB5\u300C\u63D0\u793A\u8BCD\u8349\u7A3F\u300D,\u4F60\u8981\u8F93\u51FA\u4E24\u6BB5\u5185\u5BB9:\u5148\u8F93\u51FA\u4F18\u5316\u6539\u5199\u7A3F,\u518D\u8F93\u51FA\u8BCA\u65AD\u5206\u6790\u3002";
8
+ var ROLE_FULL_EN = 'You are a senior prompt engineering expert. Given a "prompt draft" from the user, output the optimized rewrite first, then the diagnosis.';
9
9
  var ROLE_FAST_ZH = "\u4F60\u662F\u4E00\u4F4D\u8D44\u6DF1\u63D0\u793A\u8BCD\u5DE5\u7A0B\u4E13\u5BB6\u3002\u7528\u6237\u4F1A\u7ED9\u4F60\u4E00\u6BB5\u300C\u63D0\u793A\u8BCD\u8349\u7A3F\u300D,\u8BF7\u76F4\u63A5\u8F93\u51FA\u4F18\u5316\u540E\u7684\u5B8C\u6574\u63D0\u793A\u8BCD,\u4E0D\u8981\u505A\u4EFB\u4F55\u8BCA\u65AD\u5206\u6790\u3002";
10
10
  var ROLE_FAST_EN = 'You are a senior prompt engineering expert. Given a "prompt draft" from the user, output an optimized version directly \u2014 no diagnosis.';
11
11
  var ANALYSIS_ZH = `# \u5206\u6790\u7EF4\u5EA6
@@ -53,14 +53,14 @@ var RULES_ZH = `# \u4FDD\u771F\u4E0E\u660E\u786E\u5316\u539F\u5219(\u5168\u7A0B\
53
53
  - \u8BED\u4E49\u7B49\u4EF7\u662F\u5E95\u7EBF:\u5DF2\u660E\u786E\u7684\u5BF9\u8C61\u3001\u65B9\u5411\u3001\u6570\u91CF\u3001\u8303\u56F4\u3001\u7981\u6B62\u9879\u3001\u672F\u8BED\u5FC5\u987B\u4E0E\u8349\u7A3F\u4E00\u81F4,\u4E0D\u5F97\u66FF\u6362\u3001\u6269\u5927\u3001\u7F29\u5C0F\u6216\u98A0\u5012
54
54
  - \u6765\u6E90\u53EF\u56DE\u6EAF:\u4EFB\u4F55\u5177\u4F53\u5316\u7684\u5185\u5BB9\u90FD\u5FC5\u987B\u80FD\u4ECE\u8349\u7A3F\u6216\u4E0A\u4E0B\u6587\u5DF2\u786E\u8BA4\u4FE1\u606F\u627E\u5230\u4F9D\u636E;\u63A8\u65AD\u5904\u7528\u300C\u5982\u65E0\u7279\u522B\u8BF4\u660E/\u9ED8\u8BA4\u300D\u63AA\u8F9E\u4FDD\u7559\u9009\u62E9\u6743,\u65E0\u4F9D\u636E\u7684\u5B81\u53EF\u4E0D\u8865
55
55
  - \u4FDD\u771F\u81EA\u68C0:\u8F93\u51FA\u524D\u9010\u8981\u7D20\u6838\u5BF9\u2014\u2014\u8349\u7A3F\u7684\u6BCF\u4E2A\u539F\u5B50\u4FE1\u606F\u90FD\u8981\u5728\u4F18\u5316\u7A3F\u4E2D\u627E\u5230\u5BF9\u5E94,\u627E\u4E0D\u5230\u5373\u4E3A\u8BED\u4E49\u6F02\u79FB,\u5FC5\u987B\u4FEE\u6B63
56
- - \u957F\u5EA6\u7EAA\u5F8B:\u7B80\u5355\u4EFB\u52A1\u7684\u4F18\u5316\u7A3F\u63A7\u5236\u5728 800 \u5B57\u7B26\u4EE5\u5185,\u590D\u6742\u4EFB\u52A1\u53EF\u8D85\u51FA;\u4EFB\u4F55\u60C5\u51B5\u4E0B\u4FDD\u771F\u81EA\u68C0\u4F18\u5148\u4E8E\u957F\u5EA6\u2014\u2014\u8981\u7D20\u7F3A\u5931\u6BD4\u5197\u957F\u66F4\u4E25\u91CD,\u4F46\u4E5F\u4E0D\u5F97\u5197\u4F59
56
+ - \u957F\u5EA6\u7EAA\u5F8B:\u7B80\u5355\u4EFB\u52A1\u7684\u4F18\u5316\u7A3F\u63A7\u5236\u5728 500 \u5B57\u7B26\u4EE5\u5185,\u590D\u6742\u4EFB\u52A1\u53EF\u8D85\u51FA;\u4F18\u5316\u7A3F\u5C31\u662F\u63D0\u793A\u8BCD\u672C\u8EAB\u2014\u2014\u4E0D\u590D\u8FF0\u539F\u7A3F\u3001\u4E0D\u52A0\u591A\u4F59\u7684\u89E3\u91CA\u6216\u524D\u8A00;\u4EFB\u4F55\u60C5\u51B5\u4E0B\u4FDD\u771F\u81EA\u68C0\u4F18\u5148\u4E8E\u957F\u5EA6\u2014\u2014\u8981\u7D20\u7F3A\u5931\u6BD4\u5197\u957F\u66F4\u4E25\u91CD,\u4F46\u4E5F\u4E0D\u5F97\u5197\u4F59
57
57
  - \u8BED\u8A00\u5339\u914D:\u8349\u7A3F\u4EE5\u4E2D\u6587\u4E3A\u4E3B\u4F53\u5219\u8F93\u51FA\u5FC5\u987B\u4E3A\u4E2D\u6587,\u4EE5\u82F1\u6587\u4E3A\u4E3B\u4F53\u5219\u8F93\u51FA\u5FC5\u987B\u4E3A\u82F1\u6587;\u4FDD\u7559\u539F\u6587\u7684\u672F\u8BED\u4E0E\u4E13\u6709\u540D\u8BCD`;
58
58
  var RULES_EN = `# Fidelity & clarification rules (always apply)
59
59
  - Understand first: list what the draft explicitly states (subject, action, constraints, scope, terms, numbers, tone), and separate it from your guesses \u2014 guesses may shape wording only, never enter the output
60
60
  - Semantic equivalence is the floor: what the draft states (subject, direction, quantities, scope, prohibitions, terms) must survive intact \u2014 never replace, widen, narrow, or invert it
61
61
  - Traceability: every concretized detail must trace back to the draft or to information the context has confirmed; mark inferences with "unless otherwise specified / by default" phrasing; when in doubt, leave it out
62
62
  - Fidelity self-check: before output, verify every atomic element of the draft has a counterpart in your rewrite \u2014 a missing one is semantic drift and must be fixed
63
- - Length discipline: keep the rewrite under 800 characters for simple tasks; longer is allowed for complex ones. Fidelity always outranks length \u2014 a missing element is worse than verbosity, but never pad
63
+ - Length discipline: keep the rewrite under 500 characters for simple tasks; longer is allowed for complex ones. The rewrite is the prompt itself \u2014 never restate the draft or add explanations or preamble. Fidelity always outranks length \u2014 a missing element is worse than verbosity, but never pad
64
64
  - Language match: Chinese-dominant draft \u2192 Chinese output; English-dominant \u2192 English output; keep the draft's terms and proper nouns`;
65
65
  var EXAMPLE_TEMPLATE_ZH = `# \u793A\u4F8B(\u4E25\u683C\u6A21\u4EFF\u5176\u300C\u8F93\u5165 \u2192 \u8F93\u51FA\u300D\u7684\u98CE\u683C)
66
66
  \u8F93\u5165:\u5E2E\u6211\u5199\u4E2A\u8BF7\u5047\u6761
@@ -75,18 +75,18 @@ var EXAMPLE_INTENT_EN = `# Example (strictly mirror its "input \u2192 output" st
75
75
  Input: (background: the user runs a 200-member neighborhood parents' swap group; the first chain-post drew only a dozen joins, blamed on weak prizes and a messy format) redesign the chain post for me
76
76
  Output: Redesign the "hidden gems" chain post for my 200-member neighborhood swap group (mostly parents): last round drew only a dozen joins because prizes were unappealing and the format confusing \u2014 provide a simple chain-post template, low-cost but attractive prize ideas, and concrete tactics to lift participation.`;
77
77
  var FORMAT_FULL_ZH = `# \u8F93\u51FA\u683C\u5F0F(\u4E25\u683C\u9075\u5B88,\u6807\u8BB0\u884C\u5355\u72EC\u6210\u884C)
78
- ${MARKERS.analysis}
79
- \u6309\u7EF4\u5EA6\u9010\u6761\u8F93\u51FA\u8BCA\u65AD,\u6BCF\u6761\u4E00\u884C,\u683C\u5F0F:\u300C\u7EF4\u5EA6 | \u95EE\u9898 | \u5EFA\u8BAE\u300D\u3002\u67D0\u7EF4\u5EA6\u65E0\u660E\u663E\u95EE\u9898\u65F6\u5199:\u300C\u7EF4\u5EA6 | \u65E0\u660E\u663E\u95EE\u9898 | -\u300D\u3002
80
78
  ${MARKERS.optimized}
81
79
  \u8F93\u51FA\u4F18\u5316\u540E\u7684\u5B8C\u6574\u63D0\u793A\u8BCD\u5168\u6587
80
+ ${MARKERS.analysis}
81
+ \u6309\u7EF4\u5EA6\u9010\u6761\u8F93\u51FA\u8BCA\u65AD,\u6BCF\u6761\u4E00\u884C,\u683C\u5F0F:\u300C\u7EF4\u5EA6 | \u95EE\u9898 | \u5EFA\u8BAE\u300D\u3002\u67D0\u7EF4\u5EA6\u65E0\u660E\u663E\u95EE\u9898\u65F6\u5199:\u300C\u7EF4\u5EA6 | \u65E0\u660E\u663E\u95EE\u9898 | -\u300D\u3002
82
82
  ${MARKERS.end}
83
83
 
84
84
  \u9664\u4E0A\u8FF0\u6807\u8BB0\u5305\u88F9\u7684\u5185\u5BB9\u5916,\u4E0D\u8981\u8F93\u51FA\u4EFB\u4F55\u5176\u4ED6\u6587\u5B57\u3002`;
85
85
  var FORMAT_FULL_EN = `# Output format (strictly follow; markers on their own lines)
86
- ${MARKERS.analysis}
87
- One finding per line: "dimension | issue | suggestion". If a dimension is fine: "dimension | no issue | -".
88
86
  ${MARKERS.optimized}
89
87
  The full optimized prompt text
88
+ ${MARKERS.analysis}
89
+ One finding per line: "dimension | issue | suggestion". If a dimension is fine: "dimension | no issue | -".
90
90
  ${MARKERS.end}
91
91
 
92
92
  Do not output anything outside these markers.`;
@@ -115,23 +115,44 @@ function buildSystemPrompt(language, mode = "full", strategy = "template") {
115
115
  var CONTEXT_MAX_TURNS = 8;
116
116
  var CONTEXT_MAX_CHARS = 1600;
117
117
  var CONTEXT_TURN_MAX_CHARS = 600;
118
+ var CONTEXT_MIN_USER_TURNS = 1;
119
+ var CONTEXT_USER_BUDGET = 800;
118
120
  function capConversationContext(turns) {
119
121
  const recent = turns.filter((t) => t.text.trim()).slice(-CONTEXT_MAX_TURNS).map((t) => ({
120
122
  role: t.role,
121
123
  text: t.text.trim().length > CONTEXT_TURN_MAX_CHARS ? `${t.text.trim().slice(0, CONTEXT_TURN_MAX_CHARS)}\u2026` : t.text.trim()
122
124
  }));
125
+ if (recent.length === 0) return [];
126
+ const indexed = recent.map((turn, index) => ({ turn, index }));
127
+ const kept = /* @__PURE__ */ new Map();
123
128
  let budget = CONTEXT_MAX_CHARS;
124
- const kept = [];
125
- for (let i = recent.length - 1; i >= 0; i--) {
126
- const turn = recent[i];
127
- if (turn.text.length > budget) {
128
- if (kept.length === 0) kept.push({ role: turn.role, text: `${turn.text.slice(0, budget)}\u2026` });
129
- break;
129
+ const users = indexed.filter((x) => x.turn.role === "user");
130
+ let userBudget = Math.min(CONTEXT_USER_BUDGET, budget);
131
+ for (let i = users.length - 1; i >= 0; i--) {
132
+ const { turn, index } = users[i];
133
+ const keptUsers = users.length - i;
134
+ const mustKeep = keptUsers <= CONTEXT_MIN_USER_TURNS && ![...kept.values()].some((t) => t.role === "user");
135
+ if (turn.text.length <= userBudget) {
136
+ kept.set(index, turn);
137
+ userBudget -= turn.text.length;
138
+ budget -= turn.text.length;
139
+ } else if (mustKeep) {
140
+ const slice = userBudget > 16 ? userBudget : Math.min(16, budget);
141
+ if (slice > 0) {
142
+ kept.set(index, { role: turn.role, text: `${turn.text.slice(0, slice)}\u2026` });
143
+ userBudget -= slice;
144
+ budget -= slice;
145
+ }
130
146
  }
131
- kept.unshift(turn);
147
+ }
148
+ const assistants = indexed.filter((x) => x.turn.role === "assistant");
149
+ for (let i = assistants.length - 1; i >= 0; i--) {
150
+ const { turn, index } = assistants[i];
151
+ if (turn.text.length > budget) continue;
152
+ kept.set(index, turn);
132
153
  budget -= turn.text.length;
133
154
  }
134
- return kept;
155
+ return [...kept.entries()].sort(([a], [b]) => a - b).map(([, turn]) => turn);
135
156
  }
136
157
  function buildUserPayload(draft, language, context, previous) {
137
158
  const sections = [];
@@ -179,12 +200,26 @@ ${draft}`
179
200
  );
180
201
  return sections.join("\n\n");
181
202
  }
203
+ function isWideTokenChar(code) {
204
+ return code >= 4352 && code <= 4607 || // 谚文字母
205
+ code >= 11904 && code <= 12255 || // CJK 部首补充 / 康熙部首
206
+ code >= 12288 && code <= 12351 || // CJK 符号与标点(全角)
207
+ code >= 12352 && code <= 12543 || // 平假名 / 片假名
208
+ code >= 12592 && code <= 12687 || // 谚文兼容字母
209
+ code >= 13312 && code <= 19903 || // CJK 扩展 A
210
+ code >= 19968 && code <= 40959 || // CJK 统一表意文字
211
+ code >= 43360 && code <= 43391 || // 谚文字母扩展 A
212
+ code >= 44032 && code <= 55215 || // 谚文音节
213
+ code >= 63744 && code <= 64255 || // CJK 兼容表意文字
214
+ code >= 65280 && code <= 65376 || // 全角 ASCII 变体
215
+ code >= 65504 && code <= 65510 || // 全角符号
216
+ code >= 131072 && code <= 262143;
217
+ }
182
218
  function estimateTokens(text) {
183
219
  let cjk = 0;
184
220
  let other = 0;
185
221
  for (const ch of text) {
186
- const code = ch.codePointAt(0) ?? 0;
187
- if (code >= 13312 && code <= 19903 || code >= 19968 && code <= 40959 || code >= 63744 && code <= 64255) {
222
+ if (isWideTokenChar(ch.codePointAt(0) ?? 0)) {
188
223
  cjk += 1;
189
224
  } else {
190
225
  other += 1;
@@ -198,57 +233,147 @@ function findMarker(text, word, fromIndex = 0) {
198
233
  const match = re.exec(text);
199
234
  return match ? { index: match.index, length: match[0].length } : null;
200
235
  }
236
+ function findLastMarker(text, word, beforeIndex = text.length) {
237
+ const re = new RegExp(`<<<\\s*${word}\\s*>>>`, "g");
238
+ let last = null;
239
+ for (const match of text.matchAll(re)) {
240
+ if (match.index >= beforeIndex) break;
241
+ last = { index: match.index, length: match[0].length };
242
+ }
243
+ return last;
244
+ }
245
+ function stripMarkers(text) {
246
+ return text.replace(/<<<\s*(?:ANALYSIS|OPTIMIZED|END)\s*>>>/g, "");
247
+ }
248
+ function findNextMarker(text, fromIndex) {
249
+ const re = /<<<\s*(?:ANALYSIS|OPTIMIZED|END)\s*>>>/g;
250
+ re.lastIndex = fromIndex;
251
+ const match = re.exec(text);
252
+ return match ? { index: match.index, length: match[0].length } : null;
253
+ }
254
+ function segmentAfter(text, marker) {
255
+ const firstEnd = findMarker(text, "END");
256
+ if (firstEnd && marker.index > firstEnd.index) return "";
257
+ const start = marker.index + marker.length;
258
+ const next = findNextMarker(text, start);
259
+ let end = next ? next.index : text.length;
260
+ if (firstEnd && firstEnd.index > start && firstEnd.index < end) end = firstEnd.index;
261
+ return text.slice(start, end).trim();
262
+ }
263
+ var THINK_OPEN = "<think>";
264
+ var THINK_CLOSE = "</think>";
265
+ function stripThinkBlocks(text) {
266
+ let out = "";
267
+ let rest = text;
268
+ for (; ; ) {
269
+ const open = rest.indexOf(THINK_OPEN);
270
+ if (open === -1) return out + rest;
271
+ out += rest.slice(0, open);
272
+ const close = rest.indexOf(THINK_CLOSE, open + THINK_OPEN.length);
273
+ if (close === -1) return out;
274
+ rest = rest.slice(close + THINK_CLOSE.length);
275
+ }
276
+ }
277
+ function createThinkFilter() {
278
+ let buf = "";
279
+ let inThink = false;
280
+ const splitSafeTail = (tagLen) => {
281
+ const lastLt = buf.lastIndexOf("<");
282
+ const keepFrom = lastLt !== -1 && buf.length - lastLt <= tagLen - 1 ? lastLt : buf.length;
283
+ return [buf.slice(0, keepFrom), buf.slice(keepFrom)];
284
+ };
285
+ const push = (chunk) => {
286
+ buf += chunk;
287
+ let out = "";
288
+ for (; ; ) {
289
+ if (inThink) {
290
+ const close = buf.indexOf(THINK_CLOSE);
291
+ if (close === -1) {
292
+ const [emit, keep] = splitSafeTail(THINK_CLOSE.length);
293
+ buf = keep;
294
+ return out;
295
+ }
296
+ buf = buf.slice(close + THINK_CLOSE.length);
297
+ inThink = false;
298
+ continue;
299
+ }
300
+ const open = buf.indexOf(THINK_OPEN);
301
+ if (open === -1) {
302
+ const [emit, keep] = splitSafeTail(THINK_OPEN.length);
303
+ out += emit;
304
+ buf = keep;
305
+ return out;
306
+ }
307
+ out += buf.slice(0, open);
308
+ buf = buf.slice(open + THINK_OPEN.length);
309
+ inThink = true;
310
+ }
311
+ };
312
+ const flush = () => {
313
+ if (inThink) {
314
+ buf = "";
315
+ return "";
316
+ }
317
+ const rest = buf;
318
+ buf = "";
319
+ return rest;
320
+ };
321
+ return { push, flush };
322
+ }
201
323
  function parseOptimizerOutput(raw, mode = "full") {
202
- const text = raw.trim();
203
- const a = findMarker(text, "ANALYSIS");
204
- const o = findMarker(text, "OPTIMIZED");
324
+ const text = stripThinkBlocks(raw).trim();
325
+ const o = findLastMarker(text, "OPTIMIZED");
326
+ const a = findLastMarker(text, "ANALYSIS");
205
327
  const wellFormed = mode === "fast" ? true : Boolean(a && o);
206
328
  if (!a && !o) {
207
- return { analysis: "", optimized: text, wellFormed };
208
- }
209
- let analysis = "";
210
- let optimized = "";
211
- if (a && (!o || a.index < o.index)) {
212
- analysis = text.slice(a.index + a.length, o ? o.index : text.length).trim();
213
- }
214
- if (o) {
215
- const e = findMarker(text, "END", o.index + o.length);
216
- optimized = text.slice(o.index + o.length, e ? e.index : text.length).trim();
329
+ const body = stripMarkers(text).trim();
330
+ return { analysis: "", optimized: body, wellFormed: wellFormed && Boolean(body) };
217
331
  }
332
+ const optimized = o ? segmentAfter(text, o) : "";
333
+ const analysis = a ? segmentAfter(text, a) : "";
218
334
  return {
335
+ // 有标记但段落为空:保持为空(可能只是模型没写内容),绝不回退到含标记的原文。
219
336
  analysis,
220
- optimized: optimized || text,
221
- wellFormed
337
+ optimized,
338
+ // 优化稿为空 = 这次输出不可用,降级展示并让客户端弹格式警示。
339
+ wellFormed: wellFormed && Boolean(optimized)
222
340
  };
223
341
  }
224
342
  function parsePartialOptimizerOutput(raw) {
225
- const a = findMarker(raw, "ANALYSIS");
226
- const o = findMarker(raw, "OPTIMIZED");
227
- let analysis = "";
228
- let optimized = "";
229
- if (a && (!o || a.index < o.index)) {
230
- analysis = raw.slice(a.index + a.length, o ? o.index : raw.length).trim();
343
+ const text = stripThinkBlocks(raw);
344
+ const o = findLastMarker(text, "OPTIMIZED");
345
+ const a = findLastMarker(text, "ANALYSIS");
346
+ return {
347
+ analysis: a ? segmentAfter(text, a) : "",
348
+ optimized: o ? segmentAfter(text, o) : ""
349
+ };
350
+ }
351
+ function compactPartialBuffer(raw) {
352
+ const o = findLastMarker(raw, "OPTIMIZED");
353
+ const a = findLastMarker(raw, "ANALYSIS");
354
+ if (o && a && o.index < a.index) {
355
+ return {
356
+ compacted: `${MARKERS.analysis}
357
+ ${raw.slice(a.index + a.length)}`,
358
+ analysis: "",
359
+ optimized: raw.slice(o.index + o.length, a.index).trim()
360
+ };
231
361
  }
232
362
  if (o) {
233
- const e = findMarker(raw, "END", o.index + o.length);
234
- optimized = raw.slice(o.index + o.length, e ? e.index : raw.length).trim();
363
+ const analysis = a && a.index < o.index ? raw.slice(a.index + a.length, o.index).trim() : "";
364
+ return { compacted: `${MARKERS.optimized}
365
+ ${raw.slice(o.index + o.length)}`, analysis, optimized: "" };
235
366
  }
236
- return { analysis, optimized };
237
- }
238
- function compactPartialBuffer(raw) {
239
- const o = findMarker(raw, "OPTIMIZED");
240
- if (!o) return { compacted: null, analysis: "" };
241
- const a = findMarker(raw, "ANALYSIS");
242
- const analysis = a && a.index < o.index ? raw.slice(a.index + a.length, o.index).trim() : "";
243
- return { compacted: `${MARKERS.optimized}
244
- ${raw.slice(o.index + o.length)}`, analysis };
367
+ return { compacted: null, analysis: "", optimized: "" };
245
368
  }
246
369
  export {
247
370
  buildSystemPrompt,
248
371
  buildUserPayload,
249
372
  capConversationContext,
250
373
  compactPartialBuffer,
374
+ createThinkFilter,
251
375
  estimateTokens,
252
376
  parseOptimizerOutput,
253
- parsePartialOptimizerOutput
377
+ parsePartialOptimizerOutput,
378
+ stripThinkBlocks
254
379
  };
package/package.json CHANGED
@@ -1,73 +1,74 @@
1
- {
2
- "name": "@y1x1n/dsh-prompt-optimizer",
3
- "version": "0.3.16",
4
- "description": "DeepSeek Harness 插件:在发送栏旁一键分析并优化提示词(复用当前会话模型)",
5
- "license": "MIT",
6
- "type": "module",
7
- "main": "lib/index.js",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/Y1X1n/dsh-prompt-optimizer.git"
11
- },
12
- "bugs": {
13
- "url": "https://github.com/Y1X1n/dsh-prompt-optimizer/issues"
14
- },
15
- "homepage": "https://github.com/Y1X1n/dsh-prompt-optimizer#readme",
16
- "keywords": [
17
- "deepseek",
18
- "dsh",
19
- "harness",
20
- "prompt",
21
- "optimizer",
22
- "plugin",
23
- "cordis"
24
- ],
25
- "engines": {
26
- "node": ">=18"
27
- },
28
- "exports": {
29
- ".": "./lib/index.js",
30
- "./client": "./lib/client.js",
31
- "./package.json": "./package.json"
32
- },
33
- "files": [
34
- "lib/",
35
- "cordis.patch.yml",
36
- "README.md"
37
- ],
38
- "scripts": {
39
- "build": "node scripts/build.mjs",
40
- "prepare": "node scripts/build.mjs",
41
- "sync:types": "node scripts/sync-types.mjs",
42
- "typecheck": "tsc --noEmit",
43
- "test": "node test/smoke.mjs && node test/prompt.test.mjs && node test/controller.test.mjs"
44
- },
45
- "dsh": {
46
- "bundle": {
47
- "patch": "./cordis.patch.yml"
48
- },
49
- "client": {
50
- "platform": "web",
51
- "inject": [
52
- "@deepseek-ai/dsh-client-connection",
53
- "@deepseek-ai/dsh-client-ui-conversation",
54
- "@deepseek-ai/dsh-client-ui-settings",
55
- "@deepseek-ai/dsh-client-ui-settings-plugins"
56
- ]
57
- }
58
- },
59
- "dependencies": {
60
- "@deepseek-ai/dsh-settings": "^0.1.2-rc.1",
61
- "@deepseek-ai/schemastery": "^3.18.1"
62
- },
63
- "devDependencies": {
64
- "@deepseek-ai/cordis": "^4.0.2",
65
- "@deepseek-ai/dsh-host-webserver": "^0.1.2-rc.1",
66
- "@deepseek-ai/dsh-llm": "^0.1.2-rc.1",
67
- "@types/node": "^20.0.0",
68
- "@types/react": "^18.3.1",
69
- "esbuild": "^0.24.0",
70
- "react": "^18.2.0",
71
- "typescript": "^5.5.0"
72
- }
73
- }
1
+ {
2
+ "name": "@y1x1n/dsh-prompt-optimizer",
3
+ "version": "0.6.4",
4
+ "description": "DeepSeek Harness 插件:在发送栏旁一键分析并优化提示词(复用当前会话模型)。适配 dsh 0.2.2-rc.1(含官方桌面端)",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "lib/index.js",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Y1X1n/dsh-prompt-optimizer.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Y1X1n/dsh-prompt-optimizer/issues"
14
+ },
15
+ "homepage": "https://github.com/Y1X1n/dsh-prompt-optimizer#readme",
16
+ "keywords": [
17
+ "deepseek",
18
+ "dsh",
19
+ "harness",
20
+ "prompt",
21
+ "optimizer",
22
+ "plugin",
23
+ "cordis"
24
+ ],
25
+ "engines": {
26
+ "node": ">=18",
27
+ "dsh": ">=0.1.0-rc.7 <0.3.0-0"
28
+ },
29
+ "exports": {
30
+ ".": "./lib/index.js",
31
+ "./client": "./lib/client.js",
32
+ "./package.json": "./package.json"
33
+ },
34
+ "files": [
35
+ "lib/",
36
+ "cordis.patch.yml",
37
+ "README.md"
38
+ ],
39
+ "scripts": {
40
+ "build": "node scripts/build.mjs",
41
+ "prepare": "node scripts/build.mjs",
42
+ "sync:types": "node scripts/sync-types.mjs",
43
+ "typecheck": "tsc --noEmit",
44
+ "test": "node test/smoke.mjs && node test/prompt.test.mjs && node test/controller.test.mjs && node test/slot-guard.test.mjs && node test/upstream-contract.test.mjs"
45
+ },
46
+ "dsh": {
47
+ "manifestVersion": 1,
48
+ "bundle": {
49
+ "patch": "./cordis.patch.yml"
50
+ },
51
+ "client": {
52
+ "platform": "web",
53
+ "inject": [
54
+ "@deepseek-ai/dsh-client-connection",
55
+ "@deepseek-ai/dsh-client-ui-conversation",
56
+ "@deepseek-ai/dsh-client-ui-settings",
57
+ "@deepseek-ai/dsh-client-ui-settings-plugins"
58
+ ]
59
+ }
60
+ },
61
+ "dependencies": {
62
+ "@deepseek-ai/schemastery": "^3.19.0"
63
+ },
64
+ "devDependencies": {
65
+ "@deepseek-ai/cordis": "^4.1.0",
66
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.1",
67
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
68
+ "@types/node": "^20.0.0",
69
+ "@types/react": "^18.3.1",
70
+ "esbuild": "^0.24.0",
71
+ "react": "^18.2.0",
72
+ "typescript": "^5.5.0"
73
+ }
74
+ }