@nathapp/nax 0.91.7-canary.7 → 0.91.7-canary.8
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/dist/nax.js +1561 -593
- package/package.json +2 -2
package/dist/nax.js
CHANGED
|
@@ -6273,7 +6273,7 @@ function buildEnv(options) {
|
|
|
6273
6273
|
Object.assign(env, options.env ?? {});
|
|
6274
6274
|
return env;
|
|
6275
6275
|
}
|
|
6276
|
-
async function drainToEof(stream, signal) {
|
|
6276
|
+
async function drainToEof(stream, signal, onChunk) {
|
|
6277
6277
|
const reader = stream.getReader();
|
|
6278
6278
|
const capture = new BoundedCapture(_argvExecDeps.streamCaptureBytes);
|
|
6279
6279
|
const onAbort = () => {
|
|
@@ -6285,8 +6285,12 @@ async function drainToEof(stream, signal) {
|
|
|
6285
6285
|
const { done, value } = await reader.read();
|
|
6286
6286
|
if (done === true)
|
|
6287
6287
|
break;
|
|
6288
|
-
if (value !== undefined)
|
|
6288
|
+
if (value !== undefined) {
|
|
6289
|
+
try {
|
|
6290
|
+
onChunk?.(Uint8Array.from(value));
|
|
6291
|
+
} catch {}
|
|
6289
6292
|
capture.push(value);
|
|
6293
|
+
}
|
|
6290
6294
|
}
|
|
6291
6295
|
} catch {}
|
|
6292
6296
|
if (signal !== undefined)
|
|
@@ -6348,6 +6352,22 @@ class BoundedCapture {
|
|
|
6348
6352
|
return head + marker + new TextDecoder().decode(tail.subarray(start));
|
|
6349
6353
|
}
|
|
6350
6354
|
}
|
|
6355
|
+
function armDeadline(options, onTimeout) {
|
|
6356
|
+
let timerId;
|
|
6357
|
+
const release = () => {
|
|
6358
|
+
if (timerId !== undefined)
|
|
6359
|
+
_argvExecDeps.clearTimeout(timerId);
|
|
6360
|
+
timerId = undefined;
|
|
6361
|
+
};
|
|
6362
|
+
if (options.releaseDeadline?.aborted !== true) {
|
|
6363
|
+
timerId = _argvExecDeps.setTimeout(onTimeout, options.timeoutMs);
|
|
6364
|
+
options.releaseDeadline?.addEventListener("abort", release, { once: true });
|
|
6365
|
+
}
|
|
6366
|
+
return () => {
|
|
6367
|
+
release();
|
|
6368
|
+
options.releaseDeadline?.removeEventListener("abort", release);
|
|
6369
|
+
};
|
|
6370
|
+
}
|
|
6351
6371
|
async function runArgv(options) {
|
|
6352
6372
|
const signal = options.signal;
|
|
6353
6373
|
if (signal?.aborted === true) {
|
|
@@ -6373,57 +6393,60 @@ async function runArgv(options) {
|
|
|
6373
6393
|
stdoutController.abort();
|
|
6374
6394
|
stderrController.abort();
|
|
6375
6395
|
};
|
|
6376
|
-
const
|
|
6396
|
+
const clearDeadline = armDeadline(options, () => {
|
|
6377
6397
|
timedOut = true;
|
|
6378
6398
|
killGroup();
|
|
6379
6399
|
stopReaders();
|
|
6380
|
-
}
|
|
6400
|
+
});
|
|
6381
6401
|
const onAbort = () => {
|
|
6382
6402
|
aborted = true;
|
|
6383
6403
|
killGroup();
|
|
6384
6404
|
stopReaders();
|
|
6385
6405
|
};
|
|
6386
6406
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6407
|
+
try {
|
|
6408
|
+
const stdoutPromise = drainToEof(proc.stdout, stdoutController.signal, options.onOutput?.bind(undefined, "stdout"));
|
|
6409
|
+
const stderrPromise = drainToEof(proc.stderr, stderrController.signal, options.onOutput?.bind(undefined, "stderr"));
|
|
6410
|
+
const exitCode = await proc.exited;
|
|
6411
|
+
const graceMs = _argvExecDeps.drainGraceMs;
|
|
6412
|
+
let graceTimerId;
|
|
6413
|
+
const gracePromise = new Promise((resolve) => {
|
|
6414
|
+
graceTimerId = _argvExecDeps.setTimeout(() => resolve("expired"), graceMs);
|
|
6415
|
+
});
|
|
6416
|
+
const stdoutSettled = await Promise.race([
|
|
6417
|
+
stdoutPromise,
|
|
6418
|
+
gracePromise.then(() => "expired")
|
|
6419
|
+
]);
|
|
6420
|
+
const stderrSettled = await Promise.race([
|
|
6421
|
+
stderrPromise,
|
|
6422
|
+
gracePromise.then(() => "expired")
|
|
6423
|
+
]);
|
|
6424
|
+
if (graceTimerId !== undefined)
|
|
6425
|
+
_argvExecDeps.clearTimeout(graceTimerId);
|
|
6426
|
+
const stdoutClosed = stdoutSettled !== "expired";
|
|
6427
|
+
const stderrClosed = stderrSettled !== "expired";
|
|
6428
|
+
if (!stdoutClosed || !stderrClosed) {
|
|
6429
|
+
orphansKilled = true;
|
|
6430
|
+
killGroup();
|
|
6431
|
+
if (!stdoutClosed)
|
|
6432
|
+
stdoutController.abort();
|
|
6433
|
+
if (!stderrClosed)
|
|
6434
|
+
stderrController.abort();
|
|
6435
|
+
}
|
|
6436
|
+
const stdoutFinal = stdoutClosed ? stdoutSettled : await stdoutPromise;
|
|
6437
|
+
const stderrFinal = stderrClosed ? stderrSettled : await stderrPromise;
|
|
6438
|
+
return {
|
|
6439
|
+
exitCode,
|
|
6440
|
+
stdout: stdoutFinal.text,
|
|
6441
|
+
stderr: stderrFinal.text,
|
|
6442
|
+
timedOut,
|
|
6443
|
+
aborted,
|
|
6444
|
+
orphansKilled
|
|
6445
|
+
};
|
|
6446
|
+
} finally {
|
|
6447
|
+
clearDeadline();
|
|
6448
|
+
signal?.removeEventListener("abort", onAbort);
|
|
6414
6449
|
}
|
|
6415
|
-
const stdoutFinal = stdoutClosed ? stdoutSettled : await stdoutPromise;
|
|
6416
|
-
const stderrFinal = stderrClosed ? stderrSettled : await stderrPromise;
|
|
6417
|
-
_argvExecDeps.clearTimeout(timerId);
|
|
6418
|
-
signal?.removeEventListener("abort", onAbort);
|
|
6419
|
-
return {
|
|
6420
|
-
exitCode,
|
|
6421
|
-
stdout: stdoutFinal.text,
|
|
6422
|
-
stderr: stderrFinal.text,
|
|
6423
|
-
timedOut,
|
|
6424
|
-
aborted,
|
|
6425
|
-
orphansKilled
|
|
6426
|
-
};
|
|
6427
6450
|
}
|
|
6428
6451
|
var DRAIN_GRACE_MS2 = 500, STREAM_CAPTURE_BYTES = 8000000, _argvExecDeps;
|
|
6429
6452
|
var init_argv_exec = __esm(() => {
|
|
@@ -11384,7 +11407,9 @@ async function runUnwrapped(req, sandbox, env) {
|
|
|
11384
11407
|
timeoutMs: req.timeoutMs,
|
|
11385
11408
|
stripEnvVars: [...req.stripEnvVars],
|
|
11386
11409
|
...overlay !== undefined ? { env: overlay } : {},
|
|
11387
|
-
...req.signal !== undefined ? { signal: req.signal } : {}
|
|
11410
|
+
...req.signal !== undefined ? { signal: req.signal } : {},
|
|
11411
|
+
...req.releaseDeadline !== undefined ? { releaseDeadline: req.releaseDeadline } : {},
|
|
11412
|
+
...req.onOutput !== undefined ? { onOutput: req.onOutput } : {}
|
|
11388
11413
|
});
|
|
11389
11414
|
return { ...result, executed: argv, sandbox };
|
|
11390
11415
|
}
|
|
@@ -11411,7 +11436,9 @@ async function runWrapped(req, backend, policy, env) {
|
|
|
11411
11436
|
timeoutMs: req.timeoutMs,
|
|
11412
11437
|
stripEnvVars: [...req.stripEnvVars],
|
|
11413
11438
|
...req.env !== undefined ? { env: req.env } : {},
|
|
11414
|
-
...req.signal !== undefined ? { signal: req.signal } : {}
|
|
11439
|
+
...req.signal !== undefined ? { signal: req.signal } : {},
|
|
11440
|
+
...req.releaseDeadline !== undefined ? { releaseDeadline: req.releaseDeadline } : {},
|
|
11441
|
+
...req.onOutput !== undefined ? { onOutput: req.onOutput } : {}
|
|
11415
11442
|
});
|
|
11416
11443
|
const denied = result.exitCode !== 0 && LIKELY_SANDBOX_DENIAL.test(result.stderr);
|
|
11417
11444
|
const violations = backend.annotate(commandId, result.stderr);
|
|
@@ -12059,6 +12086,151 @@ var init_sandbox = __esm(() => {
|
|
|
12059
12086
|
init_srt_backend();
|
|
12060
12087
|
});
|
|
12061
12088
|
|
|
12089
|
+
// ../nax-agent/src/tools/bash-background.ts
|
|
12090
|
+
async function runBashWithBackground(request) {
|
|
12091
|
+
const background = startBashBackground(request);
|
|
12092
|
+
if (background !== undefined)
|
|
12093
|
+
return background;
|
|
12094
|
+
if (request.port === undefined)
|
|
12095
|
+
return request.launch();
|
|
12096
|
+
return runMovableForeground({ ...request, port: request.port });
|
|
12097
|
+
}
|
|
12098
|
+
function outputReplay() {
|
|
12099
|
+
let chunks = [];
|
|
12100
|
+
let bytes = 0;
|
|
12101
|
+
let sink;
|
|
12102
|
+
let replaying = false;
|
|
12103
|
+
return {
|
|
12104
|
+
append(stream, chunk) {
|
|
12105
|
+
if (sink !== undefined)
|
|
12106
|
+
return sink.append(stream, chunk);
|
|
12107
|
+
if (chunk.byteLength === 0)
|
|
12108
|
+
return;
|
|
12109
|
+
const tail = replaying ? chunk : chunk.subarray(-FOREGROUND_REPLAY_BYTES);
|
|
12110
|
+
chunks.push({ stream, chunk: Uint8Array.from(tail) });
|
|
12111
|
+
bytes += tail.byteLength;
|
|
12112
|
+
while (!replaying && bytes > FOREGROUND_REPLAY_BYTES) {
|
|
12113
|
+
const first = chunks[0];
|
|
12114
|
+
if (first === undefined)
|
|
12115
|
+
break;
|
|
12116
|
+
const dropped = Math.min(first.chunk.byteLength, bytes - FOREGROUND_REPLAY_BYTES);
|
|
12117
|
+
bytes -= dropped;
|
|
12118
|
+
if (dropped === first.chunk.byteLength)
|
|
12119
|
+
chunks.shift();
|
|
12120
|
+
else
|
|
12121
|
+
first.chunk = first.chunk.slice(dropped);
|
|
12122
|
+
}
|
|
12123
|
+
},
|
|
12124
|
+
replay(target) {
|
|
12125
|
+
replaying = true;
|
|
12126
|
+
for (const item of chunks)
|
|
12127
|
+
target.append(item.stream, item.chunk);
|
|
12128
|
+
chunks = [];
|
|
12129
|
+
bytes = 0;
|
|
12130
|
+
sink = target;
|
|
12131
|
+
}
|
|
12132
|
+
};
|
|
12133
|
+
}
|
|
12134
|
+
function commandEnd(result) {
|
|
12135
|
+
return {
|
|
12136
|
+
exitCode: result.launched.exitCode,
|
|
12137
|
+
timedOut: result.launched.timedOut,
|
|
12138
|
+
aborted: result.launched.aborted === true
|
|
12139
|
+
};
|
|
12140
|
+
}
|
|
12141
|
+
function failedEnd(error) {
|
|
12142
|
+
return { exitCode: -1, timedOut: false, aborted: false, launchError: errorMessage(error) };
|
|
12143
|
+
}
|
|
12144
|
+
function foregroundControl(request) {
|
|
12145
|
+
const controller = new AbortController;
|
|
12146
|
+
const releaseDeadline = new AbortController;
|
|
12147
|
+
const released = Promise.withResolvers();
|
|
12148
|
+
const ended = Promise.withResolvers();
|
|
12149
|
+
const output = outputReplay();
|
|
12150
|
+
let settled = false;
|
|
12151
|
+
let moved = false;
|
|
12152
|
+
const cancel = () => controller.abort();
|
|
12153
|
+
const detach = () => request.signal?.removeEventListener("abort", cancel);
|
|
12154
|
+
request.signal?.addEventListener("abort", cancel, { once: true });
|
|
12155
|
+
if (request.signal?.aborted === true)
|
|
12156
|
+
cancel();
|
|
12157
|
+
const call = {
|
|
12158
|
+
command: request.command,
|
|
12159
|
+
moveToBackground() {
|
|
12160
|
+
if (settled || moved)
|
|
12161
|
+
return;
|
|
12162
|
+
moved = true;
|
|
12163
|
+
releaseDeadline.abort();
|
|
12164
|
+
detach();
|
|
12165
|
+
const sink = request.port.adopt({
|
|
12166
|
+
command: request.command,
|
|
12167
|
+
...typeof request.description === "string" ? { description: request.description } : {},
|
|
12168
|
+
origin: "moved",
|
|
12169
|
+
ended: ended.promise,
|
|
12170
|
+
stop: cancel
|
|
12171
|
+
});
|
|
12172
|
+
output.replay(sink);
|
|
12173
|
+
released.resolve({ content: `moved to the background as ${sink.id}`, isError: false });
|
|
12174
|
+
}
|
|
12175
|
+
};
|
|
12176
|
+
return {
|
|
12177
|
+
call,
|
|
12178
|
+
released: released.promise,
|
|
12179
|
+
options: { signal: controller.signal, releaseDeadline: releaseDeadline.signal, onOutput: output.append },
|
|
12180
|
+
isForeground: () => !moved,
|
|
12181
|
+
finish(end) {
|
|
12182
|
+
settled = true;
|
|
12183
|
+
ended.resolve(end);
|
|
12184
|
+
},
|
|
12185
|
+
detach
|
|
12186
|
+
};
|
|
12187
|
+
}
|
|
12188
|
+
async function runMovableForeground(request) {
|
|
12189
|
+
const control = foregroundControl(request);
|
|
12190
|
+
const unregister = request.port.foreground(control.call);
|
|
12191
|
+
const launch = Promise.resolve().then(() => request.launch(control.options, control.isForeground));
|
|
12192
|
+
launch.then((result) => control.finish(commandEnd(result)), (error) => control.finish(failedEnd(error)));
|
|
12193
|
+
try {
|
|
12194
|
+
return await Promise.race([launch, control.released]);
|
|
12195
|
+
} finally {
|
|
12196
|
+
control.detach();
|
|
12197
|
+
unregister();
|
|
12198
|
+
}
|
|
12199
|
+
}
|
|
12200
|
+
function withBackgroundSentence(description, port) {
|
|
12201
|
+
if (port === undefined)
|
|
12202
|
+
return description;
|
|
12203
|
+
const separator = description.endsWith(" ") ? "" : " ";
|
|
12204
|
+
return `${description}${separator}Set "runInBackground": true to return at once with a task id; a notice arrives when the command ends.`;
|
|
12205
|
+
}
|
|
12206
|
+
function startBashBackground(request) {
|
|
12207
|
+
if (request.port === undefined || request.runInBackground !== true)
|
|
12208
|
+
return;
|
|
12209
|
+
const controller = new AbortController;
|
|
12210
|
+
const completion = Promise.withResolvers();
|
|
12211
|
+
const sink = request.port.adopt({
|
|
12212
|
+
command: request.command,
|
|
12213
|
+
...typeof request.description === "string" ? { description: request.description } : {},
|
|
12214
|
+
origin: "agent",
|
|
12215
|
+
ended: completion.promise,
|
|
12216
|
+
stop: () => controller.abort()
|
|
12217
|
+
});
|
|
12218
|
+
Promise.resolve().then(() => request.launch({
|
|
12219
|
+
signal: controller.signal,
|
|
12220
|
+
releaseDeadline: AbortSignal.abort(),
|
|
12221
|
+
onOutput: (stream, chunk) => sink.append(stream, chunk)
|
|
12222
|
+
})).then(({ launched }) => completion.resolve({
|
|
12223
|
+
exitCode: launched.exitCode,
|
|
12224
|
+
timedOut: launched.timedOut,
|
|
12225
|
+
aborted: launched.aborted === true
|
|
12226
|
+
}), (error) => completion.resolve({ exitCode: -1, timedOut: false, aborted: false, launchError: errorMessage(error) }));
|
|
12227
|
+
return { content: `started in the background as ${sink.id}`, isError: false };
|
|
12228
|
+
}
|
|
12229
|
+
var FOREGROUND_REPLAY_BYTES;
|
|
12230
|
+
var init_bash_background = __esm(() => {
|
|
12231
|
+
FOREGROUND_REPLAY_BYTES = 1024 * 1024;
|
|
12232
|
+
});
|
|
12233
|
+
|
|
12062
12234
|
// ../nax-agent/src/tools/truncate.ts
|
|
12063
12235
|
function truncationDirectionFor(toolName) {
|
|
12064
12236
|
if (TAIL_DIRECTION_TOOLS.has(toolName))
|
|
@@ -12259,7 +12431,9 @@ async function launchIntercepted({
|
|
|
12259
12431
|
opts,
|
|
12260
12432
|
ctx,
|
|
12261
12433
|
timeoutMs,
|
|
12262
|
-
unwrapped
|
|
12434
|
+
unwrapped,
|
|
12435
|
+
backgroundLaunch,
|
|
12436
|
+
isForeground
|
|
12263
12437
|
}) {
|
|
12264
12438
|
const interceptor = ctx.interceptor;
|
|
12265
12439
|
const intercepted = await interceptShell(command, ctx.root, interceptor);
|
|
@@ -12270,7 +12444,8 @@ async function launchIntercepted({
|
|
|
12270
12444
|
timeoutMs,
|
|
12271
12445
|
stripEnvVars: [...opts.stripEnvVars ?? []],
|
|
12272
12446
|
...agentOverlay !== undefined ? { env: agentOverlay } : {},
|
|
12273
|
-
...ctx.signal !== undefined ? { signal: ctx.signal } : {}
|
|
12447
|
+
...ctx.signal !== undefined ? { signal: ctx.signal } : {},
|
|
12448
|
+
...backgroundLaunch
|
|
12274
12449
|
};
|
|
12275
12450
|
const launched = opts.launcher !== undefined ? await opts.launcher.run({
|
|
12276
12451
|
spec: { kind: "shell", shell, command: intercepted.command },
|
|
@@ -12278,8 +12453,9 @@ async function launchIntercepted({
|
|
|
12278
12453
|
...common,
|
|
12279
12454
|
...unwrapped ? { unwrapped: true } : {}
|
|
12280
12455
|
}) : { ...await _bashToolDeps.runArgv({ argv: executed, ...common }), executed, sandbox: undefined };
|
|
12281
|
-
if (!intercepted.rewritten)
|
|
12456
|
+
if (!intercepted.rewritten || backgroundLaunch !== undefined && isForeground?.() !== true) {
|
|
12282
12457
|
return { launched, stdout: launched.stdout };
|
|
12458
|
+
}
|
|
12283
12459
|
const req = { kind: "shell", command, cwd: ctx.root, site: "bash" };
|
|
12284
12460
|
try {
|
|
12285
12461
|
const processed = interceptor?.postProcess?.(launched.stdout, req)?.output;
|
|
@@ -12304,6 +12480,7 @@ function bashToolInputSchema(opts) {
|
|
|
12304
12480
|
description: `Deadline in milliseconds (default and maximum ${BASH_TIMEOUT_MS}).`
|
|
12305
12481
|
},
|
|
12306
12482
|
description: { type: "string", description: "One short line on what this command is for." },
|
|
12483
|
+
...opts.background !== undefined ? { runInBackground: { type: "boolean" } } : {},
|
|
12307
12484
|
...opts.unsandboxedCommands === true ? { unsandboxed: { type: "boolean" }, unsandboxedReason: { type: "string" } } : {}
|
|
12308
12485
|
},
|
|
12309
12486
|
required: ["command"]
|
|
@@ -12314,7 +12491,7 @@ function createBashTool(opts = {}) {
|
|
|
12314
12491
|
return {
|
|
12315
12492
|
name: BASH_TOOL_NAME,
|
|
12316
12493
|
routineErrors: true,
|
|
12317
|
-
description: withUnsandboxedSentence(bashToolDescription(shell, opts), opts),
|
|
12494
|
+
description: withBackgroundSentence(withUnsandboxedSentence(bashToolDescription(shell, opts), opts), opts.background),
|
|
12318
12495
|
inputSchema: bashToolInputSchema(opts),
|
|
12319
12496
|
scope: { pathFields: [], commandField: "command", unsandboxedField: "unsandboxed" },
|
|
12320
12497
|
async run(input, ctx) {
|
|
@@ -12326,7 +12503,18 @@ function createBashTool(opts = {}) {
|
|
|
12326
12503
|
const timeoutMs = Math.min(Math.max(Math.trunc(requested), MIN_BASH_TIMEOUT_MS), BASH_TIMEOUT_MS);
|
|
12327
12504
|
try {
|
|
12328
12505
|
const unwrapped = input.unsandboxed === true;
|
|
12329
|
-
const
|
|
12506
|
+
const request = { command, shell, opts, ctx, timeoutMs, unwrapped };
|
|
12507
|
+
const result = await runBashWithBackground({
|
|
12508
|
+
port: opts.background,
|
|
12509
|
+
runInBackground: input.runInBackground,
|
|
12510
|
+
command,
|
|
12511
|
+
description: input.description,
|
|
12512
|
+
signal: ctx.signal,
|
|
12513
|
+
launch: (backgroundLaunch, isForeground) => launchIntercepted({ ...request, backgroundLaunch, isForeground })
|
|
12514
|
+
});
|
|
12515
|
+
if ("content" in result)
|
|
12516
|
+
return result;
|
|
12517
|
+
const { launched, stdout } = result;
|
|
12330
12518
|
const body = formatExecBody({ ...launched, stdout }, timeoutMs);
|
|
12331
12519
|
return {
|
|
12332
12520
|
content: cutToByteCap(body, ctx.readCeiling ?? READ_CEILING),
|
|
@@ -12350,6 +12538,7 @@ var init_bash = __esm(() => {
|
|
|
12350
12538
|
init_agent_output_env();
|
|
12351
12539
|
init_argv_exec();
|
|
12352
12540
|
init_sandbox();
|
|
12541
|
+
init_bash_background();
|
|
12353
12542
|
init_truncate();
|
|
12354
12543
|
_bashToolDeps = {
|
|
12355
12544
|
runArgv,
|
|
@@ -20510,6 +20699,65 @@ var init_interaction_handler = __esm(() => {
|
|
|
20510
20699
|
NO_OP_INTERACTION_HANDLER2 = NO_OP_INTERACTION_HANDLER;
|
|
20511
20700
|
});
|
|
20512
20701
|
|
|
20702
|
+
// ../nax-agent/src/coding-tools/coding-tool-extras.ts
|
|
20703
|
+
function unsandboxedToolOptions(args) {
|
|
20704
|
+
return args.unsandboxedCommands === true ? { unsandboxedCommands: true } : {};
|
|
20705
|
+
}
|
|
20706
|
+
function unsandboxedRuntimeOption(args) {
|
|
20707
|
+
if (args.unsandboxedCommands !== true)
|
|
20708
|
+
return {};
|
|
20709
|
+
return {
|
|
20710
|
+
unsandboxed: {
|
|
20711
|
+
enabled: true,
|
|
20712
|
+
bashApproval: args.bashApproval,
|
|
20713
|
+
...args.askOnUnsandboxed === true ? { alwaysAsk: true } : {}
|
|
20714
|
+
}
|
|
20715
|
+
};
|
|
20716
|
+
}
|
|
20717
|
+
function buildDeclaredCommandTools(args) {
|
|
20718
|
+
return [
|
|
20719
|
+
...args.declaredCommands.size > 0 || args.allowExec ? [
|
|
20720
|
+
createRunCommandTool(args.declaredCommands, {
|
|
20721
|
+
stripEnvVars: args.stripEnvVars,
|
|
20722
|
+
commandCwd: args.commandCwd ?? args.root,
|
|
20723
|
+
runDeclaredCommand: args.runDeclaredCommand,
|
|
20724
|
+
...args.allowExec ? {
|
|
20725
|
+
exec: {
|
|
20726
|
+
repoRoot: args.repoRoot ?? args.root,
|
|
20727
|
+
packageWorkdir: args.packageWorkdir ?? args.root,
|
|
20728
|
+
allowScripts: args.allowScripts ?? false,
|
|
20729
|
+
patterns: args.execGrant?.patterns ?? [],
|
|
20730
|
+
...args.packageName !== undefined ? { packageName: args.packageName } : {},
|
|
20731
|
+
...args.launcher !== undefined ? { launcher: args.launcher } : {},
|
|
20732
|
+
...unsandboxedToolOptions(args)
|
|
20733
|
+
}
|
|
20734
|
+
} : {}
|
|
20735
|
+
})
|
|
20736
|
+
] : [],
|
|
20737
|
+
...args.allowBash ? [
|
|
20738
|
+
createBashTool({
|
|
20739
|
+
...args.shell !== undefined ? { shell: args.shell } : {},
|
|
20740
|
+
...args.stripEnvVars !== undefined ? { stripEnvVars: args.stripEnvVars } : {},
|
|
20741
|
+
patterns: args.bashDescriptionPatterns,
|
|
20742
|
+
bashApproval: args.bashApproval,
|
|
20743
|
+
...args.humanApproval === true ? { humanApproval: true } : {},
|
|
20744
|
+
...args.launcher !== undefined ? { launcher: args.launcher } : {},
|
|
20745
|
+
...unsandboxedToolOptions(args),
|
|
20746
|
+
...bashBackgroundOption(args)
|
|
20747
|
+
})
|
|
20748
|
+
] : []
|
|
20749
|
+
];
|
|
20750
|
+
}
|
|
20751
|
+
function backgroundToolOptions(args) {
|
|
20752
|
+
return args?.backgroundCommands === undefined ? {} : { backgroundCommands: args.backgroundCommands };
|
|
20753
|
+
}
|
|
20754
|
+
function bashBackgroundOption(args) {
|
|
20755
|
+
return args.backgroundCommands === undefined ? {} : { background: args.backgroundCommands };
|
|
20756
|
+
}
|
|
20757
|
+
var init_coding_tool_extras = __esm(() => {
|
|
20758
|
+
init_tools();
|
|
20759
|
+
});
|
|
20760
|
+
|
|
20513
20761
|
// ../nax-agent/src/native/session/compaction-settings.ts
|
|
20514
20762
|
function resolveCompaction(input) {
|
|
20515
20763
|
return compactionSettingsSchema.parse(input);
|
|
@@ -20611,6 +20859,7 @@ var init_native_backend_options = __esm(() => {
|
|
|
20611
20859
|
hostPorts: strictObject({
|
|
20612
20860
|
protectedPaths: custom((value) => isRecord2(value) && isStringArray(value.gitExcludePathspecs) && isStringArray(value.gitIgnorePatterns), "must be a protected-paths policy with gitExcludePathspecs and gitIgnorePatterns string arrays").optional(),
|
|
20613
20861
|
commandShadow: custom(hasMethods2(["observe", "settle", "drain"]), "must implement observe, settle and drain").optional(),
|
|
20862
|
+
backgroundCommands: custom(hasMethods2(["adopt", "foreground"]), "must implement adopt and foreground").optional(),
|
|
20614
20863
|
commandInterceptor: custom(hasMethods2(["intercept"]), "must implement intercept").optional()
|
|
20615
20864
|
}).optional(),
|
|
20616
20865
|
bashApproval: _enum(["raw", "gated", "escalate"]).optional(),
|
|
@@ -20805,58 +21054,6 @@ var init_session_interaction = __esm(() => {
|
|
|
20805
21054
|
EMBEDDER_SCAN_BYTES = EMBEDDER_SUMMARY_BYTES * 16;
|
|
20806
21055
|
});
|
|
20807
21056
|
|
|
20808
|
-
// ../nax-agent/src/coding-tools/coding-tool-extras.ts
|
|
20809
|
-
function unsandboxedToolOptions(args) {
|
|
20810
|
-
return args.unsandboxedCommands === true ? { unsandboxedCommands: true } : {};
|
|
20811
|
-
}
|
|
20812
|
-
function unsandboxedRuntimeOption(args) {
|
|
20813
|
-
if (args.unsandboxedCommands !== true)
|
|
20814
|
-
return {};
|
|
20815
|
-
return {
|
|
20816
|
-
unsandboxed: {
|
|
20817
|
-
enabled: true,
|
|
20818
|
-
bashApproval: args.bashApproval,
|
|
20819
|
-
...args.askOnUnsandboxed === true ? { alwaysAsk: true } : {}
|
|
20820
|
-
}
|
|
20821
|
-
};
|
|
20822
|
-
}
|
|
20823
|
-
function buildDeclaredCommandTools(args) {
|
|
20824
|
-
return [
|
|
20825
|
-
...args.declaredCommands.size > 0 || args.allowExec ? [
|
|
20826
|
-
createRunCommandTool(args.declaredCommands, {
|
|
20827
|
-
stripEnvVars: args.stripEnvVars,
|
|
20828
|
-
commandCwd: args.commandCwd ?? args.root,
|
|
20829
|
-
runDeclaredCommand: args.runDeclaredCommand,
|
|
20830
|
-
...args.allowExec ? {
|
|
20831
|
-
exec: {
|
|
20832
|
-
repoRoot: args.repoRoot ?? args.root,
|
|
20833
|
-
packageWorkdir: args.packageWorkdir ?? args.root,
|
|
20834
|
-
allowScripts: args.allowScripts ?? false,
|
|
20835
|
-
patterns: args.execGrant?.patterns ?? [],
|
|
20836
|
-
...args.packageName !== undefined ? { packageName: args.packageName } : {},
|
|
20837
|
-
...args.launcher !== undefined ? { launcher: args.launcher } : {},
|
|
20838
|
-
...unsandboxedToolOptions(args)
|
|
20839
|
-
}
|
|
20840
|
-
} : {}
|
|
20841
|
-
})
|
|
20842
|
-
] : [],
|
|
20843
|
-
...args.allowBash ? [
|
|
20844
|
-
createBashTool({
|
|
20845
|
-
...args.shell !== undefined ? { shell: args.shell } : {},
|
|
20846
|
-
...args.stripEnvVars !== undefined ? { stripEnvVars: args.stripEnvVars } : {},
|
|
20847
|
-
patterns: args.bashDescriptionPatterns,
|
|
20848
|
-
bashApproval: args.bashApproval,
|
|
20849
|
-
...args.humanApproval === true ? { humanApproval: true } : {},
|
|
20850
|
-
...args.launcher !== undefined ? { launcher: args.launcher } : {},
|
|
20851
|
-
...unsandboxedToolOptions(args)
|
|
20852
|
-
})
|
|
20853
|
-
] : []
|
|
20854
|
-
];
|
|
20855
|
-
}
|
|
20856
|
-
var init_coding_tool_extras = __esm(() => {
|
|
20857
|
-
init_tools();
|
|
20858
|
-
});
|
|
20859
|
-
|
|
20860
21057
|
// ../nax-agent/src/coding-tools/coding-tool-sandbox.ts
|
|
20861
21058
|
import { mkdir as mkdir14 } from "fs/promises";
|
|
20862
21059
|
import { homedir as homedir3, tmpdir as tmpdir5 } from "os";
|
|
@@ -21069,7 +21266,8 @@ function buildCodingToolSupport(args) {
|
|
|
21069
21266
|
...args.stripEnvVars !== undefined ? { stripEnvVars: args.stripEnvVars } : {},
|
|
21070
21267
|
...args.shell !== undefined ? { shell: args.shell } : {},
|
|
21071
21268
|
...args.launcher !== undefined ? { launcher: args.launcher } : {},
|
|
21072
|
-
...unsandboxedToolOptions(args)
|
|
21269
|
+
...unsandboxedToolOptions(args),
|
|
21270
|
+
...backgroundToolOptions(args)
|
|
21073
21271
|
})
|
|
21074
21272
|
],
|
|
21075
21273
|
...args.providerIdByTool !== undefined ? { providerIdByTool: args.providerIdByTool } : {},
|
|
@@ -21239,6 +21437,7 @@ function buildSessionToolSupport(args) {
|
|
|
21239
21437
|
...args.interceptor !== undefined ? { interceptor: args.interceptor } : {},
|
|
21240
21438
|
...args.launcher !== undefined ? { launcher: args.launcher } : {},
|
|
21241
21439
|
...unsandboxedToolOptions(args),
|
|
21440
|
+
...backgroundToolOptions(args),
|
|
21242
21441
|
...postureToolOptions(args)
|
|
21243
21442
|
});
|
|
21244
21443
|
if (support === undefined) {
|
|
@@ -21328,6 +21527,7 @@ async function openNative(resolved, ctx) {
|
|
|
21328
21527
|
askOnUnsandboxed: posture.askOnUnsandboxed,
|
|
21329
21528
|
askDiscoveredTools: posture.askDiscoveredTools,
|
|
21330
21529
|
commandShadow: raw.hostPorts?.commandShadow,
|
|
21530
|
+
...backgroundToolOptions(raw.hostPorts),
|
|
21331
21531
|
...allowUnsandboxedCommands ? { unsandboxedCommands: true } : {}
|
|
21332
21532
|
});
|
|
21333
21533
|
const interactionHandler = createSessionInteractionHandler({
|
|
@@ -21406,6 +21606,7 @@ function nativeBackend(options) {
|
|
|
21406
21606
|
}
|
|
21407
21607
|
var NATIVE_BACKEND_KIND = "native", SESSION_TRANSPORT_RETRY;
|
|
21408
21608
|
var init_native_backend = __esm(() => {
|
|
21609
|
+
init_coding_tool_extras();
|
|
21409
21610
|
init_agent_logger();
|
|
21410
21611
|
init_spin_breaker();
|
|
21411
21612
|
init_models();
|
|
@@ -32590,12 +32791,21 @@ function getNextStory(prd, currentStoryId, maxRetries) {
|
|
|
32590
32791
|
function isComplete(prd) {
|
|
32591
32792
|
return prd.userStories.every((s) => s.passes || s.status === "passed" || s.status === "skipped");
|
|
32592
32793
|
}
|
|
32794
|
+
function isPendingStory(s) {
|
|
32795
|
+
return !s.passes && s.status !== "passed" && s.status !== "failed" && s.status !== "skipped" && s.status !== "blocked" && s.status !== "paused" && s.status !== "regression-failed" && s.status !== "decomposed";
|
|
32796
|
+
}
|
|
32797
|
+
function pendingStories(prd) {
|
|
32798
|
+
return prd.userStories.filter(isPendingStory);
|
|
32799
|
+
}
|
|
32800
|
+
function pendingStoryIds(prd) {
|
|
32801
|
+
return pendingStories(prd).map((s) => s.id);
|
|
32802
|
+
}
|
|
32593
32803
|
function countStories(prd) {
|
|
32594
32804
|
return {
|
|
32595
32805
|
total: prd.userStories.length,
|
|
32596
32806
|
passed: prd.userStories.filter((s) => s.passes || s.status === "passed").length,
|
|
32597
32807
|
failed: prd.userStories.filter((s) => s.status === "failed" || s.status === "regression-failed").length,
|
|
32598
|
-
pending: prd.userStories.filter(
|
|
32808
|
+
pending: prd.userStories.filter(isPendingStory).length,
|
|
32599
32809
|
skipped: prd.userStories.filter((s) => s.status === "skipped").length,
|
|
32600
32810
|
blocked: prd.userStories.filter((s) => s.status === "blocked").length,
|
|
32601
32811
|
paused: prd.userStories.filter((s) => s.status === "paused").length,
|
|
@@ -40376,6 +40586,23 @@ var init_agents_builder = __esm(() => {
|
|
|
40376
40586
|
init_rules_index_builder();
|
|
40377
40587
|
});
|
|
40378
40588
|
|
|
40589
|
+
// src/prompts/builders/background-builder.ts
|
|
40590
|
+
function buildBackgroundTasksInstructions() {
|
|
40591
|
+
return [
|
|
40592
|
+
"Use `Bash` with `runInBackground` to keep chatting while a command runs.",
|
|
40593
|
+
"Inspect background commands with `nax-tasks__list`, read their output with `nax-tasks__output`, and stop a command this chat started with `nax-tasks__stop` (no approval card).",
|
|
40594
|
+
"A [nax-tasks] notice arrives when a background command ends; read its output, report the outcome to the user and propose the next step."
|
|
40595
|
+
].join(`
|
|
40596
|
+
`);
|
|
40597
|
+
}
|
|
40598
|
+
function buildBackgroundTaskNotice(tasks) {
|
|
40599
|
+
return [
|
|
40600
|
+
...tasks.map((task) => `[nax-tasks] background command ${task.id} (${task.command}) ended: ${task.state}, exit code ${task.exitCode}, log ${task.logPath}`),
|
|
40601
|
+
"Read its output with `nax-tasks__output`, report the outcome to the user and propose the next step."
|
|
40602
|
+
].join(`
|
|
40603
|
+
`);
|
|
40604
|
+
}
|
|
40605
|
+
|
|
40379
40606
|
// src/prompts/builders/bot-checkout-state-builder.ts
|
|
40380
40607
|
function renderCheckoutState(input) {
|
|
40381
40608
|
const sha = input.headSha.slice(0, SHORT_SHA_LENGTH);
|
|
@@ -52077,7 +52304,7 @@ var package_default;
|
|
|
52077
52304
|
var init_package = __esm(() => {
|
|
52078
52305
|
package_default = {
|
|
52079
52306
|
name: "@nathapp/nax",
|
|
52080
|
-
version: "0.91.7-canary.
|
|
52307
|
+
version: "0.91.7-canary.8",
|
|
52081
52308
|
description: "AI Coding Agent Orchestrator \u2014 loops until done",
|
|
52082
52309
|
type: "module",
|
|
52083
52310
|
bin: {
|
|
@@ -52163,7 +52390,7 @@ var init_package = __esm(() => {
|
|
|
52163
52390
|
"@agentclientprotocol/sdk": "~1.7.0",
|
|
52164
52391
|
"@anthropic-ai/sandbox-runtime": "0.0.77",
|
|
52165
52392
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
52166
|
-
"@nathapp/nax-ai": "0.91.7-canary.
|
|
52393
|
+
"@nathapp/nax-ai": "0.91.7-canary.8",
|
|
52167
52394
|
chalk: "^5.6.2",
|
|
52168
52395
|
commander: "^13.1.0",
|
|
52169
52396
|
"highlight.js": "^11.12.0",
|
|
@@ -52273,6 +52500,16 @@ async function lookupContextWindow(provider, model) {
|
|
|
52273
52500
|
return;
|
|
52274
52501
|
}
|
|
52275
52502
|
}
|
|
52503
|
+
async function lookupThinkingLevels(provider, model) {
|
|
52504
|
+
const catalog = await loadCatalog(_catalogDeps.loadProviders);
|
|
52505
|
+
if (catalog === null)
|
|
52506
|
+
return;
|
|
52507
|
+
try {
|
|
52508
|
+
return catalog.model(provider, model)?.thinkingLevels;
|
|
52509
|
+
} catch {
|
|
52510
|
+
return;
|
|
52511
|
+
}
|
|
52512
|
+
}
|
|
52276
52513
|
async function listCatalogModels(providerIds) {
|
|
52277
52514
|
const catalog = await loadCatalog(_catalogDeps.loadProviders);
|
|
52278
52515
|
if (catalog === null)
|
|
@@ -74785,7 +75022,7 @@ function linkAborts(controller, signals) {
|
|
|
74785
75022
|
unlink();
|
|
74786
75023
|
};
|
|
74787
75024
|
}
|
|
74788
|
-
function
|
|
75025
|
+
function armDeadline2(controller, remainingMs) {
|
|
74789
75026
|
if (remainingMs === undefined)
|
|
74790
75027
|
return;
|
|
74791
75028
|
return setTimeout(() => controller.abort(new TurnDeadlineExpired), remainingMs);
|
|
@@ -74846,7 +75083,7 @@ async function runIteration(loop) {
|
|
|
74846
75083
|
unlink();
|
|
74847
75084
|
throw failed2(loop, undefined, controller.signal.reason);
|
|
74848
75085
|
}
|
|
74849
|
-
const timer =
|
|
75086
|
+
const timer = armDeadline2(controller, loop.deadline.remainingMs());
|
|
74850
75087
|
const call = startCall(session.stream);
|
|
74851
75088
|
const turnId = opts.turnId ?? randomUUID16();
|
|
74852
75089
|
try {
|
|
@@ -77045,18 +77282,40 @@ async function promptTrustChoice(root, parent) {
|
|
|
77045
77282
|
return "parent";
|
|
77046
77283
|
return "no";
|
|
77047
77284
|
}
|
|
77048
|
-
|
|
77049
|
-
|
|
77050
|
-
|
|
77051
|
-
|
|
77052
|
-
|
|
77053
|
-
|
|
77285
|
+
function readStdinLine(stdin = process.stdin) {
|
|
77286
|
+
return new Promise((resolve) => {
|
|
77287
|
+
if (stdin.readableEnded) {
|
|
77288
|
+
resolve(null);
|
|
77289
|
+
return;
|
|
77290
|
+
}
|
|
77291
|
+
const decoder = new TextDecoder;
|
|
77292
|
+
let buffer = "";
|
|
77293
|
+
const finish = (line) => {
|
|
77294
|
+
stdin.off("readable", onReadable);
|
|
77295
|
+
stdin.off("end", onEnd);
|
|
77296
|
+
resolve(line === null ? null : stripCarriageReturn2(line));
|
|
77297
|
+
};
|
|
77298
|
+
const onEnd = () => {
|
|
77299
|
+
buffer += decoder.decode();
|
|
77300
|
+
finish(buffer === "" ? null : buffer);
|
|
77301
|
+
};
|
|
77302
|
+
const onReadable = () => {
|
|
77303
|
+
for (let chunk = stdin.read();chunk !== null; chunk = stdin.read()) {
|
|
77304
|
+
buffer += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
|
|
77305
|
+
const newline = buffer.indexOf(`
|
|
77054
77306
|
`);
|
|
77055
|
-
|
|
77056
|
-
|
|
77057
|
-
|
|
77058
|
-
|
|
77059
|
-
|
|
77307
|
+
if (newline === -1)
|
|
77308
|
+
continue;
|
|
77309
|
+
const rest = buffer.slice(newline + 1);
|
|
77310
|
+
if (rest !== "")
|
|
77311
|
+
stdin.unshift(rest);
|
|
77312
|
+
finish(buffer.slice(0, newline));
|
|
77313
|
+
return;
|
|
77314
|
+
}
|
|
77315
|
+
};
|
|
77316
|
+
stdin.on("readable", onReadable);
|
|
77317
|
+
stdin.once("end", onEnd);
|
|
77318
|
+
});
|
|
77060
77319
|
}
|
|
77061
77320
|
function stripCarriageReturn2(line) {
|
|
77062
77321
|
return line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
@@ -77474,8 +77733,8 @@ var init_version = __esm(() => {
|
|
|
77474
77733
|
NAX_AI_VERSION = CATALOG_VERSION;
|
|
77475
77734
|
NAX_COMMIT = (() => {
|
|
77476
77735
|
try {
|
|
77477
|
-
if (/^[0-9a-f]{6,10}$/.test("
|
|
77478
|
-
return "
|
|
77736
|
+
if (/^[0-9a-f]{6,10}$/.test("a3d045c"))
|
|
77737
|
+
return "a3d045c";
|
|
77479
77738
|
} catch {}
|
|
77480
77739
|
try {
|
|
77481
77740
|
const result = Bun.spawnSync(["git", "rev-parse", "--short", "HEAD"], {
|
|
@@ -129186,6 +129445,14 @@ async function runFinish(options, deps, branch) {
|
|
|
129186
129445
|
});
|
|
129187
129446
|
}
|
|
129188
129447
|
}
|
|
129448
|
+
function iterationCapOf(options) {
|
|
129449
|
+
if (options.exitReason !== "max-iterations")
|
|
129450
|
+
return {};
|
|
129451
|
+
const pendingIds = pendingStoryIds(options.prd);
|
|
129452
|
+
if (pendingIds.length === 0)
|
|
129453
|
+
return {};
|
|
129454
|
+
return { iterationCap: { pendingIds } };
|
|
129455
|
+
}
|
|
129189
129456
|
async function runWorkflowEnd(options, deps, branch) {
|
|
129190
129457
|
if (options.exitReason === "aborted" || options.abortSignal?.aborted) {
|
|
129191
129458
|
getSafeLogger2()?.info("workflow", "Feature workflow skipped \u2014 the run was aborted", { storyId: "_run" });
|
|
@@ -129204,7 +129471,8 @@ async function runWorkflowEnd(options, deps, branch) {
|
|
|
129204
129471
|
abortSignal: options.abortSignal,
|
|
129205
129472
|
interactionChain: options.interactionChain,
|
|
129206
129473
|
statusWriter: options.statusWriter,
|
|
129207
|
-
storiesDurationMs: (deps.now ?? Date.now)() - options.startTime
|
|
129474
|
+
storiesDurationMs: (deps.now ?? Date.now)() - options.startTime,
|
|
129475
|
+
...iterationCapOf(options)
|
|
129208
129476
|
});
|
|
129209
129477
|
return {
|
|
129210
129478
|
passed: result?.passed ?? true,
|
|
@@ -129767,12 +130035,17 @@ function gateReasons(gates) {
|
|
|
129767
130035
|
return [NOTHING_VERIFIED];
|
|
129768
130036
|
return gates.failing.length > 0 ? [`gates red: ${gates.failing.join(", ")}`] : [];
|
|
129769
130037
|
}
|
|
130038
|
+
function iterationCapReason(cap) {
|
|
130039
|
+
const n = cap.pendingIds.length;
|
|
130040
|
+
return `iteration cap reached: the story loop hit its iteration limit with ${n} ${n === 1 ? "story" : "stories"} pending (${cap.pendingIds.join(", ")})`;
|
|
130041
|
+
}
|
|
129770
130042
|
function readinessReasons(f) {
|
|
129771
130043
|
const unread = f.branchReviewUnread ?? [];
|
|
129772
130044
|
const ci = ciReason(f.ci, f.ciDetail);
|
|
129773
130045
|
return [
|
|
129774
130046
|
...gateReasons(f.finalGates),
|
|
129775
130047
|
...ci === undefined ? [] : [ci],
|
|
130048
|
+
...f.iterationCap ? [iterationCapReason(f.iterationCap)] : [],
|
|
129776
130049
|
...storyReasons(f.stories),
|
|
129777
130050
|
...f.flagged > 0 ? [`${f.flagged} ruling(s) flagged for a human`] : [],
|
|
129778
130051
|
...f.branchReviewRan ? [] : ["branch review did not run"],
|
|
@@ -130553,7 +130826,8 @@ async function buildFeatureContext(input) {
|
|
|
130553
130826
|
reportPath: join157(runDir, "feature-report.md"),
|
|
130554
130827
|
packageDirs: [...new Set(storyPackageDirs.filter((d) => typeof d === "string" && d !== ""))],
|
|
130555
130828
|
...input.abortSignal ? { runSignal: input.abortSignal } : {},
|
|
130556
|
-
dryRun: input.runtime.dryRun === true
|
|
130829
|
+
dryRun: input.runtime.dryRun === true,
|
|
130830
|
+
...input.iterationCap ? { iterationCap: input.iterationCap } : {}
|
|
130557
130831
|
};
|
|
130558
130832
|
return { fc, dispose: () => dispatchAsk.dispose() };
|
|
130559
130833
|
}
|
|
@@ -132317,6 +132591,7 @@ async function publish(fc, input) {
|
|
|
132317
132591
|
branchReviewRan: input.record.reviewRan,
|
|
132318
132592
|
...input.record.reviewUnread ? { branchReviewUnread: input.record.reviewUnread } : {},
|
|
132319
132593
|
...input.record.costLimited ? { costLimited: true } : {},
|
|
132594
|
+
...fc.iterationCap ? { iterationCap: fc.iterationCap } : {},
|
|
132320
132595
|
...input.record.reReviewSkipped ? { reReviewSkipped: true } : {}
|
|
132321
132596
|
};
|
|
132322
132597
|
const dirty = await dirtyTreeReasons(fc);
|
|
@@ -134766,7 +135041,7 @@ var init_pr_step_context = __esm(() => {
|
|
|
134766
135041
|
|
|
134767
135042
|
// src/workflow/preflight-run.ts
|
|
134768
135043
|
import { mkdir as mkdir47 } from "fs/promises";
|
|
134769
|
-
function
|
|
135044
|
+
function pendingStoryIds2(prd) {
|
|
134770
135045
|
return prd.userStories.filter((s) => !s.passes && s.status !== "passed" && s.status !== "skipped").map((s) => s.id);
|
|
134771
135046
|
}
|
|
134772
135047
|
async function storePreflightTokens(meter, where) {
|
|
@@ -134802,7 +135077,7 @@ async function adoptPriorPreflight(featureDir, runDir, storyIds) {
|
|
|
134802
135077
|
async function runWorkflowPreflight(input) {
|
|
134803
135078
|
if (!resolveWorkflowConfig(input.config).preflight)
|
|
134804
135079
|
return;
|
|
134805
|
-
const storyIds =
|
|
135080
|
+
const storyIds = pendingStoryIds2(input.prd);
|
|
134806
135081
|
if (storyIds.length === 0)
|
|
134807
135082
|
return;
|
|
134808
135083
|
let dispose;
|
|
@@ -137153,42 +137428,14 @@ var init_reporters = __esm(() => {
|
|
|
137153
137428
|
init_logger2();
|
|
137154
137429
|
});
|
|
137155
137430
|
|
|
137156
|
-
// src/execution/pre-run.ts
|
|
137157
|
-
async function runPreRunPipeline(deps, prd, naxIgnoreIndex, stages) {
|
|
137158
|
-
const preRunCtx = {
|
|
137159
|
-
config: deps.config,
|
|
137160
|
-
rootConfig: deps.config,
|
|
137161
|
-
prd,
|
|
137162
|
-
projectDir: deps.workdir,
|
|
137163
|
-
workdir: deps.workdir,
|
|
137164
|
-
naxIgnoreIndex,
|
|
137165
|
-
featureDir: deps.featureDir,
|
|
137166
|
-
story: prd.userStories[0],
|
|
137167
|
-
stories: prd.userStories,
|
|
137168
|
-
runStoryWorkdirs: prd.userStories.map(storyPackageDir),
|
|
137169
|
-
routing: { complexity: "simple", modelTier: "fast", testStrategy: "test-after", reasoning: "" },
|
|
137170
|
-
hooks: deps.hooks,
|
|
137171
|
-
agentGetFn: deps.agentGetFn,
|
|
137172
|
-
agentManager: deps.agentManager,
|
|
137173
|
-
sessionManager: deps.sessionManager,
|
|
137174
|
-
runtime: deps.runtime,
|
|
137175
|
-
abortSignal: deps.abortSignal
|
|
137176
|
-
};
|
|
137177
|
-
const result = await runPipeline(stages, preRunCtx, deps.eventEmitter);
|
|
137178
|
-
logPipelineOutcome(result, "Pre-run pipeline (acceptance test setup)", prd.userStories[0]?.id);
|
|
137179
|
-
return preRunCtx;
|
|
137180
|
-
}
|
|
137181
|
-
var init_pre_run = __esm(() => {
|
|
137182
|
-
init_runner2();
|
|
137183
|
-
init_path_frame();
|
|
137184
|
-
});
|
|
137185
|
-
|
|
137186
137431
|
// src/execution/story-selector.ts
|
|
137432
|
+
function maxStoryRetries(config) {
|
|
137433
|
+
return config.execution.rectification?.maxAttemptsTotal ?? DEFAULT_MAX_STORY_RETRIES2;
|
|
137434
|
+
}
|
|
137187
137435
|
function resolveRetryCandidate(prd, lastStoryId, config) {
|
|
137188
137436
|
if (lastStoryId == null)
|
|
137189
137437
|
return null;
|
|
137190
|
-
const
|
|
137191
|
-
const story = getNextStory(prd, lastStoryId, maxRetries);
|
|
137438
|
+
const story = getNextStory(prd, lastStoryId, maxStoryRetries(config));
|
|
137192
137439
|
return story?.id === lastStoryId && story.status === "failed" ? story : null;
|
|
137193
137440
|
}
|
|
137194
137441
|
function selectNextStories(prd, config, batchPlan, currentBatchIndex, lastStoryId, useBatch) {
|
|
@@ -137273,6 +137520,55 @@ var init_story_selector = __esm(() => {
|
|
|
137273
137520
|
init_executor_types();
|
|
137274
137521
|
});
|
|
137275
137522
|
|
|
137523
|
+
// src/execution/iteration-bound.ts
|
|
137524
|
+
function workflowIterationsRemaining(prd, config, lastStoryId) {
|
|
137525
|
+
const pending = pendingStories(prd);
|
|
137526
|
+
const retry = resolveRetryCandidate(prd, lastStoryId, config) ? 1 : 0;
|
|
137527
|
+
const escalationHops = config.autoMode.escalation.enabled ? pending.filter((s) => (s.attempts ?? 0) > 0).length : 0;
|
|
137528
|
+
return pending.length + retry + escalationHops + 1;
|
|
137529
|
+
}
|
|
137530
|
+
function loopIterationLimit(prd, config, iterationsDone, lastStoryId) {
|
|
137531
|
+
return isWorkflowMode(config) ? iterationsDone + workflowIterationsRemaining(prd, config, lastStoryId) : config.execution.maxIterations;
|
|
137532
|
+
}
|
|
137533
|
+
function progressSignature(prd) {
|
|
137534
|
+
return prd.userStories.map((s) => `${s.id}:${s.status}:${s.passes ? 1 : 0}:${s.attempts ?? 0}:${s.escalations?.length ?? 0}`).join("|");
|
|
137535
|
+
}
|
|
137536
|
+
var init_iteration_bound = __esm(() => {
|
|
137537
|
+
init_config();
|
|
137538
|
+
init_prd();
|
|
137539
|
+
init_story_selector();
|
|
137540
|
+
});
|
|
137541
|
+
|
|
137542
|
+
// src/execution/pre-run.ts
|
|
137543
|
+
async function runPreRunPipeline(deps, prd, naxIgnoreIndex, stages) {
|
|
137544
|
+
const preRunCtx = {
|
|
137545
|
+
config: deps.config,
|
|
137546
|
+
rootConfig: deps.config,
|
|
137547
|
+
prd,
|
|
137548
|
+
projectDir: deps.workdir,
|
|
137549
|
+
workdir: deps.workdir,
|
|
137550
|
+
naxIgnoreIndex,
|
|
137551
|
+
featureDir: deps.featureDir,
|
|
137552
|
+
story: prd.userStories[0],
|
|
137553
|
+
stories: prd.userStories,
|
|
137554
|
+
runStoryWorkdirs: prd.userStories.map(storyPackageDir),
|
|
137555
|
+
routing: { complexity: "simple", modelTier: "fast", testStrategy: "test-after", reasoning: "" },
|
|
137556
|
+
hooks: deps.hooks,
|
|
137557
|
+
agentGetFn: deps.agentGetFn,
|
|
137558
|
+
agentManager: deps.agentManager,
|
|
137559
|
+
sessionManager: deps.sessionManager,
|
|
137560
|
+
runtime: deps.runtime,
|
|
137561
|
+
abortSignal: deps.abortSignal
|
|
137562
|
+
};
|
|
137563
|
+
const result = await runPipeline(stages, preRunCtx, deps.eventEmitter);
|
|
137564
|
+
logPipelineOutcome(result, "Pre-run pipeline (acceptance test setup)", prd.userStories[0]?.id);
|
|
137565
|
+
return preRunCtx;
|
|
137566
|
+
}
|
|
137567
|
+
var init_pre_run = __esm(() => {
|
|
137568
|
+
init_runner2();
|
|
137569
|
+
init_path_frame();
|
|
137570
|
+
});
|
|
137571
|
+
|
|
137276
137572
|
// src/execution/cost-guard.ts
|
|
137277
137573
|
async function enforceCostLimit(ctx, totalCost, costLimit, storyId) {
|
|
137278
137574
|
const enforcedCost = Math.max(totalCost, totalSpendUsd(ctx.runtime.costAggregator.snapshot()));
|
|
@@ -138248,6 +138544,31 @@ var init_parallel_batch = __esm(() => {
|
|
|
138248
138544
|
});
|
|
138249
138545
|
|
|
138250
138546
|
// src/execution/unified-executor.ts
|
|
138547
|
+
function logIterationCapReached(prd, config, limit, iterations) {
|
|
138548
|
+
const pendingIds = pendingStoryIds(prd);
|
|
138549
|
+
if (pendingIds.length === 0)
|
|
138550
|
+
return;
|
|
138551
|
+
const n = pendingIds.length;
|
|
138552
|
+
const what = `${n} ${n === 1 ? "story" : "stories"} still pending (${pendingIds.join(", ")})`;
|
|
138553
|
+
const message = isWorkflowMode(config) ? `Exit reason max-iterations: the derived loop bound (${limit}) was exhausted with ${what}; a story did not settle, check the log for retries` : `Exit reason max-iterations: hit execution.maxIterations (${limit}) with ${what}; raise execution.maxIterations or pass -m`;
|
|
138554
|
+
getSafeLogger2()?.warn("execution", message, {
|
|
138555
|
+
storyId: "_run",
|
|
138556
|
+
exitReason: "max-iterations",
|
|
138557
|
+
maxIterations: limit,
|
|
138558
|
+
iterations,
|
|
138559
|
+
pendingStoryIds: pendingIds
|
|
138560
|
+
});
|
|
138561
|
+
}
|
|
138562
|
+
function nextLoopGuard(config, state, iterations, lastSignature, limit) {
|
|
138563
|
+
if (!isWorkflowMode(config))
|
|
138564
|
+
return { stalled: false, limit, signature: lastSignature };
|
|
138565
|
+
const signature = progressSignature(state.prd);
|
|
138566
|
+
return {
|
|
138567
|
+
stalled: signature === lastSignature,
|
|
138568
|
+
limit: loopIterationLimit(state.prd, config, iterations - 1, state.lastStoryId),
|
|
138569
|
+
signature
|
|
138570
|
+
};
|
|
138571
|
+
}
|
|
138251
138572
|
async function runWorkflowPreflightOnce(ctx, prd) {
|
|
138252
138573
|
if (!isWorkflowMode(ctx.config) || ctx.dryRun)
|
|
138253
138574
|
return;
|
|
@@ -138326,6 +138647,23 @@ async function executeUnified(ctx, initialPrd) {
|
|
|
138326
138647
|
pipelineEventBus.emit({ type: "postrun:phase:started", phase: "review" });
|
|
138327
138648
|
deferredReview = await runDeferredReview(ctx.workdir, ctx.config.review, ctx.pluginRegistry, runStartRef, naxIgnoreIndex);
|
|
138328
138649
|
};
|
|
138650
|
+
const completeRun = async (naxIgnoreIndex) => {
|
|
138651
|
+
logger?.debug("execution", "All stories complete \u2014 entering completion path");
|
|
138652
|
+
if (ctx.interactionChain && isTriggerEnabled("pre-merge", ctx.config)) {
|
|
138653
|
+
const shouldProceed = await checkPreMerge({ featureName: ctx.feature, totalStories: state.prd.userStories.length, cost: state.totalCost }, ctx.config, ctx.interactionChain);
|
|
138654
|
+
if (!shouldProceed)
|
|
138655
|
+
return buildResult("pre-merge-aborted");
|
|
138656
|
+
}
|
|
138657
|
+
logger?.debug("execution", "Running deferred review");
|
|
138658
|
+
await runCompletionDeferredReview(naxIgnoreIndex);
|
|
138659
|
+
logger?.debug("execution", "Deferred review done \u2014 returning completed");
|
|
138660
|
+
return buildResult("completed");
|
|
138661
|
+
};
|
|
138662
|
+
const refreshedIsComplete = async () => {
|
|
138663
|
+
if (state.prdDirty)
|
|
138664
|
+
state = { ...state, prd: await loadPRD(ctx.prdPath), prdDirty: false };
|
|
138665
|
+
return isComplete(state.prd);
|
|
138666
|
+
};
|
|
138329
138667
|
let _executeThrew = false;
|
|
138330
138668
|
try {
|
|
138331
138669
|
if (isComplete(state.prd)) {
|
|
@@ -138351,7 +138689,9 @@ async function executeUnified(ctx, initialPrd) {
|
|
|
138351
138689
|
}, state.prd, await getRunNaxIgnoreIndex(state.prd), preRunPipeline);
|
|
138352
138690
|
}
|
|
138353
138691
|
await runWorkflowPreflightOnce(ctx, state.prd);
|
|
138354
|
-
|
|
138692
|
+
let limit = loopIterationLimit(state.prd, ctx.config, 0, null);
|
|
138693
|
+
let lastSignature;
|
|
138694
|
+
while (iterations < limit) {
|
|
138355
138695
|
iterations++;
|
|
138356
138696
|
if (Math.round(process.memoryUsage().heapUsed / 1024 / 1024) > 1024)
|
|
138357
138697
|
logger?.warn("execution", "High memory usage detected");
|
|
@@ -138368,18 +138708,12 @@ async function executeUnified(ctx, initialPrd) {
|
|
|
138368
138708
|
failed: storyCounts.failed,
|
|
138369
138709
|
total: storyCounts.total
|
|
138370
138710
|
});
|
|
138371
|
-
if (isComplete(state.prd))
|
|
138372
|
-
|
|
138373
|
-
|
|
138374
|
-
|
|
138375
|
-
|
|
138376
|
-
|
|
138377
|
-
}
|
|
138378
|
-
logger?.debug("execution", "Running deferred review");
|
|
138379
|
-
await runCompletionDeferredReview(naxIgnoreIndex);
|
|
138380
|
-
logger?.debug("execution", "Deferred review done \u2014 returning completed");
|
|
138381
|
-
return buildResult("completed");
|
|
138382
|
-
}
|
|
138711
|
+
if (isComplete(state.prd))
|
|
138712
|
+
return completeRun(naxIgnoreIndex);
|
|
138713
|
+
const guard = nextLoopGuard(ctx.config, state, iterations, lastSignature, limit);
|
|
138714
|
+
if (guard.stalled)
|
|
138715
|
+
break;
|
|
138716
|
+
({ limit, signature: lastSignature } = guard);
|
|
138383
138717
|
const costLimit = ctx.config.execution.costLimit;
|
|
138384
138718
|
const reportCost = (cost) => {
|
|
138385
138719
|
liveCost = cost;
|
|
@@ -138409,6 +138743,9 @@ async function executeUnified(ctx, initialPrd) {
|
|
|
138409
138743
|
if (seqStep.action === "return")
|
|
138410
138744
|
return buildResult(seqStep.exitReason);
|
|
138411
138745
|
}
|
|
138746
|
+
if (isWorkflowMode(ctx.config) && await refreshedIsComplete()) {
|
|
138747
|
+
return completeRun(await getRunNaxIgnoreIndex(state.prd));
|
|
138748
|
+
}
|
|
138412
138749
|
if (ctx.config.acceptance?.enabled) {
|
|
138413
138750
|
logger?.info("execution", "Running post-run pipeline (acceptance tests)");
|
|
138414
138751
|
await Promise.resolve().then(() => init_stages());
|
|
@@ -138432,6 +138769,7 @@ async function executeUnified(ctx, initialPrd) {
|
|
|
138432
138769
|
}, ctx.eventEmitter);
|
|
138433
138770
|
logPipelineOutcome(postRunResult, "Post-run pipeline (acceptance tests)");
|
|
138434
138771
|
}
|
|
138772
|
+
logIterationCapReached(state.prd, ctx.config, limit, iterations);
|
|
138435
138773
|
return buildResult("max-iterations");
|
|
138436
138774
|
} catch (err) {
|
|
138437
138775
|
_executeThrew = true;
|
|
@@ -138464,6 +138802,7 @@ var init_unified_executor = __esm(() => {
|
|
|
138464
138802
|
init_crash_recovery();
|
|
138465
138803
|
init_deferred_review();
|
|
138466
138804
|
init_escalation();
|
|
138805
|
+
init_iteration_bound();
|
|
138467
138806
|
init_iteration_runner();
|
|
138468
138807
|
init_pre_run();
|
|
138469
138808
|
init_story_selector();
|
|
@@ -144946,6 +145285,7 @@ class AskController {
|
|
|
144946
145285
|
mode;
|
|
144947
145286
|
open = new Map;
|
|
144948
145287
|
hosts = new Map;
|
|
145288
|
+
choices = new Map;
|
|
144949
145289
|
memory = new Set;
|
|
144950
145290
|
listeners = new Set;
|
|
144951
145291
|
constructor(options) {
|
|
@@ -144993,6 +145333,50 @@ class AskController {
|
|
|
144993
145333
|
this.changed();
|
|
144994
145334
|
return waiting.promise;
|
|
144995
145335
|
}
|
|
145336
|
+
requestHostChoice(card) {
|
|
145337
|
+
if (card.signal?.aborted)
|
|
145338
|
+
return Promise.resolve(card.fallback);
|
|
145339
|
+
const requestId = `host-choice-${++nextHostRequestId}`;
|
|
145340
|
+
const now = this.options.now?.() ?? new Date;
|
|
145341
|
+
const timeout = this.options.approvalTimeoutMs ?? DEFAULT_HOST_APPROVAL_TIMEOUT_MS;
|
|
145342
|
+
const waiting = Promise.withResolvers();
|
|
145343
|
+
const abort = () => this.resolveChoice(requestId, card.fallback);
|
|
145344
|
+
const timer = _askControllerDeps.setTimeout(abort, timeout);
|
|
145345
|
+
this.choices.set(requestId, {
|
|
145346
|
+
settle: waiting.resolve,
|
|
145347
|
+
fallback: card.fallback,
|
|
145348
|
+
cleanup: () => {
|
|
145349
|
+
_askControllerDeps.clearTimeout(timer);
|
|
145350
|
+
card.signal?.removeEventListener("abort", abort);
|
|
145351
|
+
}
|
|
145352
|
+
});
|
|
145353
|
+
this.open.set(requestId, {
|
|
145354
|
+
type: "host_choice",
|
|
145355
|
+
requestId,
|
|
145356
|
+
tool: card.tool,
|
|
145357
|
+
summary: card.summary,
|
|
145358
|
+
reason: card.reason,
|
|
145359
|
+
choices: card.choices,
|
|
145360
|
+
fallback: card.fallback,
|
|
145361
|
+
at: now.toISOString(),
|
|
145362
|
+
expiresAt: new Date(now.getTime() + timeout).toISOString()
|
|
145363
|
+
});
|
|
145364
|
+
card.signal?.addEventListener("abort", abort, { once: true });
|
|
145365
|
+
this.changed();
|
|
145366
|
+
return waiting.promise;
|
|
145367
|
+
}
|
|
145368
|
+
resolveChoice(requestId, id) {
|
|
145369
|
+
const request = this.choices.get(requestId);
|
|
145370
|
+
const event = this.open.get(requestId);
|
|
145371
|
+
if (!request || event?.type !== "host_choice")
|
|
145372
|
+
return;
|
|
145373
|
+
if (id !== request.fallback && !event.choices.some((choice) => choice.id === id))
|
|
145374
|
+
return;
|
|
145375
|
+
this.choices.delete(requestId);
|
|
145376
|
+
request.cleanup();
|
|
145377
|
+
request.settle(id);
|
|
145378
|
+
this.remove(requestId);
|
|
145379
|
+
}
|
|
144996
145380
|
handle(event) {
|
|
144997
145381
|
if ("requestId" in event && event.requestId.startsWith("host-"))
|
|
144998
145382
|
return;
|
|
@@ -145053,6 +145437,8 @@ class AskController {
|
|
|
145053
145437
|
reset() {
|
|
145054
145438
|
for (const requestId of [...this.hosts.keys()])
|
|
145055
145439
|
this.resolve(requestId, "deny");
|
|
145440
|
+
for (const [requestId, request] of [...this.choices])
|
|
145441
|
+
this.resolveChoice(requestId, request.fallback);
|
|
145056
145442
|
this.memory.clear();
|
|
145057
145443
|
if (this.open.size === 0)
|
|
145058
145444
|
return;
|
|
@@ -145319,9 +145705,37 @@ function withEffort2(model, level) {
|
|
|
145319
145705
|
const { model: base } = parseModelSpec(model);
|
|
145320
145706
|
return level === "default" ? base : `${base}[${level}]`;
|
|
145321
145707
|
}
|
|
145322
|
-
function
|
|
145323
|
-
|
|
145324
|
-
|
|
145708
|
+
function effortLevelsFor(supported) {
|
|
145709
|
+
if (supported === undefined)
|
|
145710
|
+
return EFFORT_LEVELS;
|
|
145711
|
+
return EFFORT_LEVELS.filter((level) => level === "default" || supported.includes(level));
|
|
145712
|
+
}
|
|
145713
|
+
function cycleEffort(level, step, levels = EFFORT_LEVELS) {
|
|
145714
|
+
const index = levels.indexOf(level);
|
|
145715
|
+
if (index >= 0)
|
|
145716
|
+
return levels[(index + step + levels.length) % levels.length] ?? "default";
|
|
145717
|
+
const rank = EFFORT_LEVELS.indexOf(level);
|
|
145718
|
+
return step === 1 ? levels.find((entry) => EFFORT_LEVELS.indexOf(entry) > rank) ?? levels[0] ?? "default" : levels.findLast((entry) => EFFORT_LEVELS.indexOf(entry) < rank) ?? levels.at(-1) ?? "default";
|
|
145719
|
+
}
|
|
145720
|
+
function clampEffort(level, levels) {
|
|
145721
|
+
if (levels.includes(level))
|
|
145722
|
+
return level;
|
|
145723
|
+
const rank = EFFORT_LEVELS.indexOf(level);
|
|
145724
|
+
let nearest = "default";
|
|
145725
|
+
let distance = Number.POSITIVE_INFINITY;
|
|
145726
|
+
for (const candidate of EFFORT_LEVELS) {
|
|
145727
|
+
if (candidate === "default" || !levels.includes(candidate))
|
|
145728
|
+
continue;
|
|
145729
|
+
const delta = Math.abs(EFFORT_LEVELS.indexOf(candidate) - rank);
|
|
145730
|
+
if (delta < distance) {
|
|
145731
|
+
nearest = candidate;
|
|
145732
|
+
distance = delta;
|
|
145733
|
+
}
|
|
145734
|
+
}
|
|
145735
|
+
return nearest;
|
|
145736
|
+
}
|
|
145737
|
+
function clampModelEffort(model, levels) {
|
|
145738
|
+
return withEffort2(model, clampEffort(modelEffort(model), levels));
|
|
145325
145739
|
}
|
|
145326
145740
|
var EFFORT_LEVELS;
|
|
145327
145741
|
var init_chat_effort = __esm(() => {
|
|
@@ -145333,8 +145747,337 @@ var init_chat_effort = __esm(() => {
|
|
|
145333
145747
|
];
|
|
145334
145748
|
});
|
|
145335
145749
|
|
|
145336
|
-
// src/chat/
|
|
145750
|
+
// src/chat/background/task-types.ts
|
|
145751
|
+
var TASK_ID_PATTERN;
|
|
145752
|
+
var init_task_types = __esm(() => {
|
|
145753
|
+
TASK_ID_PATTERN = /^bash-[0-9a-f]{8}$/;
|
|
145754
|
+
});
|
|
145755
|
+
|
|
145756
|
+
// src/chat/background/task-registry.ts
|
|
145757
|
+
import { appendFileSync as appendFileSync6, mkdirSync as mkdirSync9 } from "fs";
|
|
145337
145758
|
import { join as join181 } from "path";
|
|
145759
|
+
function terminalState(end) {
|
|
145760
|
+
if (end.aborted)
|
|
145761
|
+
return "stopped";
|
|
145762
|
+
if (end.launchError !== undefined)
|
|
145763
|
+
return "failed";
|
|
145764
|
+
return end.exitCode === 0 && !end.timedOut ? "succeeded" : "failed";
|
|
145765
|
+
}
|
|
145766
|
+
|
|
145767
|
+
class BackgroundTasks {
|
|
145768
|
+
options;
|
|
145769
|
+
entries = new Map;
|
|
145770
|
+
listeners = new Set;
|
|
145771
|
+
foregroundCalls = new Map;
|
|
145772
|
+
completions = new Set;
|
|
145773
|
+
unnoticed = new Map;
|
|
145774
|
+
notice;
|
|
145775
|
+
shuttingDown = false;
|
|
145776
|
+
constructor(options) {
|
|
145777
|
+
this.options = options;
|
|
145778
|
+
}
|
|
145779
|
+
emit() {
|
|
145780
|
+
for (const listener of [...this.listeners]) {
|
|
145781
|
+
try {
|
|
145782
|
+
listener();
|
|
145783
|
+
} catch (cause) {
|
|
145784
|
+
this.options.logger.warn("chat", "Background task lifecycle callback failed", { error: errorMessage(cause) });
|
|
145785
|
+
}
|
|
145786
|
+
}
|
|
145787
|
+
}
|
|
145788
|
+
onChange(listener) {
|
|
145789
|
+
this.listeners.add(listener);
|
|
145790
|
+
return () => {
|
|
145791
|
+
this.listeners.delete(listener);
|
|
145792
|
+
};
|
|
145793
|
+
}
|
|
145794
|
+
foreground(call) {
|
|
145795
|
+
const key = Symbol();
|
|
145796
|
+
this.foregroundCalls.set(key, call);
|
|
145797
|
+
this.emit();
|
|
145798
|
+
return () => {
|
|
145799
|
+
if (this.foregroundCalls.delete(key))
|
|
145800
|
+
this.emit();
|
|
145801
|
+
};
|
|
145802
|
+
}
|
|
145803
|
+
hasForeground() {
|
|
145804
|
+
return this.foregroundCalls.size > 0;
|
|
145805
|
+
}
|
|
145806
|
+
moveForeground() {
|
|
145807
|
+
const call = [...this.foregroundCalls.values()].at(-1);
|
|
145808
|
+
if (!call)
|
|
145809
|
+
return false;
|
|
145810
|
+
call.moveToBackground();
|
|
145811
|
+
return true;
|
|
145812
|
+
}
|
|
145813
|
+
peekNotice() {
|
|
145814
|
+
if (!this.notice && this.unnoticed.size > 0) {
|
|
145815
|
+
this.notice = {
|
|
145816
|
+
ids: [...this.unnoticed.keys()],
|
|
145817
|
+
text: buildBackgroundTaskNotice([...this.unnoticed.values()])
|
|
145818
|
+
};
|
|
145819
|
+
}
|
|
145820
|
+
return this.notice?.text;
|
|
145821
|
+
}
|
|
145822
|
+
takeNotice() {
|
|
145823
|
+
const text = this.peekNotice();
|
|
145824
|
+
for (const id of this.notice?.ids ?? [])
|
|
145825
|
+
this.unnoticed.delete(id);
|
|
145826
|
+
this.notice = undefined;
|
|
145827
|
+
return text;
|
|
145828
|
+
}
|
|
145829
|
+
stop(id) {
|
|
145830
|
+
const entry = this.entries.get(id);
|
|
145831
|
+
if (entry?.record.state !== "running") {
|
|
145832
|
+
throw new NaxError(`[chat] task ${id} is not running`, "CHAT_TASK_NOT_RUNNING", { stage: "chat", id });
|
|
145833
|
+
}
|
|
145834
|
+
entry.record = { ...entry.record, state: "stopped" };
|
|
145835
|
+
entry.handle.stop();
|
|
145836
|
+
return { ...entry.record };
|
|
145837
|
+
}
|
|
145838
|
+
async stopAll() {
|
|
145839
|
+
this.shuttingDown = true;
|
|
145840
|
+
for (const task of this.running())
|
|
145841
|
+
this.stop(task.id);
|
|
145842
|
+
while (this.completions.size > 0)
|
|
145843
|
+
await Promise.all([...this.completions]);
|
|
145844
|
+
}
|
|
145845
|
+
newId() {
|
|
145846
|
+
for (let attempt = 0;attempt < ID_ATTEMPTS; attempt++) {
|
|
145847
|
+
const id = `bash-${_backgroundTaskDeps.randomHex()}`;
|
|
145848
|
+
if (TASK_ID_PATTERN.test(id) && !this.entries.has(id))
|
|
145849
|
+
return id;
|
|
145850
|
+
}
|
|
145851
|
+
throw new NaxError("[chat] could not allocate a background task id", "CHAT_TASK_ID_FAILED", { stage: "chat" });
|
|
145852
|
+
}
|
|
145853
|
+
adopt(handle) {
|
|
145854
|
+
const id = this.newId();
|
|
145855
|
+
const entry = {
|
|
145856
|
+
record: {
|
|
145857
|
+
id,
|
|
145858
|
+
command: handle.command,
|
|
145859
|
+
description: handle.description,
|
|
145860
|
+
origin: handle.origin,
|
|
145861
|
+
startedAt: this.options.now().toISOString(),
|
|
145862
|
+
state: "running",
|
|
145863
|
+
logPath: join181(this.options.outputDir, "chat-tasks", `${id}.log`)
|
|
145864
|
+
},
|
|
145865
|
+
handle,
|
|
145866
|
+
pending: Promise.resolve(),
|
|
145867
|
+
bytes: 0,
|
|
145868
|
+
endsWithNewline: true,
|
|
145869
|
+
capped: false,
|
|
145870
|
+
logFailed: false
|
|
145871
|
+
};
|
|
145872
|
+
this.entries.set(id, entry);
|
|
145873
|
+
this.enqueue(entry, () => _backgroundTaskDeps.mkdir(join181(this.options.outputDir, "chat-tasks")));
|
|
145874
|
+
const completion = handle.ended.then((end) => {
|
|
145875
|
+
this.finalize(entry, end);
|
|
145876
|
+
this.completions.delete(completion);
|
|
145877
|
+
});
|
|
145878
|
+
this.completions.add(completion);
|
|
145879
|
+
if (this.shuttingDown)
|
|
145880
|
+
this.stop(id);
|
|
145881
|
+
this.emit();
|
|
145882
|
+
return {
|
|
145883
|
+
id,
|
|
145884
|
+
append: (_stream, chunk) => {
|
|
145885
|
+
if (entry.record.state === "running")
|
|
145886
|
+
this.append(entry, chunk);
|
|
145887
|
+
}
|
|
145888
|
+
};
|
|
145889
|
+
}
|
|
145890
|
+
enqueue(entry, action) {
|
|
145891
|
+
entry.pending = entry.pending.then(async () => {
|
|
145892
|
+
if (!entry.logFailed)
|
|
145893
|
+
await action();
|
|
145894
|
+
}).catch((cause) => {
|
|
145895
|
+
if (entry.logFailed)
|
|
145896
|
+
return;
|
|
145897
|
+
entry.logFailed = true;
|
|
145898
|
+
this.options.logger.warn("chat", "Background task logging failed; further output dropped", {
|
|
145899
|
+
id: entry.record.id,
|
|
145900
|
+
logPath: entry.record.logPath,
|
|
145901
|
+
error: errorMessage(cause)
|
|
145902
|
+
});
|
|
145903
|
+
});
|
|
145904
|
+
}
|
|
145905
|
+
append(entry, chunk) {
|
|
145906
|
+
if (entry.logFailed || entry.capped || chunk.byteLength === 0)
|
|
145907
|
+
return;
|
|
145908
|
+
const bytes = chunk.slice(0, TASK_LOG_MAX_BYTES - entry.bytes);
|
|
145909
|
+
entry.bytes += bytes.byteLength;
|
|
145910
|
+
entry.endsWithNewline = bytes[bytes.byteLength - 1] === NEWLINE_BYTE;
|
|
145911
|
+
this.enqueue(entry, () => _backgroundTaskDeps.appendLog(entry.record.logPath, bytes));
|
|
145912
|
+
if (entry.bytes === TASK_LOG_MAX_BYTES) {
|
|
145913
|
+
entry.capped = true;
|
|
145914
|
+
const marker = encoder.encode(`${entry.endsWithNewline ? "" : `
|
|
145915
|
+
`}${LOG_LIMIT_LINE}
|
|
145916
|
+
`);
|
|
145917
|
+
this.enqueue(entry, () => _backgroundTaskDeps.appendLog(entry.record.logPath, marker));
|
|
145918
|
+
}
|
|
145919
|
+
}
|
|
145920
|
+
finalize(entry, end) {
|
|
145921
|
+
entry.record = {
|
|
145922
|
+
...entry.record,
|
|
145923
|
+
state: entry.record.state === "stopped" ? "stopped" : terminalState(end),
|
|
145924
|
+
endedAt: this.options.now().toISOString(),
|
|
145925
|
+
exitCode: end.exitCode,
|
|
145926
|
+
...end.launchError !== undefined ? { note: end.launchError } : {}
|
|
145927
|
+
};
|
|
145928
|
+
const line = end.launchError !== undefined ? `[nax] launch failed: ${end.launchError}` : `[nax] exit code ${end.exitCode}`;
|
|
145929
|
+
this.append(entry, encoder.encode(`${entry.endsWithNewline ? "" : `
|
|
145930
|
+
`}${line}
|
|
145931
|
+
`));
|
|
145932
|
+
if (entry.record.state === "succeeded" || entry.record.state === "failed") {
|
|
145933
|
+
this.unnoticed.set(entry.record.id, entry.record);
|
|
145934
|
+
}
|
|
145935
|
+
this.emit();
|
|
145936
|
+
}
|
|
145937
|
+
list() {
|
|
145938
|
+
return [...this.entries.values()].reverse().map(({ record }) => ({ ...record }));
|
|
145939
|
+
}
|
|
145940
|
+
get(id) {
|
|
145941
|
+
const record = this.entries.get(id)?.record;
|
|
145942
|
+
return record ? { ...record } : undefined;
|
|
145943
|
+
}
|
|
145944
|
+
running() {
|
|
145945
|
+
return this.list().filter((task) => task.state === "running");
|
|
145946
|
+
}
|
|
145947
|
+
async output(id, lines = TASK_OUTPUT_DEFAULT_LINES) {
|
|
145948
|
+
const entry = this.entries.get(id);
|
|
145949
|
+
if (!entry || !Number.isFinite(lines) || lines < 1)
|
|
145950
|
+
return "";
|
|
145951
|
+
await entry.pending;
|
|
145952
|
+
try {
|
|
145953
|
+
const text = await _backgroundTaskDeps.readLog(entry.record.logPath);
|
|
145954
|
+
return text.replace(/\r?\n$/, "").split(/\r?\n/).slice(-Math.min(Math.floor(lines), TASK_OUTPUT_MAX_LINES)).join(`
|
|
145955
|
+
`);
|
|
145956
|
+
} catch (cause) {
|
|
145957
|
+
if (typeof cause === "object" && cause !== null && "code" in cause && cause.code === "ENOENT")
|
|
145958
|
+
return "";
|
|
145959
|
+
throw new NaxError(`[chat] could not read background task ${id} log`, "CHAT_TASK_READ_FAILED", {
|
|
145960
|
+
stage: "chat",
|
|
145961
|
+
id,
|
|
145962
|
+
cause
|
|
145963
|
+
});
|
|
145964
|
+
}
|
|
145965
|
+
}
|
|
145966
|
+
}
|
|
145967
|
+
function createBackgroundTasks(options) {
|
|
145968
|
+
return new BackgroundTasks(options);
|
|
145969
|
+
}
|
|
145970
|
+
var TASK_LOG_MAX_BYTES, TASK_OUTPUT_MAX_LINES = 500, TASK_OUTPUT_DEFAULT_LINES = 40, RANDOM_HEX_LENGTH = 8, ID_ATTEMPTS = 16, LOG_LIMIT_LINE = "[nax] log limit reached; further output dropped", encoder, NEWLINE_BYTE = 10, _backgroundTaskDeps;
|
|
145971
|
+
var init_task_registry = __esm(() => {
|
|
145972
|
+
init_internal();
|
|
145973
|
+
init_errors4();
|
|
145974
|
+
init_prompts();
|
|
145975
|
+
init_task_types();
|
|
145976
|
+
TASK_LOG_MAX_BYTES = 50 * 1024 * 1024;
|
|
145977
|
+
encoder = new TextEncoder;
|
|
145978
|
+
_backgroundTaskDeps = {
|
|
145979
|
+
randomHex: () => crypto.randomUUID().slice(0, RANDOM_HEX_LENGTH),
|
|
145980
|
+
mkdir: (path) => {
|
|
145981
|
+
mkdirSync9(path, { recursive: true });
|
|
145982
|
+
},
|
|
145983
|
+
appendLog: async (path, chunk) => {
|
|
145984
|
+
appendFileSync6(path, chunk);
|
|
145985
|
+
},
|
|
145986
|
+
readLog: (path) => Bun.file(path).text()
|
|
145987
|
+
};
|
|
145988
|
+
});
|
|
145989
|
+
|
|
145990
|
+
// src/chat/background/tasks-provider.ts
|
|
145991
|
+
function summary2(task) {
|
|
145992
|
+
const { id, command, state, startedAt, endedAt, exitCode } = task;
|
|
145993
|
+
return { id, command, state, startedAt, endedAt, exitCode };
|
|
145994
|
+
}
|
|
145995
|
+
async function inspectTask(name, tasks, input) {
|
|
145996
|
+
const id = input.task;
|
|
145997
|
+
if (typeof id !== "string" || !TASK_ID_PATTERN.test(id)) {
|
|
145998
|
+
return { isError: true, content: `[chat] invalid task id ${String(id)}` };
|
|
145999
|
+
}
|
|
146000
|
+
const task = tasks.get(id);
|
|
146001
|
+
if (!task)
|
|
146002
|
+
return { isError: true, content: `[chat] unknown task ${id}` };
|
|
146003
|
+
if (name === "stop") {
|
|
146004
|
+
if (task.state !== "running")
|
|
146005
|
+
return { isError: true, content: `[chat] task ${id} is not running` };
|
|
146006
|
+
tasks.stop(id);
|
|
146007
|
+
return { content: `stopped task ${id}` };
|
|
146008
|
+
}
|
|
146009
|
+
const lines = input.lines;
|
|
146010
|
+
if (lines !== undefined && (typeof lines !== "number" || !Number.isInteger(lines) || lines < 1 || lines > TASK_OUTPUT_MAX_LINES)) {
|
|
146011
|
+
return { isError: true, content: `[chat] lines must be an integer from 1 to ${TASK_OUTPUT_MAX_LINES}` };
|
|
146012
|
+
}
|
|
146013
|
+
return { content: JSON.stringify({ ...task, output: await tasks.output(id, lines) }) };
|
|
146014
|
+
}
|
|
146015
|
+
function taskTool(name, tasks) {
|
|
146016
|
+
return {
|
|
146017
|
+
localName: name,
|
|
146018
|
+
description: name === "output" ? "Read a bounded tail of a background command's output." : "Stop a background command started by this chat; no approval required.",
|
|
146019
|
+
inputSchema: {
|
|
146020
|
+
type: "object",
|
|
146021
|
+
properties: {
|
|
146022
|
+
task: { type: "string" },
|
|
146023
|
+
...name === "output" ? { lines: { type: "integer", minimum: 1, maximum: TASK_OUTPUT_MAX_LINES } } : {}
|
|
146024
|
+
},
|
|
146025
|
+
required: ["task"],
|
|
146026
|
+
additionalProperties: false
|
|
146027
|
+
},
|
|
146028
|
+
run: (input) => inspectTask(name, tasks, input)
|
|
146029
|
+
};
|
|
146030
|
+
}
|
|
146031
|
+
function createTasksProvider(tasks) {
|
|
146032
|
+
return {
|
|
146033
|
+
id: "nax-tasks",
|
|
146034
|
+
kind: "static",
|
|
146035
|
+
stages: ["*"],
|
|
146036
|
+
instructions: async () => buildBackgroundTasksInstructions(),
|
|
146037
|
+
tools: async () => [
|
|
146038
|
+
{
|
|
146039
|
+
localName: "list",
|
|
146040
|
+
description: "List this chat's background commands.",
|
|
146041
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
146042
|
+
run: async () => ({ content: JSON.stringify({ tasks: tasks.list().map(summary2) }) })
|
|
146043
|
+
},
|
|
146044
|
+
taskTool("output", tasks),
|
|
146045
|
+
taskTool("stop", tasks)
|
|
146046
|
+
]
|
|
146047
|
+
};
|
|
146048
|
+
}
|
|
146049
|
+
var init_tasks_provider = __esm(() => {
|
|
146050
|
+
init_prompts();
|
|
146051
|
+
init_task_registry();
|
|
146052
|
+
init_task_types();
|
|
146053
|
+
});
|
|
146054
|
+
|
|
146055
|
+
// src/chat/background/host-tasks.ts
|
|
146056
|
+
function createHostTasks(options) {
|
|
146057
|
+
const tasks = createBackgroundTasks(options);
|
|
146058
|
+
return { tasks, provider: createTasksProvider(tasks) };
|
|
146059
|
+
}
|
|
146060
|
+
var init_host_tasks = __esm(() => {
|
|
146061
|
+
init_task_registry();
|
|
146062
|
+
init_tasks_provider();
|
|
146063
|
+
});
|
|
146064
|
+
|
|
146065
|
+
// src/chat/background/tasks-listing.ts
|
|
146066
|
+
function formatTasksListing(tasks) {
|
|
146067
|
+
return tasks.map((task) => `${task.id} ${task.state} ${task.command}`).join(`
|
|
146068
|
+
`);
|
|
146069
|
+
}
|
|
146070
|
+
|
|
146071
|
+
// src/chat/background/index.ts
|
|
146072
|
+
var init_background = __esm(() => {
|
|
146073
|
+
init_host_tasks();
|
|
146074
|
+
init_task_registry();
|
|
146075
|
+
init_task_types();
|
|
146076
|
+
init_tasks_provider();
|
|
146077
|
+
});
|
|
146078
|
+
|
|
146079
|
+
// src/chat/chat-ledger.ts
|
|
146080
|
+
import { join as join182 } from "path";
|
|
145338
146081
|
function createChatLedger(options) {
|
|
145339
146082
|
const aggregators = new Map;
|
|
145340
146083
|
return {
|
|
@@ -145342,7 +146085,7 @@ function createChatLedger(options) {
|
|
|
145342
146085
|
const runId = `chat-${event.sessionId}-${options.startedAt.getTime()}`;
|
|
145343
146086
|
let aggregator = aggregators.get(runId);
|
|
145344
146087
|
if (!aggregator) {
|
|
145345
|
-
aggregator = new CostAggregator(runId,
|
|
146088
|
+
aggregator = new CostAggregator(runId, join182(options.outputDir, "cost"));
|
|
145346
146089
|
aggregators.set(runId, aggregator);
|
|
145347
146090
|
}
|
|
145348
146091
|
const exact = event.costSource !== "unpriced";
|
|
@@ -145419,6 +146162,20 @@ var init_chat_mode = __esm(() => {
|
|
|
145419
146162
|
});
|
|
145420
146163
|
|
|
145421
146164
|
// src/chat/chat-models.ts
|
|
146165
|
+
async function chatEffortLevels(input) {
|
|
146166
|
+
const bases = [...new Set(input.models.map((model) => parseModelSpec(model).model))];
|
|
146167
|
+
const entries = await Promise.all(bases.map(async (base) => {
|
|
146168
|
+
const split = base.indexOf("/");
|
|
146169
|
+
if (split <= 0)
|
|
146170
|
+
return;
|
|
146171
|
+
const provider = base.slice(0, split);
|
|
146172
|
+
const id = base.slice(split + 1);
|
|
146173
|
+
const override = input.config.agent?.native?.catalogOverrides?.find((entry) => entry.provider === provider)?.models.find((model) => model.id === id);
|
|
146174
|
+
const supported = override?.thinkingLevels ?? await input.lookupThinkingLevels(provider, id);
|
|
146175
|
+
return supported === undefined ? undefined : [base, effortLevelsFor(supported)];
|
|
146176
|
+
}));
|
|
146177
|
+
return new Map(entries.filter((entry) => entry !== undefined));
|
|
146178
|
+
}
|
|
145422
146179
|
function tierModels(config) {
|
|
145423
146180
|
const tiers = config.models.native;
|
|
145424
146181
|
const models = ["fast", "balanced", "powerful"].flatMap((tier) => {
|
|
@@ -145437,6 +146194,49 @@ async function chatModelChoices(input) {
|
|
|
145437
146194
|
} catch {}
|
|
145438
146195
|
return Object.freeze([...new Set(models)]);
|
|
145439
146196
|
}
|
|
146197
|
+
var init_chat_models = __esm(() => {
|
|
146198
|
+
init_src();
|
|
146199
|
+
init_chat_effort();
|
|
146200
|
+
});
|
|
146201
|
+
|
|
146202
|
+
// src/chat/close-confirm.ts
|
|
146203
|
+
async function cancelOwned(options, owned) {
|
|
146204
|
+
for (const job of owned) {
|
|
146205
|
+
try {
|
|
146206
|
+
await options.hostJobs?.jobs.cancel(job.id);
|
|
146207
|
+
} catch (cause) {
|
|
146208
|
+
options.logger.warn("chat", "Failed to cancel nax job on close", { jobId: job.id, error: errorMessage(cause) });
|
|
146209
|
+
}
|
|
146210
|
+
}
|
|
146211
|
+
}
|
|
146212
|
+
function createCloseConfirm(options) {
|
|
146213
|
+
return async () => {
|
|
146214
|
+
const owned = options.hostJobs?.jobs.owned() ?? [];
|
|
146215
|
+
const running = options.tasks?.running() ?? [];
|
|
146216
|
+
const decision = owned.length || running.length ? await options.asks.requestHostChoice({
|
|
146217
|
+
tool: "nax-close",
|
|
146218
|
+
summary: `${owned.length} nax job(s) and ${running.length} background command(s) still running: ${[...owned, ...running].map((item) => item.id).join(", ")}`,
|
|
146219
|
+
reason: "Background commands stop when the chat quits. Detached nax jobs can be left running.",
|
|
146220
|
+
fallback: "stay",
|
|
146221
|
+
choices: [
|
|
146222
|
+
{ id: "stop", label: "Quit and stop them" },
|
|
146223
|
+
...owned.length ? [{ id: "leave", label: "Quit and leave nax jobs running (background commands stop)" }] : [],
|
|
146224
|
+
{ id: "stay", label: "Stay in chat" }
|
|
146225
|
+
]
|
|
146226
|
+
}) : "stop";
|
|
146227
|
+
if (decision !== "stop" && decision !== "leave")
|
|
146228
|
+
return false;
|
|
146229
|
+
options.hostJobs?.chains.stop("the chat closed");
|
|
146230
|
+
await options.hostJobs?.jobs.stopLaunching();
|
|
146231
|
+
if (decision === "stop")
|
|
146232
|
+
await cancelOwned(options, options.hostJobs?.jobs.owned() ?? []);
|
|
146233
|
+
await options.tasks?.stopAll();
|
|
146234
|
+
return true;
|
|
146235
|
+
};
|
|
146236
|
+
}
|
|
146237
|
+
var init_close_confirm = __esm(() => {
|
|
146238
|
+
init_internal();
|
|
146239
|
+
});
|
|
145440
146240
|
|
|
145441
146241
|
// src/chat/jobs/chain-types.ts
|
|
145442
146242
|
var CHAIN_ID_PATTERN, CHAIN_MAX_STEPS = 6, CHAIN_CHECK_MAX_LENGTH = 200, CHAIN_PR_PLACEHOLDER = "<pr>";
|
|
@@ -145621,10 +146421,10 @@ var init_chain_argv = __esm(() => {
|
|
|
145621
146421
|
});
|
|
145622
146422
|
|
|
145623
146423
|
// src/chat/jobs/chain-store.ts
|
|
145624
|
-
import { linkSync as linkSync2, mkdirSync as
|
|
145625
|
-
import { join as
|
|
146424
|
+
import { linkSync as linkSync2, mkdirSync as mkdirSync10, renameSync as renameSync3, unlinkSync as unlinkSync2 } from "fs";
|
|
146425
|
+
import { join as join183 } from "path";
|
|
145626
146426
|
function chainsDir(outputDir) {
|
|
145627
|
-
return
|
|
146427
|
+
return join183(outputDir, CHAT_CHAINS_DIR);
|
|
145628
146428
|
}
|
|
145629
146429
|
function newChainId() {
|
|
145630
146430
|
return `chain-${_chainStoreDeps.randomHex()}`;
|
|
@@ -145640,11 +146440,11 @@ async function publishRecord(outputDir, chain, exclusive) {
|
|
|
145640
146440
|
throw new NaxError(`[chat] Invalid chain id: ${chain.id}`, "CHAT_CHAIN_INVALID_ID", { stage: "chat" });
|
|
145641
146441
|
}
|
|
145642
146442
|
const dir = chainsDir(outputDir);
|
|
145643
|
-
const temp =
|
|
146443
|
+
const temp = join183(dir, `${chain.id}.${_chainStoreDeps.randomUUID()}.tmp`);
|
|
145644
146444
|
try {
|
|
145645
146445
|
_chainStoreDeps.mkdir(dir, { recursive: true });
|
|
145646
146446
|
await _chainStoreDeps.write(temp, JSON.stringify(chain, null, 2));
|
|
145647
|
-
const destination =
|
|
146447
|
+
const destination = join183(dir, `${chain.id}.json`);
|
|
145648
146448
|
const published = publishTemp(temp, destination, exclusive);
|
|
145649
146449
|
if (exclusive) {
|
|
145650
146450
|
const cleanupCause = removeTemp(temp);
|
|
@@ -145694,18 +146494,18 @@ function removeTemp(path) {
|
|
|
145694
146494
|
}
|
|
145695
146495
|
return;
|
|
145696
146496
|
}
|
|
145697
|
-
var CHAT_CHAINS_DIR = "chat-chains",
|
|
146497
|
+
var CHAT_CHAINS_DIR = "chat-chains", RANDOM_HEX_LENGTH2 = 8, _chainStoreDeps;
|
|
145698
146498
|
var init_chain_store = __esm(() => {
|
|
145699
146499
|
init_internal();
|
|
145700
146500
|
init_errors4();
|
|
145701
146501
|
init_logger2();
|
|
145702
146502
|
init_chain_types();
|
|
145703
146503
|
_chainStoreDeps = {
|
|
145704
|
-
randomHex: () => crypto.randomUUID().slice(0,
|
|
146504
|
+
randomHex: () => crypto.randomUUID().slice(0, RANDOM_HEX_LENGTH2),
|
|
145705
146505
|
randomUUID: () => crypto.randomUUID(),
|
|
145706
146506
|
file: Bun.file,
|
|
145707
146507
|
write: Bun.write,
|
|
145708
|
-
mkdir:
|
|
146508
|
+
mkdir: mkdirSync10,
|
|
145709
146509
|
rename: renameSync3,
|
|
145710
146510
|
link: linkSync2,
|
|
145711
146511
|
unlink: unlinkSync2
|
|
@@ -145940,7 +146740,7 @@ var init_chain_controller = __esm(() => {
|
|
|
145940
146740
|
});
|
|
145941
146741
|
|
|
145942
146742
|
// src/execution/status-file-read.ts
|
|
145943
|
-
import { join as
|
|
146743
|
+
import { join as join184 } from "path";
|
|
145944
146744
|
async function readStatusFileAt(path) {
|
|
145945
146745
|
try {
|
|
145946
146746
|
const raw = await _statusFileReadDeps.file(path).json();
|
|
@@ -145950,7 +146750,7 @@ async function readStatusFileAt(path) {
|
|
|
145950
146750
|
}
|
|
145951
146751
|
}
|
|
145952
146752
|
function readStatusFile(featureDir) {
|
|
145953
|
-
return readStatusFileAt(
|
|
146753
|
+
return readStatusFileAt(join184(featureDir, "status.json"));
|
|
145954
146754
|
}
|
|
145955
146755
|
function isUsableStatusFile(value) {
|
|
145956
146756
|
if (typeof value !== "object" || value === null)
|
|
@@ -145989,7 +146789,7 @@ var init_status_file_read = __esm(() => {
|
|
|
145989
146789
|
});
|
|
145990
146790
|
|
|
145991
146791
|
// src/chat/jobs/job-outcome.ts
|
|
145992
|
-
import { join as
|
|
146792
|
+
import { join as join185 } from "path";
|
|
145993
146793
|
function projectProgress(status) {
|
|
145994
146794
|
return {
|
|
145995
146795
|
cost: status.cost.spent,
|
|
@@ -146024,7 +146824,7 @@ function runOutcome(status, job, exitCode) {
|
|
|
146024
146824
|
}
|
|
146025
146825
|
async function planOutcome(job, repoRoot) {
|
|
146026
146826
|
try {
|
|
146027
|
-
const record = await _jobOutcomeDeps.stat(
|
|
146827
|
+
const record = await _jobOutcomeDeps.stat(join185(featureDir(repoRoot, job.target), "prd.json"));
|
|
146028
146828
|
if (record.mtimeMs >= Date.parse(job.startedAt))
|
|
146029
146829
|
return { state: "succeeded" };
|
|
146030
146830
|
} catch (error) {
|
|
@@ -146063,13 +146863,13 @@ var init_job_types = __esm(() => {
|
|
|
146063
146863
|
});
|
|
146064
146864
|
|
|
146065
146865
|
// src/chat/jobs/job-store.ts
|
|
146066
|
-
import { mkdirSync as
|
|
146067
|
-
import { join as
|
|
146866
|
+
import { mkdirSync as mkdirSync11, readdirSync as readdirSync5, renameSync as renameSync4, unlinkSync as unlinkSync3 } from "fs";
|
|
146867
|
+
import { join as join186 } from "path";
|
|
146068
146868
|
function jobsDir(outputDir) {
|
|
146069
|
-
return
|
|
146869
|
+
return join186(outputDir, CHAT_JOBS_DIR);
|
|
146070
146870
|
}
|
|
146071
146871
|
function jobLogPath(outputDir, id) {
|
|
146072
|
-
return
|
|
146872
|
+
return join186(jobsDir(outputDir), `${id}.log`);
|
|
146073
146873
|
}
|
|
146074
146874
|
function newJobId(kind) {
|
|
146075
146875
|
return `${kind}-${_jobStoreDeps.randomHex()}`;
|
|
@@ -146079,11 +146879,11 @@ async function writeJobRecord(outputDir, job) {
|
|
|
146079
146879
|
throw new NaxError(`[chat-jobs] Invalid job id: ${job.id}`, "CHAT_JOB_INVALID_ID", { stage: "chat-jobs" });
|
|
146080
146880
|
}
|
|
146081
146881
|
const dir = jobsDir(outputDir);
|
|
146082
|
-
const temp =
|
|
146882
|
+
const temp = join186(dir, `${job.id}.${_jobStoreDeps.randomUUID()}.tmp`);
|
|
146083
146883
|
try {
|
|
146084
146884
|
_jobStoreDeps.mkdir(dir, { recursive: true });
|
|
146085
146885
|
await _jobStoreDeps.write(temp, JSON.stringify(job, null, 2));
|
|
146086
|
-
_jobStoreDeps.rename(temp,
|
|
146886
|
+
_jobStoreDeps.rename(temp, join186(dir, `${job.id}.json`));
|
|
146087
146887
|
} catch (cause) {
|
|
146088
146888
|
const cleanupCause = removeTemp2(temp);
|
|
146089
146889
|
throw new NaxError(`[chat-jobs] Failed to write job ${job.id}`, "CHAT_JOB_WRITE_FAILED", {
|
|
@@ -146132,21 +146932,21 @@ async function readJobRecords(outputDir) {
|
|
|
146132
146932
|
return [];
|
|
146133
146933
|
throw err;
|
|
146134
146934
|
}
|
|
146135
|
-
const records = await Promise.all(names.filter((name) => name.endsWith(".json")).map((name) => readRecord(
|
|
146935
|
+
const records = await Promise.all(names.filter((name) => name.endsWith(".json")).map((name) => readRecord(join186(dir, name))));
|
|
146136
146936
|
return records.filter((record) => record !== null).sort((a, b) => b.startedAt.localeCompare(a.startedAt));
|
|
146137
146937
|
}
|
|
146138
|
-
var CHAT_JOBS_DIR = "chat-jobs",
|
|
146938
|
+
var CHAT_JOBS_DIR = "chat-jobs", RANDOM_HEX_LENGTH3 = 8, JOB_KINDS, JOB_STATES, _jobStoreDeps;
|
|
146139
146939
|
var init_job_store = __esm(() => {
|
|
146140
146940
|
init_errors4();
|
|
146141
146941
|
init_job_types();
|
|
146142
146942
|
JOB_KINDS = ["plan", "run", "bot_review", "bot_fix"];
|
|
146143
146943
|
JOB_STATES = ["running", "succeeded", "failed", "cancelled", "lost"];
|
|
146144
146944
|
_jobStoreDeps = {
|
|
146145
|
-
randomHex: () => crypto.randomUUID().slice(0,
|
|
146945
|
+
randomHex: () => crypto.randomUUID().slice(0, RANDOM_HEX_LENGTH3),
|
|
146146
146946
|
randomUUID: () => crypto.randomUUID(),
|
|
146147
146947
|
file: Bun.file,
|
|
146148
146948
|
write: Bun.write,
|
|
146149
|
-
mkdir:
|
|
146949
|
+
mkdir: mkdirSync11,
|
|
146150
146950
|
readdir: readdirSync5,
|
|
146151
146951
|
rename: renameSync4,
|
|
146152
146952
|
unlink: unlinkSync3
|
|
@@ -146154,7 +146954,7 @@ var init_job_store = __esm(() => {
|
|
|
146154
146954
|
});
|
|
146155
146955
|
|
|
146156
146956
|
// src/chat/jobs/job-runner.ts
|
|
146157
|
-
import { closeSync, mkdirSync as
|
|
146957
|
+
import { closeSync, mkdirSync as mkdirSync12, openSync } from "fs";
|
|
146158
146958
|
|
|
146159
146959
|
class DetachedJobs {
|
|
146160
146960
|
options;
|
|
@@ -146170,6 +146970,8 @@ class DetachedJobs {
|
|
|
146170
146970
|
mutations = new Map;
|
|
146171
146971
|
polling = false;
|
|
146172
146972
|
disposed = false;
|
|
146973
|
+
launchesClosed = false;
|
|
146974
|
+
launches = new Set;
|
|
146173
146975
|
constructor(options) {
|
|
146174
146976
|
this.options = options;
|
|
146175
146977
|
}
|
|
@@ -146201,6 +147003,22 @@ class DetachedJobs {
|
|
|
146201
147003
|
}
|
|
146202
147004
|
}
|
|
146203
147005
|
async start(request) {
|
|
147006
|
+
if (this.launchesClosed) {
|
|
147007
|
+
throw new NaxError("[chat] the chat closed; cannot start a nax job", "CHAT_JOB_CLOSED", { stage: "chat" });
|
|
147008
|
+
}
|
|
147009
|
+
const launch = this.launch(request);
|
|
147010
|
+
this.launches.add(launch);
|
|
147011
|
+
try {
|
|
147012
|
+
return await launch;
|
|
147013
|
+
} finally {
|
|
147014
|
+
this.launches.delete(launch);
|
|
147015
|
+
}
|
|
147016
|
+
}
|
|
147017
|
+
async stopLaunching() {
|
|
147018
|
+
this.launchesClosed = true;
|
|
147019
|
+
await Promise.allSettled([...this.launches]);
|
|
147020
|
+
}
|
|
147021
|
+
async launch(request) {
|
|
146204
147022
|
const id = newJobId(request.kind);
|
|
146205
147023
|
const logPath = jobLogPath(this.options.outputDir, id);
|
|
146206
147024
|
let child;
|
|
@@ -146508,7 +147326,7 @@ var init_job_runner = __esm(() => {
|
|
|
146508
147326
|
clearTimeout: (handle) => globalThis.clearTimeout(handle),
|
|
146509
147327
|
openLog: (path) => openSync(path, "a"),
|
|
146510
147328
|
closeLog: (fd) => closeSync(fd),
|
|
146511
|
-
mkdir:
|
|
147329
|
+
mkdir: mkdirSync12,
|
|
146512
147330
|
readLog: (path) => Bun.file(path).text()
|
|
146513
147331
|
};
|
|
146514
147332
|
});
|
|
@@ -146540,10 +147358,10 @@ var init_job_write_guard = __esm(() => {
|
|
|
146540
147358
|
});
|
|
146541
147359
|
|
|
146542
147360
|
// src/chat/jobs/jobs-launch.ts
|
|
146543
|
-
import { join as
|
|
147361
|
+
import { join as join187, relative as relative50 } from "path";
|
|
146544
147362
|
async function lockHolder(repoRoot) {
|
|
146545
147363
|
try {
|
|
146546
|
-
const raw = await _jobsLaunchDeps.readLock(
|
|
147364
|
+
const raw = await _jobsLaunchDeps.readLock(join187(repoRoot, "nax.lock"));
|
|
146547
147365
|
if (typeof raw !== "object" || raw === null || !("pid" in raw))
|
|
146548
147366
|
return null;
|
|
146549
147367
|
const { pid } = raw;
|
|
@@ -146623,7 +147441,7 @@ async function preparePlan(input, options) {
|
|
|
146623
147441
|
}
|
|
146624
147442
|
async function resolvePlanSpec(feature, requestedSpec, options) {
|
|
146625
147443
|
const dir = featureDir(options.repoRoot, feature);
|
|
146626
|
-
const candidates = requestedSpec === undefined ? [
|
|
147444
|
+
const candidates = requestedSpec === undefined ? [join187(dir, "spec.md"), join187(options.repoRoot, ".nax", "specs", `${feature}.md`)] : [join187(options.repoRoot, requestedSpec)];
|
|
146627
147445
|
let spec;
|
|
146628
147446
|
for (const path of candidates) {
|
|
146629
147447
|
if (await _jobsLaunchDeps.exists(path)) {
|
|
@@ -146636,10 +147454,10 @@ async function resolvePlanSpec(feature, requestedSpec, options) {
|
|
|
146636
147454
|
error: `[chat] no spec for ${feature}; looked for ${candidates.map((p) => relative50(options.repoRoot, p)).join(", ")}`
|
|
146637
147455
|
};
|
|
146638
147456
|
}
|
|
146639
|
-
return { spec, prdExists: await _jobsLaunchDeps.exists(
|
|
147457
|
+
return { spec, prdExists: await _jobsLaunchDeps.exists(join187(dir, "prd.json")) };
|
|
146640
147458
|
}
|
|
146641
147459
|
async function prepareRun(input, options) {
|
|
146642
|
-
const path =
|
|
147460
|
+
const path = join187(featureDir(options.repoRoot, input.feature), "prd.json");
|
|
146643
147461
|
if (!await _jobsLaunchDeps.exists(path)) {
|
|
146644
147462
|
return { error: `[chat] no prd.json for ${input.feature}; run nax plan first` };
|
|
146645
147463
|
}
|
|
@@ -146650,13 +147468,16 @@ async function prepareRun(input, options) {
|
|
|
146650
147468
|
return { error: `[chat] prd.json for ${input.feature} is unreadable: ${errorMessage(cause)}` };
|
|
146651
147469
|
}
|
|
146652
147470
|
const { pending, total } = countStories(prd);
|
|
146653
|
-
const limit = input.maxIterations ?? options.maxIterations;
|
|
146654
|
-
const details = [
|
|
146655
|
-
|
|
147471
|
+
const limit = options.maxIterations === undefined ? undefined : input.maxIterations ?? options.maxIterations;
|
|
147472
|
+
const details = [
|
|
147473
|
+
limit === undefined ? `stories ${pending} pending of ${total}` : `stories ${pending} pending of ${total}; max iterations ${limit}`
|
|
147474
|
+
];
|
|
147475
|
+
const overLimit = limit !== undefined && pending > limit ? { pending, limit } : undefined;
|
|
147476
|
+
if (overLimit)
|
|
146656
147477
|
details.push(`warning: ${pending} stories pending but max iterations is ${limit}; pass maxIterations (nax#2706)`);
|
|
146657
147478
|
if (options.interactionPlugin === "cli")
|
|
146658
147479
|
details.push("warning: this run has no channel for its own asks; they will time out");
|
|
146659
|
-
return { input, details, ...
|
|
147480
|
+
return { input, details, ...overLimit ? { overLimit } : {} };
|
|
146660
147481
|
}
|
|
146661
147482
|
async function prepareTarget(input, options) {
|
|
146662
147483
|
if ("feature" in input) {
|
|
@@ -146670,7 +147491,7 @@ async function prepareTarget(input, options) {
|
|
|
146670
147491
|
return preparePlan(input, options);
|
|
146671
147492
|
if (input.kind === "run")
|
|
146672
147493
|
return prepareRun(input, options);
|
|
146673
|
-
if (input.kind === "bot_review" && input.decisions !== undefined && !await _jobsLaunchDeps.exists(
|
|
147494
|
+
if (input.kind === "bot_review" && input.decisions !== undefined && !await _jobsLaunchDeps.exists(join187(options.repoRoot, input.decisions))) {
|
|
146674
147495
|
return { error: `[chat] decisions file ${input.decisions} not found` };
|
|
146675
147496
|
}
|
|
146676
147497
|
return { input, details: [] };
|
|
@@ -146954,7 +147775,7 @@ var init_chain_tools = __esm(() => {
|
|
|
146954
147775
|
});
|
|
146955
147776
|
|
|
146956
147777
|
// src/chat/jobs/jobs-provider.ts
|
|
146957
|
-
function
|
|
147778
|
+
function summary3(job) {
|
|
146958
147779
|
const { id, kind, target, state, startedAt, endedAt, progress, cost, note } = job;
|
|
146959
147780
|
return { id, kind, target, state, startedAt, endedAt, progress, cost, note };
|
|
146960
147781
|
}
|
|
@@ -146989,7 +147810,7 @@ function inspectionTool(name, options) {
|
|
|
146989
147810
|
const jobs = options.jobs.list();
|
|
146990
147811
|
return {
|
|
146991
147812
|
content: JSON.stringify({
|
|
146992
|
-
jobs: jobs.slice(0, JOBS_LIST_LIMIT).map(
|
|
147813
|
+
jobs: jobs.slice(0, JOBS_LIST_LIMIT).map(summary3),
|
|
146993
147814
|
omitted: Math.max(0, jobs.length - JOBS_LIST_LIMIT),
|
|
146994
147815
|
...options.chains ? { chain: options.chains.summary() } : {}
|
|
146995
147816
|
})
|
|
@@ -147075,7 +147896,7 @@ function createHostJobs(options) {
|
|
|
147075
147896
|
jobs,
|
|
147076
147897
|
chains,
|
|
147077
147898
|
approve,
|
|
147078
|
-
maxIterations: options.config.execution.maxIterations,
|
|
147899
|
+
maxIterations: isWorkflowMode(options.config) ? undefined : options.config.execution.maxIterations,
|
|
147079
147900
|
interactionPlugin: options.config.interaction?.plugin ?? "cli"
|
|
147080
147901
|
});
|
|
147081
147902
|
const close = () => {
|
|
@@ -147086,38 +147907,17 @@ function createHostJobs(options) {
|
|
|
147086
147907
|
sessionGeneration++;
|
|
147087
147908
|
chains.stop("chat session changed");
|
|
147088
147909
|
};
|
|
147089
|
-
const confirmClose = async () => {
|
|
147090
|
-
close();
|
|
147091
|
-
const owned = jobs.owned();
|
|
147092
|
-
if (!owned.length)
|
|
147093
|
-
return;
|
|
147094
|
-
const decision = await approve({
|
|
147095
|
-
tool: "nax-jobs__close",
|
|
147096
|
-
summary: `${owned.length} nax job(s) still running: ${owned.map((job) => job.id).join(", ")}`,
|
|
147097
|
-
reason: "Yes cancels them. No keeps them running in the background; a later nax chat in this repo picks them up."
|
|
147098
|
-
});
|
|
147099
|
-
if (decision !== "allow")
|
|
147100
|
-
return;
|
|
147101
|
-
for (const job of owned) {
|
|
147102
|
-
try {
|
|
147103
|
-
await jobs.cancel(job.id);
|
|
147104
|
-
} catch (cause) {
|
|
147105
|
-
options.logger.warn("chat", "Failed to cancel nax job on close", { jobId: job.id, error: errorMessage(cause) });
|
|
147106
|
-
}
|
|
147107
|
-
}
|
|
147108
|
-
};
|
|
147109
147910
|
return {
|
|
147110
147911
|
jobs,
|
|
147111
147912
|
chains,
|
|
147112
147913
|
provider,
|
|
147113
147914
|
guard: createJobWriteGuard(jobs, options.repoRoot),
|
|
147114
|
-
confirmClose,
|
|
147115
147915
|
close,
|
|
147116
147916
|
sessionChanged
|
|
147117
147917
|
};
|
|
147118
147918
|
}
|
|
147119
147919
|
var init_jobs_host = __esm(() => {
|
|
147120
|
-
|
|
147920
|
+
init_config();
|
|
147121
147921
|
init_chain_controller();
|
|
147122
147922
|
init_job_runner();
|
|
147123
147923
|
init_job_write_guard();
|
|
@@ -147234,7 +148034,12 @@ async function sessionOptions(request, {
|
|
|
147234
148034
|
return {
|
|
147235
148035
|
backend: deps.nativeBackend({
|
|
147236
148036
|
...chatBackendPosture(mode, request.config, posture),
|
|
147237
|
-
...commandShadow !== undefined
|
|
148037
|
+
...commandShadow !== undefined || request.backgroundCommands !== undefined ? {
|
|
148038
|
+
hostPorts: {
|
|
148039
|
+
...commandShadow !== undefined ? { commandShadow } : {},
|
|
148040
|
+
...request.backgroundCommands !== undefined ? { backgroundCommands: request.backgroundCommands } : {}
|
|
148041
|
+
}
|
|
148042
|
+
} : {},
|
|
147238
148043
|
model: meta.model,
|
|
147239
148044
|
bashApproval: meta.bashApproval,
|
|
147240
148045
|
allowUnsandboxed: true,
|
|
@@ -147725,7 +148530,8 @@ class NativeChatHost {
|
|
|
147725
148530
|
models;
|
|
147726
148531
|
asks;
|
|
147727
148532
|
jobs;
|
|
147728
|
-
|
|
148533
|
+
tasks;
|
|
148534
|
+
confirmBeforeClose;
|
|
147729
148535
|
hostJobs;
|
|
147730
148536
|
fallback;
|
|
147731
148537
|
hygiene;
|
|
@@ -147774,7 +148580,6 @@ class NativeChatHost {
|
|
|
147774
148580
|
}) : undefined;
|
|
147775
148581
|
this.hostJobs = hostJobs;
|
|
147776
148582
|
this.jobs = hostJobs?.jobs;
|
|
147777
|
-
this.confirmJobsBeforeClose = hostJobs?.confirmClose;
|
|
147778
148583
|
const rules = deps.config.context.rules;
|
|
147779
148584
|
this.loopHandlers = Object.freeze([
|
|
147780
148585
|
...deps.resources?.pluginHandlers ?? [],
|
|
@@ -147799,9 +148604,15 @@ class NativeChatHost {
|
|
|
147799
148604
|
ledger: () => this.ledger,
|
|
147800
148605
|
turnListener: () => this.turnListener
|
|
147801
148606
|
});
|
|
147802
|
-
const
|
|
148607
|
+
const hostTasks = createHostTasks({ outputDir: this.outputDir, now: deps.now, logger: deps.logger });
|
|
148608
|
+
this.tasks = hostTasks.tasks;
|
|
148609
|
+
const providers = [...resources.toolProviders, ...hostJobs ? [hostJobs.provider] : [], hostTasks.provider];
|
|
147803
148610
|
this.toolProviders = resources.catalog.agents.length ? [...providers, createAgentsProvider({ catalog: resources.catalog, run: this.runs.run })] : providers;
|
|
147804
148611
|
}
|
|
148612
|
+
if (hostJobs || this.tasks) {
|
|
148613
|
+
const closeOptions = { hostJobs, tasks: this.tasks, asks: this.asks, logger: deps.logger };
|
|
148614
|
+
this.confirmBeforeClose = createCloseConfirm(closeOptions);
|
|
148615
|
+
}
|
|
147805
148616
|
this.fallback = createAskFallback({
|
|
147806
148617
|
controller: this.asks,
|
|
147807
148618
|
chain: deps.chain,
|
|
@@ -147819,6 +148630,9 @@ class NativeChatHost {
|
|
|
147819
148630
|
throw new NaxError("[chat] no session is open", "CHAT_SESSION_NOT_OPEN", { stage: "chat" });
|
|
147820
148631
|
return this.handle;
|
|
147821
148632
|
}
|
|
148633
|
+
effortLevels(model) {
|
|
148634
|
+
return this.deps.effortLevels?.get(withEffort2(model, "default")) ?? EFFORT_LEVELS;
|
|
148635
|
+
}
|
|
147822
148636
|
history() {
|
|
147823
148637
|
return this.handle?.history ?? { messages: [] };
|
|
147824
148638
|
}
|
|
@@ -147880,7 +148694,8 @@ class NativeChatHost {
|
|
|
147880
148694
|
repoRoot: this.repoRoot,
|
|
147881
148695
|
config: this.deps.config,
|
|
147882
148696
|
loopHandlers: this.loopHandlers,
|
|
147883
|
-
...this.toolProviders ? { toolProviders: this.toolProviders } : {}
|
|
148697
|
+
...this.toolProviders ? { toolProviders: this.toolProviders } : {},
|
|
148698
|
+
...this.tasks ? { backgroundCommands: this.tasks } : {}
|
|
147884
148699
|
});
|
|
147885
148700
|
await this.replace(next);
|
|
147886
148701
|
await this.jobs?.attach();
|
|
@@ -147960,6 +148775,7 @@ class NativeChatHost {
|
|
|
147960
148775
|
config: this.deps.config,
|
|
147961
148776
|
loopHandlers: this.loopHandlers,
|
|
147962
148777
|
...this.toolProviders ? { toolProviders: this.toolProviders } : {},
|
|
148778
|
+
...this.tasks ? { backgroundCommands: this.tasks } : {},
|
|
147963
148779
|
resumeId: id
|
|
147964
148780
|
});
|
|
147965
148781
|
} catch (error) {
|
|
@@ -147990,7 +148806,8 @@ class NativeChatHost {
|
|
|
147990
148806
|
repoRoot: this.repoRoot,
|
|
147991
148807
|
config: this.deps.config,
|
|
147992
148808
|
loopHandlers: this.loopHandlers,
|
|
147993
|
-
...this.toolProviders ? { toolProviders: this.toolProviders } : {}
|
|
148809
|
+
...this.toolProviders ? { toolProviders: this.toolProviders } : {},
|
|
148810
|
+
...this.tasks ? { backgroundCommands: this.tasks } : {}
|
|
147994
148811
|
});
|
|
147995
148812
|
return {
|
|
147996
148813
|
...next,
|
|
@@ -148009,7 +148826,8 @@ class NativeChatHost {
|
|
|
148009
148826
|
async switchSession(input) {
|
|
148010
148827
|
const previous = this.requireHandle();
|
|
148011
148828
|
const from = this.current();
|
|
148012
|
-
const
|
|
148829
|
+
const model = input.model === undefined ? from.model : clampModelEffort(input.model, this.effortLevels(input.model));
|
|
148830
|
+
const target = { mode: input.mode ?? from.mode, model };
|
|
148013
148831
|
if (target.mode === from.mode && target.model === from.model)
|
|
148014
148832
|
return;
|
|
148015
148833
|
try {
|
|
@@ -148119,7 +148937,11 @@ class NativeChatHost {
|
|
|
148119
148937
|
await this.hygiene.close(this.handle);
|
|
148120
148938
|
} finally {
|
|
148121
148939
|
try {
|
|
148122
|
-
|
|
148940
|
+
try {
|
|
148941
|
+
await this.tasks?.stopAll();
|
|
148942
|
+
} finally {
|
|
148943
|
+
await this.deps.resources?.teardown();
|
|
148944
|
+
}
|
|
148123
148945
|
} finally {
|
|
148124
148946
|
await this.deps.chain?.destroy();
|
|
148125
148947
|
}
|
|
@@ -148139,9 +148961,13 @@ var init_chat_host = __esm(() => {
|
|
|
148139
148961
|
init_agents_provider();
|
|
148140
148962
|
init_ask_controller();
|
|
148141
148963
|
init_ask_fallback();
|
|
148964
|
+
init_background();
|
|
148142
148965
|
init_chat_agents_listing();
|
|
148966
|
+
init_chat_effort();
|
|
148143
148967
|
init_chat_ledger();
|
|
148144
148968
|
init_chat_mode();
|
|
148969
|
+
init_chat_models();
|
|
148970
|
+
init_close_confirm();
|
|
148145
148971
|
init_jobs();
|
|
148146
148972
|
init_open_chat_session();
|
|
148147
148973
|
init_subagent_runs();
|
|
@@ -148222,7 +149048,13 @@ var init_chat_mcp = __esm(() => {
|
|
|
148222
149048
|
init_mcp2();
|
|
148223
149049
|
init_resources();
|
|
148224
149050
|
CHAT_MCP_RETRY = { maxAttempts: 1, baseDelayMs: 0 };
|
|
148225
|
-
RESERVED_SERVER_IDS = new Set([
|
|
149051
|
+
RESERVED_SERVER_IDS = new Set([
|
|
149052
|
+
"nax-skills",
|
|
149053
|
+
"nax-agents",
|
|
149054
|
+
"nax-workflow",
|
|
149055
|
+
"nax-jobs",
|
|
149056
|
+
"nax-tasks"
|
|
149057
|
+
]);
|
|
148226
149058
|
_chatMcpDeps = {
|
|
148227
149059
|
createMcpPool,
|
|
148228
149060
|
createMcpProviders,
|
|
@@ -148392,16 +149224,16 @@ var init_run_verdict = __esm(() => {
|
|
|
148392
149224
|
|
|
148393
149225
|
// src/chat/workflow/feature-state.ts
|
|
148394
149226
|
import { readdirSync as readdirSync6 } from "fs";
|
|
148395
|
-
import { join as
|
|
149227
|
+
import { join as join188, relative as relative51 } from "path";
|
|
148396
149228
|
async function readFeatureState(name, options) {
|
|
148397
149229
|
const dir = featureDir(options.repoRoot, name);
|
|
148398
149230
|
const warnings = [];
|
|
148399
149231
|
const [spec, prd, status] = await Promise.all([
|
|
148400
149232
|
readSpec(name, options.repoRoot),
|
|
148401
|
-
readPrd(
|
|
149233
|
+
readPrd(join188(dir, "prd.json"), warnings),
|
|
148402
149234
|
readStatusFile(dir)
|
|
148403
149235
|
]);
|
|
148404
|
-
if (prd && prd.pending > options.maxIterations) {
|
|
149236
|
+
if (prd && options.maxIterations !== undefined && prd.pending > options.maxIterations) {
|
|
148405
149237
|
warnings.push(`prd has ${prd.pending} stories left but execution.maxIterations is ${options.maxIterations}; pass -m ${prd.pending} to nax run (nax#2706)`);
|
|
148406
149238
|
}
|
|
148407
149239
|
const run = status ? {
|
|
@@ -148461,7 +149293,7 @@ function isMissingFile(err) {
|
|
|
148461
149293
|
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
148462
149294
|
}
|
|
148463
149295
|
function readLastRunLog(name, outputDir) {
|
|
148464
|
-
const names = directoryEntries(
|
|
149296
|
+
const names = directoryEntries(join188(outputDir, "features", name, "runs")).filter((e) => e.isFile() && e.name.endsWith(".jsonl") && e.name !== "latest.jsonl").map((e) => e.name).sort().reverse();
|
|
148465
149297
|
return names[0]?.slice(0, -".jsonl".length) ?? null;
|
|
148466
149298
|
}
|
|
148467
149299
|
async function readWorkflowStateList(options) {
|
|
@@ -148483,7 +149315,7 @@ async function readWorkflowStateList(options) {
|
|
|
148483
149315
|
async function featureRecency(dir) {
|
|
148484
149316
|
const times = await Promise.all(["spec.md", "prd.json", "status.json"].map(async (name) => {
|
|
148485
149317
|
try {
|
|
148486
|
-
return (await _featureStateDeps.file(
|
|
149318
|
+
return (await _featureStateDeps.file(join188(dir, name)).stat()).mtimeMs;
|
|
148487
149319
|
} catch (err) {
|
|
148488
149320
|
if (isMissingFile(err))
|
|
148489
149321
|
return 0;
|
|
@@ -148493,10 +149325,10 @@ async function featureRecency(dir) {
|
|
|
148493
149325
|
return Math.max(0, ...times);
|
|
148494
149326
|
}
|
|
148495
149327
|
async function readSpec(name, repoRoot) {
|
|
148496
|
-
const preferred =
|
|
149328
|
+
const preferred = join188(featureDir(repoRoot, name), "spec.md");
|
|
148497
149329
|
if (await _featureStateDeps.file(preferred).exists())
|
|
148498
149330
|
return relative51(repoRoot, preferred);
|
|
148499
|
-
const legacy =
|
|
149331
|
+
const legacy = join188(repoRoot, ".nax", "specs", `${name}.md`);
|
|
148500
149332
|
return await _featureStateDeps.file(legacy).exists() ? relative51(repoRoot, legacy) : null;
|
|
148501
149333
|
}
|
|
148502
149334
|
async function readPrd(path, warnings) {
|
|
@@ -148553,7 +149385,7 @@ var init_feature_state = __esm(() => {
|
|
|
148553
149385
|
|
|
148554
149386
|
// src/chat/workflow/workflow-provider.ts
|
|
148555
149387
|
import { readdirSync as readdirSync7, statSync as statSync15 } from "fs";
|
|
148556
|
-
import { join as
|
|
149388
|
+
import { join as join189 } from "path";
|
|
148557
149389
|
function failure7(content) {
|
|
148558
149390
|
return { content, isError: true };
|
|
148559
149391
|
}
|
|
@@ -148601,7 +149433,7 @@ async function readState(input, options) {
|
|
|
148601
149433
|
} catch (err) {
|
|
148602
149434
|
return failure7(errorMessage(err));
|
|
148603
149435
|
}
|
|
148604
|
-
if (exists3(dir, "directory") || exists3(
|
|
149436
|
+
if (exists3(dir, "directory") || exists3(join189(options.repoRoot, ".nax", "specs", `${feature}.md`), "file")) {
|
|
148605
149437
|
return { content: JSON.stringify(await readFeatureState(feature, options), null, 2) };
|
|
148606
149438
|
}
|
|
148607
149439
|
const names = knownDirectories(options.repoRoot);
|
|
@@ -148654,6 +149486,7 @@ var init_chat = __esm(() => {
|
|
|
148654
149486
|
init_chat_ledger();
|
|
148655
149487
|
init_chat_mcp();
|
|
148656
149488
|
init_chat_mode();
|
|
149489
|
+
init_chat_models();
|
|
148657
149490
|
init_jobs();
|
|
148658
149491
|
init_open_chat_session();
|
|
148659
149492
|
init_skill_invocation();
|
|
@@ -168303,7 +169136,7 @@ function optionalRows(text, prefix, style, context) {
|
|
|
168303
169136
|
}
|
|
168304
169137
|
function titleRows(model, context) {
|
|
168305
169138
|
const title = { text: model.title, bold: true };
|
|
168306
|
-
const tag = model.tag === undefined ? [] : [{ text: `${SPACE3}${model.tag}`, color: "muted" }];
|
|
169139
|
+
const tag = model.kind === "choice" || model.tag === undefined ? [] : [{ text: `${SPACE3}${model.tag}`, color: "muted" }];
|
|
168307
169140
|
return prefixedLine([title, ...tag], [], context);
|
|
168308
169141
|
}
|
|
168309
169142
|
function questionTitleRows(model, context) {
|
|
@@ -168345,20 +169178,21 @@ function countdownRow(expiresAt, nowMs) {
|
|
|
168345
169178
|
}
|
|
168346
169179
|
function approvalBody(approval, options, context) {
|
|
168347
169180
|
const indent = [styled2(SPACE3.repeat(INDENT_COLUMNS))];
|
|
169181
|
+
const border = approval.kind === "choice" ? "warning" : approval.border;
|
|
168348
169182
|
return {
|
|
168349
169183
|
head: [
|
|
168350
|
-
ruleRow(context.theme, context.width,
|
|
169184
|
+
ruleRow(context.theme, context.width, border),
|
|
168351
169185
|
...titleRows(approval, context),
|
|
168352
169186
|
CARD_BLANK,
|
|
168353
|
-
...optionalRows(approval.command, indent, { bold: true }, context),
|
|
169187
|
+
...optionalRows(approval.kind === "choice" ? undefined : approval.command, indent, { bold: true }, context),
|
|
168354
169188
|
...optionalRows(approval.summary, indent, { color: "muted" }, context),
|
|
168355
169189
|
...optionalRows(approval.reason, [], {}, context),
|
|
168356
|
-
...diffRows(approval.diff, context)
|
|
169190
|
+
...diffRows(approval.kind === "choice" ? [] : approval.diff, context)
|
|
168357
169191
|
],
|
|
168358
169192
|
tail: [
|
|
168359
169193
|
...optionRows(approval, options.selected ?? 0, context),
|
|
168360
169194
|
countdownRow(options.expiresAt, options.nowMs ?? _askCardDeps.now()),
|
|
168361
|
-
ruleRow(context.theme, context.width,
|
|
169195
|
+
ruleRow(context.theme, context.width, border)
|
|
168362
169196
|
]
|
|
168363
169197
|
};
|
|
168364
169198
|
}
|
|
@@ -168441,7 +169275,7 @@ function AskCard({
|
|
|
168441
169275
|
const [nowMs, setNowMs] = import_react30.useState(() => _askCardDeps.now());
|
|
168442
169276
|
const [selected, setSelected] = import_react30.useState(0);
|
|
168443
169277
|
const latestSelected = import_react30.useRef(0);
|
|
168444
|
-
const options = model.kind === "
|
|
169278
|
+
const options = model.kind === "question" ? [] : model.options;
|
|
168445
169279
|
const moveSelection = (next) => {
|
|
168446
169280
|
latestSelected.current = next;
|
|
168447
169281
|
setSelected(next);
|
|
@@ -168469,24 +169303,46 @@ function AskCard({
|
|
|
168469
169303
|
if (choice === "deny")
|
|
168470
169304
|
onDeclined?.();
|
|
168471
169305
|
};
|
|
169306
|
+
const moveFromKey = (key) => {
|
|
169307
|
+
if (key.shift)
|
|
169308
|
+
return;
|
|
169309
|
+
if (key.upArrow)
|
|
169310
|
+
moveSelection(Math.max(0, latestSelected.current - 1));
|
|
169311
|
+
else if (key.downArrow)
|
|
169312
|
+
moveSelection(Math.min(options.length - 1, latestSelected.current + 1));
|
|
169313
|
+
};
|
|
169314
|
+
const chooseFromKey = (input, key) => {
|
|
169315
|
+
if (model.kind !== "choice")
|
|
169316
|
+
return;
|
|
169317
|
+
if (key.escape) {
|
|
169318
|
+
controller.resolveChoice(ask.requestId, model.fallback);
|
|
169319
|
+
return;
|
|
169320
|
+
}
|
|
169321
|
+
if (key.ctrl || key.meta)
|
|
169322
|
+
return;
|
|
169323
|
+
const option = key.return ? model.options[latestSelected.current] : model.options.find((option) => String(option.index) === input);
|
|
169324
|
+
if (option)
|
|
169325
|
+
controller.resolveChoice(ask.requestId, option.id);
|
|
169326
|
+
else
|
|
169327
|
+
moveFromKey(key);
|
|
169328
|
+
};
|
|
168472
169329
|
use_input_default((input, key) => {
|
|
168473
|
-
if (model.kind
|
|
169330
|
+
if (model.kind === "question")
|
|
169331
|
+
return;
|
|
169332
|
+
if (model.kind === "choice") {
|
|
169333
|
+
chooseFromKey(input, key);
|
|
168474
169334
|
return;
|
|
169335
|
+
}
|
|
168475
169336
|
if (key.escape) {
|
|
168476
169337
|
choose("deny");
|
|
168477
169338
|
return;
|
|
168478
169339
|
}
|
|
168479
|
-
const choice = chosenOption(input, key, options, latestSelected.current);
|
|
169340
|
+
const choice = chosenOption(input, key, model.options, latestSelected.current);
|
|
168480
169341
|
if (choice !== undefined) {
|
|
168481
169342
|
choose(choice);
|
|
168482
169343
|
return;
|
|
168483
169344
|
}
|
|
168484
|
-
|
|
168485
|
-
return;
|
|
168486
|
-
if (key.upArrow)
|
|
168487
|
-
moveSelection(Math.max(0, latestSelected.current - 1));
|
|
168488
|
-
else if (key.downArrow)
|
|
168489
|
-
moveSelection(Math.min(options.length - 1, latestSelected.current + 1));
|
|
169345
|
+
moveFromKey(key);
|
|
168490
169346
|
}, { isActive: active });
|
|
168491
169347
|
const layout = askCardLayout(model, { width, budget, theme, answer, expiresAt: ask.expiresAt, nowMs, selected });
|
|
168492
169348
|
return /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
|
|
@@ -168830,6 +169686,20 @@ function askCardModel(ask, options) {
|
|
|
168830
169686
|
if (ask.type === "question") {
|
|
168831
169687
|
return { kind: "question", title: ASK_QUESTION_TITLE, text: sanitizeText(ask.text), border: "warning" };
|
|
168832
169688
|
}
|
|
169689
|
+
if (ask.type === "host_choice") {
|
|
169690
|
+
return {
|
|
169691
|
+
kind: "choice",
|
|
169692
|
+
title: sanitizeText(ask.tool),
|
|
169693
|
+
summary: sanitizeText(ask.summary),
|
|
169694
|
+
reason: sanitizeText(ask.reason),
|
|
169695
|
+
fallback: ask.fallback,
|
|
169696
|
+
options: ask.choices.map((choice, index) => ({
|
|
169697
|
+
index: index + 1,
|
|
169698
|
+
label: sanitizeText(choice.label),
|
|
169699
|
+
id: choice.id
|
|
169700
|
+
}))
|
|
169701
|
+
};
|
|
169702
|
+
}
|
|
168833
169703
|
const tool = sanitizeText(ask.tool);
|
|
168834
169704
|
const said = attribution(sanitizeText(ask.reason));
|
|
168835
169705
|
return {
|
|
@@ -168948,7 +169818,11 @@ function pickerModel(input) {
|
|
|
168948
169818
|
return {
|
|
168949
169819
|
kind: "effort",
|
|
168950
169820
|
title: TITLES3.effort,
|
|
168951
|
-
entries: EFFORT_LEVELS.map((level) => ({
|
|
169821
|
+
entries: (input.effortLevels ?? EFFORT_LEVELS).map((level) => ({
|
|
169822
|
+
value: level,
|
|
169823
|
+
label: level,
|
|
169824
|
+
current: level === current
|
|
169825
|
+
}))
|
|
168952
169826
|
};
|
|
168953
169827
|
}
|
|
168954
169828
|
if (input.kind === "model") {
|
|
@@ -169012,12 +169886,13 @@ function actionFor(host, kind, entry) {
|
|
|
169012
169886
|
function heldWarning(sessionId, pid) {
|
|
169013
169887
|
return `session ${sessionId} is in use by pid ${pid}`;
|
|
169014
169888
|
}
|
|
169015
|
-
function modelOf(state, current,
|
|
169889
|
+
function modelOf(state, current, host) {
|
|
169016
169890
|
return pickerModel({
|
|
169017
169891
|
kind: state.kind,
|
|
169018
169892
|
query: state.query,
|
|
169019
169893
|
pending: state.pending,
|
|
169020
|
-
models,
|
|
169894
|
+
models: host.models,
|
|
169895
|
+
effortLevels: host.effortLevels?.(current.model) ?? EFFORT_LEVELS,
|
|
169021
169896
|
currentModel: current.model,
|
|
169022
169897
|
currentMode: current.mode,
|
|
169023
169898
|
...state.sessions === undefined ? {} : { sessions: state.sessions },
|
|
@@ -169069,7 +169944,7 @@ function useChatPicker({ host, runControl, onError }) {
|
|
|
169069
169944
|
runControl(() => actionFor(host, kind, chosen));
|
|
169070
169945
|
}, [state, host, runControl]);
|
|
169071
169946
|
const current = state === undefined ? undefined : host.current();
|
|
169072
|
-
const model = state === undefined || current === undefined ? undefined : modelOf(state, current, host
|
|
169947
|
+
const model = state === undefined || current === undefined ? undefined : modelOf(state, current, host);
|
|
169073
169948
|
const setQuery = import_react31.useCallback((query) => {
|
|
169074
169949
|
setState((current) => current?.kind === "model" ? { ...current, query } : current);
|
|
169075
169950
|
}, []);
|
|
@@ -169079,10 +169954,10 @@ function useChatPicker({ host, runControl, onError }) {
|
|
|
169079
169954
|
const initial = entry.effortLabel ?? "default";
|
|
169080
169955
|
const level = pending.current.get(entry.value) ?? (isEffortLevel(initial) ? initial : "default");
|
|
169081
169956
|
const next = new Map(pending.current);
|
|
169082
|
-
next.set(entry.value, cycleEffort(level, step));
|
|
169957
|
+
next.set(entry.value, cycleEffort(level, step, host.effortLevels?.(entry.value) ?? EFFORT_LEVELS));
|
|
169083
169958
|
pending.current = next;
|
|
169084
169959
|
setState((current) => current?.kind === "model" ? { ...current, pending: next } : current);
|
|
169085
|
-
}, [state?.kind]);
|
|
169960
|
+
}, [state?.kind, host]);
|
|
169086
169961
|
return { model, open, cancel, choose, setQuery, cycle };
|
|
169087
169962
|
}
|
|
169088
169963
|
var import_react31;
|
|
@@ -169789,6 +170664,8 @@ var init_chat_status = __esm(async () => {
|
|
|
169789
170664
|
quit: "press ctrl-c again to quit",
|
|
169790
170665
|
clear: "esc again to clear",
|
|
169791
170666
|
busy: "esc to interrupt",
|
|
170667
|
+
background: "esc to interrupt \xB7 ctrl+b to background",
|
|
170668
|
+
backgroundTmux: "esc to interrupt \xB7 ctrl+b ctrl+b to background",
|
|
169792
170669
|
expanded: "ctrl+o to collapse",
|
|
169793
170670
|
idle: "shift+tab to cycle"
|
|
169794
170671
|
};
|
|
@@ -178064,7 +178941,7 @@ var init_layout = __esm(async () => {
|
|
|
178064
178941
|
});
|
|
178065
178942
|
|
|
178066
178943
|
// src/tui/chat/slash-commands.ts
|
|
178067
|
-
import { join as
|
|
178944
|
+
import { join as join191 } from "path";
|
|
178068
178945
|
function parseSlashCommand(text) {
|
|
178069
178946
|
if (!text.startsWith("/"))
|
|
178070
178947
|
return null;
|
|
@@ -178079,12 +178956,12 @@ async function featureMessage(command, host, show) {
|
|
|
178079
178956
|
return;
|
|
178080
178957
|
}
|
|
178081
178958
|
const dir = featureDir(host.repoRoot, feature);
|
|
178082
|
-
const spec = await _slashCommandDeps.readText(
|
|
178959
|
+
const spec = await _slashCommandDeps.readText(join191(dir, "spec.md"));
|
|
178083
178960
|
if (spec === undefined) {
|
|
178084
178961
|
show(`no feature ${feature} (looked in ${dir})`);
|
|
178085
178962
|
return;
|
|
178086
178963
|
}
|
|
178087
|
-
const prd = await _slashCommandDeps.readText(
|
|
178964
|
+
const prd = await _slashCommandDeps.readText(join191(dir, "prd.json"));
|
|
178088
178965
|
const message = command.rest.replace(/^\s*\S+\s?/, "");
|
|
178089
178966
|
return buildChatFeatureMessage({ feature, spec, prd, message });
|
|
178090
178967
|
}
|
|
@@ -178097,7 +178974,10 @@ function formatHelp(host) {
|
|
|
178097
178974
|
`);
|
|
178098
178975
|
}
|
|
178099
178976
|
function formatSessionJobs(host) {
|
|
178100
|
-
|
|
178977
|
+
if (!host.jobs && !host.tasks)
|
|
178978
|
+
return "jobs are not available in this session";
|
|
178979
|
+
return [host.jobs ? formatJobsListing(host.jobs.list()) : "", host.tasks ? formatTasksListing(host.tasks.list()) : ""].filter(Boolean).join(`
|
|
178980
|
+
`);
|
|
178101
178981
|
}
|
|
178102
178982
|
function catalogCommand(command, { host, show }) {
|
|
178103
178983
|
const resource = host.catalog?.findCommand(command.name);
|
|
@@ -178116,12 +178996,18 @@ async function effortCommand(command, { host, show }) {
|
|
|
178116
178996
|
const arg = command.args[0];
|
|
178117
178997
|
if (arg === undefined)
|
|
178118
178998
|
return { kind: "picker", picker: "effort" };
|
|
178999
|
+
const model = host.current().model;
|
|
179000
|
+
const levels = host.effortLevels?.(model) ?? EFFORT_LEVELS;
|
|
178119
179001
|
const level = arg.toLowerCase();
|
|
178120
179002
|
if (!isEffortLevel(level)) {
|
|
178121
|
-
show(`unknown effort "${arg}"; use one of: ${
|
|
179003
|
+
show(`unknown effort "${arg}"; use one of: ${levels.join(", ")}`);
|
|
179004
|
+
return;
|
|
179005
|
+
}
|
|
179006
|
+
if (!levels.includes(level)) {
|
|
179007
|
+
show(`effort "${arg}" is not available for ${model}; use one of: ${levels.join(", ")}`);
|
|
178122
179008
|
return;
|
|
178123
179009
|
}
|
|
178124
|
-
await host.switchTo({ model: withEffort2(
|
|
179010
|
+
await host.switchTo({ model: withEffort2(model, level) });
|
|
178125
179011
|
}
|
|
178126
179012
|
async function runSlashCommand(command, { host, show }) {
|
|
178127
179013
|
const arg = command.args[0];
|
|
@@ -178188,6 +179074,7 @@ async function runSlashCommand(command, { host, show }) {
|
|
|
178188
179074
|
var _slashCommandDeps, COMMANDS, COMMAND_DESCRIPTIONS;
|
|
178189
179075
|
var init_slash_commands = __esm(() => {
|
|
178190
179076
|
init_chat();
|
|
179077
|
+
init_background();
|
|
178191
179078
|
init_config();
|
|
178192
179079
|
init_prompts();
|
|
178193
179080
|
init_resources();
|
|
@@ -179029,6 +179916,8 @@ function footerHint(input) {
|
|
|
179029
179916
|
return "quit";
|
|
179030
179917
|
if (input.clearArmed)
|
|
179031
179918
|
return "clear";
|
|
179919
|
+
if (input.busy && input.backgroundable)
|
|
179920
|
+
return input.tmux ? "backgroundTmux" : "background";
|
|
179032
179921
|
if (input.busy)
|
|
179033
179922
|
return "busy";
|
|
179034
179923
|
if (input.expanded)
|
|
@@ -179058,6 +179947,8 @@ var init_use_clipboard_feedback = __esm(async () => {
|
|
|
179058
179947
|
// src/tui/chat/use-jobs.ts
|
|
179059
179948
|
function useJobs(host, { idle, deliver }) {
|
|
179060
179949
|
const jobs = host.jobs;
|
|
179950
|
+
const tasks = host.tasks;
|
|
179951
|
+
const taskTurns = import_react37.useRef(0);
|
|
179061
179952
|
const [, refresh] = import_react37.useState(0);
|
|
179062
179953
|
const latestDeliver = import_react37.useRef(deliver);
|
|
179063
179954
|
latestDeliver.current = deliver;
|
|
@@ -179065,16 +179956,21 @@ function useJobs(host, { idle, deliver }) {
|
|
|
179065
179956
|
const mounted = import_react37.useRef(false);
|
|
179066
179957
|
import_react37.useEffect(() => {
|
|
179067
179958
|
mounted.current = true;
|
|
179068
|
-
const
|
|
179959
|
+
const changed = () => refresh((revision) => revision + 1);
|
|
179960
|
+
const unsubscribe = jobs?.onChange(changed);
|
|
179961
|
+
const unsubscribeTasks = tasks?.onChange(changed);
|
|
179069
179962
|
return () => {
|
|
179070
179963
|
mounted.current = false;
|
|
179071
179964
|
unsubscribe?.();
|
|
179965
|
+
unsubscribeTasks?.();
|
|
179072
179966
|
};
|
|
179073
|
-
}, [jobs]);
|
|
179967
|
+
}, [jobs, tasks]);
|
|
179074
179968
|
import_react37.useEffect(() => {
|
|
179075
|
-
if (!idle ||
|
|
179969
|
+
if (!idle || inFlight.current)
|
|
179076
179970
|
return;
|
|
179077
|
-
const
|
|
179971
|
+
const jobNotice = jobs?.peekNotice();
|
|
179972
|
+
const source = jobNotice !== undefined ? jobs : taskTurns.current < MAX_CONSECUTIVE_TASK_NOTICE_TURNS ? tasks : undefined;
|
|
179973
|
+
const notice = jobNotice ?? source?.peekNotice();
|
|
179078
179974
|
if (notice === undefined)
|
|
179079
179975
|
return;
|
|
179080
179976
|
inFlight.current = true;
|
|
@@ -179082,10 +179978,13 @@ function useJobs(host, { idle, deliver }) {
|
|
|
179082
179978
|
let delivered = false;
|
|
179083
179979
|
try {
|
|
179084
179980
|
delivered = await latestDeliver.current(notice);
|
|
179085
|
-
if (delivered)
|
|
179086
|
-
|
|
179981
|
+
if (delivered) {
|
|
179982
|
+
source?.takeNotice();
|
|
179983
|
+
if (source === tasks)
|
|
179984
|
+
taskTurns.current++;
|
|
179985
|
+
}
|
|
179087
179986
|
} catch (error) {
|
|
179088
|
-
getLogger2()?.warn("chat", "
|
|
179987
|
+
getLogger2()?.warn("chat", "Background notice delivery failed; notice retained", { error: errorMessage(error) });
|
|
179089
179988
|
} finally {
|
|
179090
179989
|
inFlight.current = false;
|
|
179091
179990
|
if (delivered && mounted.current)
|
|
@@ -179093,9 +179992,15 @@ function useJobs(host, { idle, deliver }) {
|
|
|
179093
179992
|
}
|
|
179094
179993
|
})();
|
|
179095
179994
|
});
|
|
179096
|
-
return
|
|
179995
|
+
return {
|
|
179996
|
+
running: jobs?.running() ?? [],
|
|
179997
|
+
backgroundable: tasks?.hasForeground() ?? false,
|
|
179998
|
+
noteUserTurn: () => {
|
|
179999
|
+
taskTurns.current = 0;
|
|
180000
|
+
}
|
|
180001
|
+
};
|
|
179097
180002
|
}
|
|
179098
|
-
var import_react37;
|
|
180003
|
+
var import_react37, MAX_CONSECUTIVE_TASK_NOTICE_TURNS = 3;
|
|
179099
180004
|
var init_use_jobs = __esm(() => {
|
|
179100
180005
|
init_internal();
|
|
179101
180006
|
init_logger2();
|
|
@@ -179153,7 +180058,7 @@ function clearTimer(handle) {
|
|
|
179153
180058
|
clearTimeout(handle.current);
|
|
179154
180059
|
handle.current = undefined;
|
|
179155
180060
|
}
|
|
179156
|
-
function useChatKeys({ host, running, refresh, onError }) {
|
|
180061
|
+
function useChatKeys({ host, running, refresh, onError, onNotice }) {
|
|
179157
180062
|
const { exit } = use_app_default();
|
|
179158
180063
|
const queued = import_react40.useRef(undefined);
|
|
179159
180064
|
const interruptedAt = import_react40.useRef(undefined);
|
|
@@ -179180,6 +180085,15 @@ function useChatKeys({ host, running, refresh, onError }) {
|
|
|
179180
180085
|
async function switchMode(mode) {
|
|
179181
180086
|
await runControl(() => host.switchTo({ mode }));
|
|
179182
180087
|
}
|
|
180088
|
+
function cycleModelEffort() {
|
|
180089
|
+
const model = queued.current?.model ?? host.current().model;
|
|
180090
|
+
const levels = host.effortLevels?.(model) ?? EFFORT_LEVELS;
|
|
180091
|
+
const next = withEffort2(model, cycleEffort(modelEffort(model), 1, levels));
|
|
180092
|
+
if (running.current)
|
|
180093
|
+
queued.current = { ...queued.current, model: next };
|
|
180094
|
+
else
|
|
180095
|
+
runControl(() => host.switchTo({ model: next }));
|
|
180096
|
+
}
|
|
179183
180097
|
async function runControl(action) {
|
|
179184
180098
|
if (!canControl())
|
|
179185
180099
|
return false;
|
|
@@ -179201,10 +180115,11 @@ function useChatKeys({ host, running, refresh, onError }) {
|
|
|
179201
180115
|
async function close() {
|
|
179202
180116
|
if (closing.current || confirming.current)
|
|
179203
180117
|
return;
|
|
179204
|
-
if (host.
|
|
180118
|
+
if (host.confirmBeforeClose) {
|
|
179205
180119
|
confirming.current = true;
|
|
179206
180120
|
try {
|
|
179207
|
-
await host.
|
|
180121
|
+
if (await host.confirmBeforeClose() === false)
|
|
180122
|
+
return;
|
|
179208
180123
|
} catch (error) {
|
|
179209
180124
|
onError(error);
|
|
179210
180125
|
return;
|
|
@@ -179225,23 +180140,34 @@ function useChatKeys({ host, running, refresh, onError }) {
|
|
|
179225
180140
|
onError(error);
|
|
179226
180141
|
}
|
|
179227
180142
|
}
|
|
180143
|
+
function moveForeground() {
|
|
180144
|
+
if (!host.tasks?.moveForeground())
|
|
180145
|
+
onNotice?.("no running command to move to the background");
|
|
180146
|
+
}
|
|
180147
|
+
function interrupt() {
|
|
180148
|
+
const now = _chatKeyDeps.now();
|
|
180149
|
+
if (!running.current || interruptedAt.current !== undefined && now - interruptedAt.current <= DOUBLE_INTERRUPT_MS) {
|
|
180150
|
+
close();
|
|
180151
|
+
} else {
|
|
180152
|
+
interruptedAt.current = now;
|
|
180153
|
+
armQuit();
|
|
180154
|
+
host.cancel();
|
|
180155
|
+
refresh();
|
|
180156
|
+
}
|
|
180157
|
+
}
|
|
179228
180158
|
use_input_default((input, key) => {
|
|
179229
180159
|
if (closing.current)
|
|
179230
180160
|
return;
|
|
179231
180161
|
if (key.ctrl && input === "c") {
|
|
179232
|
-
|
|
179233
|
-
|
|
179234
|
-
|
|
179235
|
-
|
|
179236
|
-
|
|
179237
|
-
|
|
179238
|
-
|
|
179239
|
-
refresh();
|
|
179240
|
-
}
|
|
179241
|
-
} else if (key.shift && key.tab && !key.ctrl && !key.meta && !switching.current) {
|
|
179242
|
-
const mode = nextChatMode(queued.current ?? host.current().mode);
|
|
180162
|
+
interrupt();
|
|
180163
|
+
} else if (key.ctrl && input === "b" && canControl()) {
|
|
180164
|
+
moveForeground();
|
|
180165
|
+
} else if (key.ctrl && input === "t" && canControl()) {
|
|
180166
|
+
cycleModelEffort();
|
|
180167
|
+
} else if (key.shift && key.tab && !key.ctrl && !key.meta && canControl()) {
|
|
180168
|
+
const mode = nextChatMode(queued.current?.mode ?? host.current().mode);
|
|
179243
180169
|
if (running.current)
|
|
179244
|
-
queued.current = mode;
|
|
180170
|
+
queued.current = { ...queued.current, mode };
|
|
179245
180171
|
else
|
|
179246
180172
|
switchMode(mode);
|
|
179247
180173
|
}
|
|
@@ -179255,10 +180181,10 @@ function useChatKeys({ host, running, refresh, onError }) {
|
|
|
179255
180181
|
async finishTurn() {
|
|
179256
180182
|
interruptedAt.current = undefined;
|
|
179257
180183
|
clearTimer(quitExpiry);
|
|
179258
|
-
const
|
|
180184
|
+
const next = queued.current;
|
|
179259
180185
|
queued.current = undefined;
|
|
179260
|
-
if (
|
|
179261
|
-
await
|
|
180186
|
+
if (next !== undefined && !closing.current)
|
|
180187
|
+
await runControl(() => host.switchTo(next));
|
|
179262
180188
|
}
|
|
179263
180189
|
};
|
|
179264
180190
|
}
|
|
@@ -179307,6 +180233,7 @@ function ChatApp({
|
|
|
179307
180233
|
home = ""
|
|
179308
180234
|
}) {
|
|
179309
180235
|
const { stdout } = use_stdout_default();
|
|
180236
|
+
const [tmux] = import_react41.useState(() => Boolean(_chatAppDeps.tmux()));
|
|
179310
180237
|
const { copiedChars, onCopy } = useClipboardFeedback(mouse);
|
|
179311
180238
|
const [size, setSize] = import_react41.useState(() => terminalSize2(stdout));
|
|
179312
180239
|
const state = host.current();
|
|
@@ -179330,7 +180257,13 @@ function ChatApp({
|
|
|
179330
180257
|
setEntries((rows) => [...rows, entry]);
|
|
179331
180258
|
}, []);
|
|
179332
180259
|
const showError = import_react41.useCallback((error) => append({ kind: "error", text: errorMessage(error) }), [append]);
|
|
179333
|
-
const keys = useChatKeys({
|
|
180260
|
+
const keys = useChatKeys({
|
|
180261
|
+
host,
|
|
180262
|
+
running: sending,
|
|
180263
|
+
refresh: update,
|
|
180264
|
+
onError: showError,
|
|
180265
|
+
onNotice: (text) => append({ kind: "notice", text })
|
|
180266
|
+
});
|
|
179334
180267
|
const picker = useChatPicker({ host, runControl: keys.runControl, onError: showError });
|
|
179335
180268
|
const ask = host.asks.pending()[0];
|
|
179336
180269
|
const turnRunning = busy || status.running;
|
|
@@ -179442,6 +180375,7 @@ function ChatApp({
|
|
|
179442
180375
|
return;
|
|
179443
180376
|
}
|
|
179444
180377
|
if (outcome.kind === "send") {
|
|
180378
|
+
noteUserTurn();
|
|
179445
180379
|
await sendTurn(outcome.message, undefined, `/${command.name}${command.rest}`);
|
|
179446
180380
|
return;
|
|
179447
180381
|
}
|
|
@@ -179452,12 +180386,14 @@ function ChatApp({
|
|
|
179452
180386
|
const { command: failed, reason } = expandedLines.failed;
|
|
179453
180387
|
return { notice: `command /${name} not sent: !\`${failed}\` failed: ${reason}` };
|
|
179454
180388
|
}
|
|
180389
|
+
noteUserTurn();
|
|
179455
180390
|
return { message: buildCommandMessage(expandedLines.text, rest) };
|
|
179456
180391
|
});
|
|
179457
180392
|
}
|
|
179458
180393
|
async function submit(message) {
|
|
179459
180394
|
const command = parseSlashCommand(message);
|
|
179460
180395
|
if (!command) {
|
|
180396
|
+
noteUserTurn();
|
|
179461
180397
|
await sendTurn(message);
|
|
179462
180398
|
return;
|
|
179463
180399
|
}
|
|
@@ -179508,7 +180444,11 @@ function ChatApp({
|
|
|
179508
180444
|
setStatus(stopTurn);
|
|
179509
180445
|
}
|
|
179510
180446
|
}
|
|
179511
|
-
const
|
|
180447
|
+
const {
|
|
180448
|
+
running: jobs,
|
|
180449
|
+
backgroundable,
|
|
180450
|
+
noteUserTurn
|
|
180451
|
+
} = useJobs(host, {
|
|
179512
180452
|
idle: idleForJobNotice({
|
|
179513
180453
|
turnRunning,
|
|
179514
180454
|
bottomBlocked: bottomBlocked(ask, picker.model),
|
|
@@ -179534,7 +180474,14 @@ function ChatApp({
|
|
|
179534
180474
|
jobs,
|
|
179535
180475
|
state,
|
|
179536
180476
|
status,
|
|
179537
|
-
hint: copiedChars === undefined ? footerHint({
|
|
180477
|
+
hint: copiedChars === undefined ? footerHint({
|
|
180478
|
+
quitArmed: keys.quitArmed(),
|
|
180479
|
+
clearArmed,
|
|
180480
|
+
busy: turnRunning,
|
|
180481
|
+
expanded,
|
|
180482
|
+
backgroundable,
|
|
180483
|
+
tmux
|
|
180484
|
+
}) : "copied",
|
|
179538
180485
|
copiedChars,
|
|
179539
180486
|
glyphs: theme.glyphs
|
|
179540
180487
|
});
|
|
@@ -179679,7 +180626,7 @@ function ChatApp({
|
|
|
179679
180626
|
]
|
|
179680
180627
|
}, undefined, true, undefined, this);
|
|
179681
180628
|
}
|
|
179682
|
-
var import_react41, jsx_dev_runtime8, FRAME_SLACK_ROWS = 1, HEADER_ROWS = 3, FOOTER_ROWS = 1, WORKING_ROWS = 1, MIN_VIEWPORT_ROWS2 = 1, DEFAULT_COLUMNS = 80, DEFAULT_ROWS = 24, SANDBOX_WARNING = "sandbox unavailable: commands run outside the sandbox", TURN_BUSY_NOTICE = "wait for the turn to finish (Ctrl-C to interrupt)", QUIT = "quit", TELL_NAX_HINT = "tell nax what to do instead", CTRL_O = "o", DEFAULT_THEME, LISTING_TITLES, NO_ANSWER2;
|
|
180629
|
+
var import_react41, jsx_dev_runtime8, _chatAppDeps, FRAME_SLACK_ROWS = 1, HEADER_ROWS = 3, FOOTER_ROWS = 1, WORKING_ROWS = 1, MIN_VIEWPORT_ROWS2 = 1, DEFAULT_COLUMNS = 80, DEFAULT_ROWS = 24, SANDBOX_WARNING = "sandbox unavailable: commands run outside the sandbox", TURN_BUSY_NOTICE = "wait for the turn to finish (Ctrl-C to interrupt)", QUIT = "quit", TELL_NAX_HINT = "tell nax what to do instead", CTRL_O = "o", DEFAULT_THEME, LISTING_TITLES, NO_ANSWER2;
|
|
179683
180630
|
var init_ChatApp = __esm(async () => {
|
|
179684
180631
|
init_internal();
|
|
179685
180632
|
init_chat();
|
|
@@ -179712,6 +180659,7 @@ var init_ChatApp = __esm(async () => {
|
|
|
179712
180659
|
]);
|
|
179713
180660
|
import_react41 = __toESM(require_react(), 1);
|
|
179714
180661
|
jsx_dev_runtime8 = __toESM(require_jsx_dev_runtime(), 1);
|
|
180662
|
+
_chatAppDeps = { tmux: () => Bun.env.TMUX };
|
|
179715
180663
|
DEFAULT_THEME = resolveChatTheme({ env: {}, colorLevel: 0 });
|
|
179716
180664
|
LISTING_TITLES = new Map([
|
|
179717
180665
|
["help", "Commands"],
|
|
@@ -179912,7 +180860,7 @@ var init_chat2 = __esm(async () => {
|
|
|
179912
180860
|
|
|
179913
180861
|
// src/cli/chat.ts
|
|
179914
180862
|
import { homedir as homedir11 } from "os";
|
|
179915
|
-
import { dirname as dirname48, join as
|
|
180863
|
+
import { dirname as dirname48, join as join192, resolve as resolve54 } from "path";
|
|
179916
180864
|
async function interactionChain(config, deps) {
|
|
179917
180865
|
try {
|
|
179918
180866
|
return await deps.initInteractionChain(config, true);
|
|
@@ -180001,7 +180949,7 @@ async function runShell(host, deps, cwd) {
|
|
|
180001
180949
|
async function chatResources(repoRoot, config, deps) {
|
|
180002
180950
|
let registry;
|
|
180003
180951
|
try {
|
|
180004
|
-
registry = await deps.loadPlugins(
|
|
180952
|
+
registry = await deps.loadPlugins(join192(globalConfigDir(), "plugins"), join192(repoRoot, ".nax", "plugins"), config.plugins ?? [], repoRoot, config.disabledPlugins);
|
|
180005
180953
|
} catch (error) {
|
|
180006
180954
|
deps.writeErr(`nax plugins unavailable: ${errorMessage(error)}`);
|
|
180007
180955
|
registry = new PluginRegistry([]);
|
|
@@ -180019,7 +180967,11 @@ async function chatResources(repoRoot, config, deps) {
|
|
|
180019
180967
|
catalog,
|
|
180020
180968
|
toolProviders: [
|
|
180021
180969
|
createSkillsProvider(async () => catalog),
|
|
180022
|
-
createWorkflowProvider({
|
|
180970
|
+
createWorkflowProvider({
|
|
180971
|
+
repoRoot,
|
|
180972
|
+
outputDir,
|
|
180973
|
+
maxIterations: isWorkflowMode(config) ? undefined : config.execution.maxIterations
|
|
180974
|
+
}),
|
|
180023
180975
|
...mcp.providers
|
|
180024
180976
|
],
|
|
180025
180977
|
pluginHandlers: registry.getLoopHandlers(),
|
|
@@ -180057,6 +181009,11 @@ async function composeChat(options, deps, cwd) {
|
|
|
180057
181009
|
const config = options.profile?.length ? await deps.loadConfig(naxDir ?? undefined, { profile: options.profile }) : await deps.loadConfig(naxDir ?? undefined);
|
|
180058
181010
|
const repoRoot = naxDir ? dirname48(naxDir) : cwd;
|
|
180059
181011
|
const models = await discoverModels(config, deps);
|
|
181012
|
+
const effortLevels = await chatEffortLevels({
|
|
181013
|
+
config,
|
|
181014
|
+
models: options.model === undefined ? models : [...models, options.model],
|
|
181015
|
+
lookupThinkingLevels: deps.lookupThinkingLevels
|
|
181016
|
+
});
|
|
180060
181017
|
const resources = await chatResources(repoRoot, config, deps);
|
|
180061
181018
|
const log = (stage, message) => deps.writeErr(`[${stage}] ${message}`);
|
|
180062
181019
|
const logger = getSafeLogger2() ?? { warn: log, error: log, info: log, debug: log };
|
|
@@ -180067,6 +181024,7 @@ async function composeChat(options, deps, cwd) {
|
|
|
180067
181024
|
try {
|
|
180068
181025
|
host = deps.createChatHost({
|
|
180069
181026
|
models,
|
|
181027
|
+
effortLevels,
|
|
180070
181028
|
...naxEntry === undefined ? {} : { naxEntry },
|
|
180071
181029
|
config,
|
|
180072
181030
|
cwd,
|
|
@@ -180158,6 +181116,7 @@ var init_chat3 = __esm(async () => {
|
|
|
180158
181116
|
collectAuthList,
|
|
180159
181117
|
naxEntry: () => process.argv[1] === undefined ? undefined : [process.execPath, process.argv[1]],
|
|
180160
181118
|
listCatalogModels,
|
|
181119
|
+
lookupThinkingLevels,
|
|
180161
181120
|
stdinIsTTY: () => process.stdin.isTTY === true,
|
|
180162
181121
|
ensureTrusted: async (cwd) => {
|
|
180163
181122
|
await ensureProjectTrusted(await normalizeTrustPath(resolveTrustRoot(cwd)), { interactive: true });
|
|
@@ -180313,7 +181272,7 @@ var init_config_descriptions = __esm(() => {
|
|
|
180313
181272
|
"workflow.interruptRetry.budgetMultiplier": "Budget of each continue turn as a fraction of the limit that was hit, greater than 0 and at most 1 (default 0.5)",
|
|
180314
181273
|
"advisor.fallbackModels": "Models tried in order after advisor.model fails (quota, error, timeout, unparseable); default is none",
|
|
180315
181274
|
execution: "Execution limits and timeouts",
|
|
180316
|
-
"execution.maxIterations": "Max iterations per feature run
|
|
181275
|
+
"execution.maxIterations": "Max iterations per feature run (pipeline mode only; each story attempt, parallel batch and the final completion pass counts one). Workflow mode ignores it and bounds the run by the story count; maxStoriesPerFeature is its size limit",
|
|
180317
181276
|
"execution.mode": 'Run mode: "workflow" (default) runs the A5 single-implementer review loop configured by `workflow`; "pipeline" (deprecated) runs the per-story pipeline. Root-only',
|
|
180318
181277
|
"execution.iterationDelayMs": "Delay between iterations in milliseconds",
|
|
180319
181278
|
"execution.costLimit": "Max cost in USD before pausing execution (override per run with `nax run --max-cost`)",
|
|
@@ -180537,7 +181496,7 @@ var init_config_descriptions = __esm(() => {
|
|
|
180537
181496
|
|
|
180538
181497
|
// src/cli/config-get.ts
|
|
180539
181498
|
import { existsSync as existsSync26 } from "fs";
|
|
180540
|
-
import { join as
|
|
181499
|
+
import { join as join193 } from "path";
|
|
180541
181500
|
async function loadConfigFile(path) {
|
|
180542
181501
|
if (!existsSync26(path))
|
|
180543
181502
|
return null;
|
|
@@ -180559,7 +181518,7 @@ async function loadProjectConfig() {
|
|
|
180559
181518
|
const projectDir = findProjectDir(process.cwd());
|
|
180560
181519
|
if (!projectDir)
|
|
180561
181520
|
return null;
|
|
180562
|
-
const projectPath =
|
|
181521
|
+
const projectPath = join193(projectDir, "config.json");
|
|
180563
181522
|
return await loadConfigFile(projectPath);
|
|
180564
181523
|
}
|
|
180565
181524
|
var init_config_get = __esm(() => {
|
|
@@ -180570,11 +181529,11 @@ var init_config_get = __esm(() => {
|
|
|
180570
181529
|
});
|
|
180571
181530
|
|
|
180572
181531
|
// src/cli/config-profile.ts
|
|
180573
|
-
import { mkdirSync as
|
|
180574
|
-
import { join as
|
|
181532
|
+
import { mkdirSync as mkdirSync13, readdirSync as readdirSync8 } from "fs";
|
|
181533
|
+
import { join as join194 } from "path";
|
|
180575
181534
|
async function profileListCommand(startDir) {
|
|
180576
|
-
const globalProfilesDir =
|
|
180577
|
-
const projectProfilesDir =
|
|
181535
|
+
const globalProfilesDir = join194(globalConfigDir(), "profiles");
|
|
181536
|
+
const projectProfilesDir = join194(projectConfigDir(startDir), "profiles");
|
|
180578
181537
|
const globalProfiles = scanProfileDir(globalProfilesDir);
|
|
180579
181538
|
const projectProfiles = scanProfileDir(projectProfilesDir);
|
|
180580
181539
|
const activeProfile = await resolveProfileName({}, _profileCLIDeps.env, startDir);
|
|
@@ -180651,7 +181610,7 @@ function maskProfileValue(value) {
|
|
|
180651
181610
|
return value;
|
|
180652
181611
|
}
|
|
180653
181612
|
async function profileUseCommand(profileName, startDir) {
|
|
180654
|
-
const configPath =
|
|
181613
|
+
const configPath = join194(projectConfigDir(startDir), "config.json");
|
|
180655
181614
|
const configFile = Bun.file(configPath);
|
|
180656
181615
|
let existing = {};
|
|
180657
181616
|
if (await configFile.exists()) {
|
|
@@ -180672,8 +181631,8 @@ async function profileCurrentCommand(startDir) {
|
|
|
180672
181631
|
}
|
|
180673
181632
|
async function profileCreateCommand(profileName, startDir) {
|
|
180674
181633
|
validateProfileName(profileName);
|
|
180675
|
-
const profilesDir =
|
|
180676
|
-
const profilePath =
|
|
181634
|
+
const profilesDir = join194(projectConfigDir(startDir), "profiles");
|
|
181635
|
+
const profilePath = join194(profilesDir, `${profileName}.json`);
|
|
180677
181636
|
const profileFile = Bun.file(profilePath);
|
|
180678
181637
|
if (await profileFile.exists()) {
|
|
180679
181638
|
throw new NaxError(`Profile "${profileName}" already exists at ${profilePath}`, "PROFILE_ALREADY_EXISTS", {
|
|
@@ -180682,7 +181641,7 @@ async function profileCreateCommand(profileName, startDir) {
|
|
|
180682
181641
|
profilePath
|
|
180683
181642
|
});
|
|
180684
181643
|
}
|
|
180685
|
-
|
|
181644
|
+
mkdirSync13(profilesDir, { recursive: true });
|
|
180686
181645
|
await Bun.write(profilePath, "{}");
|
|
180687
181646
|
return profilePath;
|
|
180688
181647
|
}
|
|
@@ -180711,7 +181670,7 @@ var init_config_profile = __esm(() => {
|
|
|
180711
181670
|
|
|
180712
181671
|
// src/cli/config-display.ts
|
|
180713
181672
|
import { existsSync as existsSync27 } from "fs";
|
|
180714
|
-
import { join as
|
|
181673
|
+
import { join as join195 } from "path";
|
|
180715
181674
|
function rejectDiffProfileConflict(options) {
|
|
180716
181675
|
if (options.diff && (options.profile?.length ?? 0) > 0) {
|
|
180717
181676
|
console.error("Error: --diff cannot be combined with --profile");
|
|
@@ -180778,7 +181737,7 @@ async function configCommand(config, options = {}) {
|
|
|
180778
181737
|
function determineConfigSources(startDir) {
|
|
180779
181738
|
const globalPath = globalConfigPath();
|
|
180780
181739
|
const projectDir = findProjectDir(startDir ?? process.cwd());
|
|
180781
|
-
const projectPath = projectDir ?
|
|
181740
|
+
const projectPath = projectDir ? join195(projectDir, "config.json") : null;
|
|
180782
181741
|
return {
|
|
180783
181742
|
global: fileExists(globalPath) ? globalPath : null,
|
|
180784
181743
|
project: projectPath && fileExists(projectPath) ? projectPath : null
|
|
@@ -181355,7 +182314,7 @@ var init_context5 = __esm(() => {
|
|
|
181355
182314
|
|
|
181356
182315
|
// src/cli/context-fragments.ts
|
|
181357
182316
|
import { existsSync as existsSync29 } from "fs";
|
|
181358
|
-
import { join as
|
|
182317
|
+
import { join as join196 } from "path";
|
|
181359
182318
|
function listDependentStoryIds(prd, startId) {
|
|
181360
182319
|
const forward = new Map;
|
|
181361
182320
|
for (const story of prd.userStories) {
|
|
@@ -181440,7 +182399,7 @@ function resolveProjectDir(dir) {
|
|
|
181440
182399
|
return dir ?? process.cwd();
|
|
181441
182400
|
}
|
|
181442
182401
|
function featurePrdPath2(projectDir, featureId) {
|
|
181443
|
-
return
|
|
182402
|
+
return join196(featureDir(projectDir, featureId), "prd.json");
|
|
181444
182403
|
}
|
|
181445
182404
|
async function fragmentsInspectCommand(options) {
|
|
181446
182405
|
const projectDir = _contextFragmentsDeps.projectDirFor(resolveProjectDir(options.dir));
|
|
@@ -181526,7 +182485,7 @@ var init_context_fragments = __esm(() => {
|
|
|
181526
182485
|
|
|
181527
182486
|
// src/cli/cost-ledger-query.ts
|
|
181528
182487
|
import { readdir as readdir15, stat as stat18 } from "fs/promises";
|
|
181529
|
-
import { basename as basename33, dirname as dirname49, join as
|
|
182488
|
+
import { basename as basename33, dirname as dirname49, join as join197 } from "path";
|
|
181530
182489
|
function errorCode3(err) {
|
|
181531
182490
|
return typeof err === "object" && err !== null ? Reflect.get(err, "code") : undefined;
|
|
181532
182491
|
}
|
|
@@ -181564,11 +182523,11 @@ function compareStrings(a, b) {
|
|
|
181564
182523
|
async function listCostLedgerFiles(roots) {
|
|
181565
182524
|
const found = new Set;
|
|
181566
182525
|
for (const root of roots) {
|
|
181567
|
-
const dir =
|
|
182526
|
+
const dir = join197(root, COST_DIR);
|
|
181568
182527
|
for (const entry of await readEntries(dir)) {
|
|
181569
182528
|
if (entry.isDir || !entry.name.endsWith(LEDGER_SUFFIX))
|
|
181570
182529
|
continue;
|
|
181571
|
-
found.add(
|
|
182530
|
+
found.add(join197(dir, entry.name));
|
|
181572
182531
|
}
|
|
181573
182532
|
}
|
|
181574
182533
|
return [...found].sort(compareStrings);
|
|
@@ -181576,10 +182535,10 @@ async function listCostLedgerFiles(roots) {
|
|
|
181576
182535
|
async function listProjectOutputDirs(globalDir) {
|
|
181577
182536
|
const found = [];
|
|
181578
182537
|
for (const entry of await readEntries(globalDir)) {
|
|
181579
|
-
const child =
|
|
182538
|
+
const child = join197(globalDir, entry.name);
|
|
181580
182539
|
if (!await isDirectory(child))
|
|
181581
182540
|
continue;
|
|
181582
|
-
if (!await isDirectory(
|
|
182541
|
+
if (!await isDirectory(join197(child, COST_DIR)))
|
|
181583
182542
|
continue;
|
|
181584
182543
|
found.push(child);
|
|
181585
182544
|
}
|
|
@@ -181930,7 +182889,7 @@ var init_cost4 = __esm(() => {
|
|
|
181930
182889
|
});
|
|
181931
182890
|
|
|
181932
182891
|
// src/cli/gates.ts
|
|
181933
|
-
import { dirname as dirname50, join as
|
|
182892
|
+
import { dirname as dirname50, join as join198 } from "path";
|
|
181934
182893
|
async function projectRootOf(dir) {
|
|
181935
182894
|
const naxDir = findProjectDir(dir);
|
|
181936
182895
|
if (naxDir === null || realOrRaw(naxDir) === realOrRaw(globalConfigDir())) {
|
|
@@ -182048,7 +183007,7 @@ async function gatesRunCommand(opts, deps = _gatesCliDeps) {
|
|
|
182048
183007
|
if (opts.json)
|
|
182049
183008
|
deps.log(JSON.stringify(empty));
|
|
182050
183009
|
else
|
|
182051
|
-
deps.log(`no quality.commands configured in ${
|
|
183010
|
+
deps.log(`no quality.commands configured in ${join198(projectDir, PROJECT_NAX_DIR, "config.json")}; nothing was verified`);
|
|
182052
183011
|
return 2;
|
|
182053
183012
|
}
|
|
182054
183013
|
const records = [];
|
|
@@ -182114,9 +183073,9 @@ var init_gates2 = __esm(() => {
|
|
|
182114
183073
|
|
|
182115
183074
|
// src/context/injector.ts
|
|
182116
183075
|
import { existsSync as existsSync30 } from "fs";
|
|
182117
|
-
import { join as
|
|
183076
|
+
import { join as join199 } from "path";
|
|
182118
183077
|
async function detectNode(workdir) {
|
|
182119
|
-
const pkgPath =
|
|
183078
|
+
const pkgPath = join199(workdir, "package.json");
|
|
182120
183079
|
if (!existsSync30(pkgPath))
|
|
182121
183080
|
return null;
|
|
182122
183081
|
try {
|
|
@@ -182133,7 +183092,7 @@ async function detectNode(workdir) {
|
|
|
182133
183092
|
}
|
|
182134
183093
|
}
|
|
182135
183094
|
async function detectGo(workdir) {
|
|
182136
|
-
const goMod =
|
|
183095
|
+
const goMod = join199(workdir, "go.mod");
|
|
182137
183096
|
if (!existsSync30(goMod))
|
|
182138
183097
|
return null;
|
|
182139
183098
|
try {
|
|
@@ -182157,7 +183116,7 @@ async function detectGo(workdir) {
|
|
|
182157
183116
|
}
|
|
182158
183117
|
}
|
|
182159
183118
|
async function detectRust(workdir) {
|
|
182160
|
-
const cargoPath =
|
|
183119
|
+
const cargoPath = join199(workdir, "Cargo.toml");
|
|
182161
183120
|
if (!existsSync30(cargoPath))
|
|
182162
183121
|
return null;
|
|
182163
183122
|
try {
|
|
@@ -182173,8 +183132,8 @@ async function detectRust(workdir) {
|
|
|
182173
183132
|
}
|
|
182174
183133
|
}
|
|
182175
183134
|
async function detectPython(workdir) {
|
|
182176
|
-
const pyproject =
|
|
182177
|
-
const requirements =
|
|
183135
|
+
const pyproject = join199(workdir, "pyproject.toml");
|
|
183136
|
+
const requirements = join199(workdir, "requirements.txt");
|
|
182178
183137
|
if (!existsSync30(pyproject) && !existsSync30(requirements))
|
|
182179
183138
|
return null;
|
|
182180
183139
|
try {
|
|
@@ -182193,7 +183152,7 @@ async function detectPython(workdir) {
|
|
|
182193
183152
|
}
|
|
182194
183153
|
}
|
|
182195
183154
|
async function detectPhp(workdir) {
|
|
182196
|
-
const composerPath =
|
|
183155
|
+
const composerPath = join199(workdir, "composer.json");
|
|
182197
183156
|
if (!existsSync30(composerPath))
|
|
182198
183157
|
return null;
|
|
182199
183158
|
try {
|
|
@@ -182206,7 +183165,7 @@ async function detectPhp(workdir) {
|
|
|
182206
183165
|
}
|
|
182207
183166
|
}
|
|
182208
183167
|
async function detectRuby(workdir) {
|
|
182209
|
-
const gemfile =
|
|
183168
|
+
const gemfile = join199(workdir, "Gemfile");
|
|
182210
183169
|
if (!existsSync30(gemfile))
|
|
182211
183170
|
return null;
|
|
182212
183171
|
try {
|
|
@@ -182218,9 +183177,9 @@ async function detectRuby(workdir) {
|
|
|
182218
183177
|
}
|
|
182219
183178
|
}
|
|
182220
183179
|
async function detectJvm(workdir) {
|
|
182221
|
-
const pom =
|
|
182222
|
-
const gradle =
|
|
182223
|
-
const gradleKts =
|
|
183180
|
+
const pom = join199(workdir, "pom.xml");
|
|
183181
|
+
const gradle = join199(workdir, "build.gradle");
|
|
183182
|
+
const gradleKts = join199(workdir, "build.gradle.kts");
|
|
182224
183183
|
if (!existsSync30(pom) && !existsSync30(gradle) && !existsSync30(gradleKts))
|
|
182225
183184
|
return null;
|
|
182226
183185
|
try {
|
|
@@ -182228,7 +183187,7 @@ async function detectJvm(workdir) {
|
|
|
182228
183187
|
const content = await Bun.file(pom).text();
|
|
182229
183188
|
const nameMatch = content.match(/<artifactId>([^<]+)<\/artifactId>/);
|
|
182230
183189
|
const deps = [...content.matchAll(/<artifactId>([^<]+)<\/artifactId>/g)].map((m) => m[1]).filter((d) => d !== nameMatch?.[1]).slice(0, 10);
|
|
182231
|
-
const lang = existsSync30(
|
|
183190
|
+
const lang = existsSync30(join199(workdir, "src/main/kotlin")) ? "Kotlin" : "Java";
|
|
182232
183191
|
return { name: nameMatch?.[1], lang, dependencies: deps };
|
|
182233
183192
|
}
|
|
182234
183193
|
const gradleFile = existsSync30(gradleKts) ? gradleKts : gradle;
|
|
@@ -182483,7 +183442,7 @@ var init_windsurf = __esm(() => {
|
|
|
182483
183442
|
|
|
182484
183443
|
// src/context/generator/index.ts
|
|
182485
183444
|
import { existsSync as existsSync31 } from "fs";
|
|
182486
|
-
import { join as
|
|
183445
|
+
import { join as join200, relative as relative52 } from "path";
|
|
182487
183446
|
async function loadContextContent(options, config) {
|
|
182488
183447
|
if (!_generatorDeps.existsSync(options.contextPath)) {
|
|
182489
183448
|
throw new NaxError(`Context file not found: ${options.contextPath}`, "CONTEXT_FILE_NOT_FOUND", {
|
|
@@ -182504,7 +183463,7 @@ async function generateFor(agent, options, config) {
|
|
|
182504
183463
|
try {
|
|
182505
183464
|
const context = await loadContextContent(options, config);
|
|
182506
183465
|
const content = generator.generate(context);
|
|
182507
|
-
const outputPath =
|
|
183466
|
+
const outputPath = join200(options.outputDir, generator.outputFile);
|
|
182508
183467
|
validateFilePath(outputPath, options.outputDir);
|
|
182509
183468
|
if (!options.dryRun) {
|
|
182510
183469
|
await _generatorDeps.writeFile(outputPath, content);
|
|
@@ -182522,7 +183481,7 @@ async function generateAll(options, config, agentFilter) {
|
|
|
182522
183481
|
for (const [agentKey, generator] of entries) {
|
|
182523
183482
|
try {
|
|
182524
183483
|
const content = generator.generate(context);
|
|
182525
|
-
const outputPath =
|
|
183484
|
+
const outputPath = join200(options.outputDir, generator.outputFile);
|
|
182526
183485
|
validateFilePath(outputPath, options.outputDir);
|
|
182527
183486
|
if (!options.dryRun) {
|
|
182528
183487
|
await _generatorDeps.writeFile(outputPath, content);
|
|
@@ -182542,7 +183501,7 @@ async function discoverPackages(repoRoot) {
|
|
|
182542
183501
|
const glob = new Bun.Glob(pattern);
|
|
182543
183502
|
for await (const match of glob.scan({ cwd: repoRoot, dot: true })) {
|
|
182544
183503
|
const pkgRelative = match.replace(/^\.nax\/mono\//, "").replace(/\/context\.md$/, "");
|
|
182545
|
-
const pkgAbsolute =
|
|
183504
|
+
const pkgAbsolute = join200(repoRoot, pkgRelative);
|
|
182546
183505
|
if (!seen.has(pkgAbsolute)) {
|
|
182547
183506
|
seen.add(pkgAbsolute);
|
|
182548
183507
|
packages.push(pkgAbsolute);
|
|
@@ -182574,14 +183533,14 @@ async function discoverWorkspacePackages2(repoRoot) {
|
|
|
182574
183533
|
}
|
|
182575
183534
|
}
|
|
182576
183535
|
}
|
|
182577
|
-
const turboPath =
|
|
183536
|
+
const turboPath = join200(repoRoot, "turbo.json");
|
|
182578
183537
|
try {
|
|
182579
183538
|
const turbo = JSON.parse(await _generatorDeps.readTextFile(turboPath));
|
|
182580
183539
|
if (Array.isArray(turbo.packages)) {
|
|
182581
183540
|
await resolveGlobs(turbo.packages);
|
|
182582
183541
|
}
|
|
182583
183542
|
} catch {}
|
|
182584
|
-
const pkgPath =
|
|
183543
|
+
const pkgPath = join200(repoRoot, "package.json");
|
|
182585
183544
|
try {
|
|
182586
183545
|
const pkg = JSON.parse(await _generatorDeps.readTextFile(pkgPath));
|
|
182587
183546
|
const ws = pkg.workspaces;
|
|
@@ -182589,7 +183548,7 @@ async function discoverWorkspacePackages2(repoRoot) {
|
|
|
182589
183548
|
if (patterns.length > 0)
|
|
182590
183549
|
await resolveGlobs(patterns);
|
|
182591
183550
|
} catch {}
|
|
182592
|
-
const pnpmPath =
|
|
183551
|
+
const pnpmPath = join200(repoRoot, "pnpm-workspace.yaml");
|
|
182593
183552
|
try {
|
|
182594
183553
|
const raw = await _generatorDeps.readTextFile(pnpmPath);
|
|
182595
183554
|
const lines = raw.split(`
|
|
@@ -182615,7 +183574,7 @@ async function discoverWorkspacePackages2(repoRoot) {
|
|
|
182615
183574
|
async function generateForPackage(packageDir, config, dryRun = false, repoRoot) {
|
|
182616
183575
|
const resolvedRepoRoot = repoRoot ?? packageDir;
|
|
182617
183576
|
const relativePkgPath = relative52(resolvedRepoRoot, packageDir);
|
|
182618
|
-
const contextPath =
|
|
183577
|
+
const contextPath = join200(resolvedRepoRoot, ".nax", "mono", relativePkgPath, "context.md");
|
|
182619
183578
|
if (!_generatorDeps.existsSync(contextPath)) {
|
|
182620
183579
|
return [
|
|
182621
183580
|
{
|
|
@@ -182686,7 +183645,7 @@ var init_generator2 = __esm(() => {
|
|
|
182686
183645
|
|
|
182687
183646
|
// src/cli/generate.ts
|
|
182688
183647
|
import { existsSync as existsSync32 } from "fs";
|
|
182689
|
-
import { join as
|
|
183648
|
+
import { join as join201 } from "path";
|
|
182690
183649
|
async function loadCommandConfig(workdir) {
|
|
182691
183650
|
try {
|
|
182692
183651
|
return await loadConfig(workdir);
|
|
@@ -182737,7 +183696,7 @@ async function runSinglePackage(frame, pkg) {
|
|
|
182737
183696
|
if (!isRelativeAndSafe(pkg)) {
|
|
182738
183697
|
throw new NaxError(`generateCommand: package "${pkg}" is not a safe relative path (must be non-empty, relative, and free of ".." segments)`, "INVALID_PACKAGE_PATH", { stage: "generate", package: pkg });
|
|
182739
183698
|
}
|
|
182740
|
-
const packageDir =
|
|
183699
|
+
const packageDir = join201(frame.workdir, pkg);
|
|
182741
183700
|
printDryRunNotice(frame.dryRun);
|
|
182742
183701
|
console.log(source_default.blue(`\u2192 Generating agent files for package: ${pkg}`));
|
|
182743
183702
|
const pkgResults = await generateForPackage(packageDir, frame.config, frame.dryRun, frame.workdir);
|
|
@@ -182836,8 +183795,8 @@ async function generateFromConfig(frame, genOptions) {
|
|
|
182836
183795
|
await generateDiscoveredPackages(frame);
|
|
182837
183796
|
}
|
|
182838
183797
|
async function runRootGeneration(frame, options) {
|
|
182839
|
-
const contextPath = options.context ?
|
|
182840
|
-
const outputDir = options.output ?
|
|
183798
|
+
const contextPath = options.context ? join201(frame.workdir, options.context) : join201(frame.workdir, ".nax/context.md");
|
|
183799
|
+
const outputDir = options.output ? join201(frame.workdir, options.output) : frame.workdir;
|
|
182841
183800
|
const autoInject = !options.noAutoInject;
|
|
182842
183801
|
validateRootInputs(contextPath, options.agent);
|
|
182843
183802
|
printDryRunNotice(frame.dryRun);
|
|
@@ -182898,7 +183857,7 @@ var init_generate = __esm(() => {
|
|
|
182898
183857
|
|
|
182899
183858
|
// src/cli/init-context.ts
|
|
182900
183859
|
import { mkdir as mkdir52, readdir as readdir16 } from "fs/promises";
|
|
182901
|
-
import { basename as basename35, join as
|
|
183860
|
+
import { basename as basename35, join as join202, relative as relative53, sep as sep27 } from "path";
|
|
182902
183861
|
async function bunFileExists(path) {
|
|
182903
183862
|
return Bun.file(path).exists();
|
|
182904
183863
|
}
|
|
@@ -182923,14 +183882,14 @@ async function walkDir(root, current, out, maxFiles) {
|
|
|
182923
183882
|
if (entry.isDirectory()) {
|
|
182924
183883
|
if (EXCLUDED_DIR_NAMES.has(entry.name))
|
|
182925
183884
|
continue;
|
|
182926
|
-
await walkDir(root,
|
|
183885
|
+
await walkDir(root, join202(current, entry.name), out, maxFiles);
|
|
182927
183886
|
} else if (entry.isFile()) {
|
|
182928
|
-
out.push(relative53(root,
|
|
183887
|
+
out.push(relative53(root, join202(current, entry.name)).replaceAll(sep27, "/"));
|
|
182929
183888
|
}
|
|
182930
183889
|
}
|
|
182931
183890
|
}
|
|
182932
183891
|
async function readPackageManifest(projectRoot) {
|
|
182933
|
-
const packageJsonPath =
|
|
183892
|
+
const packageJsonPath = join202(projectRoot, "package.json");
|
|
182934
183893
|
if (!await bunFileExists(packageJsonPath)) {
|
|
182935
183894
|
return null;
|
|
182936
183895
|
}
|
|
@@ -182948,7 +183907,7 @@ async function readPackageManifest(projectRoot) {
|
|
|
182948
183907
|
}
|
|
182949
183908
|
}
|
|
182950
183909
|
async function readReadmeSnippet(projectRoot) {
|
|
182951
|
-
const readmePath =
|
|
183910
|
+
const readmePath = join202(projectRoot, "README.md");
|
|
182952
183911
|
if (!await bunFileExists(readmePath)) {
|
|
182953
183912
|
return null;
|
|
182954
183913
|
}
|
|
@@ -182966,7 +183925,7 @@ async function detectEntryPoints(projectRoot) {
|
|
|
182966
183925
|
const candidates = ["src/index.ts", "src/main.ts", "main.go", "src/lib.rs"];
|
|
182967
183926
|
const found = [];
|
|
182968
183927
|
for (const candidate of candidates) {
|
|
182969
|
-
const path =
|
|
183928
|
+
const path = join202(projectRoot, candidate);
|
|
182970
183929
|
if (await bunFileExists(path)) {
|
|
182971
183930
|
found.push(candidate);
|
|
182972
183931
|
}
|
|
@@ -182977,7 +183936,7 @@ async function detectConfigFiles(projectRoot) {
|
|
|
182977
183936
|
const candidates = ["tsconfig.json", "biome.json", "turbo.json", ".env.example"];
|
|
182978
183937
|
const found = [];
|
|
182979
183938
|
for (const candidate of candidates) {
|
|
182980
|
-
const path =
|
|
183939
|
+
const path = join202(projectRoot, candidate);
|
|
182981
183940
|
if (await bunFileExists(path)) {
|
|
182982
183941
|
found.push(candidate);
|
|
182983
183942
|
}
|
|
@@ -183108,8 +184067,8 @@ async function initPackage(repoRoot, packagePath, force = false) {
|
|
|
183108
184067
|
throw new NaxError(`initPackage: packagePath "${packagePath}" is not a safe relative path (must be non-empty, relative, and free of ".." segments)`, "INVALID_PACKAGE_PATH", { stage: "init-context", packagePath });
|
|
183109
184068
|
}
|
|
183110
184069
|
const logger = getLogger2();
|
|
183111
|
-
const naxDir =
|
|
183112
|
-
const contextPath =
|
|
184070
|
+
const naxDir = join202(repoRoot, ".nax", "mono", packagePath);
|
|
184071
|
+
const contextPath = join202(naxDir, "context.md");
|
|
183113
184072
|
if (await bunFileExists(contextPath) && !force) {
|
|
183114
184073
|
logger.info("init", "Package context.md already exists (use --force to overwrite)", {
|
|
183115
184074
|
storyId: "init-context",
|
|
@@ -183132,8 +184091,8 @@ async function initPackage(repoRoot, packagePath, force = false) {
|
|
|
183132
184091
|
}
|
|
183133
184092
|
async function initContext(projectRoot, options = {}) {
|
|
183134
184093
|
const logger = getLogger2();
|
|
183135
|
-
const naxDir =
|
|
183136
|
-
const contextPath =
|
|
184094
|
+
const naxDir = join202(projectRoot, ".nax");
|
|
184095
|
+
const contextPath = join202(naxDir, "context.md");
|
|
183137
184096
|
if (await bunFileExists(contextPath) && !options.force) {
|
|
183138
184097
|
logger.info("init", "context.md already exists, skipping (use --force to overwrite)", {
|
|
183139
184098
|
storyId: "init-context",
|
|
@@ -183168,9 +184127,9 @@ var init_init_context = __esm(() => {
|
|
|
183168
184127
|
|
|
183169
184128
|
// src/cli/init-detect.ts
|
|
183170
184129
|
import { existsSync as existsSync33, readFileSync as readFileSync4 } from "fs";
|
|
183171
|
-
import { join as
|
|
184130
|
+
import { join as join203 } from "path";
|
|
183172
184131
|
function readPackageJson(projectRoot) {
|
|
183173
|
-
const pkgPath =
|
|
184132
|
+
const pkgPath = join203(projectRoot, "package.json");
|
|
183174
184133
|
if (!existsSync33(pkgPath))
|
|
183175
184134
|
return;
|
|
183176
184135
|
try {
|
|
@@ -183213,41 +184172,41 @@ function detectStack(projectRoot) {
|
|
|
183213
184172
|
};
|
|
183214
184173
|
}
|
|
183215
184174
|
function detectRuntime(projectRoot) {
|
|
183216
|
-
if (existsSync33(
|
|
184175
|
+
if (existsSync33(join203(projectRoot, "bun.lockb")) || existsSync33(join203(projectRoot, "bunfig.toml"))) {
|
|
183217
184176
|
return "bun";
|
|
183218
184177
|
}
|
|
183219
|
-
if (existsSync33(
|
|
184178
|
+
if (existsSync33(join203(projectRoot, "package-lock.json")) || existsSync33(join203(projectRoot, "yarn.lock")) || existsSync33(join203(projectRoot, "pnpm-lock.yaml"))) {
|
|
183220
184179
|
return "node";
|
|
183221
184180
|
}
|
|
183222
184181
|
return "unknown";
|
|
183223
184182
|
}
|
|
183224
184183
|
function detectLanguage2(projectRoot) {
|
|
183225
|
-
if (existsSync33(
|
|
184184
|
+
if (existsSync33(join203(projectRoot, "tsconfig.json")))
|
|
183226
184185
|
return "typescript";
|
|
183227
|
-
if (existsSync33(
|
|
184186
|
+
if (existsSync33(join203(projectRoot, "pyproject.toml")) || existsSync33(join203(projectRoot, "setup.py"))) {
|
|
183228
184187
|
return "python";
|
|
183229
184188
|
}
|
|
183230
|
-
if (existsSync33(
|
|
184189
|
+
if (existsSync33(join203(projectRoot, "Cargo.toml")))
|
|
183231
184190
|
return "rust";
|
|
183232
|
-
if (existsSync33(
|
|
184191
|
+
if (existsSync33(join203(projectRoot, "go.mod")))
|
|
183233
184192
|
return "go";
|
|
183234
184193
|
return "unknown";
|
|
183235
184194
|
}
|
|
183236
184195
|
function detectLinter(projectRoot) {
|
|
183237
|
-
if (existsSync33(
|
|
184196
|
+
if (existsSync33(join203(projectRoot, "biome.json")) || existsSync33(join203(projectRoot, "biome.jsonc"))) {
|
|
183238
184197
|
return "biome";
|
|
183239
184198
|
}
|
|
183240
|
-
if (existsSync33(
|
|
184199
|
+
if (existsSync33(join203(projectRoot, ".eslintrc.json")) || existsSync33(join203(projectRoot, ".eslintrc.js")) || existsSync33(join203(projectRoot, "eslint.config.js"))) {
|
|
183241
184200
|
return "eslint";
|
|
183242
184201
|
}
|
|
183243
184202
|
return "unknown";
|
|
183244
184203
|
}
|
|
183245
184204
|
function detectMonorepo(projectRoot) {
|
|
183246
|
-
if (existsSync33(
|
|
184205
|
+
if (existsSync33(join203(projectRoot, "turbo.json")))
|
|
183247
184206
|
return "turborepo";
|
|
183248
|
-
if (existsSync33(
|
|
184207
|
+
if (existsSync33(join203(projectRoot, "nx.json")))
|
|
183249
184208
|
return "nx";
|
|
183250
|
-
if (existsSync33(
|
|
184209
|
+
if (existsSync33(join203(projectRoot, "pnpm-workspace.yaml")))
|
|
183251
184210
|
return "pnpm-workspaces";
|
|
183252
184211
|
const pkg = readPackageJson(projectRoot);
|
|
183253
184212
|
if (pkg?.workspaces)
|
|
@@ -183383,7 +184342,7 @@ var init_init_detect = () => {};
|
|
|
183383
184342
|
// src/cli/init.ts
|
|
183384
184343
|
import { existsSync as existsSync34 } from "fs";
|
|
183385
184344
|
import { mkdir as mkdir53 } from "fs/promises";
|
|
183386
|
-
import { join as
|
|
184345
|
+
import { join as join204 } from "path";
|
|
183387
184346
|
function validateProjectName(name) {
|
|
183388
184347
|
if (!name)
|
|
183389
184348
|
return { valid: false, error: "name must be non-empty" };
|
|
@@ -183419,7 +184378,7 @@ async function checkInitCollision(name, currentWorkdir, currentRemote) {
|
|
|
183419
184378
|
}
|
|
183420
184379
|
async function updateGitignore(projectRoot) {
|
|
183421
184380
|
const logger = getLogger2();
|
|
183422
|
-
const gitignorePath =
|
|
184381
|
+
const gitignorePath = join204(projectRoot, ".gitignore");
|
|
183423
184382
|
const result = await patchIgnoreFile(gitignorePath, NAX_GITIGNORE_ENTRIES);
|
|
183424
184383
|
if (result.added.length === 0) {
|
|
183425
184384
|
logger.info("init", ".gitignore already has nax entries", { path: gitignorePath });
|
|
@@ -183433,7 +184392,7 @@ async function updateGitignore(projectRoot) {
|
|
|
183433
184392
|
}
|
|
183434
184393
|
async function updateNaxignore(projectRoot) {
|
|
183435
184394
|
const logger = getLogger2();
|
|
183436
|
-
const naxignorePath =
|
|
184395
|
+
const naxignorePath = join204(projectRoot, ".naxignore");
|
|
183437
184396
|
const result = await patchIgnoreFile(naxignorePath, NAX_NAXIGNORE_ENTRIES, {
|
|
183438
184397
|
header: NAX_NAXIGNORE_HEADER,
|
|
183439
184398
|
footer: NAX_NAXIGNORE_SUGGESTIONS,
|
|
@@ -183519,7 +184478,7 @@ async function initGlobal() {
|
|
|
183519
184478
|
await mkdir53(globalDir, { recursive: true });
|
|
183520
184479
|
logger.info("init", "Created global config directory", { path: globalDir });
|
|
183521
184480
|
}
|
|
183522
|
-
const configPath =
|
|
184481
|
+
const configPath = join204(globalDir, "config.json");
|
|
183523
184482
|
if (!existsSync34(configPath)) {
|
|
183524
184483
|
await Bun.write(configPath, `${JSON.stringify(MINIMAL_GLOBAL_CONFIG, null, 2)}
|
|
183525
184484
|
`);
|
|
@@ -183527,14 +184486,14 @@ async function initGlobal() {
|
|
|
183527
184486
|
} else {
|
|
183528
184487
|
logger.info("init", "Global config already exists", { path: configPath });
|
|
183529
184488
|
}
|
|
183530
|
-
const constitutionPath =
|
|
184489
|
+
const constitutionPath = join204(globalDir, "constitution.md");
|
|
183531
184490
|
if (!existsSync34(constitutionPath)) {
|
|
183532
184491
|
await Bun.write(constitutionPath, buildConstitution({ runtime: "unknown", language: "unknown", linter: "unknown", monorepo: "none" }));
|
|
183533
184492
|
logger.info("init", "Created global constitution", { path: constitutionPath });
|
|
183534
184493
|
} else {
|
|
183535
184494
|
logger.info("init", "Global constitution already exists", { path: constitutionPath });
|
|
183536
184495
|
}
|
|
183537
|
-
const hooksDir =
|
|
184496
|
+
const hooksDir = join204(globalDir, "hooks");
|
|
183538
184497
|
if (!existsSync34(hooksDir)) {
|
|
183539
184498
|
await mkdir53(hooksDir, { recursive: true });
|
|
183540
184499
|
logger.info("init", "Created global hooks directory", { path: hooksDir });
|
|
@@ -183567,7 +184526,7 @@ async function initProject(projectRoot, options) {
|
|
|
183567
184526
|
if (detectedName && !options?.force) {
|
|
183568
184527
|
const collision = await checkInitCollision(detectedName, projectRoot, currentRemote);
|
|
183569
184528
|
if (collision.collision && collision.existing) {
|
|
183570
|
-
const configPath =
|
|
184529
|
+
const configPath = join204(projectDir, "config.json");
|
|
183571
184530
|
throw new NaxError([
|
|
183572
184531
|
`Project name collision: "${detectedName}"`,
|
|
183573
184532
|
` This project: ${projectRoot}`,
|
|
@@ -183595,7 +184554,7 @@ async function initProject(projectRoot, options) {
|
|
|
183595
184554
|
linter: stack.linter,
|
|
183596
184555
|
monorepo: stack.monorepo
|
|
183597
184556
|
});
|
|
183598
|
-
const configPath =
|
|
184557
|
+
const configPath = join204(projectDir, "config.json");
|
|
183599
184558
|
if (!existsSync34(configPath)) {
|
|
183600
184559
|
await Bun.write(configPath, `${JSON.stringify(projectConfig, null, 2)}
|
|
183601
184560
|
`);
|
|
@@ -183604,7 +184563,7 @@ async function initProject(projectRoot, options) {
|
|
|
183604
184563
|
logger.info("init", "Project config already exists", { path: configPath });
|
|
183605
184564
|
}
|
|
183606
184565
|
await initContext(projectRoot, { force: options?.force });
|
|
183607
|
-
const constitutionPath =
|
|
184566
|
+
const constitutionPath = join204(projectDir, "constitution.md");
|
|
183608
184567
|
if (!existsSync34(constitutionPath) || options?.force) {
|
|
183609
184568
|
await Bun.write(constitutionPath, buildConstitution(stack));
|
|
183610
184569
|
logger.info("init", "Created project constitution", { path: constitutionPath });
|
|
@@ -183612,7 +184571,7 @@ async function initProject(projectRoot, options) {
|
|
|
183612
184571
|
logger.info("init", "Project constitution already exists", { path: constitutionPath });
|
|
183613
184572
|
}
|
|
183614
184573
|
for (const [label, dir] of [
|
|
183615
|
-
["hooks",
|
|
184574
|
+
["hooks", join204(projectDir, "hooks")],
|
|
183616
184575
|
["features", featuresDir(projectRoot)]
|
|
183617
184576
|
]) {
|
|
183618
184577
|
if (!existsSync34(dir)) {
|
|
@@ -183752,7 +184711,7 @@ var init_plan_helpers = __esm(() => {
|
|
|
183752
184711
|
});
|
|
183753
184712
|
|
|
183754
184713
|
// src/analyze/scanner.ts
|
|
183755
|
-
import { join as
|
|
184714
|
+
import { join as join205 } from "path";
|
|
183756
184715
|
function resolveFrameworkAndRunner(language, pkg) {
|
|
183757
184716
|
if (language === "go")
|
|
183758
184717
|
return { framework: "", testRunner: "go-test" };
|
|
@@ -183774,7 +184733,7 @@ async function scanSourceRoots(workdir) {
|
|
|
183774
184733
|
});
|
|
183775
184734
|
try {
|
|
183776
184735
|
const language = await deps.detectLanguage(workdir);
|
|
183777
|
-
const pkg = await deps.readPackageJson(
|
|
184736
|
+
const pkg = await deps.readPackageJson(join205(workdir, "package.json"));
|
|
183778
184737
|
const { framework, testRunner } = resolveFrameworkAndRunner(language, pkg);
|
|
183779
184738
|
return [{ path: ".", language, framework, testRunner }];
|
|
183780
184739
|
} catch {
|
|
@@ -183792,9 +184751,9 @@ async function scanSourceRoots(workdir) {
|
|
|
183792
184751
|
packages = packages.slice(0, MAX_SOURCE_ROOTS);
|
|
183793
184752
|
}
|
|
183794
184753
|
return Promise.all(packages.map(async (pkgPath) => {
|
|
183795
|
-
const pkgDir = pkgPath === "." ? workdir :
|
|
184754
|
+
const pkgDir = pkgPath === "." ? workdir : join205(workdir, pkgPath);
|
|
183796
184755
|
const language = await deps.detectLanguage(pkgDir);
|
|
183797
|
-
const pkg = await deps.readPackageJson(
|
|
184756
|
+
const pkg = await deps.readPackageJson(join205(pkgDir, "package.json"));
|
|
183798
184757
|
const { framework, testRunner } = resolveFrameworkAndRunner(language, pkg);
|
|
183799
184758
|
return { path: pkgPath, language, framework, testRunner };
|
|
183800
184759
|
}));
|
|
@@ -183886,7 +184845,7 @@ var init_decompose_mapper = __esm(() => {
|
|
|
183886
184845
|
});
|
|
183887
184846
|
|
|
183888
184847
|
// src/cli/plan-decompose.ts
|
|
183889
|
-
import { join as
|
|
184848
|
+
import { join as join206 } from "path";
|
|
183890
184849
|
function validateDecomposedStoryIds(stories, existingIds) {
|
|
183891
184850
|
const generatedIds = new Set;
|
|
183892
184851
|
for (const story of stories) {
|
|
@@ -183900,7 +184859,7 @@ function validateDecomposedStoryIds(stories, existingIds) {
|
|
|
183900
184859
|
}
|
|
183901
184860
|
}
|
|
183902
184861
|
async function planDecomposeCommand(workdir, config, options) {
|
|
183903
|
-
const prdPath =
|
|
184862
|
+
const prdPath = join206(featureDir(workdir, options.feature), "prd.json");
|
|
183904
184863
|
if (!_planDeps.existsSync(prdPath)) {
|
|
183905
184864
|
throw new NaxError(`PRD not found: ${prdPath}`, "PRD_NOT_FOUND", {
|
|
183906
184865
|
stage: "decompose",
|
|
@@ -184055,7 +185014,7 @@ var init_plan_decompose = __esm(() => {
|
|
|
184055
185014
|
|
|
184056
185015
|
// src/cli/plan-runtime/index.ts
|
|
184057
185016
|
import { existsSync as existsSync35 } from "fs";
|
|
184058
|
-
import { join as
|
|
185017
|
+
import { join as join207 } from "path";
|
|
184059
185018
|
function createPlanRuntime(config, workdir, featureName) {
|
|
184060
185019
|
return _planDeps.createRuntime(config, workdir, featureName);
|
|
184061
185020
|
}
|
|
@@ -184107,7 +185066,7 @@ var init_plan_runtime = __esm(() => {
|
|
|
184107
185066
|
scanSourceRoots: (workdir) => scanSourceRoots(workdir),
|
|
184108
185067
|
createRuntime: (cfg, wd, featureName) => createRuntime(cfg, wd, { featureName }),
|
|
184109
185068
|
claimProjectIdentity,
|
|
184110
|
-
readPackageJson: (workdir) => Bun.file(
|
|
185069
|
+
readPackageJson: (workdir) => Bun.file(join207(workdir, "package.json")).json().catch(() => null),
|
|
184111
185070
|
spawnSync: (cmd, opts) => {
|
|
184112
185071
|
const result = Bun.spawnSync(cmd, opts ? { cwd: opts.cwd, ...opts.env ? { env: opts.env } : {} } : {});
|
|
184113
185072
|
return { stdout: result.stdout, exitCode: result.exitCode };
|
|
@@ -184130,13 +185089,13 @@ var init_plan_runtime = __esm(() => {
|
|
|
184130
185089
|
|
|
184131
185090
|
// src/plan/spec-lint-gate.ts
|
|
184132
185091
|
import { existsSync as existsSync36 } from "fs";
|
|
184133
|
-
import { join as
|
|
185092
|
+
import { join as join208 } from "path";
|
|
184134
185093
|
function assertSpecLintClean(specContent, options) {
|
|
184135
185094
|
if (options.skip === true)
|
|
184136
185095
|
return [];
|
|
184137
185096
|
const findings = lintSpecContent(specContent, {
|
|
184138
185097
|
maxAcCount: options.maxAcCount,
|
|
184139
|
-
fileExists: (path) => existsSync36(
|
|
185098
|
+
fileExists: (path) => existsSync36(join208(options.workdir, path))
|
|
184140
185099
|
});
|
|
184141
185100
|
const blocking = findings.filter((finding) => BLOCKING_SPEC_LINT_CODES.has(finding.code));
|
|
184142
185101
|
if (blocking.length > 0) {
|
|
@@ -184159,9 +185118,9 @@ var init_spec_lint_gate = __esm(() => {
|
|
|
184159
185118
|
});
|
|
184160
185119
|
|
|
184161
185120
|
// src/plan/strategies/context-builder.ts
|
|
184162
|
-
import { join as
|
|
185121
|
+
import { join as join209 } from "path";
|
|
184163
185122
|
async function buildPlanModeContext(workdir, fullConfig, options, deps) {
|
|
184164
|
-
const naxDir =
|
|
185123
|
+
const naxDir = join209(workdir, ".nax");
|
|
184165
185124
|
if (!deps.existsSync(naxDir)) {
|
|
184166
185125
|
throw new NaxError(`.nax directory not found. Run 'nax init' first in ${workdir}`, "PLAN_CONTEXT_NO_NAX_DIR", {
|
|
184167
185126
|
stage: "plan",
|
|
@@ -184169,8 +185128,8 @@ async function buildPlanModeContext(workdir, fullConfig, options, deps) {
|
|
|
184169
185128
|
});
|
|
184170
185129
|
}
|
|
184171
185130
|
validateFeatureName(options.feature);
|
|
184172
|
-
const outputDir =
|
|
184173
|
-
const outputPath =
|
|
185131
|
+
const outputDir = join209(naxDir, "features", options.feature);
|
|
185132
|
+
const outputPath = join209(outputDir, "prd.json");
|
|
184174
185133
|
const [specContent, sourceRoots, pkg] = await Promise.all([
|
|
184175
185134
|
deps.readFile(options.from),
|
|
184176
185135
|
deps.scanSourceRoots(workdir),
|
|
@@ -184199,7 +185158,7 @@ async function buildPlanModeContext(workdir, fullConfig, options, deps) {
|
|
|
184199
185158
|
...new Set(sourceRoots.map((root) => root.path).filter((path) => path !== ".").map((path) => path.startsWith("/") ? path.replace(`${workdir}/`, "") : path))
|
|
184200
185159
|
];
|
|
184201
185160
|
const packageDetails = relativePackages.length === 0 ? [] : await Promise.all(relativePackages.map(async (relativePath) => {
|
|
184202
|
-
const packageJson = await deps.readPackageJsonAt(
|
|
185161
|
+
const packageJson = await deps.readPackageJsonAt(join209(workdir, relativePath, "package.json"));
|
|
184203
185162
|
return buildPackageSummary(relativePath, packageJson);
|
|
184204
185163
|
}));
|
|
184205
185164
|
const projectName = detectProjectName(workdir, pkg);
|
|
@@ -184289,12 +185248,12 @@ var init_finalize_routing = __esm(() => {
|
|
|
184289
185248
|
|
|
184290
185249
|
// src/plan/strategies/persist-prd.ts
|
|
184291
185250
|
import { existsSync as defaultExistsSync, renameSync as defaultRenameSync } from "fs";
|
|
184292
|
-
import { dirname as dirname51, join as
|
|
185251
|
+
import { dirname as dirname51, join as join210 } from "path";
|
|
184293
185252
|
function unverifiedStampedStoryIds(prd) {
|
|
184294
185253
|
return prd.userStories.filter((story) => story.workdirSource !== undefined && (story.contextFiles?.length ?? 0) + (story.expectedFiles?.length ?? 0) + (story.modifiedFiles?.length ?? 0) > 0).map((story) => story.id);
|
|
184295
185254
|
}
|
|
184296
185255
|
function moveDraftAside(outputPath) {
|
|
184297
|
-
const rejectedPath =
|
|
185256
|
+
const rejectedPath = join210(dirname51(outputPath), "prd.rejected.json");
|
|
184298
185257
|
if (!_persistPrdDeps.existsSync(outputPath)) {
|
|
184299
185258
|
return { phrase: `no draft was on disk at ${outputPath}` };
|
|
184300
185259
|
}
|
|
@@ -184379,7 +185338,7 @@ async function finalizeAndWritePrd(args) {
|
|
|
184379
185338
|
respelled: result.respelled
|
|
184380
185339
|
});
|
|
184381
185340
|
}
|
|
184382
|
-
if (result.defaulted.length > 0 && _persistPrdDeps.existsSync(
|
|
185341
|
+
if (result.defaulted.length > 0 && _persistPrdDeps.existsSync(join210(args.repoRoot, ".nax", "mono"))) {
|
|
184383
185342
|
getLogger2().warn("plan", "stories have no resolved workdir in a monorepo: they will receive the WHOLE rule corpus and the ROOT quality.commands, not their package's", { storyIds: result.defaulted });
|
|
184384
185343
|
}
|
|
184385
185344
|
} catch (err) {
|
|
@@ -184789,13 +185748,13 @@ var init_prompts_export = __esm(() => {
|
|
|
184789
185748
|
});
|
|
184790
185749
|
|
|
184791
185750
|
// src/cli/prompts-init.ts
|
|
184792
|
-
import { existsSync as existsSync37, mkdirSync as
|
|
184793
|
-
import { join as
|
|
185751
|
+
import { existsSync as existsSync37, mkdirSync as mkdirSync14 } from "fs";
|
|
185752
|
+
import { join as join212 } from "path";
|
|
184794
185753
|
async function promptsInitCommand(options) {
|
|
184795
185754
|
const { workdir, force = false, autoWireConfig = true } = options;
|
|
184796
|
-
const templatesDir =
|
|
184797
|
-
|
|
184798
|
-
const existingFiles = TEMPLATE_ROLES.map((t) => t.file).filter((f) => existsSync37(
|
|
185755
|
+
const templatesDir = join212(workdir, ".nax", "templates");
|
|
185756
|
+
mkdirSync14(templatesDir, { recursive: true });
|
|
185757
|
+
const existingFiles = TEMPLATE_ROLES.map((t) => t.file).filter((f) => existsSync37(join212(templatesDir, f)));
|
|
184799
185758
|
if (existingFiles.length > 0 && !force) {
|
|
184800
185759
|
_promptsInitDeps.warn(`[WARN] .nax/templates/ already contains files: ${existingFiles.join(", ")}. No files overwritten.
|
|
184801
185760
|
Pass --force to overwrite existing templates.`);
|
|
@@ -184803,7 +185762,7 @@ async function promptsInitCommand(options) {
|
|
|
184803
185762
|
}
|
|
184804
185763
|
const written = [];
|
|
184805
185764
|
for (const template of TEMPLATE_ROLES) {
|
|
184806
|
-
const filePath =
|
|
185765
|
+
const filePath = join212(templatesDir, template.file);
|
|
184807
185766
|
const roleBody = unwrapProtocolRegions(template.role === "implementer" ? buildRoleTaskSection(template.role, template.variant) : buildRoleTaskSection(template.role));
|
|
184808
185767
|
const content = TEMPLATE_HEADER + roleBody;
|
|
184809
185768
|
await Bun.write(filePath, content);
|
|
@@ -184819,7 +185778,7 @@ async function promptsInitCommand(options) {
|
|
|
184819
185778
|
return written;
|
|
184820
185779
|
}
|
|
184821
185780
|
async function autoWirePromptsConfig(workdir) {
|
|
184822
|
-
const configPath =
|
|
185781
|
+
const configPath = join212(projectConfigDir(workdir), "config.json");
|
|
184823
185782
|
if (!existsSync37(configPath)) {
|
|
184824
185783
|
const exampleConfig = JSON.stringify({
|
|
184825
185784
|
prompts: {
|
|
@@ -184949,7 +185908,7 @@ function buildFrontmatter(story, ctx, role) {
|
|
|
184949
185908
|
}
|
|
184950
185909
|
|
|
184951
185910
|
// src/cli/prompts-tdd.ts
|
|
184952
|
-
import { join as
|
|
185911
|
+
import { join as join213 } from "path";
|
|
184953
185912
|
async function handleThreeSessionTddPrompts(story, ctx, outputDir, logger) {
|
|
184954
185913
|
const scopedTestCommand = commandSpecIncludes(ctx.config.quality?.commands?.testScoped, "{{files}}") ? "testScoped" : undefined;
|
|
184955
185914
|
const [testWriterPrompt, implementerPrompt, verifierPrompt] = await Promise.all([
|
|
@@ -184969,7 +185928,7 @@ ${frontmatter}---
|
|
|
184969
185928
|
|
|
184970
185929
|
${session.prompt}`;
|
|
184971
185930
|
if (outputDir) {
|
|
184972
|
-
const promptFile =
|
|
185931
|
+
const promptFile = join213(outputDir, `${story.id}.${session.role}.md`);
|
|
184973
185932
|
await Bun.write(promptFile, fullOutput);
|
|
184974
185933
|
logger.info("cli", "Written TDD prompt file", {
|
|
184975
185934
|
storyId: story.id,
|
|
@@ -184985,7 +185944,7 @@ ${"=".repeat(80)}`);
|
|
|
184985
185944
|
}
|
|
184986
185945
|
}
|
|
184987
185946
|
if (outputDir && ctx.contextMarkdown) {
|
|
184988
|
-
const contextFile =
|
|
185947
|
+
const contextFile = join213(outputDir, `${story.id}.context.md`);
|
|
184989
185948
|
const frontmatter = buildFrontmatter(story, ctx);
|
|
184990
185949
|
const contextOutput = `---
|
|
184991
185950
|
${frontmatter}---
|
|
@@ -185000,20 +185959,20 @@ var init_prompts_tdd = __esm(() => {
|
|
|
185000
185959
|
});
|
|
185001
185960
|
|
|
185002
185961
|
// src/cli/prompts-main.ts
|
|
185003
|
-
import { existsSync as existsSync38, mkdirSync as
|
|
185004
|
-
import { join as
|
|
185962
|
+
import { existsSync as existsSync38, mkdirSync as mkdirSync15 } from "fs";
|
|
185963
|
+
import { join as join214 } from "path";
|
|
185005
185964
|
async function promptsCommand(options) {
|
|
185006
185965
|
const logger = getLogger2();
|
|
185007
185966
|
const { feature, workdir, config, storyId, outputDir } = options;
|
|
185008
|
-
const naxDir =
|
|
185967
|
+
const naxDir = join214(workdir, ".nax");
|
|
185009
185968
|
if (!existsSync38(naxDir)) {
|
|
185010
185969
|
throw new NaxError(`.nax directory not found. Run 'nax init' first in ${workdir}`, "NAX_DIR_NOT_FOUND", {
|
|
185011
185970
|
stage: "cli",
|
|
185012
185971
|
workdir
|
|
185013
185972
|
});
|
|
185014
185973
|
}
|
|
185015
|
-
const featureDir =
|
|
185016
|
-
const prdPath =
|
|
185974
|
+
const featureDir = join214(naxDir, "features", feature);
|
|
185975
|
+
const prdPath = join214(featureDir, "prd.json");
|
|
185017
185976
|
if (!existsSync38(prdPath)) {
|
|
185018
185977
|
throw new NaxError(`Feature "${feature}" not found or missing prd.json`, "FEATURE_PRD_NOT_FOUND", {
|
|
185019
185978
|
stage: "cli",
|
|
@@ -185028,7 +185987,7 @@ async function promptsCommand(options) {
|
|
|
185028
185987
|
throw new NaxError(storyId ? `Story "${storyId}" not found in feature "${feature}"` : `No stories found in feature "${feature}"`, "STORY_NOT_FOUND", { stage: "cli", feature, storyId });
|
|
185029
185988
|
}
|
|
185030
185989
|
if (outputDir) {
|
|
185031
|
-
|
|
185990
|
+
mkdirSync15(outputDir, { recursive: true });
|
|
185032
185991
|
}
|
|
185033
185992
|
logger.info("cli", "Assembling prompts", {
|
|
185034
185993
|
feature,
|
|
@@ -185084,10 +186043,10 @@ ${frontmatter}---
|
|
|
185084
186043
|
|
|
185085
186044
|
${ctx.prompt}`;
|
|
185086
186045
|
if (outputDir) {
|
|
185087
|
-
const promptFile =
|
|
186046
|
+
const promptFile = join214(outputDir, `${story.id}.prompt.md`);
|
|
185088
186047
|
await Bun.write(promptFile, fullOutput);
|
|
185089
186048
|
if (ctx.contextMarkdown) {
|
|
185090
|
-
const contextFile =
|
|
186049
|
+
const contextFile = join214(outputDir, `${story.id}.context.md`);
|
|
185091
186050
|
const contextOutput = `---
|
|
185092
186051
|
${frontmatter}---
|
|
185093
186052
|
|
|
@@ -185136,8 +186095,8 @@ var init_prompts2 = __esm(() => {
|
|
|
185136
186095
|
});
|
|
185137
186096
|
|
|
185138
186097
|
// src/cli/routing-calibrate.ts
|
|
185139
|
-
import { mkdirSync as
|
|
185140
|
-
import { basename as basename38, join as
|
|
186098
|
+
import { mkdirSync as mkdirSync16 } from "fs";
|
|
186099
|
+
import { basename as basename38, join as join215 } from "path";
|
|
185141
186100
|
function resolveProjectConfigDir(workdir) {
|
|
185142
186101
|
return findProjectDir(workdir) ?? projectInputDir(workdir);
|
|
185143
186102
|
}
|
|
@@ -185269,7 +186228,7 @@ var init_routing_calibrate = __esm(() => {
|
|
|
185269
186228
|
loadRunMetrics: (outputDir) => loadRunMetrics(outputDir),
|
|
185270
186229
|
readConfig: (workdir) => loadConfig(workdir),
|
|
185271
186230
|
readProjectConfig: async (workdir) => {
|
|
185272
|
-
const filePath =
|
|
186231
|
+
const filePath = join215(resolveProjectConfigDir(workdir), "config.json");
|
|
185273
186232
|
const configFile = Bun.file(filePath);
|
|
185274
186233
|
if (!await configFile.exists())
|
|
185275
186234
|
return {};
|
|
@@ -185277,8 +186236,8 @@ var init_routing_calibrate = __esm(() => {
|
|
|
185277
186236
|
},
|
|
185278
186237
|
writeConfig: async (workdir, config) => {
|
|
185279
186238
|
const dir = resolveProjectConfigDir(workdir);
|
|
185280
|
-
|
|
185281
|
-
const filePath =
|
|
186239
|
+
mkdirSync16(dir, { recursive: true });
|
|
186240
|
+
const filePath = join215(dir, "config.json");
|
|
185282
186241
|
await saveJsonFile(filePath, config, "routing-calibrate");
|
|
185283
186242
|
},
|
|
185284
186243
|
stdout: (msg) => {
|
|
@@ -185294,7 +186253,7 @@ var init_routing_calibrate = __esm(() => {
|
|
|
185294
186253
|
|
|
185295
186254
|
// src/cli/rules-lint.ts
|
|
185296
186255
|
import { statSync as statSync16 } from "fs";
|
|
185297
|
-
import { join as
|
|
186256
|
+
import { join as join216 } from "path";
|
|
185298
186257
|
function classifyPattern(normalizedPattern) {
|
|
185299
186258
|
const segments = normalizedPattern.split("/");
|
|
185300
186259
|
const literal = [];
|
|
@@ -185313,7 +186272,7 @@ function matchLiteralPath(literalPath, cwd) {
|
|
|
185313
186272
|
if (!isRelativeAndSafe(literalPath))
|
|
185314
186273
|
return "no-match";
|
|
185315
186274
|
try {
|
|
185316
|
-
return statSync16(
|
|
186275
|
+
return statSync16(join216(cwd, literalPath)).isFile() ? "match" : "no-match";
|
|
185317
186276
|
} catch {
|
|
185318
186277
|
return "no-match";
|
|
185319
186278
|
}
|
|
@@ -185353,7 +186312,7 @@ function collectCanonicalRuleRoots(workdir, globCanonicalRuleFiles = _rulesLintD
|
|
|
185353
186312
|
const packageRel = normalized.slice(0, idx);
|
|
185354
186313
|
if (!packageRel)
|
|
185355
186314
|
continue;
|
|
185356
|
-
roots.add(
|
|
186315
|
+
roots.add(join216(workdir, packageRel));
|
|
185357
186316
|
}
|
|
185358
186317
|
return [...roots].sort();
|
|
185359
186318
|
}
|
|
@@ -185382,7 +186341,7 @@ function lintPackagePaths(rule, root, { packages, logger }) {
|
|
|
185382
186341
|
return 0;
|
|
185383
186342
|
let warningCount = 0;
|
|
185384
186343
|
for (const pattern of rule.paths ?? []) {
|
|
185385
|
-
if (packages.some((pkg) => ruleMatchesPackage([pattern], root,
|
|
186344
|
+
if (packages.some((pkg) => ruleMatchesPackage([pattern], root, join216(root, pkg), pkg)))
|
|
185386
186345
|
continue;
|
|
185387
186346
|
warningCount++;
|
|
185388
186347
|
logger.warn("rules-lint", "Canonical rule paths: glob matches no workspace package directory - paths: scopes packages; use appliesTo: for file globs", { file: rule.path ?? rule.fileName, pattern, code: "PATHS_MATCH_NO_PACKAGE", root });
|
|
@@ -185423,7 +186382,7 @@ function lintRulesForRoot(rules, root, isSinglePackageRepo, packages, deps, logg
|
|
|
185423
186382
|
if (isSinglePackageRepo && rule.paths && rule.paths.length > 0) {
|
|
185424
186383
|
warningCount++;
|
|
185425
186384
|
logger.warn("rules-lint", "Canonical rule declares paths: but the repository has no workspace packages \u2014 paths: is inert in single-package repos. Use appliesTo: for file globs.", {
|
|
185426
|
-
file:
|
|
186385
|
+
file: join216(root, CANONICAL_RULES_DIR, rule.path ?? rule.fileName),
|
|
185427
186386
|
code: "INERT_PATHS",
|
|
185428
186387
|
paths: rule.paths,
|
|
185429
186388
|
root,
|
|
@@ -185522,7 +186481,7 @@ var init_rules_lint = __esm(() => {
|
|
|
185522
186481
|
return matchLiteralPath(shape.path, cwd);
|
|
185523
186482
|
const regex = globToRegex3(normalizedPattern);
|
|
185524
186483
|
if (shape.kind === "prefixed")
|
|
185525
|
-
return scanTreeForMatch(
|
|
186484
|
+
return scanTreeForMatch(join216(cwd, shape.prefix), shape.prefix, regex);
|
|
185526
186485
|
return scanTreeForMatch(cwd, "", regex);
|
|
185527
186486
|
} catch {
|
|
185528
186487
|
return "no-match";
|
|
@@ -185536,7 +186495,7 @@ var init_rules_lint = __esm(() => {
|
|
|
185536
186495
|
|
|
185537
186496
|
// src/cli/rules-cli-deps.ts
|
|
185538
186497
|
import { mkdir as mkdir54 } from "fs/promises";
|
|
185539
|
-
import { join as
|
|
186498
|
+
import { join as join217 } from "path";
|
|
185540
186499
|
var _rulesCLIDeps;
|
|
185541
186500
|
var init_rules_cli_deps = __esm(() => {
|
|
185542
186501
|
init_canonical_loader();
|
|
@@ -185550,7 +186509,7 @@ var init_rules_cli_deps = __esm(() => {
|
|
|
185550
186509
|
fileExists: async (path) => Bun.file(path).exists(),
|
|
185551
186510
|
globInDir: (dir) => {
|
|
185552
186511
|
try {
|
|
185553
|
-
return [...new Bun.Glob("*.md").scanSync({ cwd: dir })].sort().map((f) =>
|
|
186512
|
+
return [...new Bun.Glob("*.md").scanSync({ cwd: dir })].sort().map((f) => join217(dir, f));
|
|
185554
186513
|
} catch {
|
|
185555
186514
|
return [];
|
|
185556
186515
|
}
|
|
@@ -185591,7 +186550,7 @@ var init_rules_migrate_plan = __esm(() => {
|
|
|
185591
186550
|
});
|
|
185592
186551
|
|
|
185593
186552
|
// src/cli/rules-migrate.ts
|
|
185594
|
-
import { basename as basename39, join as
|
|
186553
|
+
import { basename as basename39, join as join218 } from "path";
|
|
185595
186554
|
function neutralizeContent(content) {
|
|
185596
186555
|
let result = content;
|
|
185597
186556
|
let replacements = 0;
|
|
@@ -185640,7 +186599,7 @@ function withReviewNotice(content, replacements) {
|
|
|
185640
186599
|
}
|
|
185641
186600
|
async function collectMigrationSources(workdir) {
|
|
185642
186601
|
const sources = [];
|
|
185643
|
-
const rulesDir =
|
|
186602
|
+
const rulesDir = join218(workdir, ".claude", "rules");
|
|
185644
186603
|
const ruleFiles = _rulesCLIDeps.globInDir(rulesDir);
|
|
185645
186604
|
for (const filePath of ruleFiles) {
|
|
185646
186605
|
try {
|
|
@@ -185662,11 +186621,11 @@ async function rulesMigrateCommand(options) {
|
|
|
185662
186621
|
console.log("[WARN] Root CLAUDE.md is not a migration source. Move the rules you want migrated into .claude/rules/, or author .nax/rules/ directly.");
|
|
185663
186622
|
return { written: [], skipped: [] };
|
|
185664
186623
|
}
|
|
185665
|
-
const targetDir =
|
|
186624
|
+
const targetDir = join218(workdir, CANONICAL_RULES_DIR);
|
|
185666
186625
|
const planEntries = sources.map((source) => ({
|
|
185667
186626
|
sourcePath: source.sourcePath,
|
|
185668
186627
|
targetFileName: source.targetFileName,
|
|
185669
|
-
targetPath:
|
|
186628
|
+
targetPath: join218(targetDir, source.targetFileName),
|
|
185670
186629
|
content: source.content
|
|
185671
186630
|
}));
|
|
185672
186631
|
const plan = await planMigration(planEntries, {
|
|
@@ -185716,7 +186675,7 @@ var init_rules_migrate = __esm(() => {
|
|
|
185716
186675
|
});
|
|
185717
186676
|
|
|
185718
186677
|
// src/cli/rules.ts
|
|
185719
|
-
import { join as
|
|
186678
|
+
import { join as join219, resolve as resolve56, sep as sep29 } from "path";
|
|
185720
186679
|
async function rulesLintCommand2(options) {
|
|
185721
186680
|
return rulesLintCommand(options, {
|
|
185722
186681
|
globCanonicalRuleFiles: _rulesCLIDeps.globCanonicalRuleFiles,
|
|
@@ -185789,7 +186748,7 @@ async function exportRuleDirectory(input) {
|
|
|
185789
186748
|
await _rulesCLIDeps.writeFile(target, content);
|
|
185790
186749
|
}
|
|
185791
186750
|
const expected = new Set(rules.map((r) => resolve56(workdir, ruleDir, r.path ?? r.fileName)));
|
|
185792
|
-
for (const existing of _rulesCLIDeps.globInDir(
|
|
186751
|
+
for (const existing of _rulesCLIDeps.globInDir(join219(workdir, ruleDir))) {
|
|
185793
186752
|
if (!expected.has(resolve56(existing))) {
|
|
185794
186753
|
_rulesCLIDeps.getLogger().warn("rules-export", "Generated rules dir contains a file with no canonical source", {
|
|
185795
186754
|
file: existing,
|
|
@@ -185845,7 +186804,7 @@ ${r.content}`).join(`
|
|
|
185845
186804
|
`);
|
|
185846
186805
|
const shimContent = `${header + body}
|
|
185847
186806
|
`;
|
|
185848
|
-
const shimPath =
|
|
186807
|
+
const shimPath = join219(workdir, shimFileName);
|
|
185849
186808
|
if (options.dryRun) {
|
|
185850
186809
|
console.log(`[dry-run] Would write ${shimPath} (${shimContent.length} bytes)`);
|
|
185851
186810
|
return;
|
|
@@ -185875,7 +186834,7 @@ var init_rules = __esm(() => {
|
|
|
185875
186834
|
|
|
185876
186835
|
// src/cli/runs.ts
|
|
185877
186836
|
import { existsSync as existsSync39, readdirSync as readdirSync9 } from "fs";
|
|
185878
|
-
import { basename as basename40, join as
|
|
186837
|
+
import { basename as basename40, join as join220 } from "path";
|
|
185879
186838
|
async function resolveOutputDir2(workdir, override) {
|
|
185880
186839
|
if (override)
|
|
185881
186840
|
return override;
|
|
@@ -185919,7 +186878,7 @@ async function runsListCommand(options) {
|
|
|
185919
186878
|
const logger = getLogger2();
|
|
185920
186879
|
const { feature, workdir } = options;
|
|
185921
186880
|
const outputDir = await resolveOutputDir2(workdir, options.outputDir);
|
|
185922
|
-
const runsDir =
|
|
186881
|
+
const runsDir = join220(outputDir, "features", feature, "runs");
|
|
185923
186882
|
if (!existsSync39(runsDir)) {
|
|
185924
186883
|
logger.info("cli", "No runs found for feature", { feature, hint: `Directory not found: ${runsDir}` });
|
|
185925
186884
|
return;
|
|
@@ -185931,7 +186890,7 @@ async function runsListCommand(options) {
|
|
|
185931
186890
|
}
|
|
185932
186891
|
logger.info("cli", `Runs for ${feature}`, { count: files.length });
|
|
185933
186892
|
for (const file of files.sort().reverse()) {
|
|
185934
|
-
const logPath =
|
|
186893
|
+
const logPath = join220(runsDir, file);
|
|
185935
186894
|
const entries = await parseRunLog(logPath);
|
|
185936
186895
|
const startEvent = findRunStart(entries);
|
|
185937
186896
|
const completeEvent = findRunSummary(entries);
|
|
@@ -185958,7 +186917,7 @@ async function runsShowCommand(options) {
|
|
|
185958
186917
|
const logger = getLogger2();
|
|
185959
186918
|
const { runId, feature, workdir } = options;
|
|
185960
186919
|
const outputDir = await resolveOutputDir2(workdir, options.outputDir);
|
|
185961
|
-
const logPath =
|
|
186920
|
+
const logPath = join220(outputDir, "features", feature, "runs", `${runId}.jsonl`);
|
|
185962
186921
|
if (!existsSync39(logPath)) {
|
|
185963
186922
|
logger.error("cli", "Run not found", { runId, feature, logPath });
|
|
185964
186923
|
throw new NaxError("Run not found", "RUN_NOT_FOUND", { runId, feature, logPath });
|
|
@@ -186129,36 +187088,36 @@ var init_sandbox_probe = __esm(() => {
|
|
|
186129
187088
|
});
|
|
186130
187089
|
|
|
186131
187090
|
// src/cli/setup-analyze.ts
|
|
186132
|
-
import { join as
|
|
187091
|
+
import { join as join221 } from "path";
|
|
186133
187092
|
async function detectPackageManager(workdir) {
|
|
186134
187093
|
const { fileExists } = _analyzeRepoDeps;
|
|
186135
|
-
if (await fileExists(
|
|
187094
|
+
if (await fileExists(join221(workdir, "bun.lock")))
|
|
186136
187095
|
return { pmRunPrefix: "bun run", pmDlx: "bunx" };
|
|
186137
|
-
if (await fileExists(
|
|
187096
|
+
if (await fileExists(join221(workdir, "bun.lockb")))
|
|
186138
187097
|
return { pmRunPrefix: "bun run", pmDlx: "bunx" };
|
|
186139
|
-
if (await fileExists(
|
|
187098
|
+
if (await fileExists(join221(workdir, "package-lock.json")))
|
|
186140
187099
|
return { pmRunPrefix: "npm run", pmDlx: "npx" };
|
|
186141
|
-
if (await fileExists(
|
|
187100
|
+
if (await fileExists(join221(workdir, "yarn.lock")))
|
|
186142
187101
|
return { pmRunPrefix: "yarn", pmDlx: "yarn dlx" };
|
|
186143
|
-
if (await fileExists(
|
|
187102
|
+
if (await fileExists(join221(workdir, "pnpm-lock.yaml")))
|
|
186144
187103
|
return { pmRunPrefix: "pnpm run", pmDlx: "pnpx" };
|
|
186145
187104
|
return { pmRunPrefix: "npm run", pmDlx: "npx" };
|
|
186146
187105
|
}
|
|
186147
187106
|
async function detectOrchestrator(workdir) {
|
|
186148
187107
|
const { fileExists } = _analyzeRepoDeps;
|
|
186149
|
-
if (await fileExists(
|
|
187108
|
+
if (await fileExists(join221(workdir, "turbo.json")))
|
|
186150
187109
|
return "turbo";
|
|
186151
|
-
if (await fileExists(
|
|
187110
|
+
if (await fileExists(join221(workdir, "nx.json")))
|
|
186152
187111
|
return "nx";
|
|
186153
187112
|
return "none";
|
|
186154
187113
|
}
|
|
186155
187114
|
async function getMissingScripts(packageDir) {
|
|
186156
|
-
const pkg = await _analyzeRepoDeps.readJson(
|
|
187115
|
+
const pkg = await _analyzeRepoDeps.readJson(join221(packageDir, "package.json"));
|
|
186157
187116
|
const scripts = pkg?.scripts ?? {};
|
|
186158
187117
|
return CANONICAL_SCRIPTS.filter((s) => !(s in scripts));
|
|
186159
187118
|
}
|
|
186160
187119
|
async function buildPackageFacts(workdir, relativeDir, testPatternMap) {
|
|
186161
|
-
const packageDir = relativeDir === "" ? workdir :
|
|
187120
|
+
const packageDir = relativeDir === "" ? workdir : join221(workdir, relativeDir);
|
|
186162
187121
|
const [profile, missingScripts] = await Promise.all([
|
|
186163
187122
|
_analyzeRepoDeps.detectProjectProfile(packageDir, {}),
|
|
186164
187123
|
getMissingScripts(packageDir)
|
|
@@ -186219,7 +187178,7 @@ var init_setup_analyze = __esm(() => {
|
|
|
186219
187178
|
});
|
|
186220
187179
|
|
|
186221
187180
|
// src/cli/setup-fill.ts
|
|
186222
|
-
import { join as
|
|
187181
|
+
import { join as join222 } from "path";
|
|
186223
187182
|
async function addScriptToPackageJson(pkgJsonPath, key, value) {
|
|
186224
187183
|
const pkg = await _fillScriptsDeps.readJson(pkgJsonPath) ?? {};
|
|
186225
187184
|
const scripts = pkg.scripts ?? {};
|
|
@@ -186242,18 +187201,18 @@ async function fillScripts(workdir, analysis) {
|
|
|
186242
187201
|
if (shape === "single") {
|
|
186243
187202
|
const rootPkg = packages[0];
|
|
186244
187203
|
if (rootPkg?.missingScripts.includes(TYPE_CHECK_KEY)) {
|
|
186245
|
-
await addScriptToPackageJson(
|
|
187204
|
+
await addScriptToPackageJson(join222(workdir, "package.json"), TYPE_CHECK_KEY, TYPE_CHECK_SCRIPT);
|
|
186246
187205
|
}
|
|
186247
187206
|
return;
|
|
186248
187207
|
}
|
|
186249
187208
|
for (const pkg of packages) {
|
|
186250
187209
|
if (!pkg.missingScripts.includes(TYPE_CHECK_KEY))
|
|
186251
187210
|
continue;
|
|
186252
|
-
await addScriptToPackageJson(
|
|
187211
|
+
await addScriptToPackageJson(join222(workdir, pkg.relativeDir, "package.json"), TYPE_CHECK_KEY, TYPE_CHECK_SCRIPT);
|
|
186253
187212
|
}
|
|
186254
187213
|
if (orchestrator === "turbo" && packages.some((p) => p.missingScripts.includes(TYPE_CHECK_KEY))) {
|
|
186255
|
-
await addTurboTask(
|
|
186256
|
-
await addScriptToPackageJson(
|
|
187214
|
+
await addTurboTask(join222(workdir, "turbo.json"), TYPE_CHECK_KEY);
|
|
187215
|
+
await addScriptToPackageJson(join222(workdir, "package.json"), TYPE_CHECK_KEY, TYPE_CHECK_TURBO_PASSTHROUGH);
|
|
186257
187216
|
}
|
|
186258
187217
|
}
|
|
186259
187218
|
var TYPE_CHECK_KEY = "type-check", TYPE_CHECK_SCRIPT = "tsc --noEmit -p tsconfig.json", TYPE_CHECK_TURBO_PASSTHROUGH = "turbo run type-check", _fillScriptsDeps;
|
|
@@ -186308,17 +187267,17 @@ var init_setup_verify = __esm(() => {
|
|
|
186308
187267
|
});
|
|
186309
187268
|
|
|
186310
187269
|
// src/cli/setup-write.ts
|
|
186311
|
-
import { join as
|
|
187270
|
+
import { join as join223 } from "path";
|
|
186312
187271
|
async function writeSetupConfig(workdir, config, monoConfigs, _opts, deps = _writeSetupDeps) {
|
|
186313
|
-
const naxDir =
|
|
186314
|
-
const naxConfigPath =
|
|
187272
|
+
const naxDir = join223(workdir, ".nax");
|
|
187273
|
+
const naxConfigPath = join223(naxDir, "config.json");
|
|
186315
187274
|
const written = [];
|
|
186316
187275
|
await deps.mkdir(naxDir);
|
|
186317
187276
|
await deps.writeFile(naxConfigPath, JSON.stringify(config, null, 2));
|
|
186318
187277
|
written.push(naxConfigPath);
|
|
186319
187278
|
for (const mc of monoConfigs) {
|
|
186320
|
-
const monoDir =
|
|
186321
|
-
const monoConfigPath =
|
|
187279
|
+
const monoDir = join223(naxDir, "mono", mc.relativeDir);
|
|
187280
|
+
const monoConfigPath = join223(monoDir, "config.json");
|
|
186322
187281
|
await deps.mkdir(monoDir);
|
|
186323
187282
|
await deps.writeFile(monoConfigPath, JSON.stringify(mc.config, null, 2));
|
|
186324
187283
|
written.push(monoConfigPath);
|
|
@@ -186337,11 +187296,11 @@ var init_setup_write = __esm(() => {
|
|
|
186337
187296
|
});
|
|
186338
187297
|
|
|
186339
187298
|
// src/cli/setup.ts
|
|
186340
|
-
import { join as
|
|
187299
|
+
import { join as join224 } from "path";
|
|
186341
187300
|
async function setupCommand(options = {}) {
|
|
186342
187301
|
const workdir = options.dir ?? process.cwd();
|
|
186343
|
-
const naxDir =
|
|
186344
|
-
const naxConfigPath =
|
|
187302
|
+
const naxDir = join224(workdir, ".nax");
|
|
187303
|
+
const naxConfigPath = join224(naxDir, "config.json");
|
|
186345
187304
|
const exists = await _setupDeps.fileExists(naxConfigPath);
|
|
186346
187305
|
if (exists && !options.force) {
|
|
186347
187306
|
_setupDeps.stderr("[setup] .nax/config.json already exists. Use --force to overwrite.");
|
|
@@ -186424,7 +187383,7 @@ var init_setup = __esm(() => {
|
|
|
186424
187383
|
|
|
186425
187384
|
// src/cli/spec-lint-command.ts
|
|
186426
187385
|
import { existsSync as existsSync40 } from "fs";
|
|
186427
|
-
import { join as
|
|
187386
|
+
import { join as join225 } from "path";
|
|
186428
187387
|
async function resolveSpecPaths(options, deps) {
|
|
186429
187388
|
const explicit = (options.paths ?? []).filter((path) => path.trim().length > 0);
|
|
186430
187389
|
if (explicit.length > 0)
|
|
@@ -186440,7 +187399,7 @@ async function resolveSpecPaths(options, deps) {
|
|
|
186440
187399
|
message: `${options.feature} resolved to ${resolved.specSource.path}; a prd.json has no spec sections to lint. Pass the markdown spec explicitly.`
|
|
186441
187400
|
};
|
|
186442
187401
|
}
|
|
186443
|
-
return [
|
|
187402
|
+
return [join225(options.dir, resolved.specSource.path)];
|
|
186444
187403
|
}
|
|
186445
187404
|
async function lintOne(specPath, options, deps) {
|
|
186446
187405
|
if (!deps.fileExists(specPath)) {
|
|
@@ -186454,7 +187413,7 @@ async function lintOne(specPath, options, deps) {
|
|
|
186454
187413
|
}
|
|
186455
187414
|
const findings = lintSpecContent(content, {
|
|
186456
187415
|
maxAcCount: options.maxAcCount,
|
|
186457
|
-
fileExists: (path) => deps.fileExists(
|
|
187416
|
+
fileExists: (path) => deps.fileExists(join225(options.dir, path))
|
|
186458
187417
|
});
|
|
186459
187418
|
return {
|
|
186460
187419
|
specPath,
|
|
@@ -186666,7 +187625,7 @@ var init_status_cost = __esm(() => {
|
|
|
186666
187625
|
|
|
186667
187626
|
// src/commands/common.ts
|
|
186668
187627
|
import { existsSync as existsSync41, readdirSync as readdirSync10, realpathSync as realpathSync6 } from "fs";
|
|
186669
|
-
import { join as
|
|
187628
|
+
import { join as join226, resolve as resolve57 } from "path";
|
|
186670
187629
|
function resolveProject2(options = {}) {
|
|
186671
187630
|
const { dir, feature } = options;
|
|
186672
187631
|
let projectRoot;
|
|
@@ -186674,12 +187633,12 @@ function resolveProject2(options = {}) {
|
|
|
186674
187633
|
let configPath;
|
|
186675
187634
|
if (dir) {
|
|
186676
187635
|
projectRoot = realpathSync6(resolve57(dir));
|
|
186677
|
-
naxDir =
|
|
187636
|
+
naxDir = join226(projectRoot, ".nax");
|
|
186678
187637
|
if (!existsSync41(naxDir)) {
|
|
186679
187638
|
throw new NaxError(`Directory does not contain a nax project: ${projectRoot}
|
|
186680
187639
|
Expected to find: ${naxDir}`, "NAX_DIR_NOT_FOUND", { projectRoot, naxDir });
|
|
186681
187640
|
}
|
|
186682
|
-
configPath =
|
|
187641
|
+
configPath = join226(naxDir, "config.json");
|
|
186683
187642
|
if (!existsSync41(configPath)) {
|
|
186684
187643
|
throw new NaxError(`.nax directory found but config.json is missing: ${naxDir}
|
|
186685
187644
|
Expected to find: ${configPath}`, "CONFIG_NOT_FOUND", { naxDir, configPath });
|
|
@@ -186687,17 +187646,17 @@ Expected to find: ${configPath}`, "CONFIG_NOT_FOUND", { naxDir, configPath });
|
|
|
186687
187646
|
} else {
|
|
186688
187647
|
const found = findProjectRoot(process.cwd());
|
|
186689
187648
|
if (!found) {
|
|
186690
|
-
const cwdNaxDir =
|
|
187649
|
+
const cwdNaxDir = join226(process.cwd(), ".nax");
|
|
186691
187650
|
if (existsSync41(cwdNaxDir)) {
|
|
186692
|
-
const cwdConfigPath =
|
|
187651
|
+
const cwdConfigPath = join226(cwdNaxDir, "config.json");
|
|
186693
187652
|
throw new NaxError(`.nax directory found but config.json is missing: ${cwdNaxDir}
|
|
186694
187653
|
Expected to find: ${cwdConfigPath}`, "CONFIG_NOT_FOUND", { naxDir: cwdNaxDir, configPath: cwdConfigPath });
|
|
186695
187654
|
}
|
|
186696
187655
|
throw new NaxError("No nax project found. Run this command from within a nax project directory, or use -d flag to specify the project path.", "PROJECT_NOT_FOUND", { cwd: process.cwd() });
|
|
186697
187656
|
}
|
|
186698
187657
|
projectRoot = found;
|
|
186699
|
-
naxDir =
|
|
186700
|
-
configPath =
|
|
187658
|
+
naxDir = join226(projectRoot, ".nax");
|
|
187659
|
+
configPath = join226(naxDir, "config.json");
|
|
186701
187660
|
}
|
|
186702
187661
|
let featureDir;
|
|
186703
187662
|
if (feature) {
|
|
@@ -186706,8 +187665,8 @@ Expected to find: ${cwdConfigPath}`, "CONFIG_NOT_FOUND", { naxDir: cwdNaxDir, co
|
|
|
186706
187665
|
} catch (error) {
|
|
186707
187666
|
throw new NaxError(error.message, "FEATURE_INVALID", { feature });
|
|
186708
187667
|
}
|
|
186709
|
-
const featuresDir =
|
|
186710
|
-
featureDir =
|
|
187668
|
+
const featuresDir = join226(naxDir, "features");
|
|
187669
|
+
featureDir = join226(featuresDir, feature);
|
|
186711
187670
|
if (!existsSync41(featureDir)) {
|
|
186712
187671
|
const availableFeatures = existsSync41(featuresDir) ? readdirSync10(featuresDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name) : [];
|
|
186713
187672
|
const availableMsg = availableFeatures.length > 0 ? `
|
|
@@ -186731,7 +187690,7 @@ No features found in this project.`;
|
|
|
186731
187690
|
};
|
|
186732
187691
|
}
|
|
186733
187692
|
function resolveSingleFeature(naxDir, remediationHint = "pass -f <name>") {
|
|
186734
|
-
const featuresDir =
|
|
187693
|
+
const featuresDir = join226(naxDir, "features");
|
|
186735
187694
|
const available = existsSync41(featuresDir) ? readdirSync10(featuresDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort() : [];
|
|
186736
187695
|
if (available.length === 1)
|
|
186737
187696
|
return available[0];
|
|
@@ -186756,7 +187715,7 @@ async function resolveProjectAsync(options = {}) {
|
|
|
186756
187715
|
}
|
|
186757
187716
|
const isPlainName = !dir.includes("/") && !dir.includes("\\");
|
|
186758
187717
|
if (isPlainName) {
|
|
186759
|
-
const registryIdentityPath =
|
|
187718
|
+
const registryIdentityPath = join226(globalConfigDir(), dir, ".identity");
|
|
186760
187719
|
const identityFile = Bun.file(registryIdentityPath);
|
|
186761
187720
|
if (await identityFile.exists()) {
|
|
186762
187721
|
try {
|
|
@@ -186788,12 +187747,12 @@ function findProjectRoot(startDir) {
|
|
|
186788
187747
|
let current = resolve57(startDir);
|
|
186789
187748
|
let depth = 0;
|
|
186790
187749
|
while (depth < MAX_DIRECTORY_DEPTH) {
|
|
186791
|
-
const naxDir =
|
|
186792
|
-
const configPath =
|
|
187750
|
+
const naxDir = join226(current, ".nax");
|
|
187751
|
+
const configPath = join226(naxDir, "config.json");
|
|
186793
187752
|
if (existsSync41(configPath)) {
|
|
186794
187753
|
return realpathSync6(current);
|
|
186795
187754
|
}
|
|
186796
|
-
const parent =
|
|
187755
|
+
const parent = join226(current, "..");
|
|
186797
187756
|
if (parent === current) {
|
|
186798
187757
|
break;
|
|
186799
187758
|
}
|
|
@@ -186928,15 +187887,15 @@ var init_status_features_details = __esm(() => {
|
|
|
186928
187887
|
|
|
186929
187888
|
// src/cli/status-features.ts
|
|
186930
187889
|
import { existsSync as existsSync42, readdirSync as readdirSync11 } from "fs";
|
|
186931
|
-
import { basename as basename42, join as
|
|
187890
|
+
import { basename as basename42, join as join227, resolve as resolve58 } from "path";
|
|
186932
187891
|
async function loadProjectStatusFile(projectDir) {
|
|
186933
187892
|
const config = await _statusFeaturesDeps.loadConfig(projectDir).catch(() => null);
|
|
186934
187893
|
const projectKey = config?.name?.trim() || basename42(projectDir);
|
|
186935
187894
|
const outputDir = _statusFeaturesDeps.projectOutputDir(projectKey, config?.outputDir);
|
|
186936
|
-
return readStatusFileAt(
|
|
187895
|
+
return readStatusFileAt(join227(outputDir, "status.json"));
|
|
186937
187896
|
}
|
|
186938
187897
|
async function getFeatureSummary(featureName, featureDir, runsDir) {
|
|
186939
|
-
const prdPath =
|
|
187898
|
+
const prdPath = join227(featureDir, "prd.json");
|
|
186940
187899
|
if (!existsSync42(prdPath)) {
|
|
186941
187900
|
return {
|
|
186942
187901
|
name: featureName,
|
|
@@ -187053,7 +188012,7 @@ async function displayAllFeatures(projectRoot) {
|
|
|
187053
188012
|
console.log();
|
|
187054
188013
|
}
|
|
187055
188014
|
}
|
|
187056
|
-
const summaries = await Promise.all(features.map((name) => getFeatureSummary(name, featureDir(projectRoot, name),
|
|
188015
|
+
const summaries = await Promise.all(features.map((name) => getFeatureSummary(name, featureDir(projectRoot, name), join227(outputDir, "features", name, "runs"))));
|
|
187057
188016
|
console.log(source_default.bold(`\uD83D\uDCCA Features
|
|
187058
188017
|
`));
|
|
187059
188018
|
const header = ` ${"Feature".padEnd(25)} ${"Done".padEnd(6)} ${"Failed".padEnd(8)} ${"Pending".padEnd(9)} ${"Last Run".padEnd(22)} ${"Cost".padEnd(10)} Status`;
|
|
@@ -187081,7 +188040,7 @@ async function displayAllFeatures(projectRoot) {
|
|
|
187081
188040
|
console.log();
|
|
187082
188041
|
}
|
|
187083
188042
|
async function displayFeatureDetails(featureName, featureDir) {
|
|
187084
|
-
const prdPath =
|
|
188043
|
+
const prdPath = join227(featureDir, "prd.json");
|
|
187085
188044
|
if (!existsSync42(prdPath)) {
|
|
187086
188045
|
displayNoPrdNotice(featureName);
|
|
187087
188046
|
return;
|
|
@@ -187105,7 +188064,7 @@ async function displayFeatureDetails(featureName, featureDir) {
|
|
|
187105
188064
|
function resolveRootFromDir(dir) {
|
|
187106
188065
|
const resolved = resolve58(dir);
|
|
187107
188066
|
const naxDir = _statusFeaturesDeps.findProjectDir(resolved);
|
|
187108
|
-
return naxDir ?
|
|
188067
|
+
return naxDir ? join227(naxDir, "..") : resolved;
|
|
187109
188068
|
}
|
|
187110
188069
|
async function displayFeatureStatus(options = {}) {
|
|
187111
188070
|
if (options.feature) {
|
|
@@ -187545,7 +188504,7 @@ var init_promote_rulings = __esm(() => {
|
|
|
187545
188504
|
});
|
|
187546
188505
|
|
|
187547
188506
|
// src/cli/workflow-promote.ts
|
|
187548
|
-
import { join as
|
|
188507
|
+
import { join as join228 } from "path";
|
|
187549
188508
|
function invalid4(message, context = {}) {
|
|
187550
188509
|
return new NaxError(message, PROMOTE_INVALID, { stage: "workflow", ...context });
|
|
187551
188510
|
}
|
|
@@ -187634,7 +188593,7 @@ function promotedSidecar(target, now) {
|
|
|
187634
188593
|
async function recordAction(target) {
|
|
187635
188594
|
const now = target.forgeDeps.now();
|
|
187636
188595
|
const found = target.found;
|
|
187637
|
-
const path = found?.path ??
|
|
188596
|
+
const path = found?.path ?? join228(target.loaded.runDir, sidecarFileName(now));
|
|
187638
188597
|
const sidecar = found ? { ...found.sidecar, decisions: target.entries, outcome: "promoted", url: target.url } : promotedSidecar(target, now);
|
|
187639
188598
|
await writeSidecar(path, sidecar);
|
|
187640
188599
|
return { name: "record", status: "done" };
|
|
@@ -187731,7 +188690,7 @@ var init_workflow_promote = __esm(() => {
|
|
|
187731
188690
|
});
|
|
187732
188691
|
|
|
187733
188692
|
// src/cli/workflow-record.ts
|
|
187734
|
-
import { join as
|
|
188693
|
+
import { join as join229, relative as relative54 } from "path";
|
|
187735
188694
|
function invalid5(message, context = {}) {
|
|
187736
188695
|
return new NaxError(message, RECORD_INVALID, { stage: "workflow", ...context });
|
|
187737
188696
|
}
|
|
@@ -187803,7 +188762,7 @@ async function writeRecorded(input) {
|
|
|
187803
188762
|
if (input.opts.decisions === undefined) {
|
|
187804
188763
|
throw invalid5(`no decisions sidecar for run ${input.loaded.runId}; pass --decisions`);
|
|
187805
188764
|
}
|
|
187806
|
-
const path =
|
|
188765
|
+
const path = join229(input.loaded.runDir, sidecarFileName(input.now));
|
|
187807
188766
|
const sidecar = newSidecar(input);
|
|
187808
188767
|
await writeSidecar(path, sidecar);
|
|
187809
188768
|
return { path, sidecar };
|
|
@@ -188154,7 +189113,7 @@ var init_worktree_id2 = __esm(() => {
|
|
|
188154
189113
|
});
|
|
188155
189114
|
|
|
188156
189115
|
// src/bakeoff/contestant.ts
|
|
188157
|
-
import { basename as basename47, join as
|
|
189116
|
+
import { basename as basename47, join as join241 } from "path";
|
|
188158
189117
|
function aggregateTotals(metrics) {
|
|
188159
189118
|
let costUsd = 0;
|
|
188160
189119
|
let wallTimeMs = 0;
|
|
@@ -188185,7 +189144,7 @@ async function runContestant(agent, options, deps) {
|
|
|
188185
189144
|
};
|
|
188186
189145
|
const worktree = storyWorktreePath(options.projectRoot, storyId);
|
|
188187
189146
|
const projectKey = options.config.name?.trim() || basename47(options.projectRoot);
|
|
188188
|
-
const outputDir =
|
|
189147
|
+
const outputDir = join241(projectOutputDir(projectKey, options.outputDir), "bakeoff", feature, agent);
|
|
188189
189148
|
const context = {
|
|
188190
189149
|
profile: agent,
|
|
188191
189150
|
config: { ...pinnedConfig, outputDir },
|
|
@@ -188242,7 +189201,7 @@ var init_contestant = __esm(() => {
|
|
|
188242
189201
|
});
|
|
188243
189202
|
|
|
188244
189203
|
// src/bakeoff/pipeline-adapter.ts
|
|
188245
|
-
import { join as
|
|
189204
|
+
import { join as join242 } from "path";
|
|
188246
189205
|
function toResults(runs, result) {
|
|
188247
189206
|
const latest = runs.at(-1);
|
|
188248
189207
|
if (latest && latest.stories.length > 0) {
|
|
@@ -188268,8 +189227,8 @@ async function pipeline2(ctx) {
|
|
|
188268
189227
|
validateFeatureName(ctx.feature);
|
|
188269
189228
|
const hooks = await _pipelineAdapterDeps.loadHooksConfig(ctx.worktree, globalConfigDir());
|
|
188270
189229
|
const contestantFeatureDir = featureDir(ctx.worktree, ctx.feature);
|
|
188271
|
-
const prdPath =
|
|
188272
|
-
const statusFile =
|
|
189230
|
+
const prdPath = join242(contestantFeatureDir, "prd.json");
|
|
189231
|
+
const statusFile = join242(ctx.outputDir, "status.json");
|
|
188273
189232
|
const result = await _pipelineAdapterDeps.run({
|
|
188274
189233
|
prdPath,
|
|
188275
189234
|
workdir: ctx.worktree,
|
|
@@ -188316,9 +189275,9 @@ var init_ranking = __esm(() => {
|
|
|
188316
189275
|
});
|
|
188317
189276
|
|
|
188318
189277
|
// src/bakeoff/coordinator.ts
|
|
188319
|
-
import { join as
|
|
189278
|
+
import { join as join243 } from "path";
|
|
188320
189279
|
async function persistBakeoffResult(result, outputDir) {
|
|
188321
|
-
const filePath =
|
|
189280
|
+
const filePath = join243(outputDir, "bakeoff", result.feature, "bakeoff.json");
|
|
188322
189281
|
await Bun.write(filePath, JSON.stringify(result, null, 2));
|
|
188323
189282
|
}
|
|
188324
189283
|
async function runBakeoff(options, deps = {}) {
|
|
@@ -188360,7 +189319,7 @@ async function handleRunAction(options, deps = _bakeoffCliDeps) {
|
|
|
188360
189319
|
if (compareList.length === 0) {
|
|
188361
189320
|
return deps.runSingleAgent(options);
|
|
188362
189321
|
}
|
|
188363
|
-
const prdPath =
|
|
189322
|
+
const prdPath = join243(featureDir(options.projectRoot, options.feature), "prd.json");
|
|
188364
189323
|
await deps.assertPrdCommitted(prdPath, options.projectRoot);
|
|
188365
189324
|
const agents = options.agents ?? compareList;
|
|
188366
189325
|
return deps.runBakeoff({
|
|
@@ -188644,7 +189603,7 @@ var init_mcp3 = __esm(() => {
|
|
|
188644
189603
|
// src/commands/curator.ts
|
|
188645
189604
|
import { readdirSync as readdirSync14 } from "fs";
|
|
188646
189605
|
import { unlink as unlink14 } from "fs/promises";
|
|
188647
|
-
import { join as
|
|
189606
|
+
import { join as join245, resolve as resolve60, sep as sep30 } from "path";
|
|
188648
189607
|
function openInEditor(filePath) {
|
|
188649
189608
|
const [editor, ...args] = parseCommandToArgv(process.env.EDITOR ?? process.env.VISUAL ?? "vi");
|
|
188650
189609
|
if (!editor)
|
|
@@ -188750,7 +189709,7 @@ async function curatorStatus(options) {
|
|
|
188750
189709
|
const config = await _curatorCmdDeps.loadConfig(resolved.projectDir);
|
|
188751
189710
|
const projectKey = getProjectKey(config, resolved.projectDir);
|
|
188752
189711
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
188753
|
-
const runsDir =
|
|
189712
|
+
const runsDir = join245(outputDir, "runs");
|
|
188754
189713
|
const runIds = listRunIds(runsDir);
|
|
188755
189714
|
let runId;
|
|
188756
189715
|
if (options.run) {
|
|
@@ -188767,8 +189726,8 @@ async function curatorStatus(options) {
|
|
|
188767
189726
|
runId = runIds[runIds.length - 1];
|
|
188768
189727
|
}
|
|
188769
189728
|
console.log(`Run: ${runId}`);
|
|
188770
|
-
const runDir =
|
|
188771
|
-
const observationsPath =
|
|
189729
|
+
const runDir = join245(runsDir, runId);
|
|
189730
|
+
const observationsPath = join245(runDir, "observations.jsonl");
|
|
188772
189731
|
const observations = await parseObservations(observationsPath);
|
|
188773
189732
|
const counts = new Map;
|
|
188774
189733
|
for (const obs of observations) {
|
|
@@ -188778,7 +189737,7 @@ async function curatorStatus(options) {
|
|
|
188778
189737
|
for (const [kind, count] of counts.entries()) {
|
|
188779
189738
|
console.log(` ${kind}: ${count}`);
|
|
188780
189739
|
}
|
|
188781
|
-
const proposalsPath =
|
|
189740
|
+
const proposalsPath = join245(runDir, "curator-proposals.md");
|
|
188782
189741
|
const proposalText = await _curatorCmdDeps.readFile(proposalsPath).catch(() => null);
|
|
188783
189742
|
if (proposalText !== null) {
|
|
188784
189743
|
console.log("");
|
|
@@ -188807,8 +189766,8 @@ async function curatorCommit(options) {
|
|
|
188807
189766
|
const config = await _curatorCmdDeps.loadConfig(resolved.projectDir);
|
|
188808
189767
|
const projectKey = getProjectKey(config, resolved.projectDir);
|
|
188809
189768
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
188810
|
-
const runDir =
|
|
188811
|
-
const proposalsPath =
|
|
189769
|
+
const runDir = join245(outputDir, "runs", options.runId);
|
|
189770
|
+
const proposalsPath = join245(runDir, "curator-proposals.md");
|
|
188812
189771
|
const proposalText = await _curatorCmdDeps.readFile(proposalsPath).catch(() => null);
|
|
188813
189772
|
if (proposalText === null) {
|
|
188814
189773
|
console.log(`curator-proposals.md not found for run ${options.runId}.`);
|
|
@@ -188938,7 +189897,7 @@ async function curatorDryrun(options) {
|
|
|
188938
189897
|
const config = await _curatorCmdDeps.loadConfig(resolved.projectDir);
|
|
188939
189898
|
const projectKey = getProjectKey(config, resolved.projectDir);
|
|
188940
189899
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
188941
|
-
const runsDir =
|
|
189900
|
+
const runsDir = join245(outputDir, "runs");
|
|
188942
189901
|
const runIds = listRunIds(runsDir);
|
|
188943
189902
|
if (runIds.length === 0) {
|
|
188944
189903
|
console.log("No runs found.");
|
|
@@ -188949,7 +189908,7 @@ async function curatorDryrun(options) {
|
|
|
188949
189908
|
console.log(`Run ${options.run} not found in ${runsDir}.`);
|
|
188950
189909
|
return;
|
|
188951
189910
|
}
|
|
188952
|
-
const observationsPath =
|
|
189911
|
+
const observationsPath = join245(runsDir, runId, "observations.jsonl");
|
|
188953
189912
|
const observations = await parseObservations(observationsPath);
|
|
188954
189913
|
const thresholds = getThresholds(config);
|
|
188955
189914
|
const proposals = runHeuristics(observations, thresholds);
|
|
@@ -188981,12 +189940,12 @@ async function curatorGc(options) {
|
|
|
188981
189940
|
dropUnattributed: sweep
|
|
188982
189941
|
});
|
|
188983
189942
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
188984
|
-
const perRunsDir =
|
|
189943
|
+
const perRunsDir = join245(outputDir, "runs");
|
|
188985
189944
|
for (const runId of uniqueRunIds) {
|
|
188986
189945
|
if (!keepSet.has(runId)) {
|
|
188987
|
-
const runDir =
|
|
188988
|
-
await _curatorCmdDeps.removeFile(
|
|
188989
|
-
await _curatorCmdDeps.removeFile(
|
|
189946
|
+
const runDir = join245(perRunsDir, runId);
|
|
189947
|
+
await _curatorCmdDeps.removeFile(join245(runDir, "observations.jsonl"));
|
|
189948
|
+
await _curatorCmdDeps.removeFile(join245(runDir, "curator-proposals.md"));
|
|
188990
189949
|
}
|
|
188991
189950
|
}
|
|
188992
189951
|
const droppedRuns = Math.max(0, uniqueRunIds.length - keepSet.size);
|
|
@@ -189122,9 +190081,9 @@ setAgentRuntime(bunAgentRuntime);
|
|
|
189122
190081
|
// bin/nax.ts
|
|
189123
190082
|
init_src();
|
|
189124
190083
|
init_source();
|
|
189125
|
-
import { existsSync as existsSync50, mkdirSync as
|
|
190084
|
+
import { existsSync as existsSync50, mkdirSync as mkdirSync18, symlinkSync as symlinkSync4, unlinkSync as unlinkSync4 } from "fs";
|
|
189126
190085
|
import { homedir as homedir12 } from "os";
|
|
189127
|
-
import { join as
|
|
190086
|
+
import { join as join246 } from "path";
|
|
189128
190087
|
|
|
189129
190088
|
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/index.js
|
|
189130
190089
|
var { Argument } = require_argument();
|
|
@@ -189174,7 +190133,7 @@ init_config();
|
|
|
189174
190133
|
init_logger2();
|
|
189175
190134
|
init_detect();
|
|
189176
190135
|
init_common();
|
|
189177
|
-
import { join as
|
|
190136
|
+
import { join as join230 } from "path";
|
|
189178
190137
|
function resolveEffective(detected, configPatterns) {
|
|
189179
190138
|
if (configPatterns !== undefined)
|
|
189180
190139
|
return "config";
|
|
@@ -189259,7 +190218,7 @@ async function detectCommand(options) {
|
|
|
189259
190218
|
const rootDetected = detectionMap[""] ?? { patterns: [], confidence: "empty", sources: [] };
|
|
189260
190219
|
const pkgEntries = await Promise.all(packageDirs.map(async (dir) => {
|
|
189261
190220
|
const det = detectionMap[dir] ?? { patterns: [], confidence: "empty", sources: [] };
|
|
189262
|
-
const pkgConfigPath =
|
|
190221
|
+
const pkgConfigPath = join230(workdir, ".nax", "mono", dir, "config.json");
|
|
189263
190222
|
const pkgRaw = await loadRawConfig(pkgConfigPath);
|
|
189264
190223
|
const pkgPatterns = deepGet(pkgRaw, TEST_PATTERNS_KEY);
|
|
189265
190224
|
const effective = Array.isArray(pkgPatterns) ? pkgPatterns : undefined;
|
|
@@ -189313,13 +190272,13 @@ async function detectCommand(options) {
|
|
|
189313
190272
|
if (rootDetected.confidence === "empty") {
|
|
189314
190273
|
console.log(source_default.yellow(" root: skipped (empty detection)"));
|
|
189315
190274
|
} else {
|
|
189316
|
-
const rootConfigPath =
|
|
190275
|
+
const rootConfigPath = join230(workdir, ".nax", "config.json");
|
|
189317
190276
|
try {
|
|
189318
190277
|
const status = await applyToConfig(rootConfigPath, rootDetected.patterns, options.force ?? false);
|
|
189319
190278
|
if (status === "skipped") {
|
|
189320
190279
|
console.log(source_default.dim(" root: skipped (testFilePatterns already set; use --force to overwrite)"));
|
|
189321
190280
|
} else {
|
|
189322
|
-
console.log(source_default.green(` root: ${status} \u2192 ${
|
|
190281
|
+
console.log(source_default.green(` root: ${status} \u2192 ${join230(".nax", "config.json")}`));
|
|
189323
190282
|
}
|
|
189324
190283
|
} catch (err) {
|
|
189325
190284
|
console.error(source_default.red(` root: write failed \u2014 ${err.message}`));
|
|
@@ -189332,13 +190291,13 @@ async function detectCommand(options) {
|
|
|
189332
190291
|
console.log(source_default.dim(` ${dir}: skipped (empty detection)`));
|
|
189333
190292
|
continue;
|
|
189334
190293
|
}
|
|
189335
|
-
const pkgConfigPath =
|
|
190294
|
+
const pkgConfigPath = join230(workdir, ".nax", "mono", dir, "config.json");
|
|
189336
190295
|
try {
|
|
189337
190296
|
const status = await applyToConfig(pkgConfigPath, det.patterns, options.force ?? false);
|
|
189338
190297
|
if (status === "skipped") {
|
|
189339
190298
|
console.log(source_default.dim(` ${dir}: skipped (already set)`));
|
|
189340
190299
|
} else {
|
|
189341
|
-
console.log(source_default.green(` ${dir}: ${status} \u2192 ${
|
|
190300
|
+
console.log(source_default.green(` ${dir}: ${status} \u2192 ${join230(".nax", "mono", dir, "config.json")}`));
|
|
189342
190301
|
}
|
|
189343
190302
|
} catch (err) {
|
|
189344
190303
|
console.error(source_default.red(` ${dir}: write failed \u2014 ${err.message}`));
|
|
@@ -189363,7 +190322,7 @@ init_prd();
|
|
|
189363
190322
|
init_precheck();
|
|
189364
190323
|
init_common();
|
|
189365
190324
|
import { existsSync as existsSync43 } from "fs";
|
|
189366
|
-
import { join as
|
|
190325
|
+
import { join as join231 } from "path";
|
|
189367
190326
|
async function precheckCommand(options) {
|
|
189368
190327
|
const resolved = resolveProject2({
|
|
189369
190328
|
dir: options.dir,
|
|
@@ -189376,7 +190335,7 @@ async function precheckCommand(options) {
|
|
|
189376
190335
|
process.exit(result.passed ? EXIT_CODES.SUCCESS : EXIT_CODES.BLOCKER);
|
|
189377
190336
|
return;
|
|
189378
190337
|
}
|
|
189379
|
-
const naxDir =
|
|
190338
|
+
const naxDir = join231(resolved.projectDir, ".nax");
|
|
189380
190339
|
let featureName = options.feature;
|
|
189381
190340
|
if (!featureName) {
|
|
189382
190341
|
try {
|
|
@@ -189386,8 +190345,8 @@ async function precheckCommand(options) {
|
|
|
189386
190345
|
process.exit(1);
|
|
189387
190346
|
}
|
|
189388
190347
|
}
|
|
189389
|
-
const featureDir =
|
|
189390
|
-
const prdPath =
|
|
190348
|
+
const featureDir = join231(naxDir, "features", featureName);
|
|
190349
|
+
const prdPath = join231(featureDir, "prd.json");
|
|
189391
190350
|
if (!existsSync43(featureDir)) {
|
|
189392
190351
|
console.error(source_default.red(`Feature not found: ${featureName}`));
|
|
189393
190352
|
process.exit(1);
|
|
@@ -189417,7 +190376,7 @@ async function doctorCommand(options) {
|
|
|
189417
190376
|
init_errors4();
|
|
189418
190377
|
init_common();
|
|
189419
190378
|
import { existsSync as existsSync45 } from "fs";
|
|
189420
|
-
import { join as
|
|
190379
|
+
import { join as join234 } from "path";
|
|
189421
190380
|
|
|
189422
190381
|
// src/commands/logs-formatter.ts
|
|
189423
190382
|
init_source();
|
|
@@ -189425,14 +190384,14 @@ init_formatter();
|
|
|
189425
190384
|
init_summary();
|
|
189426
190385
|
init_bun_deps();
|
|
189427
190386
|
import { readdirSync as readdirSync13 } from "fs";
|
|
189428
|
-
import { join as
|
|
190387
|
+
import { join as join233 } from "path";
|
|
189429
190388
|
|
|
189430
190389
|
// src/commands/logs-reader.ts
|
|
189431
190390
|
init_errors4();
|
|
189432
190391
|
init_paths4();
|
|
189433
190392
|
import { existsSync as existsSync44, readdirSync as readdirSync12 } from "fs";
|
|
189434
190393
|
import { readdir as readdir17 } from "fs/promises";
|
|
189435
|
-
import { join as
|
|
190394
|
+
import { join as join232 } from "path";
|
|
189436
190395
|
var _logsReaderDeps = {
|
|
189437
190396
|
getRunsDir
|
|
189438
190397
|
};
|
|
@@ -189447,7 +190406,7 @@ async function resolveRunFileFromRegistry(runId) {
|
|
|
189447
190406
|
let exactMatch = null;
|
|
189448
190407
|
const prefixMatches = [];
|
|
189449
190408
|
for (const entry of entries) {
|
|
189450
|
-
const metaPath =
|
|
190409
|
+
const metaPath = join232(runsDir, entry, "meta.json");
|
|
189451
190410
|
try {
|
|
189452
190411
|
const meta = await Bun.file(metaPath).json();
|
|
189453
190412
|
if (meta.runId === runId) {
|
|
@@ -189483,14 +190442,14 @@ async function resolveRunFileFromRegistry(runId) {
|
|
|
189483
190442
|
return null;
|
|
189484
190443
|
}
|
|
189485
190444
|
const specificFile = files.find((f) => f === `${matched.runId}.jsonl`);
|
|
189486
|
-
return
|
|
190445
|
+
return join232(matched.eventsDir, specificFile ?? files[0]);
|
|
189487
190446
|
}
|
|
189488
190447
|
async function selectRunFile(runsDir) {
|
|
189489
190448
|
const files = readdirSync12(runsDir).filter((f) => f.endsWith(".jsonl") && f !== "latest.jsonl").sort().reverse();
|
|
189490
190449
|
if (files.length === 0) {
|
|
189491
190450
|
return null;
|
|
189492
190451
|
}
|
|
189493
|
-
return
|
|
190452
|
+
return join232(runsDir, files[0]);
|
|
189494
190453
|
}
|
|
189495
190454
|
async function extractRunSummary(filePath) {
|
|
189496
190455
|
const file = Bun.file(filePath);
|
|
@@ -189576,7 +190535,7 @@ Runs:
|
|
|
189576
190535
|
console.log(source_default.gray(" Timestamp Stories Duration Cost Status"));
|
|
189577
190536
|
console.log(source_default.gray(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
189578
190537
|
for (const file of files) {
|
|
189579
|
-
const filePath =
|
|
190538
|
+
const filePath = join233(runsDir, file);
|
|
189580
190539
|
const summary = await extractRunSummary(filePath);
|
|
189581
190540
|
const timestamp = file.replace(".jsonl", "");
|
|
189582
190541
|
const stories = summary ? `${summary.passed}/${summary.total}` : "?/?";
|
|
@@ -189709,10 +190668,10 @@ async function logsCommand(options) {
|
|
|
189709
190668
|
return;
|
|
189710
190669
|
}
|
|
189711
190670
|
const resolved = resolveProject2({ dir: options.dir });
|
|
189712
|
-
const naxDir =
|
|
190671
|
+
const naxDir = join234(resolved.projectDir, ".nax");
|
|
189713
190672
|
const featureName = resolveSingleFeature(naxDir, "pass -r <runId> (see `nax runs list`)");
|
|
189714
|
-
const featureDir =
|
|
189715
|
-
const runsDir =
|
|
190673
|
+
const featureDir = join234(naxDir, "features", featureName);
|
|
190674
|
+
const runsDir = join234(featureDir, "runs");
|
|
189716
190675
|
if (!existsSync45(runsDir)) {
|
|
189717
190676
|
throw new NaxError(`No runs directory found for feature: ${featureName}`, "LOGS_RUNS_DIR_NOT_FOUND", {
|
|
189718
190677
|
stage: "logs",
|
|
@@ -189744,7 +190703,7 @@ import { dirname as dirname52 } from "path";
|
|
|
189744
190703
|
init_errors4();
|
|
189745
190704
|
init_paths4();
|
|
189746
190705
|
import { readdir as readdir18 } from "fs/promises";
|
|
189747
|
-
import { join as
|
|
190706
|
+
import { join as join235 } from "path";
|
|
189748
190707
|
var _discoveryDeps = {
|
|
189749
190708
|
getRunsDir
|
|
189750
190709
|
};
|
|
@@ -189758,7 +190717,7 @@ async function loadMetas(runsDir) {
|
|
|
189758
190717
|
const metas = [];
|
|
189759
190718
|
for (const entry of entries) {
|
|
189760
190719
|
try {
|
|
189761
|
-
const meta = await Bun.file(
|
|
190720
|
+
const meta = await Bun.file(join235(runsDir, entry, "meta.json")).json();
|
|
189762
190721
|
metas.push(meta);
|
|
189763
190722
|
} catch {}
|
|
189764
190723
|
}
|
|
@@ -189775,7 +190734,7 @@ async function discoverRun(query, depsArg = _discoveryDeps) {
|
|
|
189775
190734
|
throw new NaxError("No runs registered", "RUN_NOT_FOUND", { runsDir });
|
|
189776
190735
|
}
|
|
189777
190736
|
const latest = metas.reduce((acc, m) => m.runId > acc.runId ? m : acc);
|
|
189778
|
-
return { meta: latest, jsonlPath:
|
|
190737
|
+
return { meta: latest, jsonlPath: join235(latest.eventsDir, `${latest.runId}.jsonl`) };
|
|
189779
190738
|
}
|
|
189780
190739
|
const matched = metas.filter((m) => matches3(m, query));
|
|
189781
190740
|
if (matched.length === 0) {
|
|
@@ -189792,7 +190751,7 @@ async function discoverRun(query, depsArg = _discoveryDeps) {
|
|
|
189792
190751
|
});
|
|
189793
190752
|
}
|
|
189794
190753
|
const meta = matched[0];
|
|
189795
|
-
return { meta, jsonlPath:
|
|
190754
|
+
return { meta, jsonlPath: join235(meta.eventsDir, `${meta.runId}.jsonl`) };
|
|
189796
190755
|
}
|
|
189797
190756
|
|
|
189798
190757
|
// src/replay/json.ts
|
|
@@ -190135,11 +191094,11 @@ init_checkpoint2();
|
|
|
190135
191094
|
init_runtime3();
|
|
190136
191095
|
init_feature_name();
|
|
190137
191096
|
import { existsSync as existsSync47 } from "fs";
|
|
190138
|
-
import { basename as basename44, join as
|
|
191097
|
+
import { basename as basename44, join as join236 } from "path";
|
|
190139
191098
|
async function defaultCheckpointExists(featureDir) {
|
|
190140
191099
|
if (!featureDir || !existsSync47(featureDir))
|
|
190141
191100
|
return false;
|
|
190142
|
-
return existsSync47(
|
|
191101
|
+
return existsSync47(join236(featureDir, "checkpoint.jsonl"));
|
|
190143
191102
|
}
|
|
190144
191103
|
async function defaultLoadCheckpoints(featureDir) {
|
|
190145
191104
|
return loadCheckpoints(featureDir);
|
|
@@ -190217,12 +191176,12 @@ function registerResumeCommand(program) {
|
|
|
190217
191176
|
`);
|
|
190218
191177
|
process.exit(1);
|
|
190219
191178
|
}
|
|
190220
|
-
const featureDir =
|
|
191179
|
+
const featureDir = join236(naxDir, "features", cmdOpts.feature);
|
|
190221
191180
|
const deps = {
|
|
190222
191181
|
..._resumeCmdDeps,
|
|
190223
191182
|
runInvocation: async (feature, opts) => {
|
|
190224
191183
|
const config = await loadConfig(naxDir ?? undefined);
|
|
190225
|
-
const prdPath =
|
|
191184
|
+
const prdPath = join236(opts.featureDir ?? "", "prd.json");
|
|
190226
191185
|
if (!existsSync(prdPath)) {
|
|
190227
191186
|
process.stderr.write(`Feature "${feature}" not found or missing prd.json
|
|
190228
191187
|
`);
|
|
@@ -190234,11 +191193,11 @@ function registerResumeCommand(program) {
|
|
|
190234
191193
|
applyResumeModeDeps(opts.featureDir ?? "", "auto");
|
|
190235
191194
|
const projectKey = config.name?.trim() || basename44(dir);
|
|
190236
191195
|
const outputDir = projectOutputDir(projectKey, config.outputDir);
|
|
190237
|
-
const statusFilePath =
|
|
190238
|
-
const runsDir =
|
|
191196
|
+
const statusFilePath = join236(outputDir, "status.json");
|
|
191197
|
+
const runsDir = join236(outputDir, "features", feature, "runs");
|
|
190239
191198
|
mkdirSync(runsDir, { recursive: true });
|
|
190240
191199
|
const runId = buildRunId(dir, new Date);
|
|
190241
|
-
const logFilePath =
|
|
191200
|
+
const logFilePath = join236(runsDir, `${runId}.jsonl`);
|
|
190242
191201
|
initLogger({ level: "info", filePath: logFilePath, useChalk: true, headless: true, suppressConsole: false });
|
|
190243
191202
|
const result = await run({
|
|
190244
191203
|
prdPath,
|
|
@@ -190275,7 +191234,7 @@ function registerResumeCommand(program) {
|
|
|
190275
191234
|
init_source();
|
|
190276
191235
|
init_paths4();
|
|
190277
191236
|
import { readdir as readdir19 } from "fs/promises";
|
|
190278
|
-
import { join as
|
|
191237
|
+
import { join as join237 } from "path";
|
|
190279
191238
|
var DEFAULT_LIMIT = 20;
|
|
190280
191239
|
var _runsCmdDeps = {
|
|
190281
191240
|
getRunsDir
|
|
@@ -190332,7 +191291,7 @@ async function runsCommand(options = {}) {
|
|
|
190332
191291
|
}
|
|
190333
191292
|
const rows = [];
|
|
190334
191293
|
for (const entry of entries) {
|
|
190335
|
-
const metaPath =
|
|
191294
|
+
const metaPath = join237(runsDir, entry, "meta.json");
|
|
190336
191295
|
let meta;
|
|
190337
191296
|
try {
|
|
190338
191297
|
meta = await Bun.file(metaPath).json();
|
|
@@ -190414,7 +191373,7 @@ init_execution();
|
|
|
190414
191373
|
init_logger2();
|
|
190415
191374
|
init_runtime3();
|
|
190416
191375
|
import { mkdir as mkdir55, unlink as unlink13 } from "fs/promises";
|
|
190417
|
-
import { basename as basename45, join as
|
|
191376
|
+
import { basename as basename45, join as join238 } from "path";
|
|
190418
191377
|
var _unlockDeps = {
|
|
190419
191378
|
findProjectDir,
|
|
190420
191379
|
loadConfig,
|
|
@@ -190478,7 +191437,7 @@ async function tryRemoveFeatureLock(outputDir, feature, force) {
|
|
|
190478
191437
|
return "removed";
|
|
190479
191438
|
}
|
|
190480
191439
|
async function listFeatureLockFeatures(outputDir) {
|
|
190481
|
-
const featuresRoot =
|
|
191440
|
+
const featuresRoot = join238(outputDir, "features");
|
|
190482
191441
|
let paths;
|
|
190483
191442
|
try {
|
|
190484
191443
|
paths = await Array.fromAsync(new Bun.Glob("*/nax.lock").scan({ cwd: featuresRoot, onlyFiles: true }));
|
|
@@ -190495,7 +191454,7 @@ async function unlockCommand(options) {
|
|
|
190495
191454
|
const workdir = options.dir ?? process.cwd();
|
|
190496
191455
|
if (options.feature !== undefined && options.feature.length > 0) {
|
|
190497
191456
|
const { outputDir } = await resolveOutputDir3(workdir);
|
|
190498
|
-
await mkdir55(
|
|
191457
|
+
await mkdir55(join238(outputDir, "features"), { recursive: true });
|
|
190499
191458
|
const outcome = await tryRemoveFeatureLock(outputDir, options.feature, options.force ?? false);
|
|
190500
191459
|
if (outcome === "skipped" || outcome === "parse-error") {
|
|
190501
191460
|
process.exit(1);
|
|
@@ -190503,7 +191462,7 @@ async function unlockCommand(options) {
|
|
|
190503
191462
|
logUnlockInfo("Feature lock removed");
|
|
190504
191463
|
process.exit(0);
|
|
190505
191464
|
}
|
|
190506
|
-
const checkoutLockPath =
|
|
191465
|
+
const checkoutLockPath = join238(workdir, "nax.lock");
|
|
190507
191466
|
let checkoutAborted = false;
|
|
190508
191467
|
const lockFile = Bun.file(checkoutLockPath);
|
|
190509
191468
|
const exists = await lockFile.exists();
|
|
@@ -192232,13 +193191,13 @@ init_version();
|
|
|
192232
193191
|
// bin/run-action.ts
|
|
192233
193192
|
init_source();
|
|
192234
193193
|
await init_cli2();
|
|
192235
|
-
import { existsSync as existsSync48, mkdirSync as
|
|
192236
|
-
import { basename as basename46, join as
|
|
193194
|
+
import { existsSync as existsSync48, mkdirSync as mkdirSync17 } from "fs";
|
|
193195
|
+
import { basename as basename46, join as join240 } from "path";
|
|
192237
193196
|
|
|
192238
193197
|
// src/cli/run-context-overrides.ts
|
|
192239
|
-
import { isAbsolute as isAbsolute43, join as
|
|
193198
|
+
import { isAbsolute as isAbsolute43, join as join239 } from "path";
|
|
192240
193199
|
function resolveCliOverridePath(workdir, value) {
|
|
192241
|
-
return isAbsolute43(value) || value.startsWith("~/") ? value :
|
|
193200
|
+
return isAbsolute43(value) || value.startsWith("~/") ? value : join239(workdir, value);
|
|
192242
193201
|
}
|
|
192243
193202
|
function resolveContextCliOverrides(workdir, options) {
|
|
192244
193203
|
const overrides = {};
|
|
@@ -192252,6 +193211,7 @@ function resolveContextCliOverrides(workdir, options) {
|
|
|
192252
193211
|
}
|
|
192253
193212
|
|
|
192254
193213
|
// src/cli/run-max-iterations.ts
|
|
193214
|
+
init_config();
|
|
192255
193215
|
function parseMaxIterationsFlag(raw) {
|
|
192256
193216
|
if (raw === undefined)
|
|
192257
193217
|
return { ok: true, value: undefined };
|
|
@@ -192266,6 +193226,11 @@ function applyMaxIterationsFlag(config, flag) {
|
|
|
192266
193226
|
return { ...config, execution: { ...config.execution } };
|
|
192267
193227
|
return { ...config, execution: { ...config.execution, maxIterations: flag } };
|
|
192268
193228
|
}
|
|
193229
|
+
function maxIterationsIgnoredNotice(config, flag) {
|
|
193230
|
+
if (flag === undefined || !isWorkflowMode(config))
|
|
193231
|
+
return;
|
|
193232
|
+
return `--max-iterations ${flag} is ignored in workflow mode: the run is bounded by its stories (pipeline mode only uses it)`;
|
|
193233
|
+
}
|
|
192269
193234
|
|
|
192270
193235
|
// src/cli/run-mode.ts
|
|
192271
193236
|
function resolveUseHeadless(input) {
|
|
@@ -192534,7 +193499,7 @@ async function resolveRunProjectContext(workdir, options) {
|
|
|
192534
193499
|
const cliOverrides = {};
|
|
192535
193500
|
const cliProfiles = options.profile ?? [];
|
|
192536
193501
|
const profileOverride = naxDir ? await resolveRunProfileOverride({
|
|
192537
|
-
prdPath:
|
|
193502
|
+
prdPath: join240(naxDir, "features", options.feature, "prd.json"),
|
|
192538
193503
|
projectRoot: workdir,
|
|
192539
193504
|
cliProfile: cliProfiles,
|
|
192540
193505
|
envProfile: process.env.NAX_PROFILE
|
|
@@ -192581,10 +193546,10 @@ async function maybeRunPlanPhase(params) {
|
|
|
192581
193546
|
}
|
|
192582
193547
|
async function runPlanningPhase(params) {
|
|
192583
193548
|
const { options, from, config, workdir, projectRoot, featureDir } = params;
|
|
192584
|
-
const planLogDir =
|
|
192585
|
-
|
|
193549
|
+
const planLogDir = join240(featureDir, "plan");
|
|
193550
|
+
mkdirSync17(planLogDir, { recursive: true });
|
|
192586
193551
|
const planLogId = new Date().toISOString().replace(/:/g, "-").replace(/\..+/, "");
|
|
192587
|
-
const planLogPath =
|
|
193552
|
+
const planLogPath = join240(planLogDir, `${planLogId}.jsonl`);
|
|
192588
193553
|
initLogger({ level: "info", filePath: planLogPath, useChalk: false, headless: true });
|
|
192589
193554
|
console.log(source_default.dim(` [Plan log: ${planLogPath}]`));
|
|
192590
193555
|
console.log(source_default.dim(" [Planning phase: generating PRD from spec]"));
|
|
@@ -192628,10 +193593,10 @@ function initRunLogging(params) {
|
|
|
192628
193593
|
const { options, config, workdir, isTTY, logLevel, formatterMode } = params;
|
|
192629
193594
|
const projectKey = config.name?.trim() || basename46(workdir);
|
|
192630
193595
|
const outputDir = projectOutputDir(projectKey, config.outputDir);
|
|
192631
|
-
const runsDir =
|
|
192632
|
-
|
|
193596
|
+
const runsDir = join240(outputDir, "features", options.feature, "runs");
|
|
193597
|
+
mkdirSync17(runsDir, { recursive: true });
|
|
192633
193598
|
const runId = new Date().toISOString().replace(/:/g, "-").replace(/\..+/, "");
|
|
192634
|
-
const logFilePath =
|
|
193599
|
+
const logFilePath = join240(runsDir, `${runId}.jsonl`);
|
|
192635
193600
|
const headlessFlag = options.headless ?? false;
|
|
192636
193601
|
const headlessEnv = process.env.NAX_HEADLESS === "1";
|
|
192637
193602
|
const useHeadless = resolveUseHeadless({ isTTY, headlessFlag, headlessEnv, formatterMode });
|
|
@@ -192651,6 +193616,9 @@ function applyRunCliOverrides(config, options, maxIterationsFlag) {
|
|
|
192651
193616
|
config.agent.default = options.agent;
|
|
192652
193617
|
}
|
|
192653
193618
|
const overridden = applyMaxIterationsFlag(config, maxIterationsFlag.value);
|
|
193619
|
+
const ignoredNotice = maxIterationsIgnoredNotice(overridden, maxIterationsFlag.value);
|
|
193620
|
+
if (ignoredNotice)
|
|
193621
|
+
console.warn(source_default.yellow(ignoredNotice));
|
|
192654
193622
|
if (options.maxCost !== undefined) {
|
|
192655
193623
|
const maxCost = Number(options.maxCost);
|
|
192656
193624
|
if (!Number.isFinite(maxCost) || maxCost <= 0) {
|
|
@@ -192665,7 +193633,7 @@ function applyRunCliOverrides(config, options, maxIterationsFlag) {
|
|
|
192665
193633
|
// bin/run-action-execute.ts
|
|
192666
193634
|
init_source();
|
|
192667
193635
|
init_execution();
|
|
192668
|
-
import { join as
|
|
193636
|
+
import { join as join244 } from "path";
|
|
192669
193637
|
init_version();
|
|
192670
193638
|
function mountRunTui(params) {
|
|
192671
193639
|
const initialStories = params.prd.userStories.map((story) => ({
|
|
@@ -192680,7 +193648,7 @@ function mountRunTui(params) {
|
|
|
192680
193648
|
stories: initialStories,
|
|
192681
193649
|
events: params.eventEmitter,
|
|
192682
193650
|
agentStreamEvents: params.agentStreamEvents,
|
|
192683
|
-
queueFilePath:
|
|
193651
|
+
queueFilePath: join244(params.workdir, ".queue.txt")
|
|
192684
193652
|
});
|
|
192685
193653
|
}
|
|
192686
193654
|
async function waitForScheduledRun(params) {
|
|
@@ -192827,7 +193795,7 @@ program2.command("setup").description("Analyze repo and generate .nax/config.jso
|
|
|
192827
193795
|
});
|
|
192828
193796
|
process.exit(exitCode);
|
|
192829
193797
|
});
|
|
192830
|
-
program2.command("run").description("Run the orchestration loop for a feature").requiredOption("-f, --feature <name>", "Feature name").option("-a, --agent <name>", "Force a specific agent").option("-m, --max-iterations <n>", "Max iterations").option("--max-cost <usd>", "Override cost limit (USD) for this run \u2014 aborts execution when exceeded").option("--dry-run", "Show plan without executing", false).option("--no-context", "Disable context builder (skip file context in prompts)").option("--rules-dir <path>", "Override rules directory (absolute, ~/\u2026 , or relative to the workdir)").option("--context-file <path>", "Project-context override file (absolute, ~/\u2026 , or relative to the workdir)").option("--no-batch", "Disable story batching (execute all stories individually)").option("--parallel <n>", "Max parallel sessions (omit = sequential)").option("--plan", "Run plan phase first before execution", false).option("--from <spec-path>", "Path to spec file (required when --plan is used)").option("--no-spec-lint", "Plan even when the spec declares sections that extract to nothing").option("--one-shot", "Skip interactive planning Q&A, use single LLM call (ACP only)", false).option("--force", "Force overwrite existing prd.json when using --plan", false).option("--headless", "Force headless mode (disable TUI, use pipe mode)", false).option("--verbose", "Enable verbose logging (debug level)", false).option("--quiet", "Quiet mode (warnings and errors only)", false).option("--silent", "Silent mode (errors only)", false).option("--json", "JSON mode (raw JSONL output to stdout)", false).option("-d, --dir <path>", "Working directory", process.cwd()).option("--skip-precheck", "Skip precheck validations (advanced users only)", false).option("--profile <name>", "Profile(s) to overlay (comma-separated or repeated; later overrides earlier)", collectProfile, []).option("--schedule <when>", "Defer run start until <when> (e.g. 30m, 1h30m, 17:00, 2026-07-02T02:00)").option("--compare <agents>", "Bake-off mode: comma-separated list of contestant agents (e.g. claude,codex)").option("--fresh", "Ignore any existing checkpoint.jsonl and re-run every incomplete story from scratch", false).addOption(new Option2("--no-resume", "Alias for --fresh: never auto-resume from a prior checkpoint").default("__UNSET__")).action(async (options) => {
|
|
193798
|
+
program2.command("run").description("Run the orchestration loop for a feature").requiredOption("-f, --feature <name>", "Feature name").option("-a, --agent <name>", "Force a specific agent").option("-m, --max-iterations <n>", "Max iterations (pipeline mode only; workflow mode ignores it)").option("--max-cost <usd>", "Override cost limit (USD) for this run \u2014 aborts execution when exceeded").option("--dry-run", "Show plan without executing", false).option("--no-context", "Disable context builder (skip file context in prompts)").option("--rules-dir <path>", "Override rules directory (absolute, ~/\u2026 , or relative to the workdir)").option("--context-file <path>", "Project-context override file (absolute, ~/\u2026 , or relative to the workdir)").option("--no-batch", "Disable story batching (execute all stories individually)").option("--parallel <n>", "Max parallel sessions (omit = sequential)").option("--plan", "Run plan phase first before execution", false).option("--from <spec-path>", "Path to spec file (required when --plan is used)").option("--no-spec-lint", "Plan even when the spec declares sections that extract to nothing").option("--one-shot", "Skip interactive planning Q&A, use single LLM call (ACP only)", false).option("--force", "Force overwrite existing prd.json when using --plan", false).option("--headless", "Force headless mode (disable TUI, use pipe mode)", false).option("--verbose", "Enable verbose logging (debug level)", false).option("--quiet", "Quiet mode (warnings and errors only)", false).option("--silent", "Silent mode (errors only)", false).option("--json", "JSON mode (raw JSONL output to stdout)", false).option("-d, --dir <path>", "Working directory", process.cwd()).option("--skip-precheck", "Skip precheck validations (advanced users only)", false).option("--profile <name>", "Profile(s) to overlay (comma-separated or repeated; later overrides earlier)", collectProfile, []).option("--schedule <when>", "Defer run start until <when> (e.g. 30m, 1h30m, 17:00, 2026-07-02T02:00)").option("--compare <agents>", "Bake-off mode: comma-separated list of contestant agents (e.g. claude,codex)").option("--fresh", "Ignore any existing checkpoint.jsonl and re-run every incomplete story from scratch", false).addOption(new Option2("--no-resume", "Alias for --fresh: never auto-resume from a prior checkpoint").default("__UNSET__")).action(async (options) => {
|
|
192831
193799
|
const workdir = resolveRunWorkdir(options);
|
|
192832
193800
|
const { maxIterationsFlag, parallel } = parseRunPreconditionFlags(options);
|
|
192833
193801
|
await validateBakeoffPreflight(options, workdir);
|
|
@@ -192846,9 +193814,9 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
192846
193814
|
process.exit(1);
|
|
192847
193815
|
}
|
|
192848
193816
|
await runTrustGate(workdir);
|
|
192849
|
-
const projectRoot =
|
|
192850
|
-
const featureDir =
|
|
192851
|
-
const prdPath =
|
|
193817
|
+
const projectRoot = join246(naxDir, "..");
|
|
193818
|
+
const featureDir = join246(naxDir, "features", options.feature);
|
|
193819
|
+
const prdPath = join246(featureDir, "prd.json");
|
|
192852
193820
|
await maybeRunPlanPhase({ options, config, workdir, projectRoot, featureDir, prdPath });
|
|
192853
193821
|
if (!existsSync50(prdPath)) {
|
|
192854
193822
|
console.error(source_default.red(`Feature "${options.feature}" not found or missing prd.json`));
|
|
@@ -192866,7 +193834,7 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
192866
193834
|
formatterMode
|
|
192867
193835
|
});
|
|
192868
193836
|
config = applyRunCliOverrides(config, options, maxIterationsFlag);
|
|
192869
|
-
const globalNaxDir =
|
|
193837
|
+
const globalNaxDir = join246(homedir12(), ".nax");
|
|
192870
193838
|
const hooks = await loadHooksConfig(naxDir, globalNaxDir);
|
|
192871
193839
|
const eventEmitter = new PipelineEventEmitter;
|
|
192872
193840
|
const agentStreamEvents = useHeadless ? undefined : new AgentStreamEventBus;
|
|
@@ -192883,7 +193851,7 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
192883
193851
|
} else {
|
|
192884
193852
|
console.log(source_default.dim(" [Headless mode \u2014 pipe output]"));
|
|
192885
193853
|
}
|
|
192886
|
-
const statusFilePath =
|
|
193854
|
+
const statusFilePath = join246(outputDir, "status.json");
|
|
192887
193855
|
await waitForScheduledRun({ scheduleGate, feature: options.feature, formatterMode, isTTY, tuiInstance });
|
|
192888
193856
|
if (options.compare) {
|
|
192889
193857
|
await runBakeoffMode({ options, workdir, outputDir, config, tuiInstance });
|
|
@@ -192904,7 +193872,7 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
192904
193872
|
agentStreamEvents,
|
|
192905
193873
|
tuiInstance
|
|
192906
193874
|
});
|
|
192907
|
-
const latestSymlink =
|
|
193875
|
+
const latestSymlink = join246(runsDir, "latest.jsonl");
|
|
192908
193876
|
try {
|
|
192909
193877
|
if (existsSync50(latestSymlink)) {
|
|
192910
193878
|
unlinkSync4(latestSymlink);
|
|
@@ -192998,9 +193966,9 @@ features.command("create <name>").description("Create a new feature").option("-d
|
|
|
192998
193966
|
console.error(source_default.red("nax not initialized. Run: nax init"));
|
|
192999
193967
|
process.exit(1);
|
|
193000
193968
|
}
|
|
193001
|
-
const featureDir =
|
|
193002
|
-
|
|
193003
|
-
await Bun.write(
|
|
193969
|
+
const featureDir = join246(naxDir, "features", name);
|
|
193970
|
+
mkdirSync18(featureDir, { recursive: true });
|
|
193971
|
+
await Bun.write(join246(featureDir, "spec.md"), `# Feature: ${name}
|
|
193004
193972
|
|
|
193005
193973
|
## Overview
|
|
193006
193974
|
|
|
@@ -193033,7 +194001,7 @@ features.command("create <name>").description("Create a new feature").option("-d
|
|
|
193033
194001
|
|
|
193034
194002
|
<!-- What this feature explicitly does NOT cover. -->
|
|
193035
194003
|
`);
|
|
193036
|
-
await Bun.write(
|
|
194004
|
+
await Bun.write(join246(featureDir, "progress.txt"), `# Progress: ${name}
|
|
193037
194005
|
|
|
193038
194006
|
Created: ${new Date().toISOString()}
|
|
193039
194007
|
|
|
@@ -193059,7 +194027,7 @@ features.command("list").description("List all features").option("-d, --dir <pat
|
|
|
193059
194027
|
console.error(source_default.red("nax not initialized."));
|
|
193060
194028
|
process.exit(1);
|
|
193061
194029
|
}
|
|
193062
|
-
const featuresDir =
|
|
194030
|
+
const featuresDir = join246(naxDir, "features");
|
|
193063
194031
|
if (!existsSync50(featuresDir)) {
|
|
193064
194032
|
console.log(source_default.dim("No features yet."));
|
|
193065
194033
|
return;
|
|
@@ -193074,7 +194042,7 @@ features.command("list").description("List all features").option("-d, --dir <pat
|
|
|
193074
194042
|
Features:
|
|
193075
194043
|
`));
|
|
193076
194044
|
for (const name of entries) {
|
|
193077
|
-
const prdPath =
|
|
194045
|
+
const prdPath = join246(featuresDir, name, "prd.json");
|
|
193078
194046
|
if (existsSync50(prdPath)) {
|
|
193079
194047
|
try {
|
|
193080
194048
|
const prd = await loadPRD(prdPath);
|
|
@@ -193146,17 +194114,17 @@ Use: nax plan -f <feature> --from <spec>`));
|
|
|
193146
194114
|
console.error(source_default.red("nax not initialized. Run: nax init"));
|
|
193147
194115
|
process.exit(1);
|
|
193148
194116
|
}
|
|
193149
|
-
const projectRoot =
|
|
194117
|
+
const projectRoot = join246(naxDir, "..");
|
|
193150
194118
|
const cliOverrides = {};
|
|
193151
194119
|
const cliProfiles = options.profile ?? [];
|
|
193152
194120
|
if (cliProfiles.length > 0) {
|
|
193153
194121
|
cliOverrides.profile = cliProfiles;
|
|
193154
194122
|
}
|
|
193155
194123
|
const config = await loadConfig(projectRoot, cliOverrides);
|
|
193156
|
-
const featureLogDir =
|
|
193157
|
-
|
|
194124
|
+
const featureLogDir = join246(naxDir, "features", options.feature, "plan");
|
|
194125
|
+
mkdirSync18(featureLogDir, { recursive: true });
|
|
193158
194126
|
const planLogId = new Date().toISOString().replace(/:/g, "-").replace(/\..+/, "");
|
|
193159
|
-
const planLogPath =
|
|
194127
|
+
const planLogPath = join246(featureLogDir, `${planLogId}.jsonl`);
|
|
193160
194128
|
initLogger({ level: "info", filePath: planLogPath, useChalk: false, headless: true });
|
|
193161
194129
|
console.log(source_default.dim(` [Plan log: ${planLogPath}]`));
|
|
193162
194130
|
try {
|
|
@@ -193685,7 +194653,7 @@ spec.command("lint [paths...]").description("Check a spec's machine-extracted se
|
|
|
193685
194653
|
return;
|
|
193686
194654
|
}
|
|
193687
194655
|
const naxDir = findProjectDir(workdir);
|
|
193688
|
-
const projectRoot = naxDir ?
|
|
194656
|
+
const projectRoot = naxDir ? join246(naxDir, "..") : workdir;
|
|
193689
194657
|
let maxAcCount;
|
|
193690
194658
|
if (naxDir) {
|
|
193691
194659
|
const config = await loadConfig(projectRoot);
|