dialectic 0.1.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.
Files changed (119) hide show
  1. package/.cursor/commands/setup-test.mdc +175 -0
  2. package/.cursor/rules/basic-code-cleanup.mdc +1110 -0
  3. package/.cursor/rules/riper5.mdc +96 -0
  4. package/.env.example +6 -0
  5. package/AGENTS.md +1052 -0
  6. package/LICENSE +21 -0
  7. package/README.md +93 -0
  8. package/WARP.md +113 -0
  9. package/dialectic-1.0.0.tgz +0 -0
  10. package/dialectic.js +10 -0
  11. package/docs/commands.md +375 -0
  12. package/docs/configuration.md +882 -0
  13. package/docs/context_summarization.md +1023 -0
  14. package/docs/debate_flow.md +1127 -0
  15. package/docs/eval_flow.md +795 -0
  16. package/docs/evaluator.md +141 -0
  17. package/examples/debate-config-openrouter.json +48 -0
  18. package/examples/debate_config1.json +48 -0
  19. package/examples/eval/eval1/eval_config1.json +13 -0
  20. package/examples/eval/eval1/result1.json +62 -0
  21. package/examples/eval/eval1/result2.json +97 -0
  22. package/examples/eval_summary_format.md +11 -0
  23. package/examples/example3/debate-config.json +64 -0
  24. package/examples/example3/eval_config2.json +25 -0
  25. package/examples/example3/problem.md +17 -0
  26. package/examples/example3/rounds_test/eval_run.sh +16 -0
  27. package/examples/example3/rounds_test/run_test.sh +16 -0
  28. package/examples/kata1/architect-only-solution_2-rounds.json +121 -0
  29. package/examples/kata1/architect-perf-solution_2-rounds.json +234 -0
  30. package/examples/kata1/debate-config-kata1.json +54 -0
  31. package/examples/kata1/eval_architect-only_2-rounds.json +97 -0
  32. package/examples/kata1/eval_architect-perf_2-rounds.json +97 -0
  33. package/examples/kata1/kata1-report.md +12224 -0
  34. package/examples/kata1/kata1-report_temps-01_01_01_07.md +2451 -0
  35. package/examples/kata1/kata1.md +5 -0
  36. package/examples/kata1/meta.txt +1 -0
  37. package/examples/kata2/debate-config.json +54 -0
  38. package/examples/kata2/eval_config1.json +21 -0
  39. package/examples/kata2/eval_config2.json +25 -0
  40. package/examples/kata2/kata2.md +5 -0
  41. package/examples/kata2/only_architect/debate-config.json +45 -0
  42. package/examples/kata2/only_architect/eval_run.sh +11 -0
  43. package/examples/kata2/only_architect/run_test.sh +5 -0
  44. package/examples/kata2/rounds_test/eval_run.sh +11 -0
  45. package/examples/kata2/rounds_test/run_test.sh +5 -0
  46. package/examples/kata2/summary_length_test/eval_run.sh +11 -0
  47. package/examples/kata2/summary_length_test/eval_run_w_clarify.sh +7 -0
  48. package/examples/kata2/summary_length_test/run_test.sh +5 -0
  49. package/examples/task-queue/debate-config.json +76 -0
  50. package/examples/task-queue/debate_report.md +566 -0
  51. package/examples/task-queue/task-queue-system.md +25 -0
  52. package/jest.config.ts +13 -0
  53. package/multi_agent_debate_spec.md +2980 -0
  54. package/package.json +38 -0
  55. package/sanity-check-problem.txt +9 -0
  56. package/src/agents/prompts/architect-prompts.ts +203 -0
  57. package/src/agents/prompts/generalist-prompts.ts +157 -0
  58. package/src/agents/prompts/index.ts +41 -0
  59. package/src/agents/prompts/judge-prompts.ts +19 -0
  60. package/src/agents/prompts/kiss-prompts.ts +230 -0
  61. package/src/agents/prompts/performance-prompts.ts +142 -0
  62. package/src/agents/prompts/prompt-types.ts +68 -0
  63. package/src/agents/prompts/security-prompts.ts +149 -0
  64. package/src/agents/prompts/shared.ts +144 -0
  65. package/src/agents/prompts/testing-prompts.ts +149 -0
  66. package/src/agents/role-based-agent.ts +386 -0
  67. package/src/cli/commands/debate.ts +761 -0
  68. package/src/cli/commands/eval.ts +475 -0
  69. package/src/cli/commands/report.ts +265 -0
  70. package/src/cli/index.ts +79 -0
  71. package/src/core/agent.ts +198 -0
  72. package/src/core/clarifications.ts +34 -0
  73. package/src/core/judge.ts +257 -0
  74. package/src/core/orchestrator.ts +432 -0
  75. package/src/core/state-manager.ts +322 -0
  76. package/src/eval/evaluator-agent.ts +130 -0
  77. package/src/eval/prompts/system.md +41 -0
  78. package/src/eval/prompts/user.md +64 -0
  79. package/src/providers/llm-provider.ts +25 -0
  80. package/src/providers/openai-provider.ts +84 -0
  81. package/src/providers/openrouter-provider.ts +122 -0
  82. package/src/providers/provider-factory.ts +64 -0
  83. package/src/types/agent.types.ts +141 -0
  84. package/src/types/config.types.ts +47 -0
  85. package/src/types/debate.types.ts +237 -0
  86. package/src/types/eval.types.ts +85 -0
  87. package/src/utils/common.ts +104 -0
  88. package/src/utils/context-formatter.ts +102 -0
  89. package/src/utils/context-summarizer.ts +143 -0
  90. package/src/utils/env-loader.ts +46 -0
  91. package/src/utils/exit-codes.ts +5 -0
  92. package/src/utils/id.ts +11 -0
  93. package/src/utils/logger.ts +48 -0
  94. package/src/utils/paths.ts +10 -0
  95. package/src/utils/progress-ui.ts +313 -0
  96. package/src/utils/prompt-loader.ts +79 -0
  97. package/src/utils/report-generator.ts +301 -0
  98. package/tests/clarifications.spec.ts +128 -0
  99. package/tests/cli.debate.spec.ts +144 -0
  100. package/tests/config-loading.spec.ts +206 -0
  101. package/tests/context-summarizer.spec.ts +131 -0
  102. package/tests/debate-config-custom.json +38 -0
  103. package/tests/env-loader.spec.ts +149 -0
  104. package/tests/eval.command.spec.ts +1191 -0
  105. package/tests/logger.spec.ts +19 -0
  106. package/tests/openai-provider.spec.ts +26 -0
  107. package/tests/openrouter-provider.spec.ts +279 -0
  108. package/tests/orchestrator-summary.spec.ts +386 -0
  109. package/tests/orchestrator.spec.ts +207 -0
  110. package/tests/prompt-loader.spec.ts +52 -0
  111. package/tests/prompts/architect.md +16 -0
  112. package/tests/provider-factory.spec.ts +150 -0
  113. package/tests/report.command.spec.ts +546 -0
  114. package/tests/role-based-agent-summary.spec.ts +476 -0
  115. package/tests/security-agent.spec.ts +221 -0
  116. package/tests/shared-prompts.spec.ts +318 -0
  117. package/tests/state-manager.spec.ts +251 -0
  118. package/tests/summary-prompts.spec.ts +153 -0
  119. package/tsconfig.json +49 -0
@@ -0,0 +1,230 @@
1
+ import { RolePrompts } from './prompt-types';
2
+ import { prependContext } from '../../utils/context-formatter';
3
+ import { appendSharedInstructions, INSTRUCTION_TYPES } from './shared';
4
+ import type { DebateContext } from '../../types/debate.types';
5
+
6
+ const BASE_SYSTEM_PROMPT = `You are the **KISS Agent** — an experienced software architect with an extreme bias toward simplicity.
7
+
8
+ Your primary mission is to minimize **accidental complexity** and produce the simplest system that still meets essential requirements.
9
+ Your focus: simplicity, minimalism, avoiding over-engineering, questioning unnecessary complexity, and championing straightforward solutions.
10
+
11
+ When proposing solutions:
12
+ - Start with the simplest possible architecture that solves the problem
13
+ - Question whether each component, pattern, or abstraction is truly necessary
14
+ - Prefer proven, simple technologies over complex frameworks
15
+ - Avoid premature optimization and over-engineering
16
+ - Justify every element of your design - if you can't justify it, remove it
17
+
18
+ Principles:
19
+ - Prefer clarity and straightforward design over cleverness or over-engineering.
20
+ - Eliminate unnecessary layers, abstractions, and dependencies (YAGNI)
21
+ - Favor standard patterns, minimal moving parts, and incremental evolution.
22
+ - When requirements are complex, separate essential from accidental complexity.
23
+ - Recommend phased implementation paths that start simple and evolve only as needed.
24
+ - Challenge assumptions that introduce complexity without clear value.
25
+ - Be adversarial to “solution bloat,” and advocate for “less is more.”
26
+ - KISS (Keep It Simple, Stupid): Prefer the simplest solution that works
27
+ - Minimal Viable Architecture: Start with the simplest architecture that meets current requirements
28
+
29
+ When reviewing or debating:
30
+ - Identify unnecessary complexity, over-engineering, or premature optimization
31
+ - Question abstractions, frameworks, or steps that don’t provide tangible value.
32
+ - Explicitly identify overdesign or premature optimization.
33
+ - Offer a simpler alternative whenever one exists, even if it’s less “elegant.”
34
+
35
+ Tone:
36
+ - Clear, direct, and skeptical.
37
+ - Avoid jargon.
38
+ - Always bring the discussion back to what’s *necessary and sufficient*.
39
+ -----
40
+ `;
41
+
42
+ /**
43
+ * Prompts for the KISS role, specializing in simplicity and challenging complexity.
44
+ *
45
+ * The KISS agent focuses on simplicity above all, questioning unnecessary complexity,
46
+ * and championing minimal viable solutions.
47
+ */
48
+ export const kissPrompts: RolePrompts = {
49
+ systemPrompt: appendSharedInstructions(BASE_SYSTEM_PROMPT, INSTRUCTION_TYPES.SYSTEM),
50
+
51
+ proposePrompt: (problem: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
52
+ const basePrompt = `
53
+ Problem to solve:
54
+ ${problem}
55
+
56
+ As a simplicity-focused architect, propose the **simplest viable solution** that solves this problem.
57
+
58
+ Structure your response as follows:
59
+
60
+ ## Core Idea
61
+ Describe the simplest design that meets the stated needs.
62
+
63
+ ## Minimal Architecture
64
+ Outline only the essential components and their interactions.
65
+ Avoid unnecessary components, layers or frameworks.
66
+
67
+ ### Non-Functional Considerations (Simplified)
68
+ #### Scalability
69
+ (Only address if truly needed. Prefer simple scaling strategies over complex ones.)
70
+ #### Security
71
+ (Use the simplest security approach that meets requirements. Avoid over-engineering.)
72
+ #### Maintainability
73
+ (Simplicity IS maintainability. Explain how keeping it simple makes it easier to maintain.)
74
+ #### Operational Concerns
75
+ (Keep deployment and operations as simple as possible. Avoid unnecessary complexity.)
76
+
77
+ ## Simplifications
78
+ List where you intentionally reduced complexity or avoided over-engineering.
79
+
80
+ ## Phased Path
81
+ If the problem has essential complexity, describe a phased approach:
82
+ 1. Minimal viable version
83
+ 2. Gradual additions as real needs arise
84
+
85
+ ## Risks of Simplicity
86
+ Mention potential risks or trade-offs of keeping it simple.
87
+
88
+ ## What We're NOT Building (YAGNI)
89
+ (Explicitly list features, components, or patterns you're deliberately omitting because they're not needed yet.)
90
+
91
+ ## Summary
92
+ Summarize why this design is the simplest practical path forward.
93
+
94
+ ---
95
+ Respond **only** in this structured format.
96
+ Challenge complexity — make the case for simplicity.
97
+ `;
98
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
99
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.PROPOSAL);
100
+ },
101
+
102
+ critiquePrompt: (proposalContent: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
103
+ const basePrompt = `Proposal to review:
104
+ ${proposalContent}
105
+
106
+ Critique this proposal with a strong simplicity bias.
107
+
108
+ Structure your response as follows:
109
+
110
+ ## Unnecessary Complexity
111
+ List parts that seem over-engineered, redundant, or unclear in value.
112
+
113
+ ## Simplification Opportunities
114
+ Suggest simpler alternatives that would achieve the same outcome.
115
+
116
+ ## Essential vs. Accidental Complexity
117
+ Identify which complexities are unavoidable and which are self-inflicted.
118
+
119
+ ## YAGNI Violations
120
+ (Point out features, components, or patterns that violate "You Aren't Gonna Need It" — things built for hypothetical future needs.)
121
+
122
+ ## Over-Engineering Concerns
123
+ (Identify areas where the solution is more complex than the problem requires. Challenge premature optimization, excessive abstraction, or unnecessary patterns.)
124
+
125
+ ## Simpler Alternatives
126
+ (Propose simpler approaches that could achieve the same goals with less complexity.)
127
+
128
+ ## Recommended Simplified Direction
129
+ Propose the simplest coherent path to achieve the same goal, even if less "complete" initially.
130
+ ---
131
+ Your tone should be direct and challenging.
132
+ Question complexity — advocate for simplicity.
133
+ `;
134
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
135
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.CRITIQUE);
136
+ },
137
+
138
+ refinePrompt: (originalContent: string, critiquesText: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
139
+ const basePrompt = `Original proposal:
140
+ ${originalContent}
141
+
142
+ Critiques:
143
+ ${critiquesText}
144
+
145
+ Refine the proposal to make it simpler, more direct, and easier to implement.
146
+
147
+ Use this structure:
148
+
149
+ ## Simplified Design
150
+ Present a cleaned-up, minimal version of the original design.
151
+
152
+ ## Reductions Made
153
+ List what was removed, merged, or simplified, and why it’s safe to do so.
154
+
155
+ ### Remaining Justifications
156
+ (If some critiques suggested simplifications you're not making, explain why those elements are truly necessary — or reconsider and remove them.)
157
+
158
+ ## Stepwise Plan
159
+ If complexity remains essential, outline a phased roadmap starting from the simplest viable base.
160
+
161
+ ## Expected Outcome
162
+ Explain how the simpler design improves clarity, maintainability, and delivery speed.
163
+
164
+ ---
165
+ Your tone should be direct and challenging.
166
+ Question complexity and advocate for simplicity.
167
+ `;
168
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
169
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.REFINEMENT);
170
+ },
171
+
172
+ summarizePrompt: (content: string, maxLength: number) => {
173
+ const basePrompt = `You are summarizing the debate history from a **simplicity perspective**. Focus on simplicity decisions, complexity challenges, and what was kept minimal.
174
+
175
+ Debate history to summarize:
176
+ ${content}
177
+
178
+ Create a concise summary (maximum ${maxLength} characters) that preserves the most important simplicity-focused insights, decisions to avoid complexity, and what was kept minimal. Focus on information that will be useful for future rounds of the debate.
179
+
180
+ ### Key Simplicity Decisions
181
+ (List the most significant decisions made to keep things simple — what was kept minimal, what complexity was avoided.)
182
+
183
+ ### Complexity Challenges Discussed
184
+ (Summarize debates around unnecessary complexity, over-engineering, or features that were questioned.)
185
+
186
+ ### YAGNI Principles Applied
187
+ (Identify areas where "You Aren't Gonna Need It" was applied — what was deliberately not built.)
188
+
189
+ ### Simplification Opportunities Identified
190
+ (Highlight areas where complexity was reduced or could be reduced further.)
191
+
192
+ ### Emerging Simplicity Consensus
193
+ (Briefly describe what the participants seem to agree upon regarding keeping things simple.)
194
+ ---
195
+ Keep it concise, factual, and focused on simplicity reasoning.
196
+ `;
197
+ return appendSharedInstructions(basePrompt, INSTRUCTION_TYPES.SUMMARIZATION);
198
+ },
199
+
200
+ clarifyPrompt: (problem: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
201
+ const basePrompt = `Problem to clarify:
202
+ ${problem}
203
+
204
+ Your goal is to identify information that would help you propose the **simplest possible solution**. Focus on questions that reveal what's truly necessary vs. what might be over-engineering.
205
+ Ask clarifying questions that aim to strip away unnecessary complexity and reveal the simplest viable solution.
206
+
207
+
208
+ Focus on:
209
+ - Core functional need vs. optional features
210
+ - Real constraints vs. assumed ones
211
+ - Which requirements are essential for version 1
212
+ - Whether simpler alternatives were already considered
213
+ - Opportunities to defer or avoid complex elements
214
+
215
+ Guidelines:
216
+ - Prefer questions that help identify the **minimum viable solution**.
217
+ - Ask about actual requirements vs. assumed complexity.
218
+ - Question whether constraints are real or can be simplified.
219
+ - Avoid questions that would lead to over-engineering.
220
+ - If the problem is already well-specified for simplicity, you may return no questions.
221
+ - Each question must be **concise and independent** — do not bundle multiple subquestions.
222
+ ---
223
+ Your tone should be direct and challenging.
224
+ Question complexity and advocate for simplicity.
225
+ `;
226
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
227
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.CLARIFICATION);
228
+ },
229
+ };
230
+
@@ -0,0 +1,142 @@
1
+ import { RolePrompts } from './prompt-types';
2
+ import { prependContext } from '../../utils/context-formatter';
3
+ import { appendSharedInstructions, INSTRUCTION_TYPES } from './shared';
4
+ import type { DebateContext } from '../../types/debate.types';
5
+
6
+ /**
7
+ * Prompts for the Performance role, specializing in system optimization and efficiency.
8
+ *
9
+ * The performance engineer focuses on latency, throughput, resource utilization,
10
+ * caching strategies, algorithmic complexity, and performance testing.
11
+ */
12
+ export const performancePrompts: RolePrompts = {
13
+ systemPrompt: appendSharedInstructions(`You are an expert **performance engineer** specializing in optimizing large-scale distributed systems.
14
+
15
+ Your focus areas:
16
+ - Runtime efficiency, throughput, latency, and scalability under load
17
+ - Resource utilization (CPU, memory, network, storage)
18
+ - Concurrency, parallelism, and synchronization bottlenecks
19
+ - Caching, batching, and data locality strategies
20
+ - Performance testing, profiling, and observability mechanisms
21
+
22
+ When proposing solutions:
23
+ - Start from the performance model — identify expected loads, bottlenecks, and constraints
24
+ - Describe key optimization strategies and trade-offs
25
+ - Address both *application-level* and *infrastructure-level* concerns
26
+
27
+ When critiquing:
28
+ - Identify performance risks, hidden bottlenecks, or poor scaling assumptions
29
+ - Evaluate resource efficiency and observability
30
+ - Suggest concrete improvements supported by reasoning or experience
31
+ `, INSTRUCTION_TYPES.SYSTEM),
32
+
33
+ proposePrompt: (problem: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
34
+ const basePrompt = `Problem to solve:
35
+ ${problem}
36
+
37
+ As a performance engineer, propose a comprehensive solution focusing on runtime efficiency, scalability, and system responsiveness.
38
+
39
+ Use this structure:
40
+ ## Performance Overview
41
+ Summarize the performance goals, expected load, and constraints.
42
+
43
+ ## Key Bottlenecks & Risks
44
+ Identify likely sources of latency, contention, or inefficiency.
45
+
46
+ ## Optimization Strategies
47
+ Outline approaches such as caching, load balancing, batching, or concurrency control.
48
+
49
+ ## Resource Utilization Plan
50
+ Describe how to manage CPU, memory, storage, and network usage efficiently.
51
+
52
+ ## Observability & Testing
53
+ Explain how performance will be measured and verified.
54
+
55
+ ## Trade-offs & Justifications
56
+ Discuss trade-offs between performance, complexity, and maintainability.`;
57
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
58
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.PROPOSAL);
59
+ },
60
+
61
+ critiquePrompt: (proposalContent: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
62
+ const basePrompt = `Review this proposal from a performance engineering perspective.
63
+
64
+ Proposal:
65
+ ${proposalContent}
66
+
67
+ Structure your response as follows:
68
+ ## Strengths
69
+ Highlight strong performance design choices, scalability principles, or efficient algorithms.
70
+
71
+ ## Weaknesses
72
+ Identify likely performance bottlenecks, over-engineering, or poor assumptions.
73
+
74
+ ## Suggested Improvements
75
+ Recommend specific optimizations, instrumentation, or architectural adjustments.
76
+
77
+ ## Critical Risks
78
+ List major performance risks or failure modes that could affect system responsiveness or stability.`;
79
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
80
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.CRITIQUE);
81
+ },
82
+
83
+ refinePrompt: (originalContent: string, critiquesText: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
84
+ const basePrompt = `Original proposal:
85
+ ${originalContent}
86
+
87
+ Critiques:
88
+ ${critiquesText}
89
+
90
+ Refine your proposal to address performance-related feedback, improving scalability, efficiency, and observability.
91
+
92
+ Use this structure:
93
+ ## Revised Performance Strategy
94
+ Summarize the main updates to your approach.
95
+
96
+ ## Changes Made
97
+ List the modifications and their rationale.
98
+
99
+ ## Expected Impact
100
+ Explain how these changes improve performance, throughput, or stability.
101
+
102
+ ## Remaining Risks
103
+ Mention open issues or trade-offs still present.`;
104
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
105
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.REFINEMENT);
106
+ },
107
+
108
+ summarizePrompt: (content: string, maxLength: number) => {
109
+ const basePrompt = `You are summarizing the debate history from a performance engineering perspective.
110
+
111
+ Debate history to summarize:
112
+ ${content}
113
+
114
+ Summarize the discussion with focus on performance goals, bottlenecks, optimization strategies, and trade-offs.
115
+
116
+ Format:
117
+ ## Performance Insights
118
+ Key learnings about system efficiency, scaling strategies, and throughput.
119
+
120
+ ## Major Decisions
121
+ Important optimization or architectural choices made.
122
+
123
+ ## Remaining Challenges
124
+ Open performance questions or unresolved risks.
125
+
126
+ Limit the summary to a maximum of ${maxLength} characters.`;
127
+ return appendSharedInstructions(basePrompt, INSTRUCTION_TYPES.SUMMARIZATION);
128
+ },
129
+
130
+ clarifyPrompt: (problem: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
131
+ const basePrompt = `You are preparing clarifying questions from a performance engineering perspective.
132
+
133
+ Problem to clarify:
134
+ ${problem}
135
+
136
+ Ask zero or more concise, high-value questions focused on runtime efficiency, scalability, load characteristics, concurrency, caching, data volume, and observability.
137
+ `;
138
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
139
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.CLARIFICATION);
140
+ },
141
+ };
142
+
@@ -0,0 +1,68 @@
1
+ import type { DebateContext } from '../../types/debate.types';
2
+
3
+ /**
4
+ * Interface defining the structure of role-based prompts for agents.
5
+ *
6
+ * Each role (architect, performance, security) provides implementations of these
7
+ * prompt templates to guide agent behavior during debate phases.
8
+ */
9
+ export interface RolePrompts {
10
+ /**
11
+ * The system prompt that primes the agent's behavior and perspective.
12
+ * This defines the agent's expertise, focus areas, and approach to problem-solving.
13
+ */
14
+ systemPrompt: string;
15
+
16
+ /**
17
+ * Generates a user prompt for the proposal phase.
18
+ * @param problem - The problem statement to solve.
19
+ * @param context - Optional debate context containing history or summaries.
20
+ * @param agentId - Optional agent ID for looking up agent-specific summary.
21
+ * @param includeFullHistory - Whether to fall back to full history when no summary is found.
22
+ * @returns A formatted prompt instructing the agent to propose a solution.
23
+ */
24
+ proposePrompt: (problem: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => string;
25
+
26
+ /**
27
+ * Generates a user prompt for the critique phase.
28
+ * @param proposalContent - The content of the proposal to critique.
29
+ * @param context - Optional debate context containing history or summaries.
30
+ * @param agentId - Optional agent ID for looking up agent-specific summary.
31
+ * @param includeFullHistory - Whether to fall back to full history when no summary is found.
32
+ * @returns A formatted prompt instructing the agent to critique the proposal.
33
+ */
34
+ critiquePrompt: (proposalContent: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => string;
35
+
36
+ /**
37
+ * Generates a user prompt for the refinement phase.
38
+ * @param originalContent - The content of the original proposal.
39
+ * @param critiquesText - The concatenated text of all critiques received.
40
+ * @param context - Optional debate context containing history or summaries.
41
+ * @param agentId - Optional agent ID for looking up agent-specific summary.
42
+ * @param includeFullHistory - Whether to fall back to full history when no summary is found.
43
+ * @returns A formatted prompt instructing the agent to refine their proposal.
44
+ */
45
+ refinePrompt: (originalContent: string, critiquesText: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => string;
46
+
47
+ /**
48
+ * Generates a user prompt for context summarization.
49
+ * @param content - The full debate history content to summarize.
50
+ * @param maxLength - Maximum length for the summary in characters.
51
+ * @returns A formatted prompt instructing the agent to summarize the content from their perspective.
52
+ */
53
+ summarizePrompt: (content: string, maxLength: number) => string;
54
+
55
+ /**
56
+ * Generates a user prompt for the clarifications phase, asking zero or more
57
+ * structured clarifying questions. The LLM must respond with ONLY JSON in the
58
+ * schema: { "questions": [ { "text": string } ] }.
59
+ *
60
+ * @param problem - The problem statement to clarify.
61
+ * @param context - Optional debate context containing history or summaries.
62
+ * @param agentId - Optional agent ID for summary/history context selection.
63
+ * @param includeFullHistory - Whether to fall back to full history when no summary is found.
64
+ * @returns A formatted prompt instructing the agent to produce structured clarifying questions.
65
+ */
66
+ clarifyPrompt: (problem: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => string;
67
+ }
68
+
@@ -0,0 +1,149 @@
1
+ import { RolePrompts } from './prompt-types';
2
+ import { prependContext } from '../../utils/context-formatter';
3
+ import { appendSharedInstructions, INSTRUCTION_TYPES } from './shared';
4
+ import type { DebateContext } from '../../types/debate.types';
5
+
6
+ /**
7
+ * Prompts for the Security role, specializing in cybersecurity and risk assessment.
8
+ *
9
+ * The security expert focuses on authentication, authorization, data protection,
10
+ * threat modeling, security controls, and compliance frameworks.
11
+ */
12
+ export const securityPrompts: RolePrompts = {
13
+ systemPrompt: appendSharedInstructions(`You are an expert **security architect and engineer** specializing in designing secure distributed systems and identifying potential threats in software architecture.
14
+
15
+ Your focus areas:
16
+ - Threat modeling (attack surfaces, trust boundaries, risk vectors)
17
+ - Authentication, authorization, encryption, and data protection
18
+ - Secure communication and identity management
19
+ - Regulatory and compliance concerns (e.g., GDPR, SOC 2)
20
+ - Secure deployment, secrets management, and operational security
21
+ - Resilience against denial-of-service, privilege escalation, and data leakage
22
+
23
+ When proposing solutions:
24
+ - Incorporate secure design principles (least privilege, defense in depth, zero trust)
25
+ - Identify critical security controls and justify their inclusion
26
+ - Discuss trade-offs between usability, performance, and security
27
+
28
+ When critiquing:
29
+ - Identify weak points, unprotected boundaries, or missing safeguards
30
+ - Evaluate how data, credentials, and trust relationships are handled
31
+ - Suggest mitigation strategies and architectural security enhancements`, INSTRUCTION_TYPES.SYSTEM),
32
+
33
+ proposePrompt: (problem: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
34
+ const basePrompt = `Problem to solve:
35
+ ${problem}
36
+
37
+ As a security specialist, propose a comprehensive solution that ensures the system design is secure by architecture and by operation.
38
+
39
+ Use this structure:
40
+ ## Security Objectives
41
+ Summarize key security goals (confidentiality, integrity, availability, compliance).
42
+
43
+ ## Threat Model
44
+ Identify main threats, attack surfaces, and trust boundaries.
45
+
46
+ ## Core Security Mechanisms
47
+ Describe authentication, authorization, data encryption, and key management mechanisms.
48
+
49
+ ## Data Protection & Privacy
50
+ Explain how sensitive data is stored, transmitted, and masked or anonymized.
51
+
52
+ ## Compliance & Operational Security
53
+ Address regulatory or compliance requirements and how they are met.
54
+
55
+ ## Trade-offs & Justifications
56
+ Discuss trade-offs between security, usability, and performance.`;
57
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
58
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.PROPOSAL);
59
+ },
60
+
61
+ critiquePrompt: (proposalContent: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
62
+ const basePrompt = `Review this proposal from a security engineering perspective.
63
+
64
+ Proposal:
65
+ ${proposalContent}
66
+
67
+ Structure your response as follows:
68
+ ## Strengths
69
+ Identify well-designed security components, strong architectural protections, or solid compliance strategies.
70
+
71
+ ## Weaknesses
72
+ Highlight vulnerabilities, missing controls, or unprotected data flows.
73
+
74
+ ## Suggested Improvements
75
+ Propose specific improvements, controls, or design adjustments to reduce risk.
76
+
77
+ ## Critical Risks
78
+ List the most severe security concerns that could lead to data breaches, privilege escalation, or service disruption.`;
79
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
80
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.CRITIQUE);
81
+ },
82
+
83
+ refinePrompt: (originalContent: string, critiquesText: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
84
+ const basePrompt = `Original proposal:
85
+ ${originalContent}
86
+
87
+ Critiques:
88
+ ${critiquesText}
89
+
90
+ Refine your proposal to address security concerns, improve resilience, and strengthen the protection of data and services.
91
+
92
+ Use this structure:
93
+ ## Revised Security Architecture
94
+ Summarize the main updates to your approach.
95
+
96
+ ## Changes Made
97
+ List modifications and how they improve security posture.
98
+
99
+ ## Expected Impact
100
+ Explain how these changes mitigate risks or enhance compliance.
101
+
102
+ ## Remaining Risks
103
+ Mention any unresolved risks, trade-offs, or constraints.`;
104
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
105
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.REFINEMENT);
106
+ },
107
+
108
+ summarizePrompt: (content: string, maxLength: number) => {
109
+ const basePrompt = `You are summarizing the debate history from a security perspective.
110
+
111
+ Debate history to summarize:
112
+ ${content}
113
+
114
+ Summarize the discussion focusing on threat modeling, security controls, and risk mitigation decisions.
115
+
116
+ Format:
117
+ ## Security Insights
118
+ Key learnings about attack surfaces, data protection, or authentication mechanisms.
119
+
120
+ ## Major Decisions
121
+ Important security-related architectural choices and mitigations made.
122
+
123
+ ## Remaining Risks
124
+ Unresolved vulnerabilities, open design questions, or compliance gaps.
125
+
126
+ Limit the summary to a maximum of ${maxLength} characters.`;
127
+ return appendSharedInstructions(basePrompt, INSTRUCTION_TYPES.SUMMARIZATION);
128
+ },
129
+
130
+ clarifyPrompt: (problem: string, context?: DebateContext, agentId?: string, includeFullHistory?: boolean) => {
131
+ const basePrompt = `You are preparing clarifying questions from a security architecture perspective.
132
+
133
+ Problem to clarify:
134
+ ${problem}
135
+
136
+ Ask zero or more concise, high-value questions focused on security, privacy, compliance, and trust boundaries.
137
+
138
+ Prioritize questions that will clarify:
139
+ - Authentication and authorization requirements
140
+ - Data sensitivity and classification
141
+ - Communication channels and encryption needs
142
+ - Access control and operational security expectations
143
+ - Compliance or regulatory constraints
144
+ `;
145
+ const promptWithContext = prependContext(basePrompt, context, agentId, includeFullHistory);
146
+ return appendSharedInstructions(promptWithContext, INSTRUCTION_TYPES.CLARIFICATION);
147
+ },
148
+ };
149
+