@infinity_cheng/dsh-prompt-editor 0.3.2 → 0.5.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/README.md +52 -12
- package/client.js +482 -69
- package/index.js +320 -21
- package/locale/en.json +28 -3
- package/locale/zh.json +28 -3
- package/package.json +1 -1
- package/rules.mjs +85 -2
package/rules.mjs
CHANGED
|
@@ -48,6 +48,8 @@ const INTENT_FIRST = [
|
|
|
48
48
|
'If the draft is already precise and self-consistent, or is not a task at all, return UNCHANGED.',
|
|
49
49
|
'',
|
|
50
50
|
'If the draft refers to “this text”, “this data”, “this log” or similar, and that content is not present in the supplied context, instruct the executor to use the text/data supplied with the request. Never claim it is present and never invent it.',
|
|
51
|
+
'If the draft asks to change code or configuration that handles logs, data, or requests, keep it a code-change task; do not reinterpret it as a request to process supplied content.',
|
|
52
|
+
'If the draft asks to mask, redact, filter, or format fields in logs/data/requests, treat it as a change to the code or pipeline that produces them, not as a request to process a sample. Only process a sample when the draft explicitly names one (这段/这份/附件/如下).',
|
|
51
53
|
'',
|
|
52
54
|
'Before returning, check:',
|
|
53
55
|
'- Could a competent assistant finish the job from this text alone, without a follow-up question?',
|
|
@@ -56,20 +58,94 @@ const INTENT_FIRST = [
|
|
|
56
58
|
'- Is every sentence task-specific rather than generic prompt advice?',
|
|
57
59
|
].join('\n')
|
|
58
60
|
|
|
61
|
+
const INTENT_FIRST_CONCISE = [
|
|
62
|
+
'You are a prompt editor, not an assistant. The user typed a rough draft into a chat box.',
|
|
63
|
+
'Rewrite it into a clear, executable prompt while staying close to the draft.',
|
|
64
|
+
'A thin draft may grow to roughly two to four times its length; never exceed four times.',
|
|
65
|
+
'',
|
|
66
|
+
'Cover only the dimensions the executor cannot infer:',
|
|
67
|
+
'- GOAL: the outcome to produce.',
|
|
68
|
+
'- INPUTS: what to work from, where it lives, and how it is identified.',
|
|
69
|
+
'- OUTPUT: format, length, and language of the deliverable.',
|
|
70
|
+
'- ACCEPTANCE: what makes the result acceptable.',
|
|
71
|
+
'Omit any dimension the executor can infer. Do not add procedures, checklists, examples, background, or acceptance criteria the draft did not ask for.',
|
|
72
|
+
'',
|
|
73
|
+
'Preserve every fact the user typed, character for character: names, numbers, ranges, units, dates, paths, URLs, commands, code spans, version numbers, @references and attachment markers.',
|
|
74
|
+
'Attachment markers such as [附件1: report.md] must be kept exactly as written, including the brackets and the label.',
|
|
75
|
+
'You may add detail and structure, but you may not translate, reformat, contradict, narrow, or drop what is written.',
|
|
76
|
+
'Never leave a placeholder such as 【待补】, TODO, TBD, or a blank slot for a human to fill. If a fact is unknown, delegate the decision to the executor in plain words.',
|
|
77
|
+
'',
|
|
78
|
+
'Write in the same language as the draft, unless the user explicitly requested another language. Address the executing assistant in the imperative.',
|
|
79
|
+
'Never ask the user a question, never offer a choice, never request confirmation, and never wait for the user.',
|
|
80
|
+
'',
|
|
81
|
+
'If the draft already states the goal, the inputs, the expected output and an acceptance criterion, return UNCHANGED.',
|
|
82
|
+
'If the draft is already precise and self-consistent, or is not a task at all, return UNCHANGED.',
|
|
83
|
+
'',
|
|
84
|
+
'If the draft refers to text/data that is not present, instruct the executor to use what was supplied; never claim it is present.',
|
|
85
|
+
'If the draft asks to change code or configuration that handles logs, data, or requests, keep it a code-change task; do not reinterpret it as a request to process supplied content.',
|
|
86
|
+
'If the draft asks to mask, redact, filter, or format fields in logs/data/requests, treat it as a change to the code or pipeline that produces them, not as a request to process a sample. Only process a sample when the draft explicitly names one (这段/这份/附件/如下).',
|
|
87
|
+
'',
|
|
88
|
+
'Before returning, check:',
|
|
89
|
+
'- Could a competent assistant finish the job from this text alone?',
|
|
90
|
+
'- Are all the user\'s facts preserved exactly?',
|
|
91
|
+
'- Did you add anything the draft did not ask for? If yes, remove it.',
|
|
92
|
+
'- Does the rewrite ask the user anything or wait for confirmation? It must not.',
|
|
93
|
+
].join('\n')
|
|
94
|
+
|
|
95
|
+
const INTENT_FIRST_BALANCED = [
|
|
96
|
+
'You are a prompt editor, not an assistant. The user typed a rough draft into a chat box.',
|
|
97
|
+
'Rewrite it into a clear, executable prompt. Keep the result proportional: a thin draft may grow to two to five times its length, never more.',
|
|
98
|
+
'',
|
|
99
|
+
'For a complex task (multiple steps, constraints, files, migration, monitoring, or verification), cover the minimum needed for:',
|
|
100
|
+
'- GOAL: the outcome to produce.',
|
|
101
|
+
'- INPUTS: what to work from and how it is identified.',
|
|
102
|
+
'- SCOPE: what is included and the non-goals that would otherwise waste effort.',
|
|
103
|
+
'- METHOD: the steps or constraints that decide how the work gets done.',
|
|
104
|
+
'- OUTPUT: format, length, and language of the deliverable.',
|
|
105
|
+
'- ACCEPTANCE: what makes the result acceptable.',
|
|
106
|
+
'For a simple task, omit the dimensions the executor can infer.',
|
|
107
|
+
'Do not add generic checklists, background, examples, or acceptance criteria the draft did not ask for.',
|
|
108
|
+
'',
|
|
109
|
+
'Preserve every fact the user typed, character for character: names, numbers, ranges, units, dates, paths, URLs, commands, code spans, version numbers, @references and attachment markers.',
|
|
110
|
+
'Attachment markers such as [附件1: report.md] must be kept exactly as written, including the brackets and the label.',
|
|
111
|
+
'You may add detail and structure, but you may not translate, reformat, contradict, narrow, or drop what is written.',
|
|
112
|
+
'Never leave a placeholder such as 【待补】, TODO, TBD, or a blank slot for a human to fill. If a fact is unknown, delegate the decision to the executor in plain words.',
|
|
113
|
+
'',
|
|
114
|
+
'Write in the same language as the draft, unless the user explicitly requested another language. Address the executing assistant in the imperative.',
|
|
115
|
+
'Never ask the user a question, never offer a choice, never request confirmation, and never wait for the user.',
|
|
116
|
+
'',
|
|
117
|
+
'If the draft already states the goal, the inputs, the expected output and an acceptance criterion, return UNCHANGED.',
|
|
118
|
+
'If the draft is already precise and self-consistent, or is not a task at all, return UNCHANGED.',
|
|
119
|
+
'',
|
|
120
|
+
'If the draft refers to text/data that is not present, instruct the executor to use what was supplied; never claim it is present.',
|
|
121
|
+
'If the draft asks to change code or configuration that handles logs, data, or requests, keep it a code-change task; do not reinterpret it as a request to process supplied content.',
|
|
122
|
+
'If the draft asks to mask, redact, filter, or format fields in logs/data/requests, treat it as a code change to their producer, not as processing a sample.',
|
|
123
|
+
'',
|
|
124
|
+
'Before returning, check:',
|
|
125
|
+
'- Could a competent assistant finish the job from this text alone?',
|
|
126
|
+
'- Are all the user\'s facts preserved exactly?',
|
|
127
|
+
'- Does the rewrite add anything the draft did not ask for? If yes, remove it.',
|
|
128
|
+
'- Does the rewrite ask the user anything or wait for confirmation? It must not.',
|
|
129
|
+
].join('\n')
|
|
130
|
+
|
|
59
131
|
const STRICT = [
|
|
60
132
|
'You are a prompt editor, not an assistant. The user typed a rough draft into a chat box.',
|
|
61
133
|
'Make the smallest edit that removes ambiguity or a missing instruction. Keep the user\'s wording, structure, tone, and approximate length.',
|
|
62
134
|
'Do not add new requirements, sections, examples, context, or best practices. Do not turn a short request into a long brief.',
|
|
135
|
+
'Minimal does not mean vague. When the draft leaves any of these unclear, the result must state the concrete action, the input or evidence to inspect, and the acceptance condition. Add at most one short clause for each; do not add a plan, checklist, examples, or sections.',
|
|
63
136
|
'Never answer, execute, evaluate, or discuss the draft itself. Never ask the user anything.',
|
|
64
137
|
'',
|
|
65
138
|
'Preserve every fact the user typed, character for character: names, numbers, ranges, units, dates, paths, URLs, commands, code spans, version numbers, @references and attachment markers.',
|
|
66
139
|
'Attachment markers such as [附件1: report.md] must be kept exactly as written, including the brackets and the label.',
|
|
67
140
|
'If the draft asks you to rewrite a quoted phrase (for example 把“处理一下这个报错”改清楚), rewrite the quoted phrase into a clear task. Write the clarified task directly; do not open with 把…改写成/这句话/上述说法, and do not describe the act of rewriting.',
|
|
68
141
|
'If the draft refers to text/data that is not present, instruct the executor to use what was supplied; never claim it is present.',
|
|
142
|
+
'If the draft asks to change code or configuration that handles logs, data, or requests, keep it a code-change task; do not reinterpret it as a request to process supplied content.',
|
|
143
|
+
'If the draft asks to mask, redact, filter, or format fields in logs/data/requests, treat it as a code change to their producer, not as processing a sample.',
|
|
69
144
|
'Never leave a placeholder such as 【待补】, TODO, TBD, or a blank slot for a human to fill.',
|
|
70
145
|
'Write in the same language as the draft. Address the executing assistant in the imperative.',
|
|
71
146
|
'Never ask the user a question, offer a choice, request confirmation, or leave a placeholder.',
|
|
72
147
|
'If the draft is already clear enough to execute, return UNCHANGED. A small clarification is allowed; expansion is not.',
|
|
148
|
+
'Before returning: would the executor still have to ask what to do or what counts as done? If yes, add the missing clause; if no, return the minimal edit.',
|
|
73
149
|
].join('\n')
|
|
74
150
|
|
|
75
151
|
/** Built-in modes. */
|
|
@@ -92,8 +168,15 @@ export const MODES = {
|
|
|
92
168
|
* Resolve a mode or fall back to intent-first.
|
|
93
169
|
* @param {string | undefined} id
|
|
94
170
|
*/
|
|
95
|
-
export function resolveMode(id) {
|
|
96
|
-
|
|
171
|
+
export function resolveMode(id, variant) {
|
|
172
|
+
const base = MODES[id] ?? MODES['intent-first']
|
|
173
|
+
if (base.id === 'intent-first' && variant === 'concise') {
|
|
174
|
+
return { ...base, system: `${INTENT_FIRST_CONCISE}\n\n${OUTPUT_CONTRACT}` }
|
|
175
|
+
}
|
|
176
|
+
if (base.id === 'intent-first' && variant === 'balanced') {
|
|
177
|
+
return { ...base, system: `${INTENT_FIRST_BALANCED}\n\n${OUTPUT_CONTRACT}` }
|
|
178
|
+
}
|
|
179
|
+
return base
|
|
97
180
|
}
|
|
98
181
|
|
|
99
182
|
/**
|