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,149 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { loadEnvironmentFile } from '../src/utils/env-loader';
4
+
5
+ // Mock fs and path modules
6
+ jest.mock('fs');
7
+ jest.mock('path');
8
+
9
+ const mockedFs = fs as jest.Mocked<typeof fs>;
10
+ const mockedPath = path as jest.Mocked<typeof path>;
11
+
12
+ // Mock dotenv
13
+ jest.mock('dotenv', () => ({
14
+ config: jest.fn()
15
+ }));
16
+ import dotenv from 'dotenv';
17
+ const mockedDotenv = dotenv as jest.Mocked<typeof dotenv>;
18
+
19
+ describe('env-loader', () => {
20
+ let originalEnv: NodeJS.ProcessEnv;
21
+ let stderrSpy: jest.SpyInstance;
22
+
23
+ beforeEach(() => {
24
+ originalEnv = process.env;
25
+ process.env = { ...originalEnv };
26
+ stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
27
+
28
+ // Reset mocks
29
+ jest.clearAllMocks();
30
+
31
+ // Setup default path mock behavior
32
+ mockedPath.resolve.mockImplementation((_cwd, filePath) => `/resolved/${filePath}`);
33
+ });
34
+
35
+ afterEach(() => {
36
+ process.env = originalEnv;
37
+ stderrSpy.mockRestore();
38
+ });
39
+
40
+ describe('loading default .env file', () => {
41
+ beforeEach(() => {
42
+ process.cwd = jest.fn().mockReturnValue('/current/dir');
43
+ });
44
+
45
+ it('should load default .env file when it exists', () => {
46
+ mockedFs.existsSync.mockReturnValue(true);
47
+ mockedDotenv.config.mockReturnValue({ parsed: { TEST_VAR: 'test_value' } } as any);
48
+
49
+ loadEnvironmentFile();
50
+
51
+ expect(mockedPath.resolve).toHaveBeenCalledWith('/current/dir', '.env');
52
+ expect(mockedFs.existsSync).toHaveBeenCalledWith('/resolved/.env');
53
+ expect(mockedDotenv.config).toHaveBeenCalledWith({ path: '/resolved/.env' });
54
+ expect(stderrSpy).not.toHaveBeenCalled();
55
+ });
56
+
57
+ it('should continue silently when default .env file does not exist', () => {
58
+ mockedFs.existsSync.mockReturnValue(false);
59
+
60
+ expect(() => loadEnvironmentFile()).not.toThrow();
61
+
62
+ expect(mockedPath.resolve).toHaveBeenCalledWith('/current/dir', '.env');
63
+ expect(mockedFs.existsSync).toHaveBeenCalledWith('/resolved/.env');
64
+ expect(mockedDotenv.config).not.toHaveBeenCalled();
65
+ expect(stderrSpy).not.toHaveBeenCalled();
66
+ });
67
+
68
+ it('should warn about missing default .env file in verbose mode', () => {
69
+ mockedFs.existsSync.mockReturnValue(false);
70
+
71
+ loadEnvironmentFile(undefined, true);
72
+
73
+ expect(stderrSpy).toHaveBeenCalledWith('No .env file found at /resolved/.env. Continuing without loading environment variables.\n');
74
+ expect(mockedDotenv.config).not.toHaveBeenCalled();
75
+ });
76
+ });
77
+
78
+ describe('loading custom env file', () => {
79
+ beforeEach(() => {
80
+ process.cwd = jest.fn().mockReturnValue('/current/dir');
81
+ });
82
+
83
+ it('should load custom env file when it exists', () => {
84
+ mockedFs.existsSync.mockReturnValue(true);
85
+ mockedDotenv.config.mockReturnValue({ parsed: { CUSTOM_VAR: 'custom_value' } } as any);
86
+
87
+ loadEnvironmentFile('custom.env');
88
+
89
+ expect(mockedPath.resolve).toHaveBeenCalledWith('/current/dir', 'custom.env');
90
+ expect(mockedFs.existsSync).toHaveBeenCalledWith('/resolved/custom.env');
91
+ expect(mockedDotenv.config).toHaveBeenCalledWith({ path: '/resolved/custom.env' });
92
+ });
93
+
94
+ it('should throw error when explicitly specified env file does not exist', () => {
95
+ mockedFs.existsSync.mockReturnValue(false);
96
+
97
+ expect(() => loadEnvironmentFile('missing.env')).toThrow('Environment file not found: /resolved/missing.env');
98
+
99
+ expect(mockedPath.resolve).toHaveBeenCalledWith('/current/dir', 'missing.env');
100
+ expect(mockedFs.existsSync).toHaveBeenCalledWith('/resolved/missing.env');
101
+ expect(mockedDotenv.config).not.toHaveBeenCalled();
102
+ });
103
+
104
+ it('should throw error when explicitly specified env file does not exist, even in verbose mode', () => {
105
+ mockedFs.existsSync.mockReturnValue(false);
106
+
107
+ expect(() => loadEnvironmentFile('missing.env', true)).toThrow('Environment file not found: /resolved/missing.env');
108
+
109
+ expect(mockedDotenv.config).not.toHaveBeenCalled();
110
+ });
111
+ });
112
+
113
+ describe('path resolution', () => {
114
+ it('should resolve paths relative to process.cwd()', () => {
115
+ process.cwd = jest.fn().mockReturnValue('/project/root');
116
+ mockedFs.existsSync.mockReturnValue(true);
117
+ mockedDotenv.config.mockReturnValue({ parsed: {} } as any);
118
+
119
+ loadEnvironmentFile('config/.env.local');
120
+
121
+ expect(mockedPath.resolve).toHaveBeenCalledWith('/project/root', 'config/.env.local');
122
+ expect(mockedFs.existsSync).toHaveBeenCalledWith('/resolved/config/.env.local');
123
+ });
124
+ });
125
+
126
+ describe('environment variable precedence', () => {
127
+ it('should not override existing environment variables', () => {
128
+ process.env.EXISTING_VAR = 'original_value';
129
+ mockedFs.existsSync.mockReturnValue(true);
130
+ mockedDotenv.config.mockReturnValue({ parsed: { EXISTING_VAR: 'new_value' } } as any);
131
+
132
+ loadEnvironmentFile();
133
+
134
+ // dotenv by default does not override existing env vars
135
+ expect(mockedDotenv.config).toHaveBeenCalledWith({ path: '/resolved/.env' });
136
+ // The original environment variable should be preserved
137
+ expect(process.env.EXISTING_VAR).toBe('original_value');
138
+ });
139
+ });
140
+
141
+ describe('dotenv error handling', () => {
142
+ it('should handle dotenv parsing errors', () => {
143
+ mockedFs.existsSync.mockReturnValue(true);
144
+ mockedDotenv.config.mockReturnValue({ error: new Error('Parse error') } as any);
145
+
146
+ expect(() => loadEnvironmentFile()).toThrow('Failed to load environment file: Parse error');
147
+ });
148
+ });
149
+ });