@ddse/acm-aicoder 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.
Files changed (165) hide show
  1. package/.aicoder/index.json +304 -0
  2. package/AICODER_IMPLEMENTATION_PLAN_PHASE2.md +284 -0
  3. package/LICENSE +21 -0
  4. package/README.md +490 -0
  5. package/bin/interactive.tsx +232 -0
  6. package/dist/bin/interactive.d.ts +3 -0
  7. package/dist/bin/interactive.d.ts.map +1 -0
  8. package/dist/bin/interactive.js +155 -0
  9. package/dist/bin/interactive.js.map +1 -0
  10. package/dist/src/config/providers.d.ts +15 -0
  11. package/dist/src/config/providers.d.ts.map +1 -0
  12. package/dist/src/config/providers.js +142 -0
  13. package/dist/src/config/providers.js.map +1 -0
  14. package/dist/src/config/session.d.ts +25 -0
  15. package/dist/src/config/session.d.ts.map +1 -0
  16. package/dist/src/config/session.js +97 -0
  17. package/dist/src/config/session.js.map +1 -0
  18. package/dist/src/context/bm25.d.ts +68 -0
  19. package/dist/src/context/bm25.d.ts.map +1 -0
  20. package/dist/src/context/bm25.js +131 -0
  21. package/dist/src/context/bm25.js.map +1 -0
  22. package/dist/src/context/code-search.d.ts +30 -0
  23. package/dist/src/context/code-search.d.ts.map +1 -0
  24. package/dist/src/context/code-search.js +150 -0
  25. package/dist/src/context/code-search.js.map +1 -0
  26. package/dist/src/context/context-pack.d.ts +25 -0
  27. package/dist/src/context/context-pack.d.ts.map +1 -0
  28. package/dist/src/context/context-pack.js +92 -0
  29. package/dist/src/context/context-pack.js.map +1 -0
  30. package/dist/src/context/dependency-mapper.d.ts +10 -0
  31. package/dist/src/context/dependency-mapper.d.ts.map +1 -0
  32. package/dist/src/context/dependency-mapper.js +62 -0
  33. package/dist/src/context/dependency-mapper.js.map +1 -0
  34. package/dist/src/context/index.d.ts +8 -0
  35. package/dist/src/context/index.d.ts.map +1 -0
  36. package/dist/src/context/index.js +9 -0
  37. package/dist/src/context/index.js.map +1 -0
  38. package/dist/src/context/symbol-extractor.d.ts +26 -0
  39. package/dist/src/context/symbol-extractor.d.ts.map +1 -0
  40. package/dist/src/context/symbol-extractor.js +129 -0
  41. package/dist/src/context/symbol-extractor.js.map +1 -0
  42. package/dist/src/context/test-mapper.d.ts +16 -0
  43. package/dist/src/context/test-mapper.d.ts.map +1 -0
  44. package/dist/src/context/test-mapper.js +66 -0
  45. package/dist/src/context/test-mapper.js.map +1 -0
  46. package/dist/src/context/types.d.ts +61 -0
  47. package/dist/src/context/types.d.ts.map +1 -0
  48. package/dist/src/context/types.js +3 -0
  49. package/dist/src/context/types.js.map +1 -0
  50. package/dist/src/context/workspace-indexer.d.ts +39 -0
  51. package/dist/src/context/workspace-indexer.d.ts.map +1 -0
  52. package/dist/src/context/workspace-indexer.js +222 -0
  53. package/dist/src/context/workspace-indexer.js.map +1 -0
  54. package/dist/src/index.d.ts +5 -0
  55. package/dist/src/index.d.ts.map +1 -0
  56. package/dist/src/index.js +6 -0
  57. package/dist/src/index.js.map +1 -0
  58. package/dist/src/registries.d.ts +34 -0
  59. package/dist/src/registries.d.ts.map +1 -0
  60. package/dist/src/registries.js +87 -0
  61. package/dist/src/registries.js.map +1 -0
  62. package/dist/src/runtime/budget-manager.d.ts +42 -0
  63. package/dist/src/runtime/budget-manager.d.ts.map +1 -0
  64. package/dist/src/runtime/budget-manager.js +82 -0
  65. package/dist/src/runtime/budget-manager.js.map +1 -0
  66. package/dist/src/runtime/interactive-runtime.d.ts +39 -0
  67. package/dist/src/runtime/interactive-runtime.d.ts.map +1 -0
  68. package/dist/src/runtime/interactive-runtime.js +321 -0
  69. package/dist/src/runtime/interactive-runtime.js.map +1 -0
  70. package/dist/src/tasks-v2/analysis-tasks.d.ts +117 -0
  71. package/dist/src/tasks-v2/analysis-tasks.d.ts.map +1 -0
  72. package/dist/src/tasks-v2/analysis-tasks.js +209 -0
  73. package/dist/src/tasks-v2/analysis-tasks.js.map +1 -0
  74. package/dist/src/tasks-v2/developer-tasks.d.ts +226 -0
  75. package/dist/src/tasks-v2/developer-tasks.d.ts.map +1 -0
  76. package/dist/src/tasks-v2/developer-tasks.js +322 -0
  77. package/dist/src/tasks-v2/developer-tasks.js.map +1 -0
  78. package/dist/src/tasks-v2/index.d.ts +3 -0
  79. package/dist/src/tasks-v2/index.d.ts.map +1 -0
  80. package/dist/src/tasks-v2/index.js +4 -0
  81. package/dist/src/tasks-v2/index.js.map +1 -0
  82. package/dist/src/tools-v2/edit-tools.d.ts +67 -0
  83. package/dist/src/tools-v2/edit-tools.d.ts.map +1 -0
  84. package/dist/src/tools-v2/edit-tools.js +117 -0
  85. package/dist/src/tools-v2/edit-tools.js.map +1 -0
  86. package/dist/src/tools-v2/index.d.ts +6 -0
  87. package/dist/src/tools-v2/index.d.ts.map +1 -0
  88. package/dist/src/tools-v2/index.js +7 -0
  89. package/dist/src/tools-v2/index.js.map +1 -0
  90. package/dist/src/tools-v2/read-tools.d.ts +129 -0
  91. package/dist/src/tools-v2/read-tools.d.ts.map +1 -0
  92. package/dist/src/tools-v2/read-tools.js +216 -0
  93. package/dist/src/tools-v2/read-tools.js.map +1 -0
  94. package/dist/src/tools-v2/search-tools.d.ts +73 -0
  95. package/dist/src/tools-v2/search-tools.d.ts.map +1 -0
  96. package/dist/src/tools-v2/search-tools.js +132 -0
  97. package/dist/src/tools-v2/search-tools.js.map +1 -0
  98. package/dist/src/tools-v2/test-tools.d.ts +59 -0
  99. package/dist/src/tools-v2/test-tools.d.ts.map +1 -0
  100. package/dist/src/tools-v2/test-tools.js +111 -0
  101. package/dist/src/tools-v2/test-tools.js.map +1 -0
  102. package/dist/src/tools-v2/workspace-context.d.ts +65 -0
  103. package/dist/src/tools-v2/workspace-context.d.ts.map +1 -0
  104. package/dist/src/tools-v2/workspace-context.js +336 -0
  105. package/dist/src/tools-v2/workspace-context.js.map +1 -0
  106. package/dist/src/ui/App.d.ts +9 -0
  107. package/dist/src/ui/App.d.ts.map +1 -0
  108. package/dist/src/ui/App.js +257 -0
  109. package/dist/src/ui/App.js.map +1 -0
  110. package/dist/src/ui/components/ChatPane.d.ts +12 -0
  111. package/dist/src/ui/components/ChatPane.d.ts.map +1 -0
  112. package/dist/src/ui/components/ChatPane.js +41 -0
  113. package/dist/src/ui/components/ChatPane.js.map +1 -0
  114. package/dist/src/ui/components/EventsPane.d.ts +12 -0
  115. package/dist/src/ui/components/EventsPane.d.ts.map +1 -0
  116. package/dist/src/ui/components/EventsPane.js +48 -0
  117. package/dist/src/ui/components/EventsPane.js.map +1 -0
  118. package/dist/src/ui/components/GoalsTasksPane.d.ts +18 -0
  119. package/dist/src/ui/components/GoalsTasksPane.d.ts.map +1 -0
  120. package/dist/src/ui/components/GoalsTasksPane.js +83 -0
  121. package/dist/src/ui/components/GoalsTasksPane.js.map +1 -0
  122. package/dist/src/ui/store.d.ts +74 -0
  123. package/dist/src/ui/store.d.ts.map +1 -0
  124. package/dist/src/ui/store.js +260 -0
  125. package/dist/src/ui/store.js.map +1 -0
  126. package/dist/tests/integration.test.d.ts +2 -0
  127. package/dist/tests/integration.test.d.ts.map +1 -0
  128. package/dist/tests/integration.test.js +415 -0
  129. package/dist/tests/integration.test.js.map +1 -0
  130. package/dist/tsconfig.tsbuildinfo +1 -0
  131. package/docs/AICODER.png +0 -0
  132. package/docs/INTERACTIVE_CLI_GUIDE.md +201 -0
  133. package/docs/TUI_MOCKUP.md +180 -0
  134. package/package.json +52 -0
  135. package/src/config/providers.ts +174 -0
  136. package/src/config/session.ts +143 -0
  137. package/src/context/bm25.ts +173 -0
  138. package/src/context/code-search.ts +188 -0
  139. package/src/context/context-pack.ts +133 -0
  140. package/src/context/dependency-mapper.ts +72 -0
  141. package/src/context/index.ts +8 -0
  142. package/src/context/symbol-extractor.ts +149 -0
  143. package/src/context/test-mapper.ts +77 -0
  144. package/src/context/types.ts +69 -0
  145. package/src/context/workspace-indexer.ts +249 -0
  146. package/src/index.ts +5 -0
  147. package/src/registries.ts +118 -0
  148. package/src/runtime/budget-manager.ts +118 -0
  149. package/src/runtime/interactive-runtime.ts +423 -0
  150. package/src/tasks-v2/analysis-tasks.ts +311 -0
  151. package/src/tasks-v2/developer-tasks.ts +437 -0
  152. package/src/tasks-v2/index.ts +3 -0
  153. package/src/tools-v2/edit-tools.ts +153 -0
  154. package/src/tools-v2/index.ts +6 -0
  155. package/src/tools-v2/read-tools.ts +286 -0
  156. package/src/tools-v2/search-tools.ts +175 -0
  157. package/src/tools-v2/test-tools.ts +147 -0
  158. package/src/tools-v2/workspace-context.ts +428 -0
  159. package/src/ui/App.tsx +392 -0
  160. package/src/ui/components/ChatPane.tsx +84 -0
  161. package/src/ui/components/EventsPane.tsx +81 -0
  162. package/src/ui/components/GoalsTasksPane.tsx +149 -0
  163. package/src/ui/store.ts +362 -0
  164. package/tests/integration.test.ts +537 -0
  165. package/tsconfig.json +22 -0
@@ -0,0 +1,362 @@
1
+ // Application state store for the interactive TUI
2
+ // Manages chat messages, tasks, events, and budget state
3
+
4
+ import { EventEmitter } from 'events';
5
+ import type { Plan, Goal, Context } from '@ddse/acm-sdk';
6
+ import type { TaskNarrative } from '@ddse/acm-runtime';
7
+ import type { BudgetStatus } from '../runtime/budget-manager.js';
8
+
9
+ export type MessageRole = 'user' | 'planner' | 'nucleus' | 'system';
10
+
11
+ export interface ChatMessage {
12
+ id: string;
13
+ role: MessageRole;
14
+ content: string;
15
+ timestamp: number;
16
+ streaming?: boolean;
17
+ }
18
+
19
+ export type TaskStatus = 'pending' | 'running' | 'succeeded' | 'failed' | 'retrying';
20
+
21
+ export interface TaskState {
22
+ id: string;
23
+ name: string;
24
+ title?: string;
25
+ objective?: string;
26
+ successCriteria?: string[];
27
+ status: TaskStatus;
28
+ progress?: number;
29
+ error?: string;
30
+ attempt?: number;
31
+ maxAttempts?: number;
32
+ outputSummary?: string;
33
+ rawOutput?: unknown;
34
+ narrative?: TaskNarrative;
35
+ }
36
+
37
+ export interface EventEntry {
38
+ id: string;
39
+ type: string;
40
+ timestamp: number;
41
+ data: any;
42
+ color?: 'green' | 'yellow' | 'red' | 'blue' | 'gray';
43
+ }
44
+
45
+ export interface AppState {
46
+ // Chat state
47
+ messages: ChatMessage[];
48
+ showReasoning: boolean;
49
+
50
+ // Goal/Plan state
51
+ currentGoal?: Goal;
52
+ currentContext?: Context;
53
+ currentPlan?: Plan;
54
+ tasks: TaskState[];
55
+ goalSummary?: string;
56
+
57
+ // Budget state
58
+ budgetStatus?: BudgetStatus;
59
+
60
+ // Event stream
61
+ events: EventEntry[];
62
+ taskOutputs: Record<string, TaskState['rawOutput']>;
63
+
64
+ // UI state
65
+ inputText: string;
66
+ isProcessing: boolean;
67
+ }
68
+
69
+ export class AppStore extends EventEmitter {
70
+ private state: AppState = {
71
+ messages: [],
72
+ showReasoning: true,
73
+ tasks: [],
74
+ events: [],
75
+ taskOutputs: {},
76
+ inputText: '',
77
+ isProcessing: false,
78
+ goalSummary: undefined,
79
+ };
80
+
81
+ getState(): AppState {
82
+ return {
83
+ ...this.state,
84
+ messages: [...this.state.messages],
85
+ showReasoning: this.state.showReasoning,
86
+ tasks: this.state.tasks.map(task => ({ ...task })),
87
+ events: [...this.state.events],
88
+ taskOutputs: { ...this.state.taskOutputs },
89
+ };
90
+ }
91
+
92
+ // Chat methods
93
+ addMessage(role: MessageRole, content: string, streaming = false): string {
94
+ const id = `msg-${Date.now()}-${Math.random()}`;
95
+ const message: ChatMessage = {
96
+ id,
97
+ role,
98
+ content,
99
+ timestamp: Date.now(),
100
+ streaming,
101
+ };
102
+
103
+ this.state.messages.push(message);
104
+ this.emit('update', this.state);
105
+ return id;
106
+ }
107
+
108
+ isReasoningVisible(): boolean {
109
+ return this.state.showReasoning;
110
+ }
111
+
112
+ setReasoningVisible(visible: boolean): void {
113
+ if (this.state.showReasoning !== visible) {
114
+ this.state.showReasoning = visible;
115
+ this.emit('update', this.state);
116
+ }
117
+ }
118
+
119
+ toggleReasoningVisible(): boolean {
120
+ this.state.showReasoning = !this.state.showReasoning;
121
+ this.emit('update', this.state);
122
+ return this.state.showReasoning;
123
+ }
124
+
125
+ updateMessage(id: string, content: string, streaming = false): void {
126
+ const message = this.state.messages.find(m => m.id === id);
127
+ if (message) {
128
+ message.content = content;
129
+ message.streaming = streaming;
130
+ this.emit('update', this.state);
131
+ }
132
+ }
133
+
134
+ appendToMessage(id: string, delta: string): void {
135
+ const message = this.state.messages.find(m => m.id === id);
136
+ if (message) {
137
+ message.content += delta;
138
+ this.emit('update', this.state);
139
+ }
140
+ }
141
+
142
+ // Goal/Plan methods
143
+ setGoal(goal: Goal, context: Context, plan: Plan): void {
144
+ this.state.currentGoal = goal;
145
+ this.state.currentContext = context;
146
+ this.state.currentPlan = plan;
147
+
148
+ // Initialize tasks from plan
149
+ this.state.tasks = plan.tasks.map((task, idx) => {
150
+ const taskId = (task as any).id || task.capability || task.capabilityRef || `task-${idx}`;
151
+ const displayName =
152
+ (task as any).name || task.capability || task.capabilityRef || `Task ${idx + 1}`;
153
+
154
+ return {
155
+ id: String(taskId),
156
+ name: String(displayName),
157
+ title: (task as any).title ?? displayName,
158
+ objective: (task as any).objective,
159
+ successCriteria: Array.isArray((task as any).successCriteria)
160
+ ? (task as any).successCriteria
161
+ : undefined,
162
+ status: 'pending' as TaskStatus,
163
+ };
164
+ });
165
+
166
+ this.state.taskOutputs = {};
167
+ this.state.goalSummary = undefined;
168
+
169
+ this.emit('update', this.state);
170
+ }
171
+
172
+ updateTaskStatus(taskId: string, status: TaskStatus, progress?: number, error?: string): void {
173
+ const task = this.state.tasks.find(t => t.id === taskId);
174
+ if (task) {
175
+ task.status = status;
176
+ if (progress !== undefined) task.progress = progress;
177
+ if (error) task.error = error;
178
+ this.emit('update', this.state);
179
+ }
180
+ }
181
+
182
+ setTaskRetry(taskId: string, attempt: number, maxAttempts: number): void {
183
+ const task = this.state.tasks.find(t => t.id === taskId);
184
+ if (task) {
185
+ task.attempt = attempt;
186
+ task.maxAttempts = maxAttempts;
187
+ task.status = 'retrying';
188
+ this.emit('update', this.state);
189
+ }
190
+ }
191
+
192
+ // Budget methods
193
+ updateBudgetStatus(status: BudgetStatus): void {
194
+ this.state.budgetStatus = status;
195
+ this.emit('update', this.state);
196
+ }
197
+
198
+ // Event methods
199
+ addEvent(type: string, data: any, color?: EventEntry['color']): void {
200
+ const event: EventEntry = {
201
+ id: `event-${Date.now()}-${Math.random()}`,
202
+ type,
203
+ timestamp: Date.now(),
204
+ data,
205
+ color,
206
+ };
207
+
208
+ this.state.events.push(event);
209
+
210
+ // Keep only last 100 events to prevent memory bloat
211
+ if (this.state.events.length > 100) {
212
+ this.state.events = this.state.events.slice(-100);
213
+ }
214
+
215
+ this.emit('update', this.state);
216
+ }
217
+
218
+ // UI methods
219
+ setInputText(text: string): void {
220
+ this.state.inputText = text;
221
+ this.emit('update', this.state);
222
+ }
223
+
224
+ setProcessing(isProcessing: boolean): void {
225
+ this.state.isProcessing = isProcessing;
226
+ this.emit('update', this.state);
227
+ }
228
+
229
+ // Lifecycle methods
230
+ clearGoal(): void {
231
+ this.state.currentGoal = undefined;
232
+ this.state.currentContext = undefined;
233
+ this.state.currentPlan = undefined;
234
+ this.state.tasks = [];
235
+ this.state.taskOutputs = {};
236
+ this.state.goalSummary = undefined;
237
+ this.emit('update', this.state);
238
+ }
239
+
240
+ reset(): void {
241
+ this.state = {
242
+ messages: [
243
+ {
244
+ id: 'welcome',
245
+ role: 'system',
246
+ content: 'Session reset. Ready for new goal.',
247
+ timestamp: Date.now(),
248
+ }
249
+ ],
250
+ showReasoning: true,
251
+ tasks: [],
252
+ events: [],
253
+ taskOutputs: {},
254
+ inputText: '',
255
+ isProcessing: false,
256
+ goalSummary: undefined,
257
+ };
258
+ this.emit('update', this.state);
259
+ }
260
+
261
+ recordTaskOutput(taskId: string, output: unknown, narrative?: TaskNarrative): void {
262
+ this.state.taskOutputs[taskId] = output;
263
+
264
+ const task = this.state.tasks.find(t => t.id === taskId);
265
+ if (task) {
266
+ task.rawOutput = output;
267
+ task.outputSummary = this.formatOutputSummary(output);
268
+ task.narrative = narrative;
269
+ }
270
+
271
+ this.emit('update', this.state);
272
+
273
+ const label = task?.name || taskId;
274
+ const summary = task?.outputSummary ?? this.formatOutputSummary(output);
275
+ const reasoning = narrative?.reasoning?.length ? narrative.reasoning.join(' ') : undefined;
276
+
277
+ if (summary || reasoning) {
278
+ const lines: string[] = [];
279
+ if (summary) {
280
+ lines.push(summary);
281
+ }
282
+ if (reasoning) {
283
+ lines.push(`Narrative: ${reasoning}`);
284
+ }
285
+ if (narrative?.postcheck && narrative.postcheck.status !== 'COMPLETE') {
286
+ lines.push(`Postcheck: ${narrative.postcheck.status}${narrative.postcheck.reason ? ` (${narrative.postcheck.reason})` : ''}`);
287
+ }
288
+ this.addMessage('system', `Task "${label}" output:\n${lines.join('\n')}`);
289
+ }
290
+ }
291
+
292
+ setGoalSummary(summary?: string): void {
293
+ this.state.goalSummary = summary;
294
+ this.emit('update', this.state);
295
+ if (summary) {
296
+ this.addMessage('system', `Goal summary:\n${summary}`);
297
+ }
298
+ }
299
+
300
+ private formatOutputSummary(output: unknown): string {
301
+ if (output === undefined || output === null) {
302
+ return 'No output produced.';
303
+ }
304
+
305
+ if (typeof output === 'string') {
306
+ const trimmed = output.trim();
307
+ return trimmed.length > 0 ? this.truncate(trimmed) : 'Output was an empty string.';
308
+ }
309
+
310
+ if (typeof output === 'number' || typeof output === 'boolean') {
311
+ return String(output);
312
+ }
313
+
314
+ if (Array.isArray(output)) {
315
+ if (output.length === 0) {
316
+ return 'Output array was empty.';
317
+ }
318
+
319
+ const preview = output
320
+ .slice(0, 3)
321
+ .map(item => this.previewValue(item))
322
+ .join('\n');
323
+
324
+ const suffix = output.length > 3 ? `\n… ${output.length - 3} more item(s)` : '';
325
+ return this.truncate(preview + suffix);
326
+ }
327
+
328
+ if (typeof output === 'object') {
329
+ return this.truncate(this.previewValue(output));
330
+ }
331
+
332
+ return this.truncate(String(output));
333
+ }
334
+
335
+ private previewValue(value: unknown): string {
336
+ if (value === null) return 'null';
337
+ if (typeof value === 'string') return value.trim() || '""';
338
+ if (typeof value === 'number' || typeof value === 'boolean') return String(value);
339
+
340
+ if (Array.isArray(value)) {
341
+ const items = value.slice(0, 3).map(v => this.previewValue(v)).join(', ');
342
+ return `[${items}${value.length > 3 ? ', …' : ''}]`;
343
+ }
344
+
345
+ if (typeof value === 'object') {
346
+ const entries = Object.entries(value as Record<string, unknown>);
347
+ const preview = entries
348
+ .slice(0, 4)
349
+ .map(([key, val]) => `${key}: ${this.previewValue(val)}`)
350
+ .join(', ');
351
+ const suffix = entries.length > 4 ? ', …' : '';
352
+ return `{ ${preview}${suffix} }`;
353
+ }
354
+
355
+ return String(value);
356
+ }
357
+
358
+ private truncate(value: string, max = 400): string {
359
+ if (value.length <= max) return value;
360
+ return `${value.slice(0, max - 1)}…`;
361
+ }
362
+ }