@mrclrchtr/supi-ask-user 1.13.0 → 1.14.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/README.md +157 -65
- package/node_modules/@mrclrchtr/supi-core/README.md +10 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +2 -1
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +98 -17
- package/node_modules/@mrclrchtr/supi-core/src/report.ts +121 -0
- package/package.json +2 -2
- package/src/api.ts +7 -5
- package/src/ask-user.ts +23 -7
- package/src/index.ts +7 -5
- package/src/normalize.ts +47 -30
- package/src/render/result.ts +72 -49
- package/src/render/transcript.ts +90 -62
- package/src/schema.ts +8 -30
- package/src/session/controller.ts +226 -193
- package/src/session/lock.ts +1 -1
- package/src/tool/guidance.ts +4 -1
- package/src/types.ts +46 -35
- package/src/ui/choose-renderer.ts +20 -4
- package/src/ui/form-component.ts +574 -0
- package/src/ui/form-render-primitives.ts +71 -0
- package/src/ui/form-render.ts +283 -0
- package/src/ui/form-review-render.ts +144 -0
- package/src/ui/form-view.ts +23 -0
- package/src/ui/{overlay.ts → form.ts} +12 -9
- package/src/ui/types.ts +7 -3
- package/src/ui/overlay-actions.ts +0 -42
- package/src/ui/overlay-component.ts +0 -400
- package/src/ui/overlay-render.ts +0 -230
- package/src/ui/overlay-view.ts +0 -327
package/src/render/transcript.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { type AgentToolResult, keyText, type Theme } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Text } from "@earendil-works/pi-tui";
|
|
3
3
|
import type { AskUserParams } from "../schema.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
AskUserDetails,
|
|
6
|
+
AskUserOutcomeKind,
|
|
7
|
+
AskUserResponse,
|
|
8
|
+
AskUserToolDetails,
|
|
9
|
+
NormalizedQuestion,
|
|
10
|
+
} from "../types.ts";
|
|
5
11
|
import { isErrorDetails } from "../types.ts";
|
|
6
|
-
import { formatAnswerSummary, formatMissingHeaders } from "./result.ts";
|
|
7
12
|
|
|
8
13
|
const COLLAPSED_ANSWER_LIMIT = 2;
|
|
9
14
|
const DEFAULT_REVIEW_KEY = "Ctrl+O";
|
|
@@ -37,9 +42,6 @@ export function renderAskUserResult(
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
function buildCollapsedResultLines(details: AskUserDetails, theme: Theme): string[] {
|
|
40
|
-
if (details.status === "cancelled") return [theme.fg("warning", "Cancelled")];
|
|
41
|
-
if (details.status === "aborted") return [theme.fg("error", "Aborted")];
|
|
42
|
-
|
|
43
45
|
const answerLines = buildAnswerLines(details, theme);
|
|
44
46
|
const shownAnswerLines = answerLines.slice(0, COLLAPSED_ANSWER_LIMIT);
|
|
45
47
|
const hiddenAnswerCount = Math.max(answerLines.length - shownAnswerLines.length, 0);
|
|
@@ -49,34 +51,36 @@ function buildCollapsedResultLines(details: AskUserDetails, theme: Theme): strin
|
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
function buildExpandedResultLines(details: AskUserDetails, theme: Theme): string[] {
|
|
52
|
-
if (details.status === "cancelled") return [theme.fg("warning", "Cancelled")];
|
|
53
|
-
if (details.status === "aborted") return [theme.fg("error", "Aborted")];
|
|
54
|
-
|
|
55
54
|
const lines = [formatStatusLine(details, theme)];
|
|
56
55
|
const title = details.title?.trim();
|
|
57
56
|
const intro = details.intro?.trim();
|
|
58
|
-
const
|
|
59
|
-
const
|
|
57
|
+
const comment = details.comment?.trim();
|
|
58
|
+
const unansweredCount = details.responses.filter((r) => !r.answer.answered).length;
|
|
60
59
|
|
|
61
60
|
if (title) lines.push(theme.fg("accent", title));
|
|
62
61
|
if (intro) lines.push(theme.fg("text", intro));
|
|
63
|
-
if (
|
|
64
|
-
lines.push(theme.fg("text", `Message: ${discussMessage}`));
|
|
65
|
-
}
|
|
66
|
-
if (missing) {
|
|
67
|
-
lines.push(theme.fg("dim", missing));
|
|
68
|
-
}
|
|
62
|
+
if (comment) lines.push(theme.fg("text", `Comment: ${comment}`));
|
|
69
63
|
|
|
70
64
|
for (const question of details.questions) {
|
|
71
65
|
lines.push("");
|
|
72
66
|
lines.push(theme.fg("accent", question.header));
|
|
73
67
|
lines.push(theme.fg("dim", question.prompt));
|
|
74
68
|
|
|
75
|
-
const
|
|
69
|
+
const resp = details.responses.find((r) => r.questionId === question.id);
|
|
70
|
+
if (resp) {
|
|
71
|
+
lines.push(...formatResponseLines(resp, question, theme));
|
|
72
|
+
if (resp.questionComment) {
|
|
73
|
+
lines.push(theme.fg("dim", ` Question comment: ${resp.questionComment}`));
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
lines.push(theme.fg("dim", "Not answered"));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (unansweredCount > 0 && details.outcome === "needs_discussion") {
|
|
81
|
+
lines.push("");
|
|
76
82
|
lines.push(
|
|
77
|
-
|
|
78
|
-
? theme.fg("text", `Answer: ${formatAnswerSummary(question, answer)}`)
|
|
79
|
-
: theme.fg("dim", "Not answered"),
|
|
83
|
+
theme.fg("dim", `${unansweredCount} question${unansweredCount > 1 ? "s" : ""} unanswered`),
|
|
80
84
|
);
|
|
81
85
|
}
|
|
82
86
|
|
|
@@ -84,28 +88,74 @@ function buildExpandedResultLines(details: AskUserDetails, theme: Theme): string
|
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
function buildAnswerLines(details: AskUserDetails, theme: Theme): string[] {
|
|
87
|
-
return details.
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
return details.responses.flatMap((resp) => {
|
|
92
|
+
if (!resp.answer.answered) return [];
|
|
93
|
+
const question = details.questions.find((q) => q.id === resp.questionId);
|
|
94
|
+
if (!question) return [];
|
|
95
|
+
|
|
96
|
+
const summary = formatAnswerLine(resp);
|
|
97
|
+
return summary
|
|
90
98
|
? [
|
|
91
|
-
`${theme.fg("success", "
|
|
99
|
+
`${theme.fg("success", "\u2713 ")}${theme.fg("accent", question.header)}: ${theme.fg("text", summary)}`,
|
|
92
100
|
]
|
|
93
101
|
: [];
|
|
94
102
|
});
|
|
95
103
|
}
|
|
96
104
|
|
|
105
|
+
function formatAnswerLine(resp: AskUserResponse): string | undefined {
|
|
106
|
+
if (!resp.answer.answered) return undefined;
|
|
107
|
+
|
|
108
|
+
if (resp.answer.kind === "choice") {
|
|
109
|
+
const selected = resp.answer.options.filter((o) => o.selected);
|
|
110
|
+
if (selected.length === 0) return undefined;
|
|
111
|
+
return selected
|
|
112
|
+
.map((o) => (o.comment ? `${o.label} (comment: ${o.comment})` : o.label))
|
|
113
|
+
.join("; ");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (resp.answer.kind === "text" && resp.answer.value) {
|
|
117
|
+
return resp.answer.value;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function formatResponseLines(
|
|
124
|
+
resp: AskUserResponse,
|
|
125
|
+
question: NormalizedQuestion,
|
|
126
|
+
theme: Theme,
|
|
127
|
+
): string[] {
|
|
128
|
+
if (resp.answer.kind === "choice") {
|
|
129
|
+
const multi = question.type === "choice" && question.multi;
|
|
130
|
+
const optionLines = resp.answer.options.map((opt) => {
|
|
131
|
+
const selected = opt.selected
|
|
132
|
+
? theme.fg("success", multi ? "[x]" : "(*)")
|
|
133
|
+
: theme.fg("dim", multi ? "[ ]" : "( )");
|
|
134
|
+
const comment = opt.comment ? theme.fg("dim", ` (comment: ${opt.comment})`) : "";
|
|
135
|
+
return `${selected} ${opt.label}${comment}`;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (resp.answer.answered) return optionLines;
|
|
139
|
+
return [theme.fg("dim", "Not answered"), ...optionLines];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (resp.answer.kind === "text" && resp.answer.answered && resp.answer.value) {
|
|
143
|
+
return [theme.fg("text", resp.answer.value)];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return [theme.fg("dim", "Not answered")];
|
|
147
|
+
}
|
|
148
|
+
|
|
97
149
|
function buildCollapsedMetaLine(
|
|
98
150
|
details: AskUserDetails,
|
|
99
151
|
hiddenAnswerCount: number,
|
|
100
152
|
theme: Theme,
|
|
101
153
|
): string {
|
|
102
154
|
const parts: string[] = [];
|
|
155
|
+
const unansweredCount = details.responses.filter((r) => !r.answer.answered).length;
|
|
103
156
|
|
|
104
|
-
if (
|
|
105
|
-
parts.push(`${
|
|
106
|
-
}
|
|
107
|
-
if (details.status === "discuss" && details.discussMessage?.trim()) {
|
|
108
|
-
parts.push("discussion message included");
|
|
157
|
+
if (unansweredCount > 0) {
|
|
158
|
+
parts.push(`${unansweredCount} unanswered`);
|
|
109
159
|
}
|
|
110
160
|
if (hiddenAnswerCount > 0) {
|
|
111
161
|
parts.push(`${hiddenAnswerCount} more answer${hiddenAnswerCount === 1 ? "" : "s"}`);
|
|
@@ -119,50 +169,28 @@ function buildCollapsedMetaLine(
|
|
|
119
169
|
}
|
|
120
170
|
|
|
121
171
|
function formatStatusLine(details: AskUserDetails, theme: Theme): string {
|
|
122
|
-
const answeredCount =
|
|
123
|
-
const totalCount = details.
|
|
172
|
+
const answeredCount = details.responses.filter((r) => r.answer.answered).length;
|
|
173
|
+
const totalCount = details.responses.length;
|
|
124
174
|
return theme.fg(
|
|
125
|
-
statusColor(details.
|
|
126
|
-
`${statusLabel(details.
|
|
175
|
+
statusColor(details.outcome),
|
|
176
|
+
`${statusLabel(details.outcome)} \u00B7 ${answeredCount}/${totalCount} answered`,
|
|
127
177
|
);
|
|
128
178
|
}
|
|
129
179
|
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function formatMissingSummary(details: AskUserDetails): string | undefined {
|
|
135
|
-
const missing = formatMissingHeaders(details.questions, details.missingQuestionIds);
|
|
136
|
-
if (!missing) return undefined;
|
|
137
|
-
return details.status === "partial"
|
|
138
|
-
? `Missing required: ${missing}`
|
|
139
|
-
: `Still missing: ${missing}`;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function statusColor(status: AskUserStatus): "success" | "warning" | "error" {
|
|
143
|
-
switch (status) {
|
|
180
|
+
function statusColor(outcome: AskUserOutcomeKind): "success" | "warning" | "error" {
|
|
181
|
+
switch (outcome) {
|
|
144
182
|
case "submitted":
|
|
145
183
|
return "success";
|
|
146
|
-
case "
|
|
147
|
-
case "discuss":
|
|
148
|
-
case "cancelled":
|
|
184
|
+
case "needs_discussion":
|
|
149
185
|
return "warning";
|
|
150
|
-
case "aborted":
|
|
151
|
-
return "error";
|
|
152
186
|
}
|
|
153
187
|
}
|
|
154
188
|
|
|
155
|
-
function statusLabel(
|
|
156
|
-
switch (
|
|
189
|
+
function statusLabel(outcome: AskUserOutcomeKind): string {
|
|
190
|
+
switch (outcome) {
|
|
157
191
|
case "submitted":
|
|
158
192
|
return "Submitted";
|
|
159
|
-
case "
|
|
160
|
-
return "
|
|
161
|
-
case "discuss":
|
|
162
|
-
return "Discuss";
|
|
163
|
-
case "cancelled":
|
|
164
|
-
return "Cancelled";
|
|
165
|
-
case "aborted":
|
|
166
|
-
return "Aborted";
|
|
193
|
+
case "needs_discussion":
|
|
194
|
+
return "Needs discussion";
|
|
167
195
|
}
|
|
168
196
|
}
|
package/src/schema.ts
CHANGED
|
@@ -7,7 +7,7 @@ const OptionSchema = Type.Object({
|
|
|
7
7
|
label: Type.String({ description: "Displayed label" }),
|
|
8
8
|
description: Type.Optional(
|
|
9
9
|
Type.String({
|
|
10
|
-
description: "Optional
|
|
10
|
+
description: "Optional description",
|
|
11
11
|
}),
|
|
12
12
|
),
|
|
13
13
|
preview: Type.Optional(
|
|
@@ -17,6 +17,9 @@ const OptionSchema = Type.Object({
|
|
|
17
17
|
),
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
const ChoiceOptionCount = { minItems: 2, maxItems: 12 } as const;
|
|
21
|
+
const QuestionCount = { minItems: 1, maxItems: 10 } as const;
|
|
22
|
+
|
|
20
23
|
const ChoiceQuestionSchema = Type.Object({
|
|
21
24
|
type: Type.Literal("choice"),
|
|
22
25
|
id: Type.String({ description: "Question id" }),
|
|
@@ -24,34 +27,19 @@ const ChoiceQuestionSchema = Type.Object({
|
|
|
24
27
|
prompt: Type.String({ description: "Question text" }),
|
|
25
28
|
options: Type.Array(OptionSchema, {
|
|
26
29
|
description: "Allowed options (2-12)",
|
|
30
|
+
...ChoiceOptionCount,
|
|
27
31
|
}),
|
|
28
|
-
required: Type.Optional(
|
|
29
|
-
Type.Boolean({
|
|
30
|
-
default: true,
|
|
31
|
-
description: "Required for full submit",
|
|
32
|
-
}),
|
|
33
|
-
),
|
|
34
32
|
multi: Type.Optional(
|
|
35
33
|
Type.Boolean({
|
|
36
34
|
default: false,
|
|
37
35
|
description: "Allow multiple selections",
|
|
38
36
|
}),
|
|
39
37
|
),
|
|
40
|
-
allowOther: Type.Optional(
|
|
41
|
-
Type.Boolean({
|
|
42
|
-
description: "Allow a custom option; single-select only",
|
|
43
|
-
}),
|
|
44
|
-
),
|
|
45
38
|
recommendation: Type.Optional(
|
|
46
39
|
Type.Union([Type.String(), Type.Array(Type.String())], {
|
|
47
40
|
description: "Recommended value(s)",
|
|
48
41
|
}),
|
|
49
42
|
),
|
|
50
|
-
initial: Type.Optional(
|
|
51
|
-
Type.Union([Type.String(), Type.Array(Type.String())], {
|
|
52
|
-
description: "Initial value(s)",
|
|
53
|
-
}),
|
|
54
|
-
),
|
|
55
43
|
});
|
|
56
44
|
|
|
57
45
|
const TextQuestionSchema = Type.Object({
|
|
@@ -59,13 +47,7 @@ const TextQuestionSchema = Type.Object({
|
|
|
59
47
|
id: Type.String({ description: "Question id" }),
|
|
60
48
|
header: Type.String({ description: "Short label" }),
|
|
61
49
|
prompt: Type.String({ description: "Question text" }),
|
|
62
|
-
|
|
63
|
-
Type.Boolean({
|
|
64
|
-
default: true,
|
|
65
|
-
description: "Required for full submit",
|
|
66
|
-
}),
|
|
67
|
-
),
|
|
68
|
-
initial: Type.Optional(Type.String({ description: "Initial text" })),
|
|
50
|
+
recommendation: Type.Optional(Type.String({ description: "Suggested prefilled text" })),
|
|
69
51
|
placeholder: Type.Optional(Type.String({ description: "Editor placeholder" })),
|
|
70
52
|
});
|
|
71
53
|
|
|
@@ -79,13 +61,9 @@ export const AskUserParamsSchema = Type.Object({
|
|
|
79
61
|
}),
|
|
80
62
|
),
|
|
81
63
|
questions: Type.Array(QuestionSchema, {
|
|
82
|
-
description: "1-
|
|
64
|
+
description: "1-10 focused questions for one decision",
|
|
65
|
+
...QuestionCount,
|
|
83
66
|
}),
|
|
84
|
-
allowPartialSubmit: Type.Optional(
|
|
85
|
-
Type.Boolean({
|
|
86
|
-
description: "Allow partial submission",
|
|
87
|
-
}),
|
|
88
|
-
),
|
|
89
67
|
});
|
|
90
68
|
|
|
91
69
|
export type AskUserParams = Static<typeof AskUserParamsSchema>;
|