@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.
- package/.aicoder/index.json +304 -0
- package/AICODER_IMPLEMENTATION_PLAN_PHASE2.md +284 -0
- package/LICENSE +21 -0
- package/README.md +490 -0
- package/bin/interactive.tsx +232 -0
- package/dist/bin/interactive.d.ts +3 -0
- package/dist/bin/interactive.d.ts.map +1 -0
- package/dist/bin/interactive.js +155 -0
- package/dist/bin/interactive.js.map +1 -0
- package/dist/src/config/providers.d.ts +15 -0
- package/dist/src/config/providers.d.ts.map +1 -0
- package/dist/src/config/providers.js +142 -0
- package/dist/src/config/providers.js.map +1 -0
- package/dist/src/config/session.d.ts +25 -0
- package/dist/src/config/session.d.ts.map +1 -0
- package/dist/src/config/session.js +97 -0
- package/dist/src/config/session.js.map +1 -0
- package/dist/src/context/bm25.d.ts +68 -0
- package/dist/src/context/bm25.d.ts.map +1 -0
- package/dist/src/context/bm25.js +131 -0
- package/dist/src/context/bm25.js.map +1 -0
- package/dist/src/context/code-search.d.ts +30 -0
- package/dist/src/context/code-search.d.ts.map +1 -0
- package/dist/src/context/code-search.js +150 -0
- package/dist/src/context/code-search.js.map +1 -0
- package/dist/src/context/context-pack.d.ts +25 -0
- package/dist/src/context/context-pack.d.ts.map +1 -0
- package/dist/src/context/context-pack.js +92 -0
- package/dist/src/context/context-pack.js.map +1 -0
- package/dist/src/context/dependency-mapper.d.ts +10 -0
- package/dist/src/context/dependency-mapper.d.ts.map +1 -0
- package/dist/src/context/dependency-mapper.js +62 -0
- package/dist/src/context/dependency-mapper.js.map +1 -0
- package/dist/src/context/index.d.ts +8 -0
- package/dist/src/context/index.d.ts.map +1 -0
- package/dist/src/context/index.js +9 -0
- package/dist/src/context/index.js.map +1 -0
- package/dist/src/context/symbol-extractor.d.ts +26 -0
- package/dist/src/context/symbol-extractor.d.ts.map +1 -0
- package/dist/src/context/symbol-extractor.js +129 -0
- package/dist/src/context/symbol-extractor.js.map +1 -0
- package/dist/src/context/test-mapper.d.ts +16 -0
- package/dist/src/context/test-mapper.d.ts.map +1 -0
- package/dist/src/context/test-mapper.js +66 -0
- package/dist/src/context/test-mapper.js.map +1 -0
- package/dist/src/context/types.d.ts +61 -0
- package/dist/src/context/types.d.ts.map +1 -0
- package/dist/src/context/types.js +3 -0
- package/dist/src/context/types.js.map +1 -0
- package/dist/src/context/workspace-indexer.d.ts +39 -0
- package/dist/src/context/workspace-indexer.d.ts.map +1 -0
- package/dist/src/context/workspace-indexer.js +222 -0
- package/dist/src/context/workspace-indexer.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/registries.d.ts +34 -0
- package/dist/src/registries.d.ts.map +1 -0
- package/dist/src/registries.js +87 -0
- package/dist/src/registries.js.map +1 -0
- package/dist/src/runtime/budget-manager.d.ts +42 -0
- package/dist/src/runtime/budget-manager.d.ts.map +1 -0
- package/dist/src/runtime/budget-manager.js +82 -0
- package/dist/src/runtime/budget-manager.js.map +1 -0
- package/dist/src/runtime/interactive-runtime.d.ts +39 -0
- package/dist/src/runtime/interactive-runtime.d.ts.map +1 -0
- package/dist/src/runtime/interactive-runtime.js +321 -0
- package/dist/src/runtime/interactive-runtime.js.map +1 -0
- package/dist/src/tasks-v2/analysis-tasks.d.ts +117 -0
- package/dist/src/tasks-v2/analysis-tasks.d.ts.map +1 -0
- package/dist/src/tasks-v2/analysis-tasks.js +209 -0
- package/dist/src/tasks-v2/analysis-tasks.js.map +1 -0
- package/dist/src/tasks-v2/developer-tasks.d.ts +226 -0
- package/dist/src/tasks-v2/developer-tasks.d.ts.map +1 -0
- package/dist/src/tasks-v2/developer-tasks.js +322 -0
- package/dist/src/tasks-v2/developer-tasks.js.map +1 -0
- package/dist/src/tasks-v2/index.d.ts +3 -0
- package/dist/src/tasks-v2/index.d.ts.map +1 -0
- package/dist/src/tasks-v2/index.js +4 -0
- package/dist/src/tasks-v2/index.js.map +1 -0
- package/dist/src/tools-v2/edit-tools.d.ts +67 -0
- package/dist/src/tools-v2/edit-tools.d.ts.map +1 -0
- package/dist/src/tools-v2/edit-tools.js +117 -0
- package/dist/src/tools-v2/edit-tools.js.map +1 -0
- package/dist/src/tools-v2/index.d.ts +6 -0
- package/dist/src/tools-v2/index.d.ts.map +1 -0
- package/dist/src/tools-v2/index.js +7 -0
- package/dist/src/tools-v2/index.js.map +1 -0
- package/dist/src/tools-v2/read-tools.d.ts +129 -0
- package/dist/src/tools-v2/read-tools.d.ts.map +1 -0
- package/dist/src/tools-v2/read-tools.js +216 -0
- package/dist/src/tools-v2/read-tools.js.map +1 -0
- package/dist/src/tools-v2/search-tools.d.ts +73 -0
- package/dist/src/tools-v2/search-tools.d.ts.map +1 -0
- package/dist/src/tools-v2/search-tools.js +132 -0
- package/dist/src/tools-v2/search-tools.js.map +1 -0
- package/dist/src/tools-v2/test-tools.d.ts +59 -0
- package/dist/src/tools-v2/test-tools.d.ts.map +1 -0
- package/dist/src/tools-v2/test-tools.js +111 -0
- package/dist/src/tools-v2/test-tools.js.map +1 -0
- package/dist/src/tools-v2/workspace-context.d.ts +65 -0
- package/dist/src/tools-v2/workspace-context.d.ts.map +1 -0
- package/dist/src/tools-v2/workspace-context.js +336 -0
- package/dist/src/tools-v2/workspace-context.js.map +1 -0
- package/dist/src/ui/App.d.ts +9 -0
- package/dist/src/ui/App.d.ts.map +1 -0
- package/dist/src/ui/App.js +257 -0
- package/dist/src/ui/App.js.map +1 -0
- package/dist/src/ui/components/ChatPane.d.ts +12 -0
- package/dist/src/ui/components/ChatPane.d.ts.map +1 -0
- package/dist/src/ui/components/ChatPane.js +41 -0
- package/dist/src/ui/components/ChatPane.js.map +1 -0
- package/dist/src/ui/components/EventsPane.d.ts +12 -0
- package/dist/src/ui/components/EventsPane.d.ts.map +1 -0
- package/dist/src/ui/components/EventsPane.js +48 -0
- package/dist/src/ui/components/EventsPane.js.map +1 -0
- package/dist/src/ui/components/GoalsTasksPane.d.ts +18 -0
- package/dist/src/ui/components/GoalsTasksPane.d.ts.map +1 -0
- package/dist/src/ui/components/GoalsTasksPane.js +83 -0
- package/dist/src/ui/components/GoalsTasksPane.js.map +1 -0
- package/dist/src/ui/store.d.ts +74 -0
- package/dist/src/ui/store.d.ts.map +1 -0
- package/dist/src/ui/store.js +260 -0
- package/dist/src/ui/store.js.map +1 -0
- package/dist/tests/integration.test.d.ts +2 -0
- package/dist/tests/integration.test.d.ts.map +1 -0
- package/dist/tests/integration.test.js +415 -0
- package/dist/tests/integration.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/AICODER.png +0 -0
- package/docs/INTERACTIVE_CLI_GUIDE.md +201 -0
- package/docs/TUI_MOCKUP.md +180 -0
- package/package.json +52 -0
- package/src/config/providers.ts +174 -0
- package/src/config/session.ts +143 -0
- package/src/context/bm25.ts +173 -0
- package/src/context/code-search.ts +188 -0
- package/src/context/context-pack.ts +133 -0
- package/src/context/dependency-mapper.ts +72 -0
- package/src/context/index.ts +8 -0
- package/src/context/symbol-extractor.ts +149 -0
- package/src/context/test-mapper.ts +77 -0
- package/src/context/types.ts +69 -0
- package/src/context/workspace-indexer.ts +249 -0
- package/src/index.ts +5 -0
- package/src/registries.ts +118 -0
- package/src/runtime/budget-manager.ts +118 -0
- package/src/runtime/interactive-runtime.ts +423 -0
- package/src/tasks-v2/analysis-tasks.ts +311 -0
- package/src/tasks-v2/developer-tasks.ts +437 -0
- package/src/tasks-v2/index.ts +3 -0
- package/src/tools-v2/edit-tools.ts +153 -0
- package/src/tools-v2/index.ts +6 -0
- package/src/tools-v2/read-tools.ts +286 -0
- package/src/tools-v2/search-tools.ts +175 -0
- package/src/tools-v2/test-tools.ts +147 -0
- package/src/tools-v2/workspace-context.ts +428 -0
- package/src/ui/App.tsx +392 -0
- package/src/ui/components/ChatPane.tsx +84 -0
- package/src/ui/components/EventsPane.tsx +81 -0
- package/src/ui/components/GoalsTasksPane.tsx +149 -0
- package/src/ui/store.ts +362 -0
- package/tests/integration.test.ts +537 -0
- package/tsconfig.json +22 -0
package/src/ui/store.ts
ADDED
|
@@ -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
|
+
}
|