@richjava/req0 0.3.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.
@@ -1232,6 +1232,28 @@ body {
1232
1232
  gap: var(--space-3);
1233
1233
  }
1234
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
+
1235
1257
  .question-card {
1236
1258
  display: flex;
1237
1259
  flex-direction: column;
@@ -1256,6 +1278,21 @@ body {
1256
1278
  font-size: var(--text-12);
1257
1279
  }
1258
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
+
1259
1296
  .question-choices {
1260
1297
  display: flex;
1261
1298
  flex-direction: column;
@@ -10,8 +10,10 @@ export declare class AgentAnswersError extends Error {
10
10
  readonly code = "agent_answers";
11
11
  constructor(message: string);
12
12
  }
13
- export type AgentQuestionsChannel = "improve" | "implement";
14
- export type AgentQuestionKind = "text" | "choice";
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"];
15
17
  export type AgentQuestionOption = {
16
18
  id: string;
17
19
  label: string;
@@ -19,6 +21,8 @@ export type AgentQuestionOption = {
19
21
  export type AgentQuestionAnswer = {
20
22
  text?: string;
21
23
  optionId?: string;
24
+ skipped?: boolean;
25
+ artifact?: string;
22
26
  };
23
27
  export type AgentQuestion = {
24
28
  id: string;
@@ -26,6 +30,8 @@ export type AgentQuestion = {
26
30
  kind: AgentQuestionKind;
27
31
  options?: AgentQuestionOption[];
28
32
  required: boolean;
33
+ allowCustom?: boolean;
34
+ accept?: string[];
29
35
  answer?: AgentQuestionAnswer;
30
36
  };
31
37
  export type AgentQuestionsRound = {
@@ -35,14 +41,19 @@ export type AgentQuestionsRound = {
35
41
  at: string;
36
42
  questions: AgentQuestion[];
37
43
  };
38
- export declare function questionsBriefSection(): string;
44
+ export declare function questionsBriefSection(options?: {
45
+ channel?: AgentQuestionsChannel;
46
+ inventIds?: boolean;
47
+ }): string;
39
48
  export declare function parseAgentQuestions(raw: unknown): AgentQuestionsRound | null;
40
49
  export declare function readAgentQuestions(paths: AgentQuestionsPaths): Promise<AgentQuestionsRound | null>;
41
50
  export declare function writeAgentQuestions(paths: AgentQuestionsPaths, round: AgentQuestionsRound): Promise<void>;
42
51
  export declare function clearAgentQuestions(paths: AgentQuestionsPaths): Promise<void>;
43
52
  export declare function isOpenQuestions(round: AgentQuestionsRound | null | undefined): round is AgentQuestionsRound;
44
53
  export declare function requiredUnanswered(round: AgentQuestionsRound): AgentQuestion[];
45
- export declare function applyAnswers(round: AgentQuestionsRound, answers: Record<string, string>): AgentQuestionsRound;
54
+ export declare function applyAnswers(round: AgentQuestionsRound, answers: Record<string, string>, options?: {
55
+ skipAll?: boolean;
56
+ }): AgentQuestionsRound;
46
57
  export declare function formatOwnerAnswers(round: AgentQuestionsRound): string;
47
58
  export declare function withOwnerAnswers(prompt: string, round: AgentQuestionsRound | null): string;
48
59
  export declare function applyAgentQuestionsGate(health: Health, round: AgentQuestionsRound | null): Health;
@@ -9,19 +9,28 @@ export class AgentAnswersError extends Error {
9
9
  this.name = "AgentAnswersError";
10
10
  }
11
11
  }
12
- export function questionsBriefSection() {
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;
13
17
  return [
14
18
  "## If you must ask",
15
19
  "",
16
- "Do not guess a required decision (trade-off, missing intent, real test user vs fixture). Do not invent BR- or UC- IDs.",
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.",
17
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.",
18
27
  "The owner answers in the cockpit. The next launch includes those answers. Then continue.",
19
28
  "Do not put secrets in this file.",
20
29
  "",
21
30
  "~~~~json",
22
31
  JSON.stringify({
23
32
  version: 1,
24
- channel: "implement",
33
+ channel,
25
34
  status: "open",
26
35
  at: "2026-01-01T00:00:00.000Z",
27
36
  questions: [
@@ -30,22 +39,24 @@ export function questionsBriefSection() {
30
39
  prompt: "Which option should we take?",
31
40
  kind: "choice",
32
41
  options: [
33
- { id: "a", label: "Option A" },
42
+ { id: "a", label: "Option A (recommended)" },
34
43
  { id: "b", label: "Option B" },
35
44
  ],
36
45
  required: true,
46
+ allowCustom: true,
37
47
  },
38
48
  {
39
49
  id: "q2",
40
- prompt: "Any extra note for the owner?",
41
- kind: "text",
50
+ prompt: "Upload a screenshot of the screen this requirement covers, if you have one.",
51
+ kind: "artifact",
42
52
  required: false,
53
+ accept: [...AUTHOR_ARTIFACT_ACCEPT],
43
54
  },
44
55
  ],
45
56
  }, null, 2),
46
57
  "~~~~",
47
58
  "",
48
- "Set `channel` to `improve` when patching the requirement pack, or `implement` when writing product code.",
59
+ "Set `channel` to `author` when filling a new pack from a description, `improve` when patching after Ready, or `implement` when writing product code.",
49
60
  "",
50
61
  ].join("\n");
51
62
  }
@@ -55,7 +66,7 @@ export function parseAgentQuestions(raw) {
55
66
  const body = raw;
56
67
  if (body.version !== 1)
57
68
  return null;
58
- if (body.channel !== "improve" && body.channel !== "implement")
69
+ if (body.channel !== "author" && body.channel !== "improve" && body.channel !== "implement")
59
70
  return null;
60
71
  if (body.status !== "open" && body.status !== "answered")
61
72
  return null;
@@ -100,15 +111,23 @@ export function isOpenQuestions(round) {
100
111
  return Boolean(round && round.status === "open" && round.questions.length > 0);
101
112
  }
102
113
  export function requiredUnanswered(round) {
103
- return round.questions.filter((question) => question.required && !hasAnswer(question));
114
+ return round.questions.filter((question) => question.required && !hasAnswer(question) && !isSkipped(question));
104
115
  }
105
- export function applyAnswers(round, answers) {
116
+ export function applyAnswers(round, answers, options = {}) {
106
117
  if (!isOpenQuestions(round)) {
107
118
  throw new AgentAnswersError("No open questions to answer.");
108
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
+ }
109
125
  const next = round.questions.map((question) => {
110
126
  const raw = answers[question.id];
111
127
  const value = typeof raw === "string" ? raw.trim() : "";
128
+ if (value === SKIP_ANSWER || (!value && options.skipAll)) {
129
+ return { ...question, answer: { skipped: true } };
130
+ }
112
131
  if (!value) {
113
132
  if (question.required) {
114
133
  throw new AgentAnswersError(`Answer is required: ${question.id}.`);
@@ -117,17 +136,17 @@ export function applyAnswers(round, answers) {
117
136
  }
118
137
  if (question.kind === "choice") {
119
138
  const option = (question.options ?? []).find((item) => item.id === value);
120
- if (!option) {
121
- throw new AgentAnswersError(`Unknown option for ${question.id}.`);
122
- }
123
- return { ...question, answer: { optionId: option.id } };
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 } };
124
147
  }
125
148
  return { ...question, answer: { text: value } };
126
149
  });
127
- const unknown = Object.keys(answers).filter((id) => !round.questions.some((question) => question.id === id));
128
- if (unknown.length) {
129
- throw new AgentAnswersError(`Unknown question id: ${unknown[0]}.`);
130
- }
131
150
  return {
132
151
  ...round,
133
152
  status: "answered",
@@ -148,6 +167,7 @@ export function formatOwnerAnswers(round) {
148
167
  return "";
149
168
  lines.push("");
150
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.");
151
171
  return lines.join("\n");
152
172
  }
153
173
  export function withOwnerAnswers(prompt, round) {
@@ -161,7 +181,7 @@ export function withOwnerAnswers(prompt, round) {
161
181
  export function applyAgentQuestionsGate(health, round) {
162
182
  if (!isOpenQuestions(round) || !health.stages)
163
183
  return health;
164
- const improve = round.channel === "improve";
184
+ const defineSide = round.channel === "improve" || round.channel === "author";
165
185
  return {
166
186
  ...health,
167
187
  howThisIsGoing: "The agent has questions.",
@@ -169,9 +189,9 @@ export function applyAgentQuestionsGate(health, round) {
169
189
  id: "answer-questions",
170
190
  label: "Continue",
171
191
  enabled: true,
172
- hint: "Answer each required question, then Continue.",
192
+ hint: "Answer each required question, then Continue. You may skip a question or all of them.",
173
193
  },
174
- stages: gateStages(health.stages, improve),
194
+ stages: gateStages(health.stages, defineSide),
175
195
  };
176
196
  }
177
197
  function gateStages(stages, improve) {
@@ -224,9 +244,9 @@ function parseQuestion(raw) {
224
244
  return null;
225
245
  if (typeof body.prompt !== "string" || !body.prompt.trim())
226
246
  return null;
227
- if (body.kind !== "text" && body.kind !== "choice")
247
+ if (body.kind !== "text" && body.kind !== "choice" && body.kind !== "artifact")
228
248
  return null;
229
- const required = body.required === false ? false : true;
249
+ const required = body.kind === "artifact" ? body.required === true : body.required === false ? false : true;
230
250
  let options;
231
251
  if (body.kind === "choice") {
232
252
  if (!Array.isArray(body.options) || body.options.length < 2)
@@ -247,14 +267,30 @@ function parseQuestion(raw) {
247
267
  options.push({ id: option.id, label: option.label });
248
268
  }
249
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
+ }
250
281
  let answer;
251
282
  if (body.answer && typeof body.answer === "object") {
252
283
  const value = body.answer;
284
+ if (value.skipped === true)
285
+ answer = { skipped: true };
253
286
  if (typeof value.text === "string" && value.text.trim())
254
- answer = { text: value.text.trim() };
287
+ answer = { ...answer, text: value.text.trim() };
255
288
  if (typeof value.optionId === "string" && value.optionId.trim()) {
256
289
  answer = { ...answer, optionId: value.optionId.trim() };
257
290
  }
291
+ if (typeof value.artifact === "string" && value.artifact.trim()) {
292
+ answer = { ...answer, artifact: value.artifact.trim() };
293
+ }
258
294
  }
259
295
  return {
260
296
  id: body.id.trim(),
@@ -262,17 +298,30 @@ function parseQuestion(raw) {
262
298
  kind: body.kind,
263
299
  ...(options ? { options } : {}),
264
300
  required,
301
+ ...(body.kind === "choice" && body.allowCustom === true ? { allowCustom: true } : {}),
302
+ ...(accept ? { accept } : {}),
265
303
  ...(answer ? { answer } : {}),
266
304
  };
267
305
  }
268
306
  function hasAnswer(question) {
269
- return Boolean(question.answer?.text?.trim() || question.answer?.optionId?.trim());
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;
270
311
  }
271
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.`;
272
317
  if (question.kind === "choice") {
273
318
  const id = question.answer?.optionId;
274
319
  const option = question.options?.find((item) => item.id === id);
275
- return option?.label ?? 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 ?? "";
276
325
  }
277
326
  return question.answer?.text?.trim() ?? "";
278
327
  }
@@ -0,0 +1,103 @@
1
+ import type { AdapterId, Finding, Health, ProductRepo, ReadyMeter, SpecAst } from "./types.js";
2
+ export declare const AUTHOR_MAX_ROUNDS = 8;
3
+ export declare const AUTHOR_BRIEF_FILE = "author-brief.md";
4
+ export declare const AUTHOR_RUN_FILE = "author-run.json";
5
+ export declare const AUTHOR_AGENT_LOG = "author-agent.log";
6
+ export declare const AUTHOR_STOPPED = "Owner stopped authoring.";
7
+ export declare const AUTHOR_CAPPED = "Authoring stopped after 8 rounds. Keep editing, or Improve it once Ready is blocked.";
8
+ export declare const AUTHOR_ARTIFACT_MIMES: Record<string, string>;
9
+ export type AuthorQualityTarget = "spec_valid" | "ready";
10
+ export type AuthorRunStatus = "running" | "waiting_questions" | "done" | "stopped";
11
+ export type AuthorRun = {
12
+ version: 1;
13
+ status: AuthorRunStatus;
14
+ qualityTarget: AuthorQualityTarget;
15
+ description: string;
16
+ round: number;
17
+ at: string;
18
+ specHash?: string;
19
+ message?: string;
20
+ };
21
+ export type AuthorStepAction = "wait_questions" | "check" | "relaunch" | "done" | "capped";
22
+ export type AuthorStep = {
23
+ action: AuthorStepAction;
24
+ run: AuthorRun;
25
+ message: string;
26
+ };
27
+ export type AuthorPaths = {
28
+ id: string;
29
+ root: string;
30
+ requirement: string;
31
+ personas: string;
32
+ derived: string;
33
+ authorBrief: string;
34
+ authorRun: string;
35
+ context: string;
36
+ };
37
+ export type SiblingSummary = {
38
+ id: string;
39
+ title: string;
40
+ overview: string;
41
+ specIds: string[];
42
+ actors: string[];
43
+ };
44
+ export declare class AuthorLockedError extends Error {
45
+ readonly code = "author_gate";
46
+ constructor(message?: string);
47
+ }
48
+ export declare class AuthorArtifactError extends Error {
49
+ readonly code = "author_artifact";
50
+ constructor(message: string);
51
+ }
52
+ export declare function authorQualityTarget(hasApiKey: boolean): AuthorQualityTarget;
53
+ export declare function authorQualityMet(health: Pick<Health, "spec" | "ready">, target: AuthorQualityTarget): boolean;
54
+ export declare function shouldOfferAuthor(health: Pick<Health, "spec">, run: AuthorRun | null): boolean;
55
+ export declare function isAuthorActive(run: AuthorRun | null | undefined): boolean;
56
+ export declare function parseAuthorRun(raw: unknown): AuthorRun | null;
57
+ export declare function readAuthorRun(paths: Pick<AuthorPaths, "authorRun">): Promise<AuthorRun | null>;
58
+ export declare function writeAuthorRun(paths: Pick<AuthorPaths, "derived" | "authorRun">, run: AuthorRun): Promise<void>;
59
+ export declare function nextAuthorStep(input: {
60
+ run: AuthorRun;
61
+ specState: Health["spec"]["state"];
62
+ readyState: ReadyMeter["state"];
63
+ jevCurrent: boolean;
64
+ openQuestions: boolean;
65
+ hasApiKey: boolean;
66
+ justChecked?: boolean;
67
+ }): AuthorStep;
68
+ export declare function applyAuthorGate(health: Health, run: AuthorRun | null): Health;
69
+ export declare function titleFromRequirementId(id: string): string;
70
+ export declare function seedAuthorMarkdown(id: string, description: string, current: string): string;
71
+ export declare function summarizeRequirementMarkdown(id: string, markdown: string): SiblingSummary;
72
+ export declare function emitAuthorBrief(input: {
73
+ id: string;
74
+ description: string;
75
+ qualityTarget: AuthorQualityTarget;
76
+ round: number;
77
+ markdown: string;
78
+ compileFindings: Finding[];
79
+ spec: SpecAst | null;
80
+ ready: ReadyMeter | null;
81
+ siblings: SiblingSummary[];
82
+ product: {
83
+ empty: boolean;
84
+ stack: string;
85
+ adapter: AdapterId;
86
+ layout: string;
87
+ instruction: string;
88
+ };
89
+ contextFiles: string[];
90
+ }): string;
91
+ export declare function authorPrompt(briefPath: string): string;
92
+ export declare function sanitizeArtifactFilename(filename: string, mime: string): string;
93
+ export declare function decodeArtifactData(raw: string, mime: string): Buffer;
94
+ export declare function writeAuthorArtifact(paths: Pick<AuthorPaths, "context">, filename: string, mime: string, data: string): Promise<string>;
95
+ export declare function listContextFiles(paths: Pick<AuthorPaths, "context">): Promise<string[]>;
96
+ export declare function listProductLayout(repoRoot: string | null): Promise<string>;
97
+ export declare function productBriefBits(repo: ProductRepo, layout: string): {
98
+ empty: boolean;
99
+ stack: string;
100
+ adapter: AdapterId;
101
+ layout: string;
102
+ instruction: string;
103
+ };