@richjava/req0 0.2.0 → 0.4.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.
@@ -16,11 +16,21 @@
16
16
  <body>
17
17
  <div class="app-shell app-shell-pipeline">
18
18
  <header class="topbar">
19
- <div class="topbar-start">
19
+ <div class="topbar-brand">
20
20
  <button type="button" class="home-btn" id="home-btn" aria-label="All requirements">
21
21
  <img class="logo-horiz" src="/req0-logo-horiz.png" alt="Req0" width="148" height="36" />
22
22
  </button>
23
- <button type="button" class="btn-secondary hidden" id="all-requirements">All requirements</button>
23
+ <p class="project-name" id="project-name"></p>
24
+ </div>
25
+ </header>
26
+ <header class="subbar" id="subbar">
27
+ <div class="topbar-start">
28
+ <button type="button" class="btn-secondary hidden" id="all-requirements">
29
+ <svg viewBox="0 0 16 16" aria-hidden="true">
30
+ <path d="M13 8H3.5M6.2 4.8 3 8l3.2 3.2" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>
31
+ </svg>
32
+ All requirements
33
+ </button>
24
34
  <div class="topbar-copy">
25
35
  <p class="sidebar-pack" id="pack-title">Loading…</p>
26
36
  <p class="going" id="how-going">Loading…</p>
@@ -101,7 +111,29 @@
101
111
  <button type="button" class="btn-secondary cta" id="review-reject">Reject</button>
102
112
  <button type="button" class="btn-primary cta" id="review-accept" disabled>Accept</button>
103
113
  </div>
114
+ <div class="review-actions hidden" id="question-actions">
115
+ <button type="button" class="btn-secondary cta" id="question-skip-all">Skip all</button>
116
+ <button type="button" class="btn-secondary cta" id="question-stop">Stop</button>
117
+ <button type="button" class="btn-primary cta" id="question-continue" disabled>Continue</button>
118
+ </div>
119
+ </div>
120
+ <div class="author-describe hidden" id="author-describe" hidden>
121
+ <label class="field">
122
+ What should this requirement cover?
123
+ <textarea class="input" id="author-description" rows="5" placeholder="A short description is enough. The agent will ask questions to fill the rest."></textarea>
124
+ </label>
125
+ <button type="button" class="btn-primary cta" id="author-start">Start</button>
126
+ </div>
127
+ <div class="qa-tab-bar hidden" id="define-tabs" role="tablist" hidden>
128
+ <button type="button" class="qa-tab is-active" role="tab" id="define-tab-questions" aria-selected="true" aria-controls="define-questions">
129
+ Questions
130
+ </button>
131
+ <button type="button" class="qa-tab" role="tab" id="define-tab-activity" aria-selected="false" aria-controls="define-activity">
132
+ Activity
133
+ </button>
104
134
  </div>
135
+ <div class="question-panel hidden" id="define-questions" hidden></div>
136
+ <ul class="activity-log list-rows hidden" id="define-activity" hidden></ul>
105
137
  <div id="editor" class="markdown-editor" aria-label="requirement.md"></div>
106
138
  <div class="review-diff hidden" id="review-diff" hidden></div>
107
139
  <p class="save-state" id="save-state"></p>
@@ -133,7 +165,16 @@
133
165
  <button type="button" class="pill-btn cta" id="action-build-stop" hidden disabled></button>
134
166
  </div>
135
167
  </div>
136
- <p class="nav-label">Activity</p>
168
+ <div class="qa-tab-bar hidden" id="implement-tabs" role="tablist" hidden>
169
+ <button type="button" class="qa-tab is-active" role="tab" id="implement-tab-questions" aria-selected="true" aria-controls="implement-questions">
170
+ Questions
171
+ </button>
172
+ <button type="button" class="qa-tab" role="tab" id="implement-tab-activity" aria-selected="false" aria-controls="implement-activity">
173
+ Activity
174
+ </button>
175
+ </div>
176
+ <p class="nav-label" id="implement-activity-label">Activity</p>
177
+ <div class="question-panel hidden" id="implement-questions" hidden></div>
137
178
  <ol id="implement-activity" class="list-rows activity-log activity-log-main"></ol>
138
179
  </section>
139
180
 
@@ -166,6 +207,13 @@
166
207
  </div>
167
208
  </div>
168
209
  </div>
210
+ <dialog id="discard-questions-dialog" class="confirm-dialog">
211
+ <p>Stop and discard unanswered questions?</p>
212
+ <div class="dialog-actions">
213
+ <button type="button" class="btn-secondary" id="discard-questions-cancel">Cancel</button>
214
+ <button type="button" class="btn-primary cta-danger" id="discard-questions-confirm">Stop</button>
215
+ </div>
216
+ </dialog>
169
217
  <dialog id="ignore-build-dialog" class="confirm-dialog">
170
218
  <p>Was implementation successful?</p>
171
219
  <div class="dialog-actions">
@@ -242,7 +242,8 @@ body {
242
242
  margin-top: var(--space-3);
243
243
  }
244
244
 
245
- .topbar {
245
+ .topbar,
246
+ .subbar {
246
247
  display: flex;
247
248
  align-items: center;
248
249
  justify-content: space-between;
@@ -252,6 +253,24 @@ body {
252
253
  background: var(--surface-1);
253
254
  }
254
255
 
256
+ .topbar-brand {
257
+ display: flex;
258
+ align-items: center;
259
+ gap: var(--space-4);
260
+ min-width: 0;
261
+ }
262
+
263
+ .project-name {
264
+ margin: 0;
265
+ min-width: 0;
266
+ font-size: var(--text-16);
267
+ font-weight: 600;
268
+ color: var(--text-primary);
269
+ overflow: hidden;
270
+ text-overflow: ellipsis;
271
+ white-space: nowrap;
272
+ }
273
+
255
274
  .topbar-start {
256
275
  display: flex;
257
276
  align-items: center;
@@ -283,9 +302,18 @@ body {
283
302
  }
284
303
 
285
304
  #all-requirements {
305
+ display: inline-flex;
306
+ align-items: center;
307
+ gap: 6px;
286
308
  flex-shrink: 0;
287
309
  white-space: nowrap;
288
- align-self: flex-start;
310
+ align-self: center;
311
+ }
312
+
313
+ #all-requirements svg {
314
+ width: 1rem;
315
+ height: 1rem;
316
+ flex-shrink: 0;
289
317
  }
290
318
 
291
319
  .topbar-copy {
@@ -800,8 +828,7 @@ body {
800
828
  margin: 0;
801
829
  color: var(--text-muted);
802
830
  font-size: var(--text-13);
803
- max-width: 16rem;
804
- text-align: right;
831
+ max-width: 32rem;
805
832
  }
806
833
 
807
834
  .btn-primary,
@@ -1199,6 +1226,83 @@ body {
1199
1226
  color: var(--color-primary);
1200
1227
  }
1201
1228
 
1229
+ .question-panel {
1230
+ display: flex;
1231
+ flex-direction: column;
1232
+ gap: var(--space-3);
1233
+ }
1234
+
1235
+ .author-describe {
1236
+ display: flex;
1237
+ flex-direction: column;
1238
+ gap: var(--space-3);
1239
+ margin-bottom: var(--space-4);
1240
+ padding: var(--space-4);
1241
+ border: 1px solid var(--border-subtle);
1242
+ border-radius: var(--radius-md);
1243
+ background: var(--surface-2);
1244
+ }
1245
+
1246
+ .author-describe .field {
1247
+ display: flex;
1248
+ flex-direction: column;
1249
+ gap: var(--space-2);
1250
+ }
1251
+
1252
+ .author-describe textarea.input {
1253
+ min-height: 7rem;
1254
+ resize: vertical;
1255
+ }
1256
+
1257
+ .question-card {
1258
+ display: flex;
1259
+ flex-direction: column;
1260
+ gap: var(--space-3);
1261
+ padding: var(--space-4);
1262
+ border: 1px solid var(--border-subtle);
1263
+ border-radius: var(--radius-md);
1264
+ background: var(--surface-2);
1265
+ }
1266
+
1267
+ .question-card-prompt {
1268
+ margin: 0;
1269
+ color: var(--text-primary);
1270
+ font-size: var(--text-14);
1271
+ font-weight: 650;
1272
+ line-height: 1.4;
1273
+ }
1274
+
1275
+ .question-card-meta {
1276
+ margin: 0;
1277
+ color: var(--text-muted);
1278
+ font-size: var(--text-12);
1279
+ }
1280
+
1281
+ .question-card-row {
1282
+ display: flex;
1283
+ align-items: center;
1284
+ justify-content: space-between;
1285
+ gap: var(--space-3);
1286
+ }
1287
+
1288
+ .question-suggested {
1289
+ display: inline-block;
1290
+ margin-left: var(--space-2);
1291
+ color: var(--color-primary);
1292
+ font-size: var(--text-12);
1293
+ font-weight: 650;
1294
+ }
1295
+
1296
+ .question-choices {
1297
+ display: flex;
1298
+ flex-direction: column;
1299
+ gap: var(--space-2);
1300
+ }
1301
+
1302
+ .question-choices .stack-choice {
1303
+ padding: var(--space-3);
1304
+ }
1305
+
1202
1306
  .activity-log .list-row,
1203
1307
  #proof-report.list-rows .list-row {
1204
1308
  cursor: default;
@@ -1686,7 +1790,7 @@ body {
1686
1790
  border-bottom: 1px solid var(--border-subtle);
1687
1791
  }
1688
1792
 
1689
- .topbar,
1793
+ .subbar,
1690
1794
  .topbar-start,
1691
1795
  .create-bar {
1692
1796
  flex-direction: column;
@@ -0,0 +1,59 @@
1
+ import type { Health } from "./types.js";
2
+ export type AgentQuestionsPaths = {
3
+ derived: string;
4
+ agentQuestions: string;
5
+ };
6
+ export declare const AGENT_QUESTIONS_FILE = "agent-questions.json";
7
+ export declare const AGENT_QUESTIONS_PATH = "derived/agent-questions.json";
8
+ export declare const AGENT_QUESTIONS_WAITING = "Waiting on owner questions.";
9
+ export declare class AgentAnswersError extends Error {
10
+ readonly code = "agent_answers";
11
+ constructor(message: string);
12
+ }
13
+ export type AgentQuestionsChannel = "author" | "improve" | "implement";
14
+ export type AgentQuestionKind = "text" | "choice" | "artifact";
15
+ export declare const SKIP_ANSWER = "__skip__";
16
+ export declare const AUTHOR_ARTIFACT_ACCEPT: readonly ["image/png", "image/jpeg", "image/webp"];
17
+ export type AgentQuestionOption = {
18
+ id: string;
19
+ label: string;
20
+ };
21
+ export type AgentQuestionAnswer = {
22
+ text?: string;
23
+ optionId?: string;
24
+ skipped?: boolean;
25
+ artifact?: string;
26
+ };
27
+ export type AgentQuestion = {
28
+ id: string;
29
+ prompt: string;
30
+ kind: AgentQuestionKind;
31
+ options?: AgentQuestionOption[];
32
+ required: boolean;
33
+ allowCustom?: boolean;
34
+ accept?: string[];
35
+ answer?: AgentQuestionAnswer;
36
+ };
37
+ export type AgentQuestionsRound = {
38
+ version: 1;
39
+ channel: AgentQuestionsChannel;
40
+ status: "open" | "answered";
41
+ at: string;
42
+ questions: AgentQuestion[];
43
+ };
44
+ export declare function questionsBriefSection(options?: {
45
+ channel?: AgentQuestionsChannel;
46
+ inventIds?: boolean;
47
+ }): string;
48
+ export declare function parseAgentQuestions(raw: unknown): AgentQuestionsRound | null;
49
+ export declare function readAgentQuestions(paths: AgentQuestionsPaths): Promise<AgentQuestionsRound | null>;
50
+ export declare function writeAgentQuestions(paths: AgentQuestionsPaths, round: AgentQuestionsRound): Promise<void>;
51
+ export declare function clearAgentQuestions(paths: AgentQuestionsPaths): Promise<void>;
52
+ export declare function isOpenQuestions(round: AgentQuestionsRound | null | undefined): round is AgentQuestionsRound;
53
+ export declare function requiredUnanswered(round: AgentQuestionsRound): AgentQuestion[];
54
+ export declare function applyAnswers(round: AgentQuestionsRound, answers: Record<string, string>, options?: {
55
+ skipAll?: boolean;
56
+ }): AgentQuestionsRound;
57
+ export declare function formatOwnerAnswers(round: AgentQuestionsRound): string;
58
+ export declare function withOwnerAnswers(prompt: string, round: AgentQuestionsRound | null): string;
59
+ export declare function applyAgentQuestionsGate(health: Health, round: AgentQuestionsRound | null): Health;
@@ -0,0 +1,327 @@
1
+ import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
2
+ export const AGENT_QUESTIONS_FILE = "agent-questions.json";
3
+ export const AGENT_QUESTIONS_PATH = `derived/${AGENT_QUESTIONS_FILE}`;
4
+ export const AGENT_QUESTIONS_WAITING = "Waiting on owner questions.";
5
+ export class AgentAnswersError extends Error {
6
+ code = "agent_answers";
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "AgentAnswersError";
10
+ }
11
+ }
12
+ export const SKIP_ANSWER = "__skip__";
13
+ export const AUTHOR_ARTIFACT_ACCEPT = ["image/png", "image/jpeg", "image/webp"];
14
+ export function questionsBriefSection(options = {}) {
15
+ const channel = options.channel ?? "implement";
16
+ const invent = options.inventIds === true;
17
+ return [
18
+ "## If you must ask",
19
+ "",
20
+ invent
21
+ ? "Do not guess a required decision. You may assign the first BR-NNN and UC-NNN IDs in this pack. Do not copy IDs from sibling packs."
22
+ : "Do not guess a required decision (trade-off, missing intent, real test user vs fixture). Do not invent BR- or UC- IDs.",
23
+ `Write \`${AGENT_QUESTIONS_PATH}\` using the shape below, replace the file, then **stop**. Do not patch \`requirement.md\` or product code in the same turn.`,
24
+ "At most four questions. Highest-leverage gaps first. For `choice`, put your recommended option first. Set `allowCustom` true when the owner may type something else.",
25
+ "The owner may skip one question or all of them. Skipped is not an answer: do not assume. Ask a different question later, or leave that gap in `## Open questions`.",
26
+ "If a screenshot or mock would resolve a gap, use `kind: \"artifact\"` (PNG/JPG/WebP). The owner may skip the upload.",
27
+ "The owner answers in the cockpit. The next launch includes those answers. Then continue.",
28
+ "Do not put secrets in this file.",
29
+ "",
30
+ "~~~~json",
31
+ JSON.stringify({
32
+ version: 1,
33
+ channel,
34
+ status: "open",
35
+ at: "2026-01-01T00:00:00.000Z",
36
+ questions: [
37
+ {
38
+ id: "q1",
39
+ prompt: "Which option should we take?",
40
+ kind: "choice",
41
+ options: [
42
+ { id: "a", label: "Option A (recommended)" },
43
+ { id: "b", label: "Option B" },
44
+ ],
45
+ required: true,
46
+ allowCustom: true,
47
+ },
48
+ {
49
+ id: "q2",
50
+ prompt: "Upload a screenshot of the screen this requirement covers, if you have one.",
51
+ kind: "artifact",
52
+ required: false,
53
+ accept: [...AUTHOR_ARTIFACT_ACCEPT],
54
+ },
55
+ ],
56
+ }, null, 2),
57
+ "~~~~",
58
+ "",
59
+ "Set `channel` to `author` when filling a new pack from a description, `improve` when patching after Ready, or `implement` when writing product code.",
60
+ "",
61
+ ].join("\n");
62
+ }
63
+ export function parseAgentQuestions(raw) {
64
+ if (!raw || typeof raw !== "object")
65
+ return null;
66
+ const body = raw;
67
+ if (body.version !== 1)
68
+ return null;
69
+ if (body.channel !== "author" && body.channel !== "improve" && body.channel !== "implement")
70
+ return null;
71
+ if (body.status !== "open" && body.status !== "answered")
72
+ return null;
73
+ if (typeof body.at !== "string" || !body.at.trim())
74
+ return null;
75
+ if (!Array.isArray(body.questions) || body.questions.length === 0)
76
+ return null;
77
+ const questions = [];
78
+ for (const item of body.questions) {
79
+ const parsed = parseQuestion(item);
80
+ if (!parsed)
81
+ return null;
82
+ questions.push(parsed);
83
+ }
84
+ const ids = new Set(questions.map((question) => question.id));
85
+ if (ids.size !== questions.length)
86
+ return null;
87
+ return {
88
+ version: 1,
89
+ channel: body.channel,
90
+ status: body.status,
91
+ at: body.at,
92
+ questions,
93
+ };
94
+ }
95
+ export async function readAgentQuestions(paths) {
96
+ try {
97
+ return parseAgentQuestions(JSON.parse(await readFile(paths.agentQuestions, "utf8")));
98
+ }
99
+ catch {
100
+ return null;
101
+ }
102
+ }
103
+ export async function writeAgentQuestions(paths, round) {
104
+ await mkdir(paths.derived, { recursive: true });
105
+ await writeFile(paths.agentQuestions, `${JSON.stringify(round, null, 2)}\n`, "utf8");
106
+ }
107
+ export async function clearAgentQuestions(paths) {
108
+ await unlink(paths.agentQuestions).catch(() => undefined);
109
+ }
110
+ export function isOpenQuestions(round) {
111
+ return Boolean(round && round.status === "open" && round.questions.length > 0);
112
+ }
113
+ export function requiredUnanswered(round) {
114
+ return round.questions.filter((question) => question.required && !hasAnswer(question) && !isSkipped(question));
115
+ }
116
+ export function applyAnswers(round, answers, options = {}) {
117
+ if (!isOpenQuestions(round)) {
118
+ throw new AgentAnswersError("No open questions to answer.");
119
+ }
120
+ const known = new Set(round.questions.map((question) => question.id));
121
+ const unknown = Object.keys(answers).filter((id) => !known.has(id));
122
+ if (unknown.length) {
123
+ throw new AgentAnswersError(`Unknown question id: ${unknown[0]}.`);
124
+ }
125
+ const next = round.questions.map((question) => {
126
+ const raw = answers[question.id];
127
+ const value = typeof raw === "string" ? raw.trim() : "";
128
+ if (value === SKIP_ANSWER || (!value && options.skipAll)) {
129
+ return { ...question, answer: { skipped: true } };
130
+ }
131
+ if (!value) {
132
+ if (question.required) {
133
+ throw new AgentAnswersError(`Answer is required: ${question.id}.`);
134
+ }
135
+ return { ...question, answer: undefined };
136
+ }
137
+ if (question.kind === "choice") {
138
+ const option = (question.options ?? []).find((item) => item.id === value);
139
+ if (option)
140
+ return { ...question, answer: { optionId: option.id } };
141
+ if (question.allowCustom)
142
+ return { ...question, answer: { text: value } };
143
+ throw new AgentAnswersError(`Unknown option for ${question.id}.`);
144
+ }
145
+ if (question.kind === "artifact") {
146
+ return { ...question, answer: { artifact: value } };
147
+ }
148
+ return { ...question, answer: { text: value } };
149
+ });
150
+ return {
151
+ ...round,
152
+ status: "answered",
153
+ at: new Date().toISOString(),
154
+ questions: next,
155
+ };
156
+ }
157
+ export function formatOwnerAnswers(round) {
158
+ const lines = ["Owner answers:", ""];
159
+ for (const question of round.questions) {
160
+ const answer = answerLabel(question);
161
+ if (!answer)
162
+ continue;
163
+ lines.push(`- ${question.id}: ${question.prompt}`);
164
+ lines.push(` Answer: ${answer}`);
165
+ }
166
+ if (lines.length === 2)
167
+ return "";
168
+ lines.push("");
169
+ lines.push("Use these answers. Do not ask the same questions again unless a new required decision appears.");
170
+ lines.push("Skipped questions are not answers. Do not invent facts for them.");
171
+ return lines.join("\n");
172
+ }
173
+ export function withOwnerAnswers(prompt, round) {
174
+ if (!round || round.status !== "answered")
175
+ return prompt;
176
+ const block = formatOwnerAnswers(round);
177
+ if (!block)
178
+ return prompt;
179
+ return `${prompt}\n\n${block}`;
180
+ }
181
+ export function applyAgentQuestionsGate(health, round) {
182
+ if (!isOpenQuestions(round) || !health.stages)
183
+ return health;
184
+ const defineSide = round.channel === "improve" || round.channel === "author";
185
+ return {
186
+ ...health,
187
+ howThisIsGoing: "The agent has questions.",
188
+ nextAction: {
189
+ id: "answer-questions",
190
+ label: "Continue",
191
+ enabled: true,
192
+ hint: "Answer each required question, then Continue. You may skip a question or all of them.",
193
+ },
194
+ stages: gateStages(health.stages, defineSide),
195
+ };
196
+ }
197
+ function gateStages(stages, improve) {
198
+ return {
199
+ ready: {
200
+ ...stages.ready,
201
+ enabled: false,
202
+ hint: improve ? "Answer the agent's questions on Define." : stages.ready.hint,
203
+ },
204
+ build: improve
205
+ ? { ...stages.build, enabled: false }
206
+ : {
207
+ id: "answer-questions",
208
+ label: "Continue",
209
+ enabled: false,
210
+ hidden: true,
211
+ hint: "Answer the agent's questions.",
212
+ },
213
+ proof: { ...stages.proof, enabled: false },
214
+ ...(stages.fixFromProof ? { fixFromProof: { ...stages.fixFromProof, enabled: false } } : {}),
215
+ ...(stages.ignoreBuild ? { ignoreBuild: { ...stages.ignoreBuild, enabled: false } } : {}),
216
+ ...(stages.stopImplement
217
+ ? {
218
+ stopImplement: improve
219
+ ? { ...stages.stopImplement, enabled: false }
220
+ : {
221
+ id: "stop-implement",
222
+ label: "Stop",
223
+ enabled: true,
224
+ hint: "Discard unanswered questions. Build stays failed until you Reimplement or Ignore.",
225
+ },
226
+ }
227
+ : !improve
228
+ ? {
229
+ stopImplement: {
230
+ id: "stop-implement",
231
+ label: "Stop",
232
+ enabled: true,
233
+ hint: "Discard unanswered questions. Build stays failed until you Reimplement or Ignore.",
234
+ },
235
+ }
236
+ : {}),
237
+ };
238
+ }
239
+ function parseQuestion(raw) {
240
+ if (!raw || typeof raw !== "object")
241
+ return null;
242
+ const body = raw;
243
+ if (typeof body.id !== "string" || !body.id.trim())
244
+ return null;
245
+ if (typeof body.prompt !== "string" || !body.prompt.trim())
246
+ return null;
247
+ if (body.kind !== "text" && body.kind !== "choice" && body.kind !== "artifact")
248
+ return null;
249
+ const required = body.kind === "artifact" ? body.required === true : body.required === false ? false : true;
250
+ let options;
251
+ if (body.kind === "choice") {
252
+ if (!Array.isArray(body.options) || body.options.length < 2)
253
+ return null;
254
+ options = [];
255
+ const ids = new Set();
256
+ for (const item of body.options) {
257
+ if (!item || typeof item !== "object")
258
+ return null;
259
+ const option = item;
260
+ if (typeof option.id !== "string" || !option.id.trim())
261
+ return null;
262
+ if (typeof option.label !== "string" || !option.label.trim())
263
+ return null;
264
+ if (ids.has(option.id))
265
+ return null;
266
+ ids.add(option.id);
267
+ options.push({ id: option.id, label: option.label });
268
+ }
269
+ }
270
+ let accept;
271
+ if (body.kind === "artifact") {
272
+ if (Array.isArray(body.accept) && body.accept.length) {
273
+ accept = body.accept.filter((item) => typeof item === "string" && Boolean(item.trim()));
274
+ if (!accept.length)
275
+ accept = [...AUTHOR_ARTIFACT_ACCEPT];
276
+ }
277
+ else {
278
+ accept = [...AUTHOR_ARTIFACT_ACCEPT];
279
+ }
280
+ }
281
+ let answer;
282
+ if (body.answer && typeof body.answer === "object") {
283
+ const value = body.answer;
284
+ if (value.skipped === true)
285
+ answer = { skipped: true };
286
+ if (typeof value.text === "string" && value.text.trim())
287
+ answer = { ...answer, text: value.text.trim() };
288
+ if (typeof value.optionId === "string" && value.optionId.trim()) {
289
+ answer = { ...answer, optionId: value.optionId.trim() };
290
+ }
291
+ if (typeof value.artifact === "string" && value.artifact.trim()) {
292
+ answer = { ...answer, artifact: value.artifact.trim() };
293
+ }
294
+ }
295
+ return {
296
+ id: body.id.trim(),
297
+ prompt: body.prompt.trim(),
298
+ kind: body.kind,
299
+ ...(options ? { options } : {}),
300
+ required,
301
+ ...(body.kind === "choice" && body.allowCustom === true ? { allowCustom: true } : {}),
302
+ ...(accept ? { accept } : {}),
303
+ ...(answer ? { answer } : {}),
304
+ };
305
+ }
306
+ function hasAnswer(question) {
307
+ return Boolean(question.answer?.text?.trim() || question.answer?.optionId?.trim() || question.answer?.artifact?.trim());
308
+ }
309
+ function isSkipped(question) {
310
+ return question.answer?.skipped === true;
311
+ }
312
+ function answerLabel(question) {
313
+ if (question.answer?.skipped)
314
+ return "Skipped. Do not assume an answer.";
315
+ if (question.answer?.artifact)
316
+ return `Uploaded context/${question.answer.artifact}. Read that file.`;
317
+ if (question.kind === "choice") {
318
+ const id = question.answer?.optionId;
319
+ const option = question.options?.find((item) => item.id === id);
320
+ if (option)
321
+ return option.label;
322
+ if (question.allowCustom && question.answer?.text?.trim())
323
+ return question.answer.text.trim();
324
+ return id ?? "";
325
+ }
326
+ return question.answer?.text?.trim() ?? "";
327
+ }