@nathapp/nax 0.43.1 → 0.45.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/bin/nax.ts +22 -0
- package/dist/nax.js +320 -88
- package/package.json +1 -1
- package/src/agents/acp/adapter.ts +98 -5
- package/src/agents/claude-decompose.ts +6 -21
- package/src/agents/types-extended.ts +1 -1
- package/src/cli/plan.ts +4 -11
- package/src/cli/status-features.ts +19 -0
- package/src/config/test-strategy.ts +70 -0
- package/src/execution/lifecycle/acceptance-loop.ts +2 -0
- package/src/execution/lifecycle/run-setup.ts +4 -0
- package/src/execution/parallel-coordinator.ts +3 -1
- package/src/execution/parallel-executor.ts +3 -0
- package/src/execution/runner-execution.ts +16 -2
- package/src/execution/runner.ts +4 -0
- package/src/execution/story-context.ts +6 -0
- package/src/prd/schema.ts +4 -14
- package/src/precheck/index.ts +155 -44
- package/src/verification/rectification-loop.ts +18 -5
package/src/precheck/index.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
* Runs all prechecks with formatted output. Stops on first Tier 1 blocker (fail-fast).
|
|
5
5
|
* Collects all Tier 2 warnings. Formats human-readable output with emoji indicators.
|
|
6
6
|
* Supports --json flag for machine-readable output.
|
|
7
|
+
*
|
|
8
|
+
* Check categories:
|
|
9
|
+
* - **Environment checks** — no PRD needed (git, deps, agent CLI, stale lock)
|
|
10
|
+
* - **Project checks** — require PRD (validation, story counts, story size gate)
|
|
7
11
|
*/
|
|
8
12
|
|
|
9
13
|
import type { NaxConfig } from "../config";
|
|
@@ -80,8 +84,136 @@ export interface PrecheckResultWithCode {
|
|
|
80
84
|
flaggedStories?: import("./story-size-gate").FlaggedStory[];
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
88
|
+
// Check list definitions — shared between runEnvironmentPrecheck and runPrecheck
|
|
89
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
type CheckFn = () => Promise<Check | Check[]>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Early environment checks — git repo, clean tree, stale lock.
|
|
95
|
+
* Fast checks that run first in both runEnvironmentPrecheck and runPrecheck.
|
|
96
|
+
* In runPrecheck, PRD validation is inserted after these (original order preserved).
|
|
97
|
+
*/
|
|
98
|
+
function getEarlyEnvironmentBlockers(workdir: string): CheckFn[] {
|
|
99
|
+
return [() => checkGitRepoExists(workdir), () => checkWorkingTreeClean(workdir), () => checkStaleLock(workdir)];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Late environment checks — agent CLI, deps, commands, git user.
|
|
104
|
+
* Run after PRD validation in runPrecheck; all included in runEnvironmentPrecheck.
|
|
105
|
+
*/
|
|
106
|
+
function getLateEnvironmentBlockers(config: NaxConfig, workdir: string): CheckFn[] {
|
|
107
|
+
return [
|
|
108
|
+
() => checkAgentCLI(config),
|
|
109
|
+
() => checkDependenciesInstalled(workdir),
|
|
110
|
+
() => checkTestCommand(config),
|
|
111
|
+
() => checkLintCommand(config),
|
|
112
|
+
() => checkTypecheckCommand(config),
|
|
113
|
+
() => checkGitUserConfigured(workdir),
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** All environment checks — no PRD needed. Used by runEnvironmentPrecheck. */
|
|
118
|
+
function getEnvironmentBlockers(config: NaxConfig, workdir: string): CheckFn[] {
|
|
119
|
+
return [...getEarlyEnvironmentBlockers(workdir), ...getLateEnvironmentBlockers(config, workdir)];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Environment warnings — no PRD needed. */
|
|
123
|
+
function getEnvironmentWarnings(config: NaxConfig, workdir: string): CheckFn[] {
|
|
124
|
+
return [
|
|
125
|
+
() => checkClaudeMdExists(workdir),
|
|
126
|
+
() => checkDiskSpace(),
|
|
127
|
+
() => checkOptionalCommands(config, workdir),
|
|
128
|
+
() => checkGitignoreCoversNax(workdir),
|
|
129
|
+
() => checkPromptOverrideFiles(config, workdir),
|
|
130
|
+
() => checkMultiAgentHealth(),
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Project checks — require PRD. */
|
|
135
|
+
function getProjectBlockers(prd: PRD): CheckFn[] {
|
|
136
|
+
return [() => checkPRDValid(prd)];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Project warnings — require PRD. */
|
|
140
|
+
function getProjectWarnings(prd: PRD): CheckFn[] {
|
|
141
|
+
return [() => checkPendingStories(prd)];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Normalize check result to array (some checks return Check[]) */
|
|
145
|
+
function normalizeChecks(result: Check | Check[]): Check[] {
|
|
146
|
+
return Array.isArray(result) ? result : [result];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Result from environment-only precheck */
|
|
150
|
+
export interface EnvironmentPrecheckResult {
|
|
151
|
+
/** Whether all environment checks passed (no blockers) */
|
|
152
|
+
passed: boolean;
|
|
153
|
+
/** Blocker check results */
|
|
154
|
+
blockers: Check[];
|
|
155
|
+
/** Warning check results */
|
|
156
|
+
warnings: Check[];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Run environment-only prechecks (no PRD needed).
|
|
161
|
+
*
|
|
162
|
+
* Use before plan phase to catch environment issues early,
|
|
163
|
+
* before expensive LLM calls are made.
|
|
164
|
+
*/
|
|
165
|
+
export async function runEnvironmentPrecheck(
|
|
166
|
+
config: NaxConfig,
|
|
167
|
+
workdir: string,
|
|
168
|
+
options?: { format?: "human" | "json"; silent?: boolean },
|
|
169
|
+
): Promise<EnvironmentPrecheckResult> {
|
|
170
|
+
const format = options?.format ?? "human";
|
|
171
|
+
const silent = options?.silent ?? false;
|
|
172
|
+
|
|
173
|
+
const passed: Check[] = [];
|
|
174
|
+
const blockers: Check[] = [];
|
|
175
|
+
const warnings: Check[] = [];
|
|
176
|
+
|
|
177
|
+
// Environment blockers — fail-fast
|
|
178
|
+
for (const checkFn of getEnvironmentBlockers(config, workdir)) {
|
|
179
|
+
const checks = normalizeChecks(await checkFn());
|
|
180
|
+
let blocked = false;
|
|
181
|
+
for (const check of checks) {
|
|
182
|
+
if (!silent && format === "human") printCheckResult(check);
|
|
183
|
+
if (check.passed) {
|
|
184
|
+
passed.push(check);
|
|
185
|
+
} else {
|
|
186
|
+
blockers.push(check);
|
|
187
|
+
blocked = true;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (blocked) break;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Environment warnings — only if no blockers
|
|
195
|
+
if (blockers.length === 0) {
|
|
196
|
+
for (const checkFn of getEnvironmentWarnings(config, workdir)) {
|
|
197
|
+
for (const check of normalizeChecks(await checkFn())) {
|
|
198
|
+
if (!silent && format === "human") printCheckResult(check);
|
|
199
|
+
if (check.passed) {
|
|
200
|
+
passed.push(check);
|
|
201
|
+
} else {
|
|
202
|
+
warnings.push(check);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (!silent && format === "json") {
|
|
209
|
+
console.log(JSON.stringify({ passed: blockers.length === 0, blockers, warnings }, null, 2));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return { passed: blockers.length === 0, blockers, warnings };
|
|
213
|
+
}
|
|
214
|
+
|
|
83
215
|
/**
|
|
84
|
-
* Run all precheck validations.
|
|
216
|
+
* Run all precheck validations (environment + project).
|
|
85
217
|
* Returns result, exit code, and formatted output.
|
|
86
218
|
*/
|
|
87
219
|
export async function runPrecheck(
|
|
@@ -98,67 +230,46 @@ export async function runPrecheck(
|
|
|
98
230
|
const warnings: Check[] = [];
|
|
99
231
|
|
|
100
232
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
101
|
-
// Tier 1 Blockers
|
|
233
|
+
// Tier 1 Blockers — environment + project, fail-fast on first failure
|
|
102
234
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
103
235
|
|
|
236
|
+
// Original order preserved: early env → PRD valid → late env
|
|
237
|
+
// checkPRDValid at position 4 ensures test environments that lack agent CLI
|
|
238
|
+
// still get EXIT_CODES.INVALID_PRD (2) rather than a generic blocker (1)
|
|
104
239
|
const tier1Checks = [
|
|
105
|
-
(
|
|
106
|
-
()
|
|
107
|
-
(
|
|
108
|
-
() => checkPRDValid(prd),
|
|
109
|
-
() => checkAgentCLI(config),
|
|
110
|
-
() => checkDependenciesInstalled(workdir),
|
|
111
|
-
() => checkTestCommand(config),
|
|
112
|
-
() => checkLintCommand(config),
|
|
113
|
-
() => checkTypecheckCommand(config),
|
|
114
|
-
() => checkGitUserConfigured(workdir),
|
|
240
|
+
...getEarlyEnvironmentBlockers(workdir),
|
|
241
|
+
...getProjectBlockers(prd),
|
|
242
|
+
...getLateEnvironmentBlockers(config, workdir),
|
|
115
243
|
];
|
|
116
244
|
|
|
245
|
+
let tier1Blocked = false;
|
|
117
246
|
for (const checkFn of tier1Checks) {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
blockers.push(result);
|
|
128
|
-
// Fail-fast: stop on first blocker
|
|
129
|
-
break;
|
|
247
|
+
for (const check of normalizeChecks(await checkFn())) {
|
|
248
|
+
if (format === "human") printCheckResult(check);
|
|
249
|
+
if (check.passed) {
|
|
250
|
+
passed.push(check);
|
|
251
|
+
} else {
|
|
252
|
+
blockers.push(check);
|
|
253
|
+
tier1Blocked = true;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
130
256
|
}
|
|
257
|
+
if (tier1Blocked) break;
|
|
131
258
|
}
|
|
132
259
|
|
|
133
260
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
134
|
-
// Tier 2 Warnings
|
|
261
|
+
// Tier 2 Warnings — environment + project, run all regardless of failures
|
|
135
262
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
136
263
|
|
|
137
264
|
let flaggedStories: import("./story-size-gate").FlaggedStory[] = [];
|
|
138
265
|
|
|
139
266
|
// Only run Tier 2 if no blockers
|
|
140
267
|
if (blockers.length === 0) {
|
|
141
|
-
const tier2Checks = [
|
|
142
|
-
() => checkClaudeMdExists(workdir),
|
|
143
|
-
() => checkDiskSpace(),
|
|
144
|
-
() => checkPendingStories(prd),
|
|
145
|
-
() => checkOptionalCommands(config, workdir),
|
|
146
|
-
() => checkGitignoreCoversNax(workdir),
|
|
147
|
-
() => checkPromptOverrideFiles(config, workdir),
|
|
148
|
-
() => checkMultiAgentHealth(),
|
|
149
|
-
];
|
|
268
|
+
const tier2Checks = [...getEnvironmentWarnings(config, workdir), ...getProjectWarnings(prd)];
|
|
150
269
|
|
|
151
270
|
for (const checkFn of tier2Checks) {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
// Handle both single checks and arrays of checks
|
|
155
|
-
const checksToProcess = Array.isArray(result) ? result : [result];
|
|
156
|
-
|
|
157
|
-
for (const check of checksToProcess) {
|
|
158
|
-
if (format === "human") {
|
|
159
|
-
printCheckResult(check);
|
|
160
|
-
}
|
|
161
|
-
|
|
271
|
+
for (const check of normalizeChecks(await checkFn())) {
|
|
272
|
+
if (format === "human") printCheckResult(check);
|
|
162
273
|
if (check.passed) {
|
|
163
274
|
passed.push(check);
|
|
164
275
|
} else {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Used by: src/pipeline/stages/rectify.ts, src/execution/lifecycle/run-regression.ts
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { getAgent } from "../agents";
|
|
10
|
+
import { getAgent as _getAgent } from "../agents";
|
|
11
11
|
import type { NaxConfig } from "../config";
|
|
12
12
|
import { resolveModel } from "../config";
|
|
13
13
|
import { resolvePermissions } from "../config/permissions";
|
|
@@ -16,7 +16,7 @@ import { getSafeLogger } from "../logger";
|
|
|
16
16
|
import type { UserStory } from "../prd";
|
|
17
17
|
import { getExpectedFiles } from "../prd";
|
|
18
18
|
import { type RectificationState, createRectificationPrompt, shouldRetryRectification } from "./rectification";
|
|
19
|
-
import { fullSuite as
|
|
19
|
+
import { fullSuite as _fullSuite } from "./runners";
|
|
20
20
|
|
|
21
21
|
export interface RectificationLoopOptions {
|
|
22
22
|
config: NaxConfig;
|
|
@@ -26,11 +26,21 @@ export interface RectificationLoopOptions {
|
|
|
26
26
|
timeoutSeconds: number;
|
|
27
27
|
testOutput: string;
|
|
28
28
|
promptPrefix?: string;
|
|
29
|
+
featureName?: string;
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
33
|
+
// Injectable dependencies
|
|
34
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
export const _rectificationDeps = {
|
|
37
|
+
getAgent: _getAgent as (name: string) => import("../agents/types").AgentAdapter | undefined,
|
|
38
|
+
runVerification: _fullSuite as typeof _fullSuite,
|
|
39
|
+
};
|
|
40
|
+
|
|
31
41
|
/** Run the rectification retry loop. Returns true if all failures were fixed. */
|
|
32
42
|
export async function runRectificationLoop(opts: RectificationLoopOptions): Promise<boolean> {
|
|
33
|
-
const { config, workdir, story, testCommand, timeoutSeconds, testOutput, promptPrefix } = opts;
|
|
43
|
+
const { config, workdir, story, testCommand, timeoutSeconds, testOutput, promptPrefix, featureName } = opts;
|
|
34
44
|
const logger = getSafeLogger();
|
|
35
45
|
const rectificationConfig = config.execution.rectification;
|
|
36
46
|
const testSummary = parseBunTestOutput(testOutput);
|
|
@@ -59,7 +69,7 @@ export async function runRectificationLoop(opts: RectificationLoopOptions): Prom
|
|
|
59
69
|
let rectificationPrompt = createRectificationPrompt(testSummary.failures, story, rectificationConfig);
|
|
60
70
|
if (promptPrefix) rectificationPrompt = `${promptPrefix}\n\n${rectificationPrompt}`;
|
|
61
71
|
|
|
62
|
-
const agent = getAgent(config.autoMode.defaultAgent);
|
|
72
|
+
const agent = _rectificationDeps.getAgent(config.autoMode.defaultAgent);
|
|
63
73
|
if (!agent) {
|
|
64
74
|
logger?.error("rectification", "Agent not found, cannot retry");
|
|
65
75
|
break;
|
|
@@ -78,6 +88,9 @@ export async function runRectificationLoop(opts: RectificationLoopOptions): Prom
|
|
|
78
88
|
pipelineStage: "rectification",
|
|
79
89
|
config,
|
|
80
90
|
maxInteractionTurns: config.agent?.maxInteractionTurns,
|
|
91
|
+
featureName,
|
|
92
|
+
storyId: story.id,
|
|
93
|
+
sessionRole: "implementer",
|
|
81
94
|
});
|
|
82
95
|
|
|
83
96
|
if (agentResult.success) {
|
|
@@ -94,7 +107,7 @@ export async function runRectificationLoop(opts: RectificationLoopOptions): Prom
|
|
|
94
107
|
});
|
|
95
108
|
}
|
|
96
109
|
|
|
97
|
-
const retryVerification = await runVerification({
|
|
110
|
+
const retryVerification = await _rectificationDeps.runVerification({
|
|
98
111
|
workdir,
|
|
99
112
|
expectedFiles: getExpectedFiles(story),
|
|
100
113
|
command: testCommand,
|