mcp-rubber-duck 1.2.5 ā 1.4.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/.env.desktop.example +1 -1
- package/.env.pi.example +1 -1
- package/.env.template +1 -1
- package/.eslintrc.json +1 -0
- package/CHANGELOG.md +19 -0
- package/README.md +238 -44
- package/assets/mcp-rubber-duck.png +0 -0
- package/audit-ci.json +2 -1
- package/config/config.example.json +4 -4
- package/dist/config/config.js +4 -4
- package/dist/config/config.js.map +1 -1
- package/dist/config/types.d.ts +78 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +150 -0
- package/dist/server.js.map +1 -1
- package/dist/services/consensus.d.ts +28 -0
- package/dist/services/consensus.d.ts.map +1 -0
- package/dist/services/consensus.js +257 -0
- package/dist/services/consensus.js.map +1 -0
- package/dist/tools/duck-debate.d.ts +16 -0
- package/dist/tools/duck-debate.d.ts.map +1 -0
- package/dist/tools/duck-debate.js +272 -0
- package/dist/tools/duck-debate.js.map +1 -0
- package/dist/tools/duck-iterate.d.ts +14 -0
- package/dist/tools/duck-iterate.d.ts.map +1 -0
- package/dist/tools/duck-iterate.js +195 -0
- package/dist/tools/duck-iterate.js.map +1 -0
- package/dist/tools/duck-judge.d.ts +15 -0
- package/dist/tools/duck-judge.d.ts.map +1 -0
- package/dist/tools/duck-judge.js +208 -0
- package/dist/tools/duck-judge.js.map +1 -0
- package/dist/tools/duck-vote.d.ts +14 -0
- package/dist/tools/duck-vote.d.ts.map +1 -0
- package/dist/tools/duck-vote.js +46 -0
- package/dist/tools/duck-vote.js.map +1 -0
- package/docker-compose.yml +1 -1
- package/package.json +1 -1
- package/src/config/config.ts +4 -4
- package/src/config/types.ts +92 -0
- package/src/server.ts +154 -0
- package/src/services/consensus.ts +324 -0
- package/src/tools/duck-debate.ts +383 -0
- package/src/tools/duck-iterate.ts +253 -0
- package/src/tools/duck-judge.ts +301 -0
- package/src/tools/duck-vote.ts +87 -0
- package/tests/consensus.test.ts +282 -0
- package/tests/duck-debate.test.ts +286 -0
- package/tests/duck-iterate.test.ts +249 -0
- package/tests/duck-judge.test.ts +296 -0
- package/tests/duck-vote.test.ts +250 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ProviderManager } from '../providers/manager.js';
|
|
2
|
+
import { DebateFormat } from '../config/types.js';
|
|
3
|
+
export interface DuckDebateArgs {
|
|
4
|
+
prompt: string;
|
|
5
|
+
rounds?: number;
|
|
6
|
+
providers?: string[];
|
|
7
|
+
format: DebateFormat;
|
|
8
|
+
synthesizer?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function duckDebateTool(providerManager: ProviderManager, args: Record<string, unknown>): Promise<{
|
|
11
|
+
content: {
|
|
12
|
+
type: string;
|
|
13
|
+
text: string;
|
|
14
|
+
}[];
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=duck-debate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duck-debate.d.ts","sourceRoot":"","sources":["../../src/tools/duck-debate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,YAAY,EAKb,MAAM,oBAAoB,CAAC;AAG5B,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAID,wBAAsB,cAAc,CAClC,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;GAgH9B"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { logger } from '../utils/logger.js';
|
|
2
|
+
const DEFAULT_ROUNDS = 3;
|
|
3
|
+
export async function duckDebateTool(providerManager, args) {
|
|
4
|
+
const { prompt, rounds = DEFAULT_ROUNDS, providers, format, synthesizer, } = args;
|
|
5
|
+
// Validate inputs
|
|
6
|
+
if (!prompt || typeof prompt !== 'string') {
|
|
7
|
+
throw new Error('Prompt/topic is required');
|
|
8
|
+
}
|
|
9
|
+
if (!format || !['oxford', 'socratic', 'adversarial'].includes(format)) {
|
|
10
|
+
throw new Error('Format must be "oxford", "socratic", or "adversarial"');
|
|
11
|
+
}
|
|
12
|
+
if (rounds < 1 || rounds > 10) {
|
|
13
|
+
throw new Error('Rounds must be between 1 and 10');
|
|
14
|
+
}
|
|
15
|
+
// Get providers
|
|
16
|
+
const allProviders = providerManager.getProviderNames();
|
|
17
|
+
// If providers explicitly specified but less than 2, error
|
|
18
|
+
if (providers && providers.length < 2) {
|
|
19
|
+
throw new Error('At least 2 providers are required for a debate');
|
|
20
|
+
}
|
|
21
|
+
const debateProviders = providers && providers.length >= 2
|
|
22
|
+
? providers
|
|
23
|
+
: allProviders;
|
|
24
|
+
if (debateProviders.length < 2) {
|
|
25
|
+
throw new Error('At least 2 providers are required for a debate');
|
|
26
|
+
}
|
|
27
|
+
// Validate providers exist
|
|
28
|
+
for (const p of debateProviders) {
|
|
29
|
+
if (!allProviders.includes(p)) {
|
|
30
|
+
throw new Error(`Provider "${p}" not found`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
logger.info(`Starting ${format} debate with ${debateProviders.length} participants for ${rounds} rounds`);
|
|
34
|
+
// Assign positions based on format
|
|
35
|
+
const participants = assignPositions(debateProviders, format, providerManager);
|
|
36
|
+
// Run debate rounds
|
|
37
|
+
const debateRounds = [];
|
|
38
|
+
for (let roundNum = 1; roundNum <= rounds; roundNum++) {
|
|
39
|
+
logger.info(`Debate round ${roundNum}/${rounds}`);
|
|
40
|
+
const roundArguments = [];
|
|
41
|
+
// Each participant argues in this round
|
|
42
|
+
for (const participant of participants) {
|
|
43
|
+
const argumentPrompt = buildArgumentPrompt(prompt, format, participant, roundNum, debateRounds, participants);
|
|
44
|
+
const response = await providerManager.askDuck(participant.provider, argumentPrompt);
|
|
45
|
+
roundArguments.push({
|
|
46
|
+
round: roundNum,
|
|
47
|
+
provider: participant.provider,
|
|
48
|
+
nickname: participant.nickname,
|
|
49
|
+
position: participant.position,
|
|
50
|
+
content: response.content,
|
|
51
|
+
timestamp: new Date(),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
debateRounds.push(roundArguments);
|
|
55
|
+
}
|
|
56
|
+
// Generate synthesis
|
|
57
|
+
const synthesizerProvider = synthesizer || debateProviders[0];
|
|
58
|
+
const synthesisPrompt = buildSynthesisPrompt(prompt, format, debateRounds, participants);
|
|
59
|
+
const synthesisResponse = await providerManager.askDuck(synthesizerProvider, synthesisPrompt);
|
|
60
|
+
const result = {
|
|
61
|
+
topic: prompt,
|
|
62
|
+
format,
|
|
63
|
+
participants,
|
|
64
|
+
rounds: debateRounds,
|
|
65
|
+
synthesis: synthesisResponse.content,
|
|
66
|
+
synthesizer: synthesizerProvider,
|
|
67
|
+
totalRounds: rounds,
|
|
68
|
+
};
|
|
69
|
+
// Format output
|
|
70
|
+
const formattedOutput = formatDebateResult(result);
|
|
71
|
+
logger.info(`Debate completed: ${rounds} rounds, synthesized by ${synthesizerProvider}`);
|
|
72
|
+
return {
|
|
73
|
+
content: [
|
|
74
|
+
{
|
|
75
|
+
type: 'text',
|
|
76
|
+
text: formattedOutput,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function assignPositions(providers, format, providerManager) {
|
|
82
|
+
const participants = [];
|
|
83
|
+
for (let i = 0; i < providers.length; i++) {
|
|
84
|
+
const provider = providers[i];
|
|
85
|
+
const providerInfo = providerManager.getProvider(provider);
|
|
86
|
+
let position;
|
|
87
|
+
if (format === 'oxford') {
|
|
88
|
+
// Oxford: alternating pro/con
|
|
89
|
+
position = i % 2 === 0 ? 'pro' : 'con';
|
|
90
|
+
}
|
|
91
|
+
else if (format === 'adversarial') {
|
|
92
|
+
// Adversarial: first is defender, rest are challengers (con)
|
|
93
|
+
position = i === 0 ? 'pro' : 'con';
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Socratic: all neutral, questioning each other
|
|
97
|
+
position = 'neutral';
|
|
98
|
+
}
|
|
99
|
+
participants.push({
|
|
100
|
+
provider,
|
|
101
|
+
nickname: providerInfo.nickname,
|
|
102
|
+
position,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return participants;
|
|
106
|
+
}
|
|
107
|
+
function buildArgumentPrompt(topic, format, participant, round, previousRounds, allParticipants) {
|
|
108
|
+
const previousContext = buildPreviousContext(previousRounds);
|
|
109
|
+
if (format === 'oxford') {
|
|
110
|
+
return buildOxfordPrompt(topic, participant, round, previousContext);
|
|
111
|
+
}
|
|
112
|
+
else if (format === 'socratic') {
|
|
113
|
+
return buildSocraticPrompt(topic, participant, round, previousContext, allParticipants);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
return buildAdversarialPrompt(topic, participant, round, previousContext);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function buildPreviousContext(previousRounds) {
|
|
120
|
+
if (previousRounds.length === 0) {
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
let context = '\n\nPREVIOUS ARGUMENTS:\n';
|
|
124
|
+
for (const round of previousRounds) {
|
|
125
|
+
for (const arg of round) {
|
|
126
|
+
const posLabel = arg.position === 'pro' ? '[PRO]' :
|
|
127
|
+
arg.position === 'con' ? '[CON]' : '[NEUTRAL]';
|
|
128
|
+
context += `\n--- Round ${arg.round} - ${arg.nickname} ${posLabel} ---\n`;
|
|
129
|
+
context += `${arg.content}\n`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return context;
|
|
133
|
+
}
|
|
134
|
+
function buildOxfordPrompt(topic, participant, round, previousContext) {
|
|
135
|
+
const position = participant.position === 'pro' ? 'IN FAVOR OF' : 'AGAINST';
|
|
136
|
+
const positionLabel = participant.position === 'pro' ? 'PRO' : 'CON';
|
|
137
|
+
return `You are participating in an Oxford-style debate.
|
|
138
|
+
|
|
139
|
+
TOPIC: "${topic}"
|
|
140
|
+
|
|
141
|
+
YOUR POSITION: ${position} (${positionLabel})
|
|
142
|
+
ROUND: ${round}
|
|
143
|
+
|
|
144
|
+
${previousContext}
|
|
145
|
+
|
|
146
|
+
INSTRUCTIONS:
|
|
147
|
+
1. Present clear, logical arguments ${position.toLowerCase()} the topic
|
|
148
|
+
2. ${round > 1 ? 'Address and rebut opposing arguments from previous rounds' : 'Establish your core thesis and supporting points'}
|
|
149
|
+
3. Use evidence, examples, and reasoning
|
|
150
|
+
4. Be persuasive but intellectually honest
|
|
151
|
+
5. Keep your argument focused and structured
|
|
152
|
+
|
|
153
|
+
Present your argument for Round ${round}:`;
|
|
154
|
+
}
|
|
155
|
+
function buildSocraticPrompt(topic, participant, round, previousContext, allParticipants) {
|
|
156
|
+
const otherParticipants = allParticipants
|
|
157
|
+
.filter(p => p.provider !== participant.provider)
|
|
158
|
+
.map(p => p.nickname)
|
|
159
|
+
.join(', ');
|
|
160
|
+
return `You are participating in a Socratic dialogue.
|
|
161
|
+
|
|
162
|
+
TOPIC: "${topic}"
|
|
163
|
+
|
|
164
|
+
YOUR ROLE: Philosophical inquirer exploring the topic through questions and reasoning
|
|
165
|
+
OTHER PARTICIPANTS: ${otherParticipants}
|
|
166
|
+
ROUND: ${round}
|
|
167
|
+
|
|
168
|
+
${previousContext}
|
|
169
|
+
|
|
170
|
+
INSTRUCTIONS:
|
|
171
|
+
1. ${round === 1 ? 'Begin by questioning assumptions about the topic' : 'Build on previous responses with deeper questions'}
|
|
172
|
+
2. Use the Socratic method: ask probing questions that reveal underlying assumptions
|
|
173
|
+
3. Offer your own perspective while remaining open to other views
|
|
174
|
+
4. Seek to understand the truth through dialogue, not to "win"
|
|
175
|
+
5. Challenge ideas respectfully and constructively
|
|
176
|
+
|
|
177
|
+
Present your contribution to Round ${round}:`;
|
|
178
|
+
}
|
|
179
|
+
function buildAdversarialPrompt(topic, participant, round, previousContext) {
|
|
180
|
+
const role = participant.position === 'pro' ? 'DEFENDER' : 'CHALLENGER';
|
|
181
|
+
const instruction = participant.position === 'pro'
|
|
182
|
+
? 'Defend the proposition and address all critiques raised'
|
|
183
|
+
: 'Attack weaknesses in the arguments, find flaws, and present counter-examples';
|
|
184
|
+
return `You are participating in an adversarial debate.
|
|
185
|
+
|
|
186
|
+
TOPIC: "${topic}"
|
|
187
|
+
|
|
188
|
+
YOUR ROLE: ${role}
|
|
189
|
+
ROUND: ${round}
|
|
190
|
+
|
|
191
|
+
${previousContext}
|
|
192
|
+
|
|
193
|
+
INSTRUCTIONS:
|
|
194
|
+
1. ${instruction}
|
|
195
|
+
2. Be rigorous and thorough in your analysis
|
|
196
|
+
3. ${participant.position === 'con' ? 'Identify logical fallacies, weak evidence, or missing considerations' : 'Strengthen your position against attacks'}
|
|
197
|
+
4. Use concrete examples and evidence
|
|
198
|
+
5. Be intellectually aggressive but fair
|
|
199
|
+
|
|
200
|
+
Present your ${role.toLowerCase()} argument for Round ${round}:`;
|
|
201
|
+
}
|
|
202
|
+
function buildSynthesisPrompt(topic, format, rounds, participants) {
|
|
203
|
+
let transcript = '';
|
|
204
|
+
for (const round of rounds) {
|
|
205
|
+
for (const arg of round) {
|
|
206
|
+
const posLabel = arg.position === 'pro' ? '[PRO]' :
|
|
207
|
+
arg.position === 'con' ? '[CON]' : '[NEUTRAL]';
|
|
208
|
+
transcript += `\n--- Round ${arg.round} - ${arg.nickname} ${posLabel} ---\n`;
|
|
209
|
+
transcript += `${arg.content}\n`;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const participantList = participants
|
|
213
|
+
.map(p => `${p.nickname} (${p.position})`)
|
|
214
|
+
.join(', ');
|
|
215
|
+
return `You are the moderator synthesizing a ${format} debate.
|
|
216
|
+
|
|
217
|
+
TOPIC: "${topic}"
|
|
218
|
+
PARTICIPANTS: ${participantList}
|
|
219
|
+
|
|
220
|
+
DEBATE TRANSCRIPT:
|
|
221
|
+
${transcript}
|
|
222
|
+
|
|
223
|
+
YOUR TASK:
|
|
224
|
+
1. Summarize the key arguments from each side
|
|
225
|
+
2. Identify the strongest points made
|
|
226
|
+
3. Note where participants agreed or found common ground
|
|
227
|
+
4. Highlight unresolved tensions or questions
|
|
228
|
+
5. Provide a balanced conclusion (who had stronger arguments, or if it was a draw)
|
|
229
|
+
6. Suggest what additional considerations might be valuable
|
|
230
|
+
|
|
231
|
+
Provide your synthesis:`;
|
|
232
|
+
}
|
|
233
|
+
function formatDebateResult(result) {
|
|
234
|
+
const formatEmoji = result.format === 'oxford' ? 'š' :
|
|
235
|
+
result.format === 'socratic' ? 'šļø' : 'āļø';
|
|
236
|
+
let output = `${formatEmoji} **${result.format.charAt(0).toUpperCase() + result.format.slice(1)} Debate**\n`;
|
|
237
|
+
output += `āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n\n`;
|
|
238
|
+
output += `**Topic:** "${result.topic}"\n`;
|
|
239
|
+
output += `**Format:** ${result.format}\n`;
|
|
240
|
+
output += `**Rounds:** ${result.totalRounds}\n\n`;
|
|
241
|
+
// Participants
|
|
242
|
+
output += `**Participants:**\n`;
|
|
243
|
+
for (const p of result.participants) {
|
|
244
|
+
const posEmoji = p.position === 'pro' ? 'ā
' : p.position === 'con' ? 'ā' : 'š';
|
|
245
|
+
output += ` ${posEmoji} ${p.nickname} (${p.position})\n`;
|
|
246
|
+
}
|
|
247
|
+
output += `\n`;
|
|
248
|
+
// Debate rounds
|
|
249
|
+
output += `**Debate Transcript:**\n`;
|
|
250
|
+
output += `āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`;
|
|
251
|
+
for (let i = 0; i < result.rounds.length; i++) {
|
|
252
|
+
output += `\nš¢ **ROUND ${i + 1}**\n`;
|
|
253
|
+
for (const arg of result.rounds[i]) {
|
|
254
|
+
const posEmoji = arg.position === 'pro' ? 'ā
' : arg.position === 'con' ? 'ā' : 'š';
|
|
255
|
+
output += `\n${posEmoji} **${arg.nickname}** [${arg.position.toUpperCase()}]:\n`;
|
|
256
|
+
// Truncate long arguments
|
|
257
|
+
const displayContent = arg.content.length > 800
|
|
258
|
+
? arg.content.substring(0, 800) + '...[truncated]'
|
|
259
|
+
: arg.content;
|
|
260
|
+
output += `${displayContent}\n`;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Synthesis
|
|
264
|
+
output += `\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`;
|
|
265
|
+
output += `šÆ **Synthesis** (by ${result.synthesizer})\n`;
|
|
266
|
+
output += `āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`;
|
|
267
|
+
output += `${result.synthesis}\n`;
|
|
268
|
+
output += `\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`;
|
|
269
|
+
output += `š ${result.totalRounds} rounds completed with ${result.participants.length} participants\n`;
|
|
270
|
+
return output;
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=duck-debate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duck-debate.js","sourceRoot":"","sources":["../../src/tools/duck-debate.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAU5C,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,eAAgC,EAChC,IAA6B;IAE7B,MAAM,EACJ,MAAM,EACN,MAAM,GAAG,cAAc,EACvB,SAAS,EACT,MAAM,EACN,WAAW,GACZ,GAAG,IAAiC,CAAC;IAEtC,kBAAkB;IAClB,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC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,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;YACpF,MAAM,IAAI,KAAK,QAAQ,MAAM,GAAG,CAAC,QAAQ,OAAO,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;YAEjF,0BAA0B;YAC1B,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG;gBAC7C,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,gBAAgB;gBAClD,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;YAChB,MAAM,IAAI,GAAG,cAAc,IAAI,CAAC;QAClC,CAAC;IACH,CAAC;IAED,YAAY;IACZ,MAAM,IAAI,6CAA6C,CAAC;IACxD,MAAM,IAAI,wBAAwB,MAAM,CAAC,WAAW,KAAK,CAAC;IAC1D,MAAM,IAAI,yCAAyC,CAAC;IACpD,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC;IAElC,MAAM,IAAI,6CAA6C,CAAC;IACxD,MAAM,IAAI,MAAM,MAAM,CAAC,WAAW,0BAA0B,MAAM,CAAC,YAAY,CAAC,MAAM,iBAAiB,CAAC;IAExG,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ProviderManager } from '../providers/manager.js';
|
|
2
|
+
export interface DuckIterateArgs {
|
|
3
|
+
prompt: string;
|
|
4
|
+
iterations?: number;
|
|
5
|
+
providers: [string, string];
|
|
6
|
+
mode: 'refine' | 'critique-improve';
|
|
7
|
+
}
|
|
8
|
+
export declare function duckIterateTool(providerManager: ProviderManager, args: Record<string, unknown>): Promise<{
|
|
9
|
+
content: {
|
|
10
|
+
type: string;
|
|
11
|
+
text: string;
|
|
12
|
+
}[];
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=duck-iterate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duck-iterate.d.ts","sourceRoot":"","sources":["../../src/tools/duck-iterate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI1D,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,IAAI,EAAE,QAAQ,GAAG,kBAAkB,CAAC;CACrC;AAKD,wBAAsB,eAAe,CACnC,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;GAkH9B"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { logger } from '../utils/logger.js';
|
|
2
|
+
const DEFAULT_ITERATIONS = 3;
|
|
3
|
+
const CONVERGENCE_THRESHOLD = 0.8; // 80% similarity indicates convergence
|
|
4
|
+
export async function duckIterateTool(providerManager, args) {
|
|
5
|
+
const { prompt, iterations = DEFAULT_ITERATIONS, providers, mode, } = args;
|
|
6
|
+
// Validate inputs
|
|
7
|
+
if (!prompt || typeof prompt !== 'string') {
|
|
8
|
+
throw new Error('Prompt is required');
|
|
9
|
+
}
|
|
10
|
+
if (!providers || !Array.isArray(providers) || providers.length !== 2) {
|
|
11
|
+
throw new Error('Exactly 2 providers are required for iteration');
|
|
12
|
+
}
|
|
13
|
+
if (!mode || !['refine', 'critique-improve'].includes(mode)) {
|
|
14
|
+
throw new Error('Mode must be either "refine" or "critique-improve"');
|
|
15
|
+
}
|
|
16
|
+
if (iterations < 1 || iterations > 10) {
|
|
17
|
+
throw new Error('Iterations must be between 1 and 10');
|
|
18
|
+
}
|
|
19
|
+
// Validate providers exist
|
|
20
|
+
const providerNames = providerManager.getProviderNames();
|
|
21
|
+
for (const p of providers) {
|
|
22
|
+
if (!providerNames.includes(p)) {
|
|
23
|
+
throw new Error(`Provider "${p}" not found`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
logger.info(`Starting ${mode} iteration with ${providers.join(' <-> ')} for ${iterations} rounds`);
|
|
27
|
+
const rounds = [];
|
|
28
|
+
let lastResponse = '';
|
|
29
|
+
let converged = false;
|
|
30
|
+
// Round 1: Initial generation by provider A
|
|
31
|
+
const initialResponse = await providerManager.askDuck(providers[0], prompt);
|
|
32
|
+
const providerAInfo = providerManager.getProvider(providers[0]);
|
|
33
|
+
rounds.push({
|
|
34
|
+
round: 1,
|
|
35
|
+
provider: providers[0],
|
|
36
|
+
nickname: providerAInfo.nickname,
|
|
37
|
+
role: 'generator',
|
|
38
|
+
content: initialResponse.content,
|
|
39
|
+
timestamp: new Date(),
|
|
40
|
+
});
|
|
41
|
+
lastResponse = initialResponse.content;
|
|
42
|
+
logger.info(`Round 1: ${providers[0]} generated initial response`);
|
|
43
|
+
// Subsequent rounds: Alternate between providers
|
|
44
|
+
for (let i = 2; i <= iterations; i++) {
|
|
45
|
+
const isProviderA = i % 2 === 1;
|
|
46
|
+
const currentProvider = isProviderA ? providers[0] : providers[1];
|
|
47
|
+
const providerInfo = providerManager.getProvider(currentProvider);
|
|
48
|
+
const iterationPrompt = buildIterationPrompt(prompt, lastResponse, mode, i, rounds);
|
|
49
|
+
const response = await providerManager.askDuck(currentProvider, iterationPrompt);
|
|
50
|
+
// Check for convergence
|
|
51
|
+
if (checkConvergence(lastResponse, response.content)) {
|
|
52
|
+
converged = true;
|
|
53
|
+
logger.info(`Convergence detected at round ${i}`);
|
|
54
|
+
}
|
|
55
|
+
const role = mode === 'refine' ? 'refiner' : (i % 2 === 0 ? 'critic' : 'refiner');
|
|
56
|
+
rounds.push({
|
|
57
|
+
round: i,
|
|
58
|
+
provider: currentProvider,
|
|
59
|
+
nickname: providerInfo.nickname,
|
|
60
|
+
role,
|
|
61
|
+
content: response.content,
|
|
62
|
+
timestamp: new Date(),
|
|
63
|
+
});
|
|
64
|
+
lastResponse = response.content;
|
|
65
|
+
logger.info(`Round ${i}: ${currentProvider} ${role === 'critic' ? 'critiqued' : 'refined'}`);
|
|
66
|
+
if (converged) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const result = {
|
|
71
|
+
prompt,
|
|
72
|
+
mode,
|
|
73
|
+
providers,
|
|
74
|
+
rounds,
|
|
75
|
+
finalResponse: lastResponse,
|
|
76
|
+
totalIterations: rounds.length,
|
|
77
|
+
converged,
|
|
78
|
+
};
|
|
79
|
+
// Format output
|
|
80
|
+
const formattedOutput = formatIterationResult(result);
|
|
81
|
+
logger.info(`Iteration completed: ${rounds.length} rounds, converged: ${converged}`);
|
|
82
|
+
return {
|
|
83
|
+
content: [
|
|
84
|
+
{
|
|
85
|
+
type: 'text',
|
|
86
|
+
text: formattedOutput,
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function buildIterationPrompt(originalPrompt, previousResponse, mode, round, previousRounds) {
|
|
92
|
+
if (mode === 'refine') {
|
|
93
|
+
return `You are refining a response through iterative improvement.
|
|
94
|
+
|
|
95
|
+
ORIGINAL TASK:
|
|
96
|
+
${originalPrompt}
|
|
97
|
+
|
|
98
|
+
PREVIOUS RESPONSE (Round ${round - 1}):
|
|
99
|
+
${previousResponse}
|
|
100
|
+
|
|
101
|
+
YOUR TASK:
|
|
102
|
+
Improve upon the previous response. Make it:
|
|
103
|
+
- More accurate
|
|
104
|
+
- More complete
|
|
105
|
+
- Clearer and better structured
|
|
106
|
+
- More practical and actionable
|
|
107
|
+
|
|
108
|
+
Provide your improved version directly. Do not explain what you changed - just give the improved response.`;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// critique-improve mode
|
|
112
|
+
const isEvenRound = round % 2 === 0;
|
|
113
|
+
if (isEvenRound) {
|
|
114
|
+
// Critic round
|
|
115
|
+
return `You are a critical reviewer evaluating a response.
|
|
116
|
+
|
|
117
|
+
ORIGINAL TASK:
|
|
118
|
+
${originalPrompt}
|
|
119
|
+
|
|
120
|
+
RESPONSE TO CRITIQUE:
|
|
121
|
+
${previousResponse}
|
|
122
|
+
|
|
123
|
+
YOUR TASK:
|
|
124
|
+
Provide a thorough critique of this response:
|
|
125
|
+
1. Identify specific weaknesses, errors, or gaps
|
|
126
|
+
2. Point out unclear or confusing parts
|
|
127
|
+
3. Suggest concrete improvements
|
|
128
|
+
4. Note any missing considerations
|
|
129
|
+
|
|
130
|
+
Be constructive but thorough. Format as a bulleted critique.`;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// Improvement round based on critique
|
|
134
|
+
const lastCritique = previousRounds[previousRounds.length - 1]?.content || '';
|
|
135
|
+
const lastGoodResponse = previousRounds[previousRounds.length - 2]?.content || previousResponse;
|
|
136
|
+
return `You are improving a response based on critical feedback.
|
|
137
|
+
|
|
138
|
+
ORIGINAL TASK:
|
|
139
|
+
${originalPrompt}
|
|
140
|
+
|
|
141
|
+
PREVIOUS RESPONSE:
|
|
142
|
+
${lastGoodResponse}
|
|
143
|
+
|
|
144
|
+
CRITIQUE RECEIVED:
|
|
145
|
+
${lastCritique}
|
|
146
|
+
|
|
147
|
+
YOUR TASK:
|
|
148
|
+
Create an improved response that addresses the critique points while maintaining the strengths of the original. Provide only the improved response, not meta-commentary.`;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function checkConvergence(previous, current) {
|
|
153
|
+
// Simple similarity check based on length and common words
|
|
154
|
+
const prevWords = new Set(previous.toLowerCase().split(/\s+/));
|
|
155
|
+
const currWords = new Set(current.toLowerCase().split(/\s+/));
|
|
156
|
+
const intersection = new Set([...prevWords].filter(x => currWords.has(x)));
|
|
157
|
+
const union = new Set([...prevWords, ...currWords]);
|
|
158
|
+
const similarity = intersection.size / union.size;
|
|
159
|
+
// Also check if lengths are similar
|
|
160
|
+
const lengthRatio = Math.min(previous.length, current.length) / Math.max(previous.length, current.length);
|
|
161
|
+
return similarity > CONVERGENCE_THRESHOLD && lengthRatio > 0.8;
|
|
162
|
+
}
|
|
163
|
+
function formatIterationResult(result) {
|
|
164
|
+
let output = `š **Iterative Refinement Results**\n`;
|
|
165
|
+
output += `āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n\n`;
|
|
166
|
+
output += `**Mode:** ${result.mode}\n`;
|
|
167
|
+
output += `**Providers:** ${result.providers.join(' ā ')}\n`;
|
|
168
|
+
output += `**Iterations:** ${result.totalIterations}`;
|
|
169
|
+
if (result.converged) {
|
|
170
|
+
output += ` (converged early ā)`;
|
|
171
|
+
}
|
|
172
|
+
output += `\n\n`;
|
|
173
|
+
// Show each round
|
|
174
|
+
output += `**Iteration History:**\n`;
|
|
175
|
+
output += `āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`;
|
|
176
|
+
for (const round of result.rounds) {
|
|
177
|
+
const roleEmoji = round.role === 'generator' ? 'šÆ' :
|
|
178
|
+
round.role === 'critic' ? 'š' : 'āØ';
|
|
179
|
+
output += `\n${roleEmoji} **Round ${round.round}: ${round.nickname}** (${round.role})\n`;
|
|
180
|
+
// Truncate long content for display
|
|
181
|
+
const displayContent = round.content.length > 500
|
|
182
|
+
? round.content.substring(0, 500) + '...[truncated]'
|
|
183
|
+
: round.content;
|
|
184
|
+
output += `${displayContent}\n`;
|
|
185
|
+
}
|
|
186
|
+
// Final response
|
|
187
|
+
output += `\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`;
|
|
188
|
+
output += `š **Final Response:**\n`;
|
|
189
|
+
output += `āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`;
|
|
190
|
+
output += `${result.finalResponse}\n`;
|
|
191
|
+
output += `\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`;
|
|
192
|
+
output += `š ${result.totalIterations} rounds completed\n`;
|
|
193
|
+
return output;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=duck-iterate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duck-iterate.js","sourceRoot":"","sources":["../../src/tools/duck-iterate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAS5C,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,qBAAqB,GAAG,GAAG,CAAC,CAAC,uCAAuC;AAE1E,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,eAAgC,EAChC,IAA6B;IAE7B,MAAM,EACJ,MAAM,EACN,UAAU,GAAG,kBAAkB,EAC/B,SAAS,EACT,IAAI,GACL,GAAG,IAAkC,CAAC;IAEvC,kBAAkB;IAClB,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,UAAU,GAAG,CAAC,IAAI,UAAU,GAAG,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;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,CAAC;QACrB,MAAM,IAAI,sBAAsB,CAAC;IACnC,CAAC;IACD,MAAM,IAAI,MAAM,CAAC;IAEjB,kBAAkB;IAClB,MAAM,IAAI,0BAA0B,CAAC;IACrC,MAAM,IAAI,yCAAyC,CAAC;IAEpD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACnC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;QACvD,MAAM,IAAI,KAAK,SAAS,YAAY,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,QAAQ,OAAO,KAAK,CAAC,IAAI,KAAK,CAAC;QAEzF,oCAAoC;QACpC,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG;YAC/C,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,gBAAgB;YACpD,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QAClB,MAAM,IAAI,GAAG,cAAc,IAAI,CAAC;IAClC,CAAC;IAED,iBAAiB;IACjB,MAAM,IAAI,6CAA6C,CAAC;IACxD,MAAM,IAAI,0BAA0B,CAAC;IACrC,MAAM,IAAI,yCAAyC,CAAC;IACpD,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,IAAI,CAAC;IACtC,MAAM,IAAI,6CAA6C,CAAC;IACxD,MAAM,IAAI,MAAM,MAAM,CAAC,eAAe,qBAAqB,CAAC;IAE5D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ProviderManager } from '../providers/manager.js';
|
|
2
|
+
import { DuckResponse } from '../config/types.js';
|
|
3
|
+
export interface DuckJudgeArgs {
|
|
4
|
+
responses: DuckResponse[];
|
|
5
|
+
judge?: string;
|
|
6
|
+
criteria?: string[];
|
|
7
|
+
persona?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function duckJudgeTool(providerManager: ProviderManager, args: Record<string, unknown>): Promise<{
|
|
10
|
+
content: {
|
|
11
|
+
type: string;
|
|
12
|
+
text: string;
|
|
13
|
+
}[];
|
|
14
|
+
}>;
|
|
15
|
+
//# sourceMappingURL=duck-judge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duck-judge.d.ts","sourceRoot":"","sources":["../../src/tools/duck-judge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAmB,MAAM,oBAAoB,CAAC;AAGnE,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAcD,wBAAsB,aAAa,CACjC,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;GAwD9B"}
|