1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
import { useCallback } from "react";
export type QuickActionType =
| "create_file"
| "create_task"
| "run_task"
| "advance_phase"
| "derive_tasks"
| "update_file";
export interface QuickAction {
type: QuickActionType;
label: string;
description?: string;
data?: Record<string, unknown>;
}
interface QuickActionButtonsProps {
actions: QuickAction[];
onAction: (action: QuickAction) => void;
loading?: boolean;
}
const ACTION_ICONS: Record<QuickActionType, string> = {
create_file: "[+]",
create_task: "[T]",
run_task: "[>]",
advance_phase: "[→]",
derive_tasks: "[≡]",
update_file: "[*]",
};
const ACTION_COLORS: Record<QuickActionType, string> = {
create_file: "border-blue-400/30 hover:border-blue-400/60 text-blue-400",
create_task: "border-green-400/30 hover:border-green-400/60 text-green-400",
run_task: "border-yellow-400/30 hover:border-yellow-400/60 text-yellow-400",
advance_phase: "border-purple-400/30 hover:border-purple-400/60 text-purple-400",
derive_tasks: "border-cyan-400/30 hover:border-cyan-400/60 text-cyan-400",
update_file: "border-orange-400/30 hover:border-orange-400/60 text-orange-400",
};
export function QuickActionButtons({
actions,
onAction,
loading = false,
}: QuickActionButtonsProps) {
const handleClick = useCallback(
(action: QuickAction) => {
if (!loading) {
onAction(action);
}
},
[onAction, loading]
);
if (actions.length === 0) return null;
return (
<div className="flex flex-wrap gap-2 mt-2">
{actions.map((action, index) => (
<button
key={`${action.type}-${index}`}
onClick={() => handleClick(action)}
disabled={loading}
className={`
flex items-center gap-1.5 px-2 py-1
font-mono text-[10px] uppercase
border transition-colors
disabled:opacity-50 disabled:cursor-not-allowed
${ACTION_COLORS[action.type]}
`}
title={action.description}
>
<span>{ACTION_ICONS[action.type]}</span>
<span>{action.label}</span>
</button>
))}
</div>
);
}
/**
* Parse tool call results to extract suggested quick actions.
* This is used by ContractCliInput to detect actionable results.
*/
export function parseActionsFromToolCalls(
toolCalls: { name: string; success: boolean; message: string }[]
): QuickAction[] {
const actions: QuickAction[] = [];
for (const tc of toolCalls) {
if (!tc.success) continue;
switch (tc.name) {
case "derive_tasks_from_file":
// When tasks are parsed, offer to create them
if (tc.message.includes("task") || tc.message.includes("Found")) {
actions.push({
type: "derive_tasks",
label: "Review & Create Tasks",
description: "Review parsed tasks and create them with chaining",
});
}
break;
case "process_task_completion":
// Check for suggested actions in the result
if (tc.message.includes("next task")) {
actions.push({
type: "run_task",
label: "Run Next Task",
description: "Continue with the next chained task",
});
}
if (tc.message.includes("advance") || tc.message.includes("phase")) {
actions.push({
type: "advance_phase",
label: "Advance Phase",
description: "Move to the next contract phase",
});
}
break;
case "get_phase_checklist":
// When checklist shows missing items, offer to create them
if (tc.message.includes("missing") || tc.message.includes("not created")) {
actions.push({
type: "create_file",
label: "Create Missing Files",
description: "Create files from recommended templates",
});
}
break;
case "advance_phase":
// After phase transition, suggest creating files
actions.push({
type: "create_file",
label: "Create Phase Files",
description: "Create recommended files for this phase",
});
break;
}
}
return actions;
}
/**
* Parse LLM response text to detect suggested actions.
* Used as a fallback when structured action data isn't available.
*/
export function parseActionsFromText(text: string): QuickAction[] {
const actions: QuickAction[] = [];
const lower = text.toLowerCase();
// Detect file creation suggestions
if (
lower.includes("create a file") ||
lower.includes("create the file") ||
lower.includes("should i create")
) {
actions.push({
type: "create_file",
label: "Create File",
description: "Create the suggested file",
});
}
// Detect task creation suggestions
if (
lower.includes("create tasks") ||
lower.includes("create these tasks") ||
lower.includes("create chained tasks")
) {
actions.push({
type: "create_task",
label: "Create Tasks",
description: "Create the suggested tasks",
});
}
// Detect phase advancement suggestions
if (
lower.includes("advance to") ||
lower.includes("ready to move to") ||
lower.includes("transition to")
) {
const phases = ["specify", "plan", "execute", "review"];
for (const phase of phases) {
if (lower.includes(phase)) {
actions.push({
type: "advance_phase",
label: `Advance to ${phase.charAt(0).toUpperCase() + phase.slice(1)}`,
description: `Move to the ${phase} phase`,
data: { phase },
});
break;
}
}
}
// Detect run task suggestions
if (
lower.includes("run the task") ||
lower.includes("start the task") ||
lower.includes("run task")
) {
actions.push({
type: "run_task",
label: "Run Task",
description: "Start the suggested task",
});
}
return actions;
}
|