@richjava/req0 0.1.0 → 0.3.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/cockpit/app.js +466 -70
- package/cockpit/index.html +50 -8
- package/cockpit/styles.css +106 -5
- package/dist/agent-questions.d.ts +48 -0
- package/dist/agent-questions.js +278 -0
- package/dist/cli.js +6 -2
- package/dist/fix-from-proof.js +2 -0
- package/dist/implement-brief.js +2 -1
- package/dist/implement.d.ts +6 -0
- package/dist/implement.js +71 -20
- package/dist/improve.js +4 -3
- package/dist/pack.d.ts +20 -2
- package/dist/pack.js +128 -13
- package/dist/ready.js +7 -0
- package/dist/server.d.ts +2 -1
- package/dist/server.js +146 -20
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
package/cockpit/index.html
CHANGED
|
@@ -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-
|
|
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
|
-
<
|
|
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,9 +111,14 @@
|
|
|
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-stop">Stop</button>
|
|
116
|
+
<button type="button" class="btn-primary cta" id="question-continue" disabled>Continue</button>
|
|
117
|
+
</div>
|
|
104
118
|
</div>
|
|
105
119
|
<div id="editor" class="markdown-editor" aria-label="requirement.md"></div>
|
|
106
120
|
<div class="review-diff hidden" id="review-diff" hidden></div>
|
|
121
|
+
<div class="question-panel hidden" id="define-questions" hidden></div>
|
|
107
122
|
<p class="save-state" id="save-state"></p>
|
|
108
123
|
</section>
|
|
109
124
|
|
|
@@ -133,8 +148,17 @@
|
|
|
133
148
|
<button type="button" class="pill-btn cta" id="action-build-stop" hidden disabled></button>
|
|
134
149
|
</div>
|
|
135
150
|
</div>
|
|
136
|
-
<
|
|
137
|
-
|
|
151
|
+
<div class="qa-tab-bar hidden" id="implement-tabs" role="tablist" hidden>
|
|
152
|
+
<button type="button" class="qa-tab is-active" role="tab" id="implement-tab-questions" aria-selected="true" aria-controls="implement-questions">
|
|
153
|
+
Questions
|
|
154
|
+
</button>
|
|
155
|
+
<button type="button" class="qa-tab" role="tab" id="implement-tab-activity" aria-selected="false" aria-controls="implement-activity">
|
|
156
|
+
Activity
|
|
157
|
+
</button>
|
|
158
|
+
</div>
|
|
159
|
+
<p class="nav-label" id="implement-activity-label">Activity</p>
|
|
160
|
+
<div class="question-panel hidden" id="implement-questions" hidden></div>
|
|
161
|
+
<ol id="implement-activity" class="list-rows activity-log activity-log-main"></ol>
|
|
138
162
|
</section>
|
|
139
163
|
|
|
140
164
|
<section class="panel stage-view hidden" id="view-qa" data-view="qa" hidden>
|
|
@@ -145,16 +169,34 @@
|
|
|
145
169
|
<button type="button" class="pill-btn cta" id="action-fix-proof" hidden disabled></button>
|
|
146
170
|
</div>
|
|
147
171
|
</div>
|
|
148
|
-
<
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
172
|
+
<div class="qa-tab-bar hidden" id="qa-tabs" role="tablist" hidden>
|
|
173
|
+
<button type="button" class="qa-tab is-active" role="tab" id="qa-tab-activity" aria-selected="true" aria-controls="qa-activity-panel">
|
|
174
|
+
Activity
|
|
175
|
+
</button>
|
|
176
|
+
<button type="button" class="qa-tab" role="tab" id="qa-tab-report" aria-selected="false" aria-controls="qa-report-panel">
|
|
177
|
+
Report
|
|
178
|
+
</button>
|
|
179
|
+
</div>
|
|
180
|
+
<p class="nav-label" id="qa-activity-label">Activity</p>
|
|
181
|
+
<div id="qa-activity-panel">
|
|
182
|
+
<ol id="qa-activity" class="list-rows activity-log activity-log-main"></ol>
|
|
183
|
+
</div>
|
|
184
|
+
<div id="qa-report-panel" class="hidden" hidden>
|
|
185
|
+
<div id="proof-report" class="proof-report md-preview"></div>
|
|
186
|
+
</div>
|
|
152
187
|
</section>
|
|
153
188
|
</div>
|
|
154
189
|
</div>
|
|
155
190
|
</div>
|
|
156
191
|
</div>
|
|
157
192
|
</div>
|
|
193
|
+
<dialog id="discard-questions-dialog" class="confirm-dialog">
|
|
194
|
+
<p>Stop and discard unanswered questions?</p>
|
|
195
|
+
<div class="dialog-actions">
|
|
196
|
+
<button type="button" class="btn-secondary" id="discard-questions-cancel">Cancel</button>
|
|
197
|
+
<button type="button" class="btn-primary cta-danger" id="discard-questions-confirm">Stop</button>
|
|
198
|
+
</div>
|
|
199
|
+
</dialog>
|
|
158
200
|
<dialog id="ignore-build-dialog" class="confirm-dialog">
|
|
159
201
|
<p>Was implementation successful?</p>
|
|
160
202
|
<div class="dialog-actions">
|
package/cockpit/styles.css
CHANGED
|
@@ -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:
|
|
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:
|
|
804
|
-
text-align: right;
|
|
831
|
+
max-width: 32rem;
|
|
805
832
|
}
|
|
806
833
|
|
|
807
834
|
.btn-primary,
|
|
@@ -1165,6 +1192,80 @@ body {
|
|
|
1165
1192
|
list-style: none;
|
|
1166
1193
|
}
|
|
1167
1194
|
|
|
1195
|
+
.activity-log-main {
|
|
1196
|
+
max-height: min(32rem, 60vh);
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
.qa-tab-bar {
|
|
1200
|
+
display: flex;
|
|
1201
|
+
gap: 2px;
|
|
1202
|
+
margin: 0 0 var(--space-3);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
.qa-tab {
|
|
1206
|
+
appearance: none;
|
|
1207
|
+
border: 0;
|
|
1208
|
+
background: transparent;
|
|
1209
|
+
color: var(--text-secondary);
|
|
1210
|
+
font-family: var(--font-ui);
|
|
1211
|
+
font-size: var(--text-13);
|
|
1212
|
+
font-weight: 700;
|
|
1213
|
+
height: 1.75rem;
|
|
1214
|
+
padding: 0 var(--space-3);
|
|
1215
|
+
border-radius: var(--radius-sm);
|
|
1216
|
+
cursor: pointer;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
.qa-tab:hover {
|
|
1220
|
+
background: var(--surface-hover);
|
|
1221
|
+
color: var(--text-primary);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
.qa-tab.is-active {
|
|
1225
|
+
background: var(--surface-selected);
|
|
1226
|
+
color: var(--color-primary);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
.question-panel {
|
|
1230
|
+
display: flex;
|
|
1231
|
+
flex-direction: column;
|
|
1232
|
+
gap: var(--space-3);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
.question-card {
|
|
1236
|
+
display: flex;
|
|
1237
|
+
flex-direction: column;
|
|
1238
|
+
gap: var(--space-3);
|
|
1239
|
+
padding: var(--space-4);
|
|
1240
|
+
border: 1px solid var(--border-subtle);
|
|
1241
|
+
border-radius: var(--radius-md);
|
|
1242
|
+
background: var(--surface-2);
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
.question-card-prompt {
|
|
1246
|
+
margin: 0;
|
|
1247
|
+
color: var(--text-primary);
|
|
1248
|
+
font-size: var(--text-14);
|
|
1249
|
+
font-weight: 650;
|
|
1250
|
+
line-height: 1.4;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
.question-card-meta {
|
|
1254
|
+
margin: 0;
|
|
1255
|
+
color: var(--text-muted);
|
|
1256
|
+
font-size: var(--text-12);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
.question-choices {
|
|
1260
|
+
display: flex;
|
|
1261
|
+
flex-direction: column;
|
|
1262
|
+
gap: var(--space-2);
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
.question-choices .stack-choice {
|
|
1266
|
+
padding: var(--space-3);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1168
1269
|
.activity-log .list-row,
|
|
1169
1270
|
#proof-report.list-rows .list-row {
|
|
1170
1271
|
cursor: default;
|
|
@@ -1652,7 +1753,7 @@ body {
|
|
|
1652
1753
|
border-bottom: 1px solid var(--border-subtle);
|
|
1653
1754
|
}
|
|
1654
1755
|
|
|
1655
|
-
.
|
|
1756
|
+
.subbar,
|
|
1656
1757
|
.topbar-start,
|
|
1657
1758
|
.create-bar {
|
|
1658
1759
|
flex-direction: column;
|
|
@@ -0,0 +1,48 @@
|
|
|
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 = "improve" | "implement";
|
|
14
|
+
export type AgentQuestionKind = "text" | "choice";
|
|
15
|
+
export type AgentQuestionOption = {
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
};
|
|
19
|
+
export type AgentQuestionAnswer = {
|
|
20
|
+
text?: string;
|
|
21
|
+
optionId?: string;
|
|
22
|
+
};
|
|
23
|
+
export type AgentQuestion = {
|
|
24
|
+
id: string;
|
|
25
|
+
prompt: string;
|
|
26
|
+
kind: AgentQuestionKind;
|
|
27
|
+
options?: AgentQuestionOption[];
|
|
28
|
+
required: boolean;
|
|
29
|
+
answer?: AgentQuestionAnswer;
|
|
30
|
+
};
|
|
31
|
+
export type AgentQuestionsRound = {
|
|
32
|
+
version: 1;
|
|
33
|
+
channel: AgentQuestionsChannel;
|
|
34
|
+
status: "open" | "answered";
|
|
35
|
+
at: string;
|
|
36
|
+
questions: AgentQuestion[];
|
|
37
|
+
};
|
|
38
|
+
export declare function questionsBriefSection(): string;
|
|
39
|
+
export declare function parseAgentQuestions(raw: unknown): AgentQuestionsRound | null;
|
|
40
|
+
export declare function readAgentQuestions(paths: AgentQuestionsPaths): Promise<AgentQuestionsRound | null>;
|
|
41
|
+
export declare function writeAgentQuestions(paths: AgentQuestionsPaths, round: AgentQuestionsRound): Promise<void>;
|
|
42
|
+
export declare function clearAgentQuestions(paths: AgentQuestionsPaths): Promise<void>;
|
|
43
|
+
export declare function isOpenQuestions(round: AgentQuestionsRound | null | undefined): round is AgentQuestionsRound;
|
|
44
|
+
export declare function requiredUnanswered(round: AgentQuestionsRound): AgentQuestion[];
|
|
45
|
+
export declare function applyAnswers(round: AgentQuestionsRound, answers: Record<string, string>): AgentQuestionsRound;
|
|
46
|
+
export declare function formatOwnerAnswers(round: AgentQuestionsRound): string;
|
|
47
|
+
export declare function withOwnerAnswers(prompt: string, round: AgentQuestionsRound | null): string;
|
|
48
|
+
export declare function applyAgentQuestionsGate(health: Health, round: AgentQuestionsRound | null): Health;
|
|
@@ -0,0 +1,278 @@
|
|
|
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 function questionsBriefSection() {
|
|
13
|
+
return [
|
|
14
|
+
"## If you must ask",
|
|
15
|
+
"",
|
|
16
|
+
"Do not guess a required decision (trade-off, missing intent, real test user vs fixture). Do not invent BR- or UC- IDs.",
|
|
17
|
+
`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.`,
|
|
18
|
+
"The owner answers in the cockpit. The next launch includes those answers. Then continue.",
|
|
19
|
+
"Do not put secrets in this file.",
|
|
20
|
+
"",
|
|
21
|
+
"~~~~json",
|
|
22
|
+
JSON.stringify({
|
|
23
|
+
version: 1,
|
|
24
|
+
channel: "implement",
|
|
25
|
+
status: "open",
|
|
26
|
+
at: "2026-01-01T00:00:00.000Z",
|
|
27
|
+
questions: [
|
|
28
|
+
{
|
|
29
|
+
id: "q1",
|
|
30
|
+
prompt: "Which option should we take?",
|
|
31
|
+
kind: "choice",
|
|
32
|
+
options: [
|
|
33
|
+
{ id: "a", label: "Option A" },
|
|
34
|
+
{ id: "b", label: "Option B" },
|
|
35
|
+
],
|
|
36
|
+
required: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "q2",
|
|
40
|
+
prompt: "Any extra note for the owner?",
|
|
41
|
+
kind: "text",
|
|
42
|
+
required: false,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
}, null, 2),
|
|
46
|
+
"~~~~",
|
|
47
|
+
"",
|
|
48
|
+
"Set `channel` to `improve` when patching the requirement pack, or `implement` when writing product code.",
|
|
49
|
+
"",
|
|
50
|
+
].join("\n");
|
|
51
|
+
}
|
|
52
|
+
export function parseAgentQuestions(raw) {
|
|
53
|
+
if (!raw || typeof raw !== "object")
|
|
54
|
+
return null;
|
|
55
|
+
const body = raw;
|
|
56
|
+
if (body.version !== 1)
|
|
57
|
+
return null;
|
|
58
|
+
if (body.channel !== "improve" && body.channel !== "implement")
|
|
59
|
+
return null;
|
|
60
|
+
if (body.status !== "open" && body.status !== "answered")
|
|
61
|
+
return null;
|
|
62
|
+
if (typeof body.at !== "string" || !body.at.trim())
|
|
63
|
+
return null;
|
|
64
|
+
if (!Array.isArray(body.questions) || body.questions.length === 0)
|
|
65
|
+
return null;
|
|
66
|
+
const questions = [];
|
|
67
|
+
for (const item of body.questions) {
|
|
68
|
+
const parsed = parseQuestion(item);
|
|
69
|
+
if (!parsed)
|
|
70
|
+
return null;
|
|
71
|
+
questions.push(parsed);
|
|
72
|
+
}
|
|
73
|
+
const ids = new Set(questions.map((question) => question.id));
|
|
74
|
+
if (ids.size !== questions.length)
|
|
75
|
+
return null;
|
|
76
|
+
return {
|
|
77
|
+
version: 1,
|
|
78
|
+
channel: body.channel,
|
|
79
|
+
status: body.status,
|
|
80
|
+
at: body.at,
|
|
81
|
+
questions,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export async function readAgentQuestions(paths) {
|
|
85
|
+
try {
|
|
86
|
+
return parseAgentQuestions(JSON.parse(await readFile(paths.agentQuestions, "utf8")));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export async function writeAgentQuestions(paths, round) {
|
|
93
|
+
await mkdir(paths.derived, { recursive: true });
|
|
94
|
+
await writeFile(paths.agentQuestions, `${JSON.stringify(round, null, 2)}\n`, "utf8");
|
|
95
|
+
}
|
|
96
|
+
export async function clearAgentQuestions(paths) {
|
|
97
|
+
await unlink(paths.agentQuestions).catch(() => undefined);
|
|
98
|
+
}
|
|
99
|
+
export function isOpenQuestions(round) {
|
|
100
|
+
return Boolean(round && round.status === "open" && round.questions.length > 0);
|
|
101
|
+
}
|
|
102
|
+
export function requiredUnanswered(round) {
|
|
103
|
+
return round.questions.filter((question) => question.required && !hasAnswer(question));
|
|
104
|
+
}
|
|
105
|
+
export function applyAnswers(round, answers) {
|
|
106
|
+
if (!isOpenQuestions(round)) {
|
|
107
|
+
throw new AgentAnswersError("No open questions to answer.");
|
|
108
|
+
}
|
|
109
|
+
const next = round.questions.map((question) => {
|
|
110
|
+
const raw = answers[question.id];
|
|
111
|
+
const value = typeof raw === "string" ? raw.trim() : "";
|
|
112
|
+
if (!value) {
|
|
113
|
+
if (question.required) {
|
|
114
|
+
throw new AgentAnswersError(`Answer is required: ${question.id}.`);
|
|
115
|
+
}
|
|
116
|
+
return { ...question, answer: undefined };
|
|
117
|
+
}
|
|
118
|
+
if (question.kind === "choice") {
|
|
119
|
+
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 } };
|
|
124
|
+
}
|
|
125
|
+
return { ...question, answer: { text: value } };
|
|
126
|
+
});
|
|
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
|
+
return {
|
|
132
|
+
...round,
|
|
133
|
+
status: "answered",
|
|
134
|
+
at: new Date().toISOString(),
|
|
135
|
+
questions: next,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
export function formatOwnerAnswers(round) {
|
|
139
|
+
const lines = ["Owner answers:", ""];
|
|
140
|
+
for (const question of round.questions) {
|
|
141
|
+
const answer = answerLabel(question);
|
|
142
|
+
if (!answer)
|
|
143
|
+
continue;
|
|
144
|
+
lines.push(`- ${question.id}: ${question.prompt}`);
|
|
145
|
+
lines.push(` Answer: ${answer}`);
|
|
146
|
+
}
|
|
147
|
+
if (lines.length === 2)
|
|
148
|
+
return "";
|
|
149
|
+
lines.push("");
|
|
150
|
+
lines.push("Use these answers. Do not ask the same questions again unless a new required decision appears.");
|
|
151
|
+
return lines.join("\n");
|
|
152
|
+
}
|
|
153
|
+
export function withOwnerAnswers(prompt, round) {
|
|
154
|
+
if (!round || round.status !== "answered")
|
|
155
|
+
return prompt;
|
|
156
|
+
const block = formatOwnerAnswers(round);
|
|
157
|
+
if (!block)
|
|
158
|
+
return prompt;
|
|
159
|
+
return `${prompt}\n\n${block}`;
|
|
160
|
+
}
|
|
161
|
+
export function applyAgentQuestionsGate(health, round) {
|
|
162
|
+
if (!isOpenQuestions(round) || !health.stages)
|
|
163
|
+
return health;
|
|
164
|
+
const improve = round.channel === "improve";
|
|
165
|
+
return {
|
|
166
|
+
...health,
|
|
167
|
+
howThisIsGoing: "The agent has questions.",
|
|
168
|
+
nextAction: {
|
|
169
|
+
id: "answer-questions",
|
|
170
|
+
label: "Continue",
|
|
171
|
+
enabled: true,
|
|
172
|
+
hint: "Answer each required question, then Continue.",
|
|
173
|
+
},
|
|
174
|
+
stages: gateStages(health.stages, improve),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function gateStages(stages, improve) {
|
|
178
|
+
return {
|
|
179
|
+
ready: {
|
|
180
|
+
...stages.ready,
|
|
181
|
+
enabled: false,
|
|
182
|
+
hint: improve ? "Answer the agent's questions on Define." : stages.ready.hint,
|
|
183
|
+
},
|
|
184
|
+
build: improve
|
|
185
|
+
? { ...stages.build, enabled: false }
|
|
186
|
+
: {
|
|
187
|
+
id: "answer-questions",
|
|
188
|
+
label: "Continue",
|
|
189
|
+
enabled: false,
|
|
190
|
+
hidden: true,
|
|
191
|
+
hint: "Answer the agent's questions.",
|
|
192
|
+
},
|
|
193
|
+
proof: { ...stages.proof, enabled: false },
|
|
194
|
+
...(stages.fixFromProof ? { fixFromProof: { ...stages.fixFromProof, enabled: false } } : {}),
|
|
195
|
+
...(stages.ignoreBuild ? { ignoreBuild: { ...stages.ignoreBuild, enabled: false } } : {}),
|
|
196
|
+
...(stages.stopImplement
|
|
197
|
+
? {
|
|
198
|
+
stopImplement: improve
|
|
199
|
+
? { ...stages.stopImplement, enabled: false }
|
|
200
|
+
: {
|
|
201
|
+
id: "stop-implement",
|
|
202
|
+
label: "Stop",
|
|
203
|
+
enabled: true,
|
|
204
|
+
hint: "Discard unanswered questions. Build stays failed until you Reimplement or Ignore.",
|
|
205
|
+
},
|
|
206
|
+
}
|
|
207
|
+
: !improve
|
|
208
|
+
? {
|
|
209
|
+
stopImplement: {
|
|
210
|
+
id: "stop-implement",
|
|
211
|
+
label: "Stop",
|
|
212
|
+
enabled: true,
|
|
213
|
+
hint: "Discard unanswered questions. Build stays failed until you Reimplement or Ignore.",
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
: {}),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function parseQuestion(raw) {
|
|
220
|
+
if (!raw || typeof raw !== "object")
|
|
221
|
+
return null;
|
|
222
|
+
const body = raw;
|
|
223
|
+
if (typeof body.id !== "string" || !body.id.trim())
|
|
224
|
+
return null;
|
|
225
|
+
if (typeof body.prompt !== "string" || !body.prompt.trim())
|
|
226
|
+
return null;
|
|
227
|
+
if (body.kind !== "text" && body.kind !== "choice")
|
|
228
|
+
return null;
|
|
229
|
+
const required = body.required === false ? false : true;
|
|
230
|
+
let options;
|
|
231
|
+
if (body.kind === "choice") {
|
|
232
|
+
if (!Array.isArray(body.options) || body.options.length < 2)
|
|
233
|
+
return null;
|
|
234
|
+
options = [];
|
|
235
|
+
const ids = new Set();
|
|
236
|
+
for (const item of body.options) {
|
|
237
|
+
if (!item || typeof item !== "object")
|
|
238
|
+
return null;
|
|
239
|
+
const option = item;
|
|
240
|
+
if (typeof option.id !== "string" || !option.id.trim())
|
|
241
|
+
return null;
|
|
242
|
+
if (typeof option.label !== "string" || !option.label.trim())
|
|
243
|
+
return null;
|
|
244
|
+
if (ids.has(option.id))
|
|
245
|
+
return null;
|
|
246
|
+
ids.add(option.id);
|
|
247
|
+
options.push({ id: option.id, label: option.label });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
let answer;
|
|
251
|
+
if (body.answer && typeof body.answer === "object") {
|
|
252
|
+
const value = body.answer;
|
|
253
|
+
if (typeof value.text === "string" && value.text.trim())
|
|
254
|
+
answer = { text: value.text.trim() };
|
|
255
|
+
if (typeof value.optionId === "string" && value.optionId.trim()) {
|
|
256
|
+
answer = { ...answer, optionId: value.optionId.trim() };
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
id: body.id.trim(),
|
|
261
|
+
prompt: body.prompt.trim(),
|
|
262
|
+
kind: body.kind,
|
|
263
|
+
...(options ? { options } : {}),
|
|
264
|
+
required,
|
|
265
|
+
...(answer ? { answer } : {}),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function hasAnswer(question) {
|
|
269
|
+
return Boolean(question.answer?.text?.trim() || question.answer?.optionId?.trim());
|
|
270
|
+
}
|
|
271
|
+
function answerLabel(question) {
|
|
272
|
+
if (question.kind === "choice") {
|
|
273
|
+
const id = question.answer?.optionId;
|
|
274
|
+
const option = question.options?.find((item) => item.id === id);
|
|
275
|
+
return option?.label ?? id ?? "";
|
|
276
|
+
}
|
|
277
|
+
return question.answer?.text?.trim() ?? "";
|
|
278
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import { isRequirementId } from "./compile.js";
|
|
|
10
10
|
import { adapterInstructions, ImplementDisabledError, ImplementLockedError } from "./implement.js";
|
|
11
11
|
import { FixFromProofLockedError } from "./fix-from-proof.js";
|
|
12
12
|
import { StackRequiredError, UnknownStackError } from "./stack.js";
|
|
13
|
-
import { checkPack, compilePack, createPack, findRequirementsDir, finishImplement, implementPack, provePack, resolveCockpitPack, resolvePack } from "./pack.js";
|
|
13
|
+
import { checkPack, compilePack, createPack, findRequirementsDir, finishImplement, implementPack, provePack, resolveCockpitPack, resolvePack, shouldRefreshForWatch } from "./pack.js";
|
|
14
14
|
import { ProveLockedError } from "./proof.js";
|
|
15
15
|
import { createAppState, createCockpitServer, refresh } from "./server.js";
|
|
16
16
|
loadProjectEnv();
|
|
@@ -207,7 +207,11 @@ async function startCockpit(cwd) {
|
|
|
207
207
|
};
|
|
208
208
|
for (const watchPath of watchTargets) {
|
|
209
209
|
try {
|
|
210
|
-
const watcher = watch(watchPath, { recursive: Boolean(requirementsDir) }, () =>
|
|
210
|
+
const watcher = watch(watchPath, { recursive: Boolean(requirementsDir) }, (_event, filename) => {
|
|
211
|
+
if (!shouldRefreshForWatch(watchPath, filename))
|
|
212
|
+
return;
|
|
213
|
+
schedule();
|
|
214
|
+
});
|
|
211
215
|
watcher.on("error", (err) => {
|
|
212
216
|
console.error(`File watch unavailable (${err.message}). Save from the cockpit still compiles.`);
|
|
213
217
|
});
|
package/dist/fix-from-proof.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { questionsBriefSection } from "./agent-questions.js";
|
|
1
2
|
export class FixFromProofLockedError extends Error {
|
|
2
3
|
code = "fix_from_proof_gate";
|
|
3
4
|
constructor(message = "Fix from proof is only after Ready, a succeeded Build, and a Proof that failed or needs review.") {
|
|
@@ -56,6 +57,7 @@ export function emitFixFromProofBrief(input) {
|
|
|
56
57
|
}
|
|
57
58
|
lines.push("");
|
|
58
59
|
}
|
|
60
|
+
lines.push(questionsBriefSection().trimEnd(), "");
|
|
59
61
|
lines.push("## Done means", "", "The existing app matches the named cases in the proof report. Personas and `fixtures/runtime.yaml` still match that app. At most 3 `npx ampx sandbox --once` deploys. After the third, stop and report what is still failing. A coding-agent run finishing is **Build Succeeded**, not “the app boots.” Re-prove is next.", "");
|
|
60
62
|
return `${lines.join("\n")}\n`;
|
|
61
63
|
}
|
package/dist/implement-brief.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { questionsBriefSection } from "./agent-questions.js";
|
|
1
2
|
import { DEFAULT_STACK, isAmplifyStack, stackInstruction } from "./stack.js";
|
|
2
3
|
export function emitImplementBrief(input) {
|
|
3
4
|
const { spec, repo, adapter, personas } = input;
|
|
@@ -61,7 +62,7 @@ export function emitImplementBrief(input) {
|
|
|
61
62
|
lines.push("## Open questions", "", spec.optional["Open questions"].trim(), "");
|
|
62
63
|
}
|
|
63
64
|
lines.push("## Product README", "", "Write `README.md` at the product repo root so a stranger can run the app. If a README already exists, update the setup section. Use this requirement's title and the pack paths below. Do not invent a product name.", "", "~~~~markdown", productReadmeTemplate(spec, repo.stack), "~~~~", "");
|
|
64
|
-
lines.push("## Pack files", "", "- Seed the app from existing `fixtures/personas.yaml`. Do not add roles. Do not invent emails.", "- `fixtures/runtime.yaml` may be a stub. Set `baseUrl`, `startCommand`, and `resetCommand` to the app you started. Keep login selectors unless you change `/login` to match — then change both.", "- Write or update the product-repo `.env.example` with variable names only. No real keys.", "- Write `README.md` at the product repo root using the Product README section. Use this requirement's title and pack paths. Do not invent a product name.", "- The seed/reset script command must match `runtime.yaml` `resetCommand`.", "- First-party `/login` must match those selectors.", "", "## Security baseline", "", "- No production credentials in the spec or this brief.", "- Secrets via environment variables.", "- Personas are test-only.", "", "## Done means", "", isAmplifyStack(repo.stack)
|
|
65
|
+
lines.push("## Pack files", "", "- Seed the app from existing `fixtures/personas.yaml`. Do not add roles. Do not invent emails.", "- `fixtures/runtime.yaml` may be a stub. Set `baseUrl`, `startCommand`, and `resetCommand` to the app you started. Keep login selectors unless you change `/login` to match — then change both.", "- Write or update the product-repo `.env.example` with variable names only. No real keys.", "- Write `README.md` at the product repo root using the Product README section. Use this requirement's title and pack paths. Do not invent a product name.", "- The seed/reset script command must match `runtime.yaml` `resetCommand`.", "- First-party `/login` must match those selectors.", "", questionsBriefSection().trimEnd(), "", "## Security baseline", "", "- No production credentials in the spec or this brief.", "- Secrets via environment variables.", "- Personas are test-only.", "", "## Done means", "", isAmplifyStack(repo.stack)
|
|
65
66
|
? "The app exists in the recorded stack. AWS identity was available (profile or inherited keys). `npx ampx sandbox --once` has been run. `amplify_outputs.json` has real Cognito ids, not `REPLACE_VIA_SANDBOX`. Personas are seeded in Cognito. `fixtures/runtime.yaml` matches that app. Product `.env.example` has names only. Product `README.md` has setup for this stack."
|
|
66
67
|
: "The app exists in the recorded stack. Personas are seeded. `fixtures/runtime.yaml` matches that app. Product `.env.example` has names only. Product `README.md` has setup for this stack.", "A coding-agent run finishing is **Build Succeeded**, not “the app boots.” Boot and login are Proof (Milestone 4).", "");
|
|
67
68
|
return `${lines.join("\n")}\n`;
|
package/dist/implement.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare const IMPLEMENT_MAX_MS: number;
|
|
|
8
8
|
export declare const IMPLEMENT_STOPPED = "Owner stopped Implement.";
|
|
9
9
|
export declare const IMPLEMENT_SANDBOX_CAP = "Stopped after 3 sandbox deploys. Reimplement or Ignore, then Prove.";
|
|
10
10
|
export declare const IMPLEMENT_TIME_CAP = "Stopped after 20 minutes. Reimplement or Ignore, then Prove.";
|
|
11
|
+
/** Cursor `--print` can emit `result` and then hang. Kill the leftover process after this grace. */
|
|
12
|
+
export declare const IMPLEMENT_EXIT_GRACE_MS = 3000;
|
|
11
13
|
export type ImplementStop = {
|
|
12
14
|
reason?: string;
|
|
13
15
|
};
|
|
@@ -35,6 +37,8 @@ export type LaunchAdapterDeps = {
|
|
|
35
37
|
maxMs?: number;
|
|
36
38
|
heartbeatLabel?: string;
|
|
37
39
|
cliName?: string;
|
|
40
|
+
/** After a stream `result` event, kill a hung CLI if it has not exited. Default 3s. */
|
|
41
|
+
exitGraceMs?: number;
|
|
38
42
|
};
|
|
39
43
|
export type LaunchAdapterResult = {
|
|
40
44
|
ok: boolean;
|
|
@@ -61,10 +65,12 @@ export declare function attachAgentLog(child: ChildProcess, logPath: string, onL
|
|
|
61
65
|
sandboxMax?: number;
|
|
62
66
|
maxMs?: number;
|
|
63
67
|
heartbeatLabel?: string;
|
|
68
|
+
exitGraceMs?: number;
|
|
64
69
|
}): Promise<{
|
|
65
70
|
code: number | null;
|
|
66
71
|
}>;
|
|
67
72
|
export declare function requestImplementStop(child: ChildProcess | undefined, stop: ImplementStop, reason: string): void;
|
|
68
73
|
export declare function killImplementTree(child?: ChildProcess): void;
|
|
69
74
|
export declare function isSandboxOnceStart(line: string): boolean;
|
|
75
|
+
export declare function agentStreamOutcome(line: string): "success" | "error" | null;
|
|
70
76
|
export declare function summarizeAgentLine(line: string): string | null;
|