@nathapp/nax 0.90.3 → 0.90.4
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/README.md +2 -1
- package/dist/nax.js +1138 -551
- package/package.json +2 -2
package/dist/nax.js
CHANGED
|
@@ -25579,6 +25579,10 @@ var init_schemas_execution = __esm(() => {
|
|
|
25579
25579
|
setupCommand: null,
|
|
25580
25580
|
timeoutSeconds: 300
|
|
25581
25581
|
}),
|
|
25582
|
+
preRun: array(object({
|
|
25583
|
+
command: string2().min(1, "execution.preRun[].command must be non-empty"),
|
|
25584
|
+
timeoutSeconds: number2().int().min(1).default(300)
|
|
25585
|
+
})).default([]),
|
|
25582
25586
|
storyIsolation: _enum(["shared", "worktree"]).default("shared"),
|
|
25583
25587
|
flakeDetection: FlakeDetectionConfigSchema.default({
|
|
25584
25588
|
enabled: true,
|
|
@@ -26431,7 +26435,8 @@ var init_schemas3 = __esm(() => {
|
|
|
26431
26435
|
maxMutants: 3,
|
|
26432
26436
|
timeoutSeconds: 60
|
|
26433
26437
|
},
|
|
26434
|
-
commandInterceptor: CommandInterceptorConfigSchema.parse({})
|
|
26438
|
+
commandInterceptor: CommandInterceptorConfigSchema.parse({}),
|
|
26439
|
+
preRun: ExecutionConfigSchema.shape.preRun.parse(undefined)
|
|
26435
26440
|
}),
|
|
26436
26441
|
install: InstallConfigSchema.default({ allowScripts: false }),
|
|
26437
26442
|
quality: QualityConfigSchema.default({
|
|
@@ -49281,7 +49286,7 @@ var package_default;
|
|
|
49281
49286
|
var init_package = __esm(() => {
|
|
49282
49287
|
package_default = {
|
|
49283
49288
|
name: "@nathapp/nax",
|
|
49284
|
-
version: "0.90.
|
|
49289
|
+
version: "0.90.4",
|
|
49285
49290
|
description: "AI Coding Agent Orchestrator \u2014 loops until done",
|
|
49286
49291
|
type: "module",
|
|
49287
49292
|
bin: {
|
|
@@ -49367,7 +49372,7 @@ var init_package = __esm(() => {
|
|
|
49367
49372
|
"@agentclientprotocol/sdk": "~1.7.0",
|
|
49368
49373
|
"@anthropic-ai/sandbox-runtime": "0.0.77",
|
|
49369
49374
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
49370
|
-
"@nathapp/nax-ai": "0.90.
|
|
49375
|
+
"@nathapp/nax-ai": "0.90.4",
|
|
49371
49376
|
chalk: "^5.6.2",
|
|
49372
49377
|
commander: "^13.1.0",
|
|
49373
49378
|
ink: "^6.7.0",
|
|
@@ -74652,8 +74657,8 @@ var init_version = __esm(() => {
|
|
|
74652
74657
|
NAX_AI_VERSION = CATALOG_VERSION;
|
|
74653
74658
|
NAX_COMMIT = (() => {
|
|
74654
74659
|
try {
|
|
74655
|
-
if (/^[0-9a-f]{6,10}$/.test("
|
|
74656
|
-
return "
|
|
74660
|
+
if (/^[0-9a-f]{6,10}$/.test("4c3ad20"))
|
|
74661
|
+
return "4c3ad20";
|
|
74657
74662
|
} catch {}
|
|
74658
74663
|
try {
|
|
74659
74664
|
const result = Bun.spawnSync(["git", "rev-parse", "--short", "HEAD"], {
|
|
@@ -79578,11 +79583,14 @@ var init_client5 = __esm(() => {
|
|
|
79578
79583
|
|
|
79579
79584
|
// src/mcp/lock.ts
|
|
79580
79585
|
import { createHash as createHash21 } from "crypto";
|
|
79581
|
-
import { mkdir as mkdir27, readFile as readFile10, writeFile as writeFile11 } from "fs/promises";
|
|
79582
|
-
import { join as join77 } from "path";
|
|
79586
|
+
import { lstat as lstat4, mkdir as mkdir27, readFile as readFile10, writeFile as writeFile11 } from "fs/promises";
|
|
79587
|
+
import { dirname as dirname31, join as join77 } from "path";
|
|
79583
79588
|
function mcpLockPath(projectRoot) {
|
|
79584
79589
|
return join77(projectRoot, PROJECT_NAX_DIR, MCP_LOCK_FILENAME);
|
|
79585
79590
|
}
|
|
79591
|
+
function globalMcpLockPath(globalDir) {
|
|
79592
|
+
return join77(globalDir ?? globalConfigDir(), MCP_LOCK_FILENAME);
|
|
79593
|
+
}
|
|
79586
79594
|
function canonical4(value) {
|
|
79587
79595
|
if (Array.isArray(value))
|
|
79588
79596
|
return value.map(canonical4);
|
|
@@ -79594,9 +79602,9 @@ function canonical4(value) {
|
|
|
79594
79602
|
function schemaHash(schema) {
|
|
79595
79603
|
return createHash21("sha256").update(JSON.stringify(canonical4(schema) ?? null)).digest("hex").slice(0, 16);
|
|
79596
79604
|
}
|
|
79597
|
-
async function
|
|
79605
|
+
async function parseLockFile(path) {
|
|
79598
79606
|
try {
|
|
79599
|
-
const parsed = JSON.parse(await readFile10(
|
|
79607
|
+
const parsed = JSON.parse(await readFile10(path, "utf8"));
|
|
79600
79608
|
if (parsed?.version !== 1 || typeof parsed.servers !== "object" || parsed.servers === null)
|
|
79601
79609
|
return;
|
|
79602
79610
|
return parsed;
|
|
@@ -79604,15 +79612,41 @@ async function readMcpLock(projectRoot) {
|
|
|
79604
79612
|
return;
|
|
79605
79613
|
}
|
|
79606
79614
|
}
|
|
79607
|
-
|
|
79615
|
+
function errorCode(err) {
|
|
79616
|
+
return typeof err === "object" && err !== null ? Reflect.get(err, "code") : undefined;
|
|
79617
|
+
}
|
|
79618
|
+
async function lockPresence(path) {
|
|
79619
|
+
try {
|
|
79620
|
+
await lstat4(path);
|
|
79621
|
+
return "present";
|
|
79622
|
+
} catch (err) {
|
|
79623
|
+
return errorCode(err) === MISSING_CODE ? "absent" : "unreadable";
|
|
79624
|
+
}
|
|
79625
|
+
}
|
|
79626
|
+
async function resolveMcpLock(projectRoot, globalDir) {
|
|
79627
|
+
const projectPath = mcpLockPath(projectRoot);
|
|
79628
|
+
const presence = await lockPresence(projectPath);
|
|
79629
|
+
if (presence === "unreadable")
|
|
79630
|
+
return;
|
|
79631
|
+
if (presence === "present") {
|
|
79632
|
+
const projectLock = await parseLockFile(projectPath);
|
|
79633
|
+
return projectLock === undefined ? undefined : { ...projectLock, source: "project" };
|
|
79634
|
+
}
|
|
79635
|
+
const globalLock = await parseLockFile(globalMcpLockPath(globalDir));
|
|
79636
|
+
return globalLock === undefined ? undefined : { ...globalLock, source: "global" };
|
|
79637
|
+
}
|
|
79638
|
+
async function writeMcpLockAt(path, lock) {
|
|
79608
79639
|
const servers = Object.fromEntries(Object.entries(lock.servers).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([id, tools]) => [
|
|
79609
79640
|
id,
|
|
79610
79641
|
Object.fromEntries(Object.entries(tools).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0))
|
|
79611
79642
|
]));
|
|
79612
|
-
await mkdir27(
|
|
79613
|
-
await writeFile11(
|
|
79643
|
+
await mkdir27(dirname31(path), { recursive: true });
|
|
79644
|
+
await writeFile11(path, `${JSON.stringify({ version: 1, servers }, null, 2)}
|
|
79614
79645
|
`);
|
|
79615
79646
|
}
|
|
79647
|
+
async function writeMcpLock(projectRoot, lock) {
|
|
79648
|
+
await writeMcpLockAt(mcpLockPath(projectRoot), lock);
|
|
79649
|
+
}
|
|
79616
79650
|
function applyLock(locked, discovered) {
|
|
79617
79651
|
const admitted = [];
|
|
79618
79652
|
const withheld = [];
|
|
@@ -79627,7 +79661,7 @@ function applyLock(locked, discovered) {
|
|
|
79627
79661
|
}
|
|
79628
79662
|
return { admitted, withheld };
|
|
79629
79663
|
}
|
|
79630
|
-
var MCP_LOCK_FILENAME = "mcp-lock.json", MCP_LOCK_REFRESH_COMMAND = "nax mcp lock";
|
|
79664
|
+
var MCP_LOCK_FILENAME = "mcp-lock.json", MCP_LOCK_REFRESH_COMMAND = "nax mcp lock", MISSING_CODE = "ENOENT";
|
|
79631
79665
|
var init_lock = __esm(() => {
|
|
79632
79666
|
init_config();
|
|
79633
79667
|
});
|
|
@@ -79785,13 +79819,18 @@ var init_pool = __esm(() => {
|
|
|
79785
79819
|
});
|
|
79786
79820
|
|
|
79787
79821
|
// src/mcp/provider.ts
|
|
79822
|
+
function lockSourceOf(lock) {
|
|
79823
|
+
if (lock === undefined)
|
|
79824
|
+
return "none";
|
|
79825
|
+
return lock.source ?? "project";
|
|
79826
|
+
}
|
|
79788
79827
|
function createMcpProviders(args) {
|
|
79789
79828
|
const servers = Object.entries(args.config?.servers ?? {}).filter(([, server]) => server.enabled);
|
|
79790
79829
|
if (servers.length === 0)
|
|
79791
79830
|
return [];
|
|
79792
79831
|
for (const [id] of servers)
|
|
79793
79832
|
validateProviderId(id);
|
|
79794
|
-
const read = args.readLock ??
|
|
79833
|
+
const read = args.readLock ?? resolveMcpLock;
|
|
79795
79834
|
let lockPromise;
|
|
79796
79835
|
const lock = () => lockPromise ??= read(args.projectRoot);
|
|
79797
79836
|
return servers.map(([serverId, server]) => {
|
|
@@ -79825,14 +79864,17 @@ function createMcpProviders(args) {
|
|
|
79825
79864
|
}
|
|
79826
79865
|
if (discovered.length === 0)
|
|
79827
79866
|
return [];
|
|
79828
|
-
const
|
|
79867
|
+
const resolved = await lock();
|
|
79868
|
+
const lockSource = lockSourceOf(resolved);
|
|
79869
|
+
const { admitted, withheld } = applyLock(resolved?.servers[serverId], discovered);
|
|
79829
79870
|
for (const entry of withheld) {
|
|
79830
|
-
args.onWithheld?.({ serverId, name: entry.name, reason: entry.reason });
|
|
79871
|
+
args.onWithheld?.({ serverId, name: entry.name, reason: entry.reason, lockSource });
|
|
79831
79872
|
getSafeLogger2()?.warn("mcp", `[provider] ${serverId}__${entry.name} withheld`, {
|
|
79832
79873
|
storyId: args.storyId,
|
|
79833
79874
|
serverId,
|
|
79834
79875
|
tool: entry.name,
|
|
79835
79876
|
reason: entry.reason,
|
|
79877
|
+
lockSource,
|
|
79836
79878
|
refresh: MCP_LOCK_REFRESH_COMMAND
|
|
79837
79879
|
});
|
|
79838
79880
|
}
|
|
@@ -79975,7 +80017,7 @@ var init_nax_index_flags = __esm(() => {
|
|
|
79975
80017
|
|
|
79976
80018
|
// src/runstate/repair.ts
|
|
79977
80019
|
import { appendFile as appendFile6, mkdir as mkdir29, rename as rename8 } from "fs/promises";
|
|
79978
|
-
import { dirname as
|
|
80020
|
+
import { dirname as dirname32 } from "path";
|
|
79979
80021
|
async function damageOf(f, hidden) {
|
|
79980
80022
|
const file = Bun.file(f.path);
|
|
79981
80023
|
const exists = await file.exists();
|
|
@@ -79987,7 +80029,7 @@ async function damageOf(f, hidden) {
|
|
|
79987
80029
|
];
|
|
79988
80030
|
}
|
|
79989
80031
|
async function restore(f) {
|
|
79990
|
-
await mkdir29(
|
|
80032
|
+
await mkdir29(dirname32(f.path), { recursive: true });
|
|
79991
80033
|
const tmp = `${f.path}.runstate-${crypto.randomUUID()}`;
|
|
79992
80034
|
await Bun.write(tmp, f.content);
|
|
79993
80035
|
await rename8(tmp, f.path);
|
|
@@ -80710,7 +80752,7 @@ var init_tree_snapshot = __esm(() => {
|
|
|
80710
80752
|
});
|
|
80711
80753
|
|
|
80712
80754
|
// src/review/reviewer-guard/deps.ts
|
|
80713
|
-
import { lstat as
|
|
80755
|
+
import { lstat as lstat5, rm as rm8 } from "fs/promises";
|
|
80714
80756
|
function guardGitError(args, cwd, stderr) {
|
|
80715
80757
|
return new NaxError(`[${STAGE6}] git ${args.join(" ")} failed: ${stderr.trim()}`, "REVIEWER_GUARD_GIT_FAILED", {
|
|
80716
80758
|
stage: STAGE6,
|
|
@@ -80742,7 +80784,7 @@ var init_deps = __esm(() => {
|
|
|
80742
80784
|
init_hardened_git();
|
|
80743
80785
|
_snapshotDeps = {
|
|
80744
80786
|
rm: rm8,
|
|
80745
|
-
lstat:
|
|
80787
|
+
lstat: lstat5,
|
|
80746
80788
|
snapshotWorkingTree,
|
|
80747
80789
|
changedPathsBetween,
|
|
80748
80790
|
git: runHardenedGit,
|
|
@@ -85213,7 +85255,7 @@ function naxCheckedBlock2(gates, e2eGate) {
|
|
|
85213
85255
|
nax runs the e2e suite as a repository gate on the host; do not list e2e journeys in cannotVerify.` : "";
|
|
85214
85256
|
return `## What nax already checked
|
|
85215
85257
|
nax ran these gates on this story before your review: lint ${state("lint")}, typecheck ${state("typecheck")}, scoped tests ${state("scoped")}.
|
|
85216
|
-
After your review nax runs the full test suite on this story, and once every story is done it runs the repository gates. Both run only when the workflow reaches them: a red gate, or a finding left open, can end the story before the suite.
|
|
85258
|
+
After your review nax runs the full test suite on this story, and once every story is done it runs the repository gates. Both run only when the workflow reaches them: a red gate, or a finding left open, can end the story before the suite. nax records whether each one ran and what it returned, so never list the full suite or the repository gates in "cannotVerify", even though they have not run yet.
|
|
85217
85259
|
If you have a shell tool, run this story's own test files with one scoped test command before you give the spec verdict.${e2e}`;
|
|
85218
85260
|
}
|
|
85219
85261
|
function buildWorkflowStoryReviewPrompt(input) {
|
|
@@ -90861,7 +90903,7 @@ var init_nbf_worth_check = __esm(() => {
|
|
|
90861
90903
|
|
|
90862
90904
|
// src/operations/nbf-worth-check-audit.ts
|
|
90863
90905
|
import { mkdir as mkdir31 } from "fs/promises";
|
|
90864
|
-
import { dirname as
|
|
90906
|
+
import { dirname as dirname33, join as join96 } from "path";
|
|
90865
90907
|
function fileRecord(record) {
|
|
90866
90908
|
const parsed = record.result?.parsed === true;
|
|
90867
90909
|
return {
|
|
@@ -90943,7 +90985,7 @@ var init_nbf_worth_check_audit = __esm(() => {
|
|
|
90943
90985
|
init_runtime3();
|
|
90944
90986
|
_nbfWorthCheckAuditDeps = {
|
|
90945
90987
|
write: async (path, record) => {
|
|
90946
|
-
await mkdir31(
|
|
90988
|
+
await mkdir31(dirname33(path), { recursive: true });
|
|
90947
90989
|
await Bun.write(path, JSON.stringify(record, null, 2));
|
|
90948
90990
|
},
|
|
90949
90991
|
now: () => Date.now(),
|
|
@@ -94892,7 +94934,13 @@ var init_acceptance2 = __esm(() => {
|
|
|
94892
94934
|
// src/cli/features-acceptance.ts
|
|
94893
94935
|
import { existsSync as existsSync15 } from "fs";
|
|
94894
94936
|
import { join as join101, relative as relative32 } from "path";
|
|
94895
|
-
|
|
94937
|
+
function toResolutionError(err) {
|
|
94938
|
+
return {
|
|
94939
|
+
code: err instanceof NaxError ? err.code : "UNKNOWN",
|
|
94940
|
+
message: errorMessage(err)
|
|
94941
|
+
};
|
|
94942
|
+
}
|
|
94943
|
+
async function resolveFeatureAcceptance(featureName, workdir, configOverrides) {
|
|
94896
94944
|
let enabled = true;
|
|
94897
94945
|
try {
|
|
94898
94946
|
const naxDir = findProjectDir(workdir);
|
|
@@ -94900,7 +94948,7 @@ async function resolveFeatureAcceptance(featureName, workdir) {
|
|
|
94900
94948
|
return { status: "no-prd", enabled, groups: [] };
|
|
94901
94949
|
}
|
|
94902
94950
|
const repoRoot = join101(naxDir, "..");
|
|
94903
|
-
const config = await loadConfig(workdir);
|
|
94951
|
+
const config = await loadConfig(workdir, configOverrides);
|
|
94904
94952
|
enabled = config.acceptance?.enabled ?? true;
|
|
94905
94953
|
if (!enabled) {
|
|
94906
94954
|
return { status: "disabled", enabled: false, groups: [] };
|
|
@@ -94925,11 +94973,13 @@ async function resolveFeatureAcceptance(featureName, workdir) {
|
|
|
94925
94973
|
}));
|
|
94926
94974
|
return { status: "ok", enabled, groups };
|
|
94927
94975
|
} catch (err) {
|
|
94976
|
+
const error = toResolutionError(err);
|
|
94928
94977
|
getSafeLogger2()?.warn("acceptance", "Failed to resolve feature acceptance targets", {
|
|
94929
94978
|
featureName,
|
|
94930
|
-
|
|
94979
|
+
code: error.code,
|
|
94980
|
+
cause: error.message
|
|
94931
94981
|
});
|
|
94932
|
-
return { status: "
|
|
94982
|
+
return { status: "error", enabled, groups: [], error };
|
|
94933
94983
|
}
|
|
94934
94984
|
}
|
|
94935
94985
|
async function resolveGroupCommand(repoRoot, packageDir, rootCommand) {
|
|
@@ -94942,16 +94992,65 @@ var init_features_acceptance = __esm(() => {
|
|
|
94942
94992
|
init_internal();
|
|
94943
94993
|
init_acceptance2();
|
|
94944
94994
|
init_config();
|
|
94995
|
+
init_errors4();
|
|
94945
94996
|
init_logger2();
|
|
94946
94997
|
init_prd();
|
|
94947
94998
|
});
|
|
94948
94999
|
|
|
95000
|
+
// src/cli/resolve-run-profile.ts
|
|
95001
|
+
async function resolveRunProfileOverride(opts) {
|
|
95002
|
+
const cliChain = parseProfileList(opts.cliProfile);
|
|
95003
|
+
if (cliChain.length > 0)
|
|
95004
|
+
return cliChain;
|
|
95005
|
+
if (opts.envProfile)
|
|
95006
|
+
return;
|
|
95007
|
+
const readJson = opts._readJson ?? (async (path) => {
|
|
95008
|
+
const file = Bun.file(path);
|
|
95009
|
+
if (!await file.exists())
|
|
95010
|
+
return;
|
|
95011
|
+
return file.json();
|
|
95012
|
+
});
|
|
95013
|
+
try {
|
|
95014
|
+
const prd = await readJson(opts.prdPath);
|
|
95015
|
+
const rp = prd?.routingProfile;
|
|
95016
|
+
const prdChain = parseProfileList(typeof rp === "string" || Array.isArray(rp) ? rp : undefined);
|
|
95017
|
+
if (prdChain.length > 0) {
|
|
95018
|
+
const listNames = opts._listProfileNames ?? (async () => (await listProfiles(opts.projectRoot)).map((p) => p.name));
|
|
95019
|
+
const available = await listNames();
|
|
95020
|
+
const missing = prdChain.filter((name) => name !== "default" && !available.includes(name));
|
|
95021
|
+
if (missing.length === 0)
|
|
95022
|
+
return prdChain;
|
|
95023
|
+
getSafeLogger2()?.warn("run", `PRD was planned with config profile(s) "${prdChain.join(",")}" but ${missing.join(", ")} not found \u2014 continuing with current config resolution`, { storyId: "prd", plannedProfile: prdChain.join(","), missing });
|
|
95024
|
+
}
|
|
95025
|
+
} catch {}
|
|
95026
|
+
return;
|
|
95027
|
+
}
|
|
95028
|
+
var init_resolve_run_profile = __esm(() => {
|
|
95029
|
+
init_config();
|
|
95030
|
+
init_logger2();
|
|
95031
|
+
});
|
|
95032
|
+
|
|
94949
95033
|
// src/cli/features-resolve.ts
|
|
94950
95034
|
import { existsSync as existsSync16, readdirSync as readdirSync3 } from "fs";
|
|
94951
95035
|
import { join as join102, relative as relative33 } from "path";
|
|
94952
|
-
async function
|
|
95036
|
+
async function resolveConfigOverrides(featureName, workdir, repoRoot, opts) {
|
|
95037
|
+
let prdPath;
|
|
94953
95038
|
try {
|
|
94954
|
-
|
|
95039
|
+
prdPath = join102(featureDir(repoRoot, featureName), "prd.json");
|
|
95040
|
+
} catch {
|
|
95041
|
+
return;
|
|
95042
|
+
}
|
|
95043
|
+
const chain = await resolveRunProfileOverride({
|
|
95044
|
+
prdPath,
|
|
95045
|
+
projectRoot: workdir,
|
|
95046
|
+
cliProfile: opts?.profile,
|
|
95047
|
+
envProfile: opts?.envProfile ?? process.env.NAX_PROFILE
|
|
95048
|
+
});
|
|
95049
|
+
return chain && chain.length > 0 ? { profile: chain } : undefined;
|
|
95050
|
+
}
|
|
95051
|
+
async function resolveTestPatterns(workdir, configOverrides) {
|
|
95052
|
+
try {
|
|
95053
|
+
const config = await loadConfig(workdir, configOverrides);
|
|
94955
95054
|
const resolved = await resolveTestFilePatterns(config, workdir);
|
|
94956
95055
|
return { regex: resolved.regex.map((r) => r.source), resolution: resolved.resolution };
|
|
94957
95056
|
} catch {
|
|
@@ -95016,7 +95115,7 @@ function discoverCandidates(naxDir) {
|
|
|
95016
95115
|
return existsSync16(join102(dir, "prd.json")) || existsSync16(join102(dir, "spec.md"));
|
|
95017
95116
|
}).map((e) => e.name).sort();
|
|
95018
95117
|
}
|
|
95019
|
-
async function resolveFeatureSpec(name, workdir) {
|
|
95118
|
+
async function resolveFeatureSpec(name, workdir, opts) {
|
|
95020
95119
|
const naxDir = findProjectDir(workdir);
|
|
95021
95120
|
if (!naxDir) {
|
|
95022
95121
|
return {
|
|
@@ -95057,12 +95156,13 @@ async function resolveFeatureSpec(name, workdir) {
|
|
|
95057
95156
|
validateFeatureName(name);
|
|
95058
95157
|
const { source, checked } = await searchSpecSource(naxDir, repoRoot, name);
|
|
95059
95158
|
if (source) {
|
|
95159
|
+
const configOverrides = await resolveConfigOverrides(name, workdir, repoRoot, opts);
|
|
95060
95160
|
return {
|
|
95061
95161
|
status: "ok",
|
|
95062
95162
|
featureName: name,
|
|
95063
95163
|
specSource: source,
|
|
95064
|
-
acceptance: await resolveFeatureAcceptance(name, workdir),
|
|
95065
|
-
testPatterns: await resolveTestPatterns(workdir),
|
|
95164
|
+
acceptance: await resolveFeatureAcceptance(name, workdir, configOverrides),
|
|
95165
|
+
testPatterns: await resolveTestPatterns(workdir, configOverrides),
|
|
95066
95166
|
message: `resolved spec: ${source.path}`
|
|
95067
95167
|
};
|
|
95068
95168
|
}
|
|
@@ -95104,12 +95204,13 @@ async function resolveFeatureSpec(name, workdir) {
|
|
|
95104
95204
|
const onlyName = candidates[0];
|
|
95105
95205
|
const { source, checked } = await searchSpecSource(naxDir, repoRoot, onlyName);
|
|
95106
95206
|
if (source) {
|
|
95207
|
+
const configOverrides = await resolveConfigOverrides(onlyName, workdir, repoRoot, opts);
|
|
95107
95208
|
return {
|
|
95108
95209
|
status: "ok",
|
|
95109
95210
|
featureName: onlyName,
|
|
95110
95211
|
specSource: source,
|
|
95111
|
-
acceptance: await resolveFeatureAcceptance(onlyName, workdir),
|
|
95112
|
-
testPatterns: await resolveTestPatterns(workdir),
|
|
95212
|
+
acceptance: await resolveFeatureAcceptance(onlyName, workdir, configOverrides),
|
|
95213
|
+
testPatterns: await resolveTestPatterns(workdir, configOverrides),
|
|
95113
95214
|
message: `resolved spec: ${source.path}`
|
|
95114
95215
|
};
|
|
95115
95216
|
}
|
|
@@ -95126,6 +95227,7 @@ var init_features_resolve = __esm(() => {
|
|
|
95126
95227
|
init_test_runners();
|
|
95127
95228
|
init_feature_name();
|
|
95128
95229
|
init_features_acceptance();
|
|
95230
|
+
init_resolve_run_profile();
|
|
95129
95231
|
});
|
|
95130
95232
|
|
|
95131
95233
|
// src/cli/trust-gate.ts
|
|
@@ -95866,7 +95968,7 @@ var init_approvals = __esm(() => {
|
|
|
95866
95968
|
});
|
|
95867
95969
|
|
|
95868
95970
|
// src/cli/auth-list.ts
|
|
95869
|
-
function
|
|
95971
|
+
function errorCode2(error, fallback) {
|
|
95870
95972
|
if (typeof error === "object" && error !== null && "code" in error && typeof error.code === "string") {
|
|
95871
95973
|
return error.code;
|
|
95872
95974
|
}
|
|
@@ -95934,7 +96036,7 @@ async function readExecStatus(providerId) {
|
|
|
95934
96036
|
return { status: "declined" };
|
|
95935
96037
|
return stamp.account === undefined ? { status: "served" } : { status: "served", account: safeAccountLabel(stamp.account) };
|
|
95936
96038
|
} catch (error) {
|
|
95937
|
-
return { status: "error", code:
|
|
96039
|
+
return { status: "error", code: errorCode2(error, "CREDENTIAL_HELPER_FAILED") };
|
|
95938
96040
|
}
|
|
95939
96041
|
}
|
|
95940
96042
|
function renderExecStatus(exec) {
|
|
@@ -96026,7 +96128,7 @@ async function authLoginCommand(providerId, method) {
|
|
|
96026
96128
|
}
|
|
96027
96129
|
}
|
|
96028
96130
|
} catch (error) {
|
|
96029
|
-
_cliAuthDeps.log(`Warning: credential helper status check failed: ${
|
|
96131
|
+
_cliAuthDeps.log(`Warning: credential helper status check failed: ${errorCode2(error, "CREDENTIAL_HELPER_FAILED")}`);
|
|
96030
96132
|
}
|
|
96031
96133
|
if ((await ambientShadows([result.providerId])).length > 0) {
|
|
96032
96134
|
_cliAuthDeps.log(source_default.yellow(`Note: ${result.providerId} also has credentials in your environment. The stored credential ` + `takes precedence from now on \u2014 run \`nax auth rm ${result.providerId}\` to go back to the environment.`));
|
|
@@ -96070,7 +96172,7 @@ async function authListCommand(providerIds = [], options = {}) {
|
|
|
96070
96172
|
if (options.json) {
|
|
96071
96173
|
_cliAuthDeps.log(JSON.stringify({
|
|
96072
96174
|
error: {
|
|
96073
|
-
code:
|
|
96175
|
+
code: errorCode2(error, "AUTH_LIST_FAILED"),
|
|
96074
96176
|
message: error instanceof Error ? error.message : String(error)
|
|
96075
96177
|
}
|
|
96076
96178
|
}));
|
|
@@ -99679,8 +99781,413 @@ var init_context_fragments = __esm(() => {
|
|
|
99679
99781
|
};
|
|
99680
99782
|
});
|
|
99681
99783
|
|
|
99784
|
+
// src/cli/cost-ledger-query.ts
|
|
99785
|
+
import { readdir as readdir9, stat as stat11 } from "fs/promises";
|
|
99786
|
+
import { basename as basename19, dirname as dirname34, join as join109 } from "path";
|
|
99787
|
+
function errorCode3(err) {
|
|
99788
|
+
return typeof err === "object" && err !== null ? Reflect.get(err, "code") : undefined;
|
|
99789
|
+
}
|
|
99790
|
+
function isMissing(err) {
|
|
99791
|
+
return errorCode3(err) === MISSING_CODE2;
|
|
99792
|
+
}
|
|
99793
|
+
function isAbsentOrNotDir(err) {
|
|
99794
|
+
const code = errorCode3(err);
|
|
99795
|
+
return code === MISSING_CODE2 || code === NOT_A_DIRECTORY_CODE;
|
|
99796
|
+
}
|
|
99797
|
+
async function readEntries(dir) {
|
|
99798
|
+
try {
|
|
99799
|
+
const entries = await readdir9(dir, { withFileTypes: true });
|
|
99800
|
+
return entries.map((entry) => ({ name: String(entry.name), isDir: entry.isDirectory() }));
|
|
99801
|
+
} catch (err) {
|
|
99802
|
+
if (isMissing(err))
|
|
99803
|
+
return [];
|
|
99804
|
+
throw err;
|
|
99805
|
+
}
|
|
99806
|
+
}
|
|
99807
|
+
async function isDirectory(path) {
|
|
99808
|
+
try {
|
|
99809
|
+
return (await stat11(path)).isDirectory();
|
|
99810
|
+
} catch (err) {
|
|
99811
|
+
if (isAbsentOrNotDir(err))
|
|
99812
|
+
return false;
|
|
99813
|
+
throw err;
|
|
99814
|
+
}
|
|
99815
|
+
}
|
|
99816
|
+
function compareStrings(a, b) {
|
|
99817
|
+
if (a === b)
|
|
99818
|
+
return 0;
|
|
99819
|
+
return a < b ? -1 : 1;
|
|
99820
|
+
}
|
|
99821
|
+
async function listCostLedgerFiles(roots) {
|
|
99822
|
+
const found = new Set;
|
|
99823
|
+
for (const root of roots) {
|
|
99824
|
+
const dir = join109(root, COST_DIR);
|
|
99825
|
+
for (const entry of await readEntries(dir)) {
|
|
99826
|
+
if (entry.isDir || !entry.name.endsWith(LEDGER_SUFFIX))
|
|
99827
|
+
continue;
|
|
99828
|
+
found.add(join109(dir, entry.name));
|
|
99829
|
+
}
|
|
99830
|
+
}
|
|
99831
|
+
return [...found].sort(compareStrings);
|
|
99832
|
+
}
|
|
99833
|
+
async function listProjectOutputDirs(globalDir) {
|
|
99834
|
+
const found = [];
|
|
99835
|
+
for (const entry of await readEntries(globalDir)) {
|
|
99836
|
+
const child = join109(globalDir, entry.name);
|
|
99837
|
+
if (!await isDirectory(child))
|
|
99838
|
+
continue;
|
|
99839
|
+
if (!await isDirectory(join109(child, COST_DIR)))
|
|
99840
|
+
continue;
|
|
99841
|
+
found.push(child);
|
|
99842
|
+
}
|
|
99843
|
+
return found.sort(compareStrings);
|
|
99844
|
+
}
|
|
99845
|
+
function newAccumulator() {
|
|
99846
|
+
return {
|
|
99847
|
+
calls: 0,
|
|
99848
|
+
errorCalls: 0,
|
|
99849
|
+
input: 0,
|
|
99850
|
+
output: 0,
|
|
99851
|
+
cacheRead: 0,
|
|
99852
|
+
cacheWrite: 0,
|
|
99853
|
+
exactUsd: 0,
|
|
99854
|
+
estimatedUsd: 0,
|
|
99855
|
+
runIds: new Set
|
|
99856
|
+
};
|
|
99857
|
+
}
|
|
99858
|
+
function toTotals(acc) {
|
|
99859
|
+
return {
|
|
99860
|
+
calls: acc.calls,
|
|
99861
|
+
errorCalls: acc.errorCalls,
|
|
99862
|
+
runs: acc.runIds.size,
|
|
99863
|
+
input: acc.input,
|
|
99864
|
+
output: acc.output,
|
|
99865
|
+
cacheRead: acc.cacheRead,
|
|
99866
|
+
cacheWrite: acc.cacheWrite,
|
|
99867
|
+
costUsd: acc.exactUsd + acc.estimatedUsd,
|
|
99868
|
+
exactUsd: acc.exactUsd,
|
|
99869
|
+
estimatedUsd: acc.estimatedUsd
|
|
99870
|
+
};
|
|
99871
|
+
}
|
|
99872
|
+
function isRecord12(value) {
|
|
99873
|
+
return typeof value === "object" && value !== null;
|
|
99874
|
+
}
|
|
99875
|
+
function finiteNumber(value) {
|
|
99876
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
99877
|
+
}
|
|
99878
|
+
function stringField(row, field) {
|
|
99879
|
+
const value = row[field];
|
|
99880
|
+
return typeof value === "string" ? value : null;
|
|
99881
|
+
}
|
|
99882
|
+
function parseRow(line) {
|
|
99883
|
+
let parsed;
|
|
99884
|
+
try {
|
|
99885
|
+
parsed = JSON.parse(line);
|
|
99886
|
+
} catch {
|
|
99887
|
+
return null;
|
|
99888
|
+
}
|
|
99889
|
+
if (!isRecord12(parsed))
|
|
99890
|
+
return null;
|
|
99891
|
+
if (finiteNumber(parsed.ts) === null)
|
|
99892
|
+
return null;
|
|
99893
|
+
if (parsed.costUsd !== undefined && finiteNumber(parsed.costUsd) === null)
|
|
99894
|
+
return null;
|
|
99895
|
+
return parsed;
|
|
99896
|
+
}
|
|
99897
|
+
function projectOf(row, file) {
|
|
99898
|
+
return stringField(row, "projectKey") ?? basename19(dirname34(dirname34(file)));
|
|
99899
|
+
}
|
|
99900
|
+
function isKept(row, project, query) {
|
|
99901
|
+
const ts = finiteNumber(row.ts);
|
|
99902
|
+
if (ts === null)
|
|
99903
|
+
return false;
|
|
99904
|
+
if (query.sinceMs !== undefined && ts < query.sinceMs)
|
|
99905
|
+
return false;
|
|
99906
|
+
if (query.untilMs !== undefined && ts >= query.untilMs)
|
|
99907
|
+
return false;
|
|
99908
|
+
if (query.projects !== undefined && !query.projects.includes(project))
|
|
99909
|
+
return false;
|
|
99910
|
+
if (query.feature !== undefined && stringField(row, "featureName") !== query.feature)
|
|
99911
|
+
return false;
|
|
99912
|
+
if (query.runId !== undefined && stringField(row, "runId") !== query.runId)
|
|
99913
|
+
return false;
|
|
99914
|
+
return true;
|
|
99915
|
+
}
|
|
99916
|
+
function isExactRow(row) {
|
|
99917
|
+
if (row.confidence === "exact")
|
|
99918
|
+
return true;
|
|
99919
|
+
return row.kind === "error" && finiteNumber(row.exactCostUsd) !== null;
|
|
99920
|
+
}
|
|
99921
|
+
function accumulateRow(acc, row) {
|
|
99922
|
+
const tokens = isRecord12(row.tokens) ? row.tokens : {};
|
|
99923
|
+
const costUsd = finiteNumber(row.costUsd) ?? 0;
|
|
99924
|
+
acc.calls += 1;
|
|
99925
|
+
if (row.kind === "error")
|
|
99926
|
+
acc.errorCalls += 1;
|
|
99927
|
+
acc.input += finiteNumber(tokens.input) ?? 0;
|
|
99928
|
+
acc.output += finiteNumber(tokens.output) ?? 0;
|
|
99929
|
+
acc.cacheRead += finiteNumber(tokens.cacheRead) ?? 0;
|
|
99930
|
+
acc.cacheWrite += finiteNumber(tokens.cacheWrite) ?? 0;
|
|
99931
|
+
if (isExactRow(row))
|
|
99932
|
+
acc.exactUsd += costUsd;
|
|
99933
|
+
else
|
|
99934
|
+
acc.estimatedUsd += costUsd;
|
|
99935
|
+
const runId = stringField(row, "runId");
|
|
99936
|
+
if (runId !== null)
|
|
99937
|
+
acc.runIds.add(runId);
|
|
99938
|
+
}
|
|
99939
|
+
function groupValues(row, groupBy, project) {
|
|
99940
|
+
return groupBy.map((key) => {
|
|
99941
|
+
if (key === "project")
|
|
99942
|
+
return project;
|
|
99943
|
+
return stringField(row, GROUP_FIELDS[key]) ?? NO_VALUE;
|
|
99944
|
+
});
|
|
99945
|
+
}
|
|
99946
|
+
function bucketFor(buckets, groupBy, values) {
|
|
99947
|
+
const id = JSON.stringify(values);
|
|
99948
|
+
const existing = buckets.get(id);
|
|
99949
|
+
if (existing !== undefined)
|
|
99950
|
+
return existing.acc;
|
|
99951
|
+
const acc = newAccumulator();
|
|
99952
|
+
buckets.set(id, { key: Object.fromEntries(groupBy.map((key, i) => [key, values[i]])), acc });
|
|
99953
|
+
return acc;
|
|
99954
|
+
}
|
|
99955
|
+
async function queryCostLedger(files, query) {
|
|
99956
|
+
const total = newAccumulator();
|
|
99957
|
+
const buckets = new Map;
|
|
99958
|
+
let skippedRows = 0;
|
|
99959
|
+
for (const file of files) {
|
|
99960
|
+
const text = await _costLedgerQueryDeps.readLedgerFile(file);
|
|
99961
|
+
for (const line of text.split(`
|
|
99962
|
+
`)) {
|
|
99963
|
+
if (line.trim() === "")
|
|
99964
|
+
continue;
|
|
99965
|
+
const row = parseRow(line);
|
|
99966
|
+
if (row === null) {
|
|
99967
|
+
skippedRows += 1;
|
|
99968
|
+
continue;
|
|
99969
|
+
}
|
|
99970
|
+
const project = projectOf(row, file);
|
|
99971
|
+
if (!isKept(row, project, query))
|
|
99972
|
+
continue;
|
|
99973
|
+
accumulateRow(total, row);
|
|
99974
|
+
if (query.groupBy.length === 0)
|
|
99975
|
+
continue;
|
|
99976
|
+
accumulateRow(bucketFor(buckets, query.groupBy, groupValues(row, query.groupBy, project)), row);
|
|
99977
|
+
}
|
|
99978
|
+
}
|
|
99979
|
+
const groups = [...buckets.values()].map(({ key, acc }) => ({ ...toTotals(acc), key })).sort((a, b) => b.costUsd - a.costUsd);
|
|
99980
|
+
return {
|
|
99981
|
+
schemaVersion: 1,
|
|
99982
|
+
sinceMs: query.sinceMs ?? null,
|
|
99983
|
+
untilMs: query.untilMs ?? null,
|
|
99984
|
+
groups,
|
|
99985
|
+
total: toTotals(total),
|
|
99986
|
+
skippedRows,
|
|
99987
|
+
filesScanned: files.length
|
|
99988
|
+
};
|
|
99989
|
+
}
|
|
99990
|
+
function costUsageError(message) {
|
|
99991
|
+
return new NaxError(`[cost] ${message}`, "COST_USAGE", { stage: "cost" });
|
|
99992
|
+
}
|
|
99993
|
+
function daysInMonth(year, month) {
|
|
99994
|
+
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
99995
|
+
}
|
|
99996
|
+
function parseDay(value, flag) {
|
|
99997
|
+
const match = DAY_PATTERN.exec(value);
|
|
99998
|
+
if (match === null)
|
|
99999
|
+
throw costUsageError(`${flag} must be YYYY-MM-DD, got "${value}"`);
|
|
100000
|
+
const [, year, month, day] = match;
|
|
100001
|
+
const parsed = { year: Number(year), month: Number(month), day: Number(day) };
|
|
100002
|
+
if (parsed.month < 1 || parsed.month > 12 || parsed.day < 1 || parsed.day > daysInMonth(parsed.year, parsed.month)) {
|
|
100003
|
+
throw costUsageError(`${flag} is not a real calendar date: "${value}"`);
|
|
100004
|
+
}
|
|
100005
|
+
return parsed;
|
|
100006
|
+
}
|
|
100007
|
+
function dayStartMs(day, utc, dayOffset = 0) {
|
|
100008
|
+
const { year, month, day: date } = day;
|
|
100009
|
+
return utc ? Date.UTC(year, month - 1, date + dayOffset) : new Date(year, month - 1, date + dayOffset).getTime();
|
|
100010
|
+
}
|
|
100011
|
+
function dayOf(nowMs, utc) {
|
|
100012
|
+
const now = new Date(nowMs);
|
|
100013
|
+
if (utc)
|
|
100014
|
+
return { year: now.getUTCFullYear(), month: now.getUTCMonth() + 1, day: now.getUTCDate() };
|
|
100015
|
+
return { year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate() };
|
|
100016
|
+
}
|
|
100017
|
+
function resolveCostWindow(opts) {
|
|
100018
|
+
const utc = opts.utc === true;
|
|
100019
|
+
if (opts.today === true && (opts.since !== undefined || opts.until !== undefined)) {
|
|
100020
|
+
throw costUsageError("--today cannot be combined with --since or --until");
|
|
100021
|
+
}
|
|
100022
|
+
const window2 = {};
|
|
100023
|
+
if (opts.today === true)
|
|
100024
|
+
window2.sinceMs = dayStartMs(dayOf(opts.nowMs, utc), utc);
|
|
100025
|
+
if (opts.since !== undefined)
|
|
100026
|
+
window2.sinceMs = dayStartMs(parseDay(opts.since, "--since"), utc);
|
|
100027
|
+
if (opts.until !== undefined)
|
|
100028
|
+
window2.untilMs = dayStartMs(parseDay(opts.until, "--until"), utc, 1);
|
|
100029
|
+
return window2;
|
|
100030
|
+
}
|
|
100031
|
+
var COST_DIR = "cost", LEDGER_SUFFIX = ".jsonl", MISSING_CODE2 = "ENOENT", NOT_A_DIRECTORY_CODE = "ENOTDIR", _costLedgerQueryDeps, GROUP_FIELDS, COST_GROUP_KEYS, NO_VALUE = "(none)", DAY_PATTERN;
|
|
100032
|
+
var init_cost_ledger_query = __esm(() => {
|
|
100033
|
+
init_errors4();
|
|
100034
|
+
_costLedgerQueryDeps = {
|
|
100035
|
+
readLedgerFile: (path) => Bun.file(path).text()
|
|
100036
|
+
};
|
|
100037
|
+
GROUP_FIELDS = {
|
|
100038
|
+
model: "model",
|
|
100039
|
+
stage: "stage",
|
|
100040
|
+
role: "sessionRole",
|
|
100041
|
+
project: "projectKey",
|
|
100042
|
+
feature: "featureName",
|
|
100043
|
+
run: "runId",
|
|
100044
|
+
story: "storyId"
|
|
100045
|
+
};
|
|
100046
|
+
COST_GROUP_KEYS = [
|
|
100047
|
+
"model",
|
|
100048
|
+
"stage",
|
|
100049
|
+
"role",
|
|
100050
|
+
"project",
|
|
100051
|
+
"feature",
|
|
100052
|
+
"run",
|
|
100053
|
+
"story"
|
|
100054
|
+
];
|
|
100055
|
+
DAY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
100056
|
+
});
|
|
100057
|
+
|
|
100058
|
+
// src/cli/cost.ts
|
|
100059
|
+
import { basename as basename20 } from "path";
|
|
100060
|
+
async function resolveProjectOutputDir(dir) {
|
|
100061
|
+
const config = await loadConfig(dir).catch(() => null);
|
|
100062
|
+
return projectOutputDir(config?.name?.trim() || basename20(dir), config?.outputDir);
|
|
100063
|
+
}
|
|
100064
|
+
function costUsageError2(message, data = {}) {
|
|
100065
|
+
return new NaxError(`[cost] ${message}`, "COST_USAGE", { stage: "cost", ...data });
|
|
100066
|
+
}
|
|
100067
|
+
function parseGroupBy(by) {
|
|
100068
|
+
const raw = by?.trim() ?? "";
|
|
100069
|
+
if (raw === "")
|
|
100070
|
+
return [];
|
|
100071
|
+
return raw.split(",").map((part) => {
|
|
100072
|
+
const key = COST_GROUP_KEYS.find((candidate) => candidate === part.trim());
|
|
100073
|
+
if (key === undefined) {
|
|
100074
|
+
throw costUsageError2(`unknown --by key "${part.trim()}"; expected one of ${COST_GROUP_KEYS.join(", ")}`, {
|
|
100075
|
+
key: part.trim()
|
|
100076
|
+
});
|
|
100077
|
+
}
|
|
100078
|
+
return key;
|
|
100079
|
+
});
|
|
100080
|
+
}
|
|
100081
|
+
function buildQuery(opts, deps, groupBy) {
|
|
100082
|
+
const { sinceMs, untilMs } = resolveCostWindow({
|
|
100083
|
+
today: opts.today === true,
|
|
100084
|
+
since: opts.since,
|
|
100085
|
+
until: opts.until,
|
|
100086
|
+
utc: opts.utc === true,
|
|
100087
|
+
nowMs: deps.now()
|
|
100088
|
+
});
|
|
100089
|
+
return {
|
|
100090
|
+
...sinceMs === undefined ? {} : { sinceMs },
|
|
100091
|
+
...untilMs === undefined ? {} : { untilMs },
|
|
100092
|
+
...opts.project === undefined ? {} : { projects: [opts.project] },
|
|
100093
|
+
...opts.feature === undefined ? {} : { feature: opts.feature },
|
|
100094
|
+
...opts.run === undefined ? {} : { runId: opts.run },
|
|
100095
|
+
groupBy
|
|
100096
|
+
};
|
|
100097
|
+
}
|
|
100098
|
+
async function ledgerFiles(opts, deps) {
|
|
100099
|
+
const roots = opts.here === true ? [await deps.resolveProjectOutputDir(opts.dir)] : await deps.listProjectOutputDirs(deps.globalConfigDir());
|
|
100100
|
+
return await deps.listCostLedgerFiles(roots);
|
|
100101
|
+
}
|
|
100102
|
+
function numericCells(total) {
|
|
100103
|
+
return [
|
|
100104
|
+
String(total.calls),
|
|
100105
|
+
String(total.runs),
|
|
100106
|
+
String(total.input),
|
|
100107
|
+
String(total.output),
|
|
100108
|
+
String(total.cacheRead),
|
|
100109
|
+
String(total.cacheWrite),
|
|
100110
|
+
total.costUsd.toFixed(2)
|
|
100111
|
+
];
|
|
100112
|
+
}
|
|
100113
|
+
function totalCells(labelColumnCount, total) {
|
|
100114
|
+
const blanks = Array.from({ length: Math.max(labelColumnCount - 1, 0) }, () => "");
|
|
100115
|
+
return ["TOTAL", ...blanks, ...numericCells(total)];
|
|
100116
|
+
}
|
|
100117
|
+
function tableRows(report, groupBy, labelColumnCount) {
|
|
100118
|
+
const rows = report.groups.map((row) => [...groupBy.map((key) => row.key[key] ?? ""), ...numericCells(row)]);
|
|
100119
|
+
rows.push(totalCells(labelColumnCount, report.total));
|
|
100120
|
+
return rows;
|
|
100121
|
+
}
|
|
100122
|
+
function labelColumns(groupBy) {
|
|
100123
|
+
return groupBy.length === 0 ? [""] : [...groupBy];
|
|
100124
|
+
}
|
|
100125
|
+
function formatTable(header, rows, labelColumnCount) {
|
|
100126
|
+
const width = header.map((cell, index) => Math.max(cell.length, ...rows.map((row) => (row[index] ?? "").length)));
|
|
100127
|
+
const line = (cells) => cells.map((cell, index) => index < labelColumnCount ? cell.padEnd(width[index]) : cell.padStart(width[index])).join(COLUMN_GAP).trimEnd();
|
|
100128
|
+
return [line(header), ...rows.map(line)];
|
|
100129
|
+
}
|
|
100130
|
+
function tableLines(report, groupBy) {
|
|
100131
|
+
const label = labelColumns(groupBy);
|
|
100132
|
+
return formatTable([...label, ...NUMERIC_COLUMNS], tableRows(report, groupBy, label.length), label.length);
|
|
100133
|
+
}
|
|
100134
|
+
function renderReport(report, groupBy, opts, deps) {
|
|
100135
|
+
if (opts.json === true) {
|
|
100136
|
+
deps.log(JSON.stringify(report));
|
|
100137
|
+
return;
|
|
100138
|
+
}
|
|
100139
|
+
for (const line of tableLines(report, groupBy))
|
|
100140
|
+
deps.log(line);
|
|
100141
|
+
deps.log(`exact $${report.total.exactUsd.toFixed(2)} / estimated $${report.total.estimatedUsd.toFixed(2)}`);
|
|
100142
|
+
if (report.skippedRows > 0)
|
|
100143
|
+
deps.log(`skipped ${report.skippedRows} unparseable row(s)`);
|
|
100144
|
+
}
|
|
100145
|
+
async function costCommand(opts, deps = _costCliDeps) {
|
|
100146
|
+
try {
|
|
100147
|
+
const groupBy = parseGroupBy(opts.by);
|
|
100148
|
+
const query = buildQuery(opts, deps, groupBy);
|
|
100149
|
+
const files = await ledgerFiles(opts, deps);
|
|
100150
|
+
renderReport(await deps.queryCostLedger(files, query), groupBy, opts, deps);
|
|
100151
|
+
return 0;
|
|
100152
|
+
} catch (err) {
|
|
100153
|
+
deps.logErr(`Error: ${errorMessage(err)}`);
|
|
100154
|
+
return 1;
|
|
100155
|
+
}
|
|
100156
|
+
}
|
|
100157
|
+
function registerCostCommand(program, deps = _costCliDeps) {
|
|
100158
|
+
return program.command("cost").description("Report the per-call cost ledger across projects").option("--today", "Only today (local midnight; UTC midnight with --utc)", false).option("--since <date>", "First day of the window, YYYY-MM-DD (inclusive)").option("--until <date>", "Last day of the window, YYYY-MM-DD (inclusive)").option("--utc", "Read --today/--since/--until in UTC instead of local time", false).option("--by <keys>", `Comma list of group keys: ${COST_GROUP_KEYS.join(", ")}`).option("--project <name>", "Only rows whose project key matches").option("--here", "Scan only the project at --dir instead of every project", false).option("--feature <name>", "Only rows whose feature name matches").option("--run <runId>", "Only rows whose run id matches").option("--json", "Emit one machine-readable CostLedgerReport document", false).option("-d, --dir <path>", "Project directory used by --here", process.cwd()).action(async (o) => {
|
|
100159
|
+
deps.exit(await costCommand(o, deps));
|
|
100160
|
+
});
|
|
100161
|
+
}
|
|
100162
|
+
var _costCliDeps, NUMERIC_COLUMNS, COLUMN_GAP = " ";
|
|
100163
|
+
var init_cost3 = __esm(() => {
|
|
100164
|
+
init_internal();
|
|
100165
|
+
init_config();
|
|
100166
|
+
init_errors4();
|
|
100167
|
+
init_runtime3();
|
|
100168
|
+
init_cost_ledger_query();
|
|
100169
|
+
_costCliDeps = {
|
|
100170
|
+
log: (msg) => {
|
|
100171
|
+
console.log(msg);
|
|
100172
|
+
},
|
|
100173
|
+
logErr: (msg) => {
|
|
100174
|
+
console.error(msg);
|
|
100175
|
+
},
|
|
100176
|
+
exit: (code) => {
|
|
100177
|
+
process.exit(code);
|
|
100178
|
+
},
|
|
100179
|
+
now: () => Date.now(),
|
|
100180
|
+
globalConfigDir,
|
|
100181
|
+
resolveProjectOutputDir,
|
|
100182
|
+
listProjectOutputDirs,
|
|
100183
|
+
listCostLedgerFiles,
|
|
100184
|
+
queryCostLedger
|
|
100185
|
+
};
|
|
100186
|
+
NUMERIC_COLUMNS = ["calls", "runs", "input", "output", "cacheRead", "cacheWrite", "costUsd"];
|
|
100187
|
+
});
|
|
100188
|
+
|
|
99682
100189
|
// src/finish/gates/quality.ts
|
|
99683
|
-
import { join as
|
|
100190
|
+
import { join as join110 } from "path";
|
|
99684
100191
|
function classifyGateExit(res) {
|
|
99685
100192
|
if (res.timedOut)
|
|
99686
100193
|
return "timed-out";
|
|
@@ -99739,7 +100246,7 @@ async function resolveGateCommands(repoRoot, packageDirs) {
|
|
|
99739
100246
|
const overlayCommands = overlayCommandsOf(override);
|
|
99740
100247
|
if (!overlayCommands)
|
|
99741
100248
|
continue;
|
|
99742
|
-
const packageCwd =
|
|
100249
|
+
const packageCwd = join110(repoRoot, packageDir);
|
|
99743
100250
|
for (const gate of GATE_ORDER) {
|
|
99744
100251
|
const command = overlayCommands[gate];
|
|
99745
100252
|
if (!isConfigured(command))
|
|
@@ -99798,7 +100305,7 @@ ${res.output}`);
|
|
|
99798
100305
|
passed: false,
|
|
99799
100306
|
ran,
|
|
99800
100307
|
failing: [],
|
|
99801
|
-
output: `[quality] no quality.commands configured in ${
|
|
100308
|
+
output: `[quality] no quality.commands configured in ${join110(repoRoot, PROJECT_NAX_DIR, "config.json")} \u2014 nothing was verified`
|
|
99802
100309
|
};
|
|
99803
100310
|
}
|
|
99804
100311
|
return { passed: failing.length === 0, ran, failing, output: chunks.join(`
|
|
@@ -99818,13 +100325,13 @@ var init_quality2 = __esm(() => {
|
|
|
99818
100325
|
});
|
|
99819
100326
|
|
|
99820
100327
|
// src/cli/gates.ts
|
|
99821
|
-
import { dirname as
|
|
100328
|
+
import { dirname as dirname35, join as join111 } from "path";
|
|
99822
100329
|
async function projectRootOf(dir) {
|
|
99823
100330
|
const naxDir = findProjectDir(dir);
|
|
99824
100331
|
if (naxDir === null || realOrRaw(naxDir) === realOrRaw(globalConfigDir())) {
|
|
99825
100332
|
throw new NaxError(`no nax project found at or above ${dir}`, "GATES_NO_PROJECT", { stage: "gates-run", dir });
|
|
99826
100333
|
}
|
|
99827
|
-
return await normalizeTrustPath(
|
|
100334
|
+
return await normalizeTrustPath(dirname35(naxDir));
|
|
99828
100335
|
}
|
|
99829
100336
|
async function ensureTrusted(projectDir, deps, interactive) {
|
|
99830
100337
|
try {
|
|
@@ -99936,7 +100443,7 @@ async function gatesRunCommand(opts, deps = _gatesCliDeps) {
|
|
|
99936
100443
|
if (opts.json)
|
|
99937
100444
|
deps.log(JSON.stringify(empty));
|
|
99938
100445
|
else
|
|
99939
|
-
deps.log(`no quality.commands configured in ${
|
|
100446
|
+
deps.log(`no quality.commands configured in ${join111(projectDir, PROJECT_NAX_DIR, "config.json")}; nothing was verified`);
|
|
99940
100447
|
return 2;
|
|
99941
100448
|
}
|
|
99942
100449
|
const records = [];
|
|
@@ -100002,9 +100509,9 @@ var init_gates = __esm(() => {
|
|
|
100002
100509
|
|
|
100003
100510
|
// src/context/injector.ts
|
|
100004
100511
|
import { existsSync as existsSync21 } from "fs";
|
|
100005
|
-
import { join as
|
|
100512
|
+
import { join as join112 } from "path";
|
|
100006
100513
|
async function detectNode(workdir) {
|
|
100007
|
-
const pkgPath =
|
|
100514
|
+
const pkgPath = join112(workdir, "package.json");
|
|
100008
100515
|
if (!existsSync21(pkgPath))
|
|
100009
100516
|
return null;
|
|
100010
100517
|
try {
|
|
@@ -100021,7 +100528,7 @@ async function detectNode(workdir) {
|
|
|
100021
100528
|
}
|
|
100022
100529
|
}
|
|
100023
100530
|
async function detectGo(workdir) {
|
|
100024
|
-
const goMod =
|
|
100531
|
+
const goMod = join112(workdir, "go.mod");
|
|
100025
100532
|
if (!existsSync21(goMod))
|
|
100026
100533
|
return null;
|
|
100027
100534
|
try {
|
|
@@ -100045,7 +100552,7 @@ async function detectGo(workdir) {
|
|
|
100045
100552
|
}
|
|
100046
100553
|
}
|
|
100047
100554
|
async function detectRust(workdir) {
|
|
100048
|
-
const cargoPath =
|
|
100555
|
+
const cargoPath = join112(workdir, "Cargo.toml");
|
|
100049
100556
|
if (!existsSync21(cargoPath))
|
|
100050
100557
|
return null;
|
|
100051
100558
|
try {
|
|
@@ -100061,8 +100568,8 @@ async function detectRust(workdir) {
|
|
|
100061
100568
|
}
|
|
100062
100569
|
}
|
|
100063
100570
|
async function detectPython(workdir) {
|
|
100064
|
-
const pyproject =
|
|
100065
|
-
const requirements =
|
|
100571
|
+
const pyproject = join112(workdir, "pyproject.toml");
|
|
100572
|
+
const requirements = join112(workdir, "requirements.txt");
|
|
100066
100573
|
if (!existsSync21(pyproject) && !existsSync21(requirements))
|
|
100067
100574
|
return null;
|
|
100068
100575
|
try {
|
|
@@ -100081,7 +100588,7 @@ async function detectPython(workdir) {
|
|
|
100081
100588
|
}
|
|
100082
100589
|
}
|
|
100083
100590
|
async function detectPhp(workdir) {
|
|
100084
|
-
const composerPath =
|
|
100591
|
+
const composerPath = join112(workdir, "composer.json");
|
|
100085
100592
|
if (!existsSync21(composerPath))
|
|
100086
100593
|
return null;
|
|
100087
100594
|
try {
|
|
@@ -100094,7 +100601,7 @@ async function detectPhp(workdir) {
|
|
|
100094
100601
|
}
|
|
100095
100602
|
}
|
|
100096
100603
|
async function detectRuby(workdir) {
|
|
100097
|
-
const gemfile =
|
|
100604
|
+
const gemfile = join112(workdir, "Gemfile");
|
|
100098
100605
|
if (!existsSync21(gemfile))
|
|
100099
100606
|
return null;
|
|
100100
100607
|
try {
|
|
@@ -100106,9 +100613,9 @@ async function detectRuby(workdir) {
|
|
|
100106
100613
|
}
|
|
100107
100614
|
}
|
|
100108
100615
|
async function detectJvm(workdir) {
|
|
100109
|
-
const pom =
|
|
100110
|
-
const gradle =
|
|
100111
|
-
const gradleKts =
|
|
100616
|
+
const pom = join112(workdir, "pom.xml");
|
|
100617
|
+
const gradle = join112(workdir, "build.gradle");
|
|
100618
|
+
const gradleKts = join112(workdir, "build.gradle.kts");
|
|
100112
100619
|
if (!existsSync21(pom) && !existsSync21(gradle) && !existsSync21(gradleKts))
|
|
100113
100620
|
return null;
|
|
100114
100621
|
try {
|
|
@@ -100116,7 +100623,7 @@ async function detectJvm(workdir) {
|
|
|
100116
100623
|
const content = await Bun.file(pom).text();
|
|
100117
100624
|
const nameMatch = content.match(/<artifactId>([^<]+)<\/artifactId>/);
|
|
100118
100625
|
const deps = [...content.matchAll(/<artifactId>([^<]+)<\/artifactId>/g)].map((m) => m[1]).filter((d) => d !== nameMatch?.[1]).slice(0, 10);
|
|
100119
|
-
const lang = existsSync21(
|
|
100626
|
+
const lang = existsSync21(join112(workdir, "src/main/kotlin")) ? "Kotlin" : "Java";
|
|
100120
100627
|
return { name: nameMatch?.[1], lang, dependencies: deps };
|
|
100121
100628
|
}
|
|
100122
100629
|
const gradleFile = existsSync21(gradleKts) ? gradleKts : gradle;
|
|
@@ -100371,7 +100878,7 @@ var init_windsurf = __esm(() => {
|
|
|
100371
100878
|
|
|
100372
100879
|
// src/context/generator/index.ts
|
|
100373
100880
|
import { existsSync as existsSync22 } from "fs";
|
|
100374
|
-
import { join as
|
|
100881
|
+
import { join as join113, relative as relative34 } from "path";
|
|
100375
100882
|
async function loadContextContent(options, config) {
|
|
100376
100883
|
if (!_generatorDeps.existsSync(options.contextPath)) {
|
|
100377
100884
|
throw new NaxError(`Context file not found: ${options.contextPath}`, "CONTEXT_FILE_NOT_FOUND", {
|
|
@@ -100392,7 +100899,7 @@ async function generateFor(agent, options, config) {
|
|
|
100392
100899
|
try {
|
|
100393
100900
|
const context = await loadContextContent(options, config);
|
|
100394
100901
|
const content = generator.generate(context);
|
|
100395
|
-
const outputPath =
|
|
100902
|
+
const outputPath = join113(options.outputDir, generator.outputFile);
|
|
100396
100903
|
validateFilePath(outputPath, options.outputDir);
|
|
100397
100904
|
if (!options.dryRun) {
|
|
100398
100905
|
await _generatorDeps.writeFile(outputPath, content);
|
|
@@ -100410,7 +100917,7 @@ async function generateAll(options, config, agentFilter) {
|
|
|
100410
100917
|
for (const [agentKey, generator] of entries) {
|
|
100411
100918
|
try {
|
|
100412
100919
|
const content = generator.generate(context);
|
|
100413
|
-
const outputPath =
|
|
100920
|
+
const outputPath = join113(options.outputDir, generator.outputFile);
|
|
100414
100921
|
validateFilePath(outputPath, options.outputDir);
|
|
100415
100922
|
if (!options.dryRun) {
|
|
100416
100923
|
await _generatorDeps.writeFile(outputPath, content);
|
|
@@ -100430,7 +100937,7 @@ async function discoverPackages(repoRoot) {
|
|
|
100430
100937
|
const glob = new Bun.Glob(pattern);
|
|
100431
100938
|
for await (const match of glob.scan({ cwd: repoRoot, dot: true })) {
|
|
100432
100939
|
const pkgRelative = match.replace(/^\.nax\/mono\//, "").replace(/\/context\.md$/, "");
|
|
100433
|
-
const pkgAbsolute =
|
|
100940
|
+
const pkgAbsolute = join113(repoRoot, pkgRelative);
|
|
100434
100941
|
if (!seen.has(pkgAbsolute)) {
|
|
100435
100942
|
seen.add(pkgAbsolute);
|
|
100436
100943
|
packages.push(pkgAbsolute);
|
|
@@ -100462,14 +100969,14 @@ async function discoverWorkspacePackages2(repoRoot) {
|
|
|
100462
100969
|
}
|
|
100463
100970
|
}
|
|
100464
100971
|
}
|
|
100465
|
-
const turboPath =
|
|
100972
|
+
const turboPath = join113(repoRoot, "turbo.json");
|
|
100466
100973
|
try {
|
|
100467
100974
|
const turbo = JSON.parse(await _generatorDeps.readTextFile(turboPath));
|
|
100468
100975
|
if (Array.isArray(turbo.packages)) {
|
|
100469
100976
|
await resolveGlobs(turbo.packages);
|
|
100470
100977
|
}
|
|
100471
100978
|
} catch {}
|
|
100472
|
-
const pkgPath =
|
|
100979
|
+
const pkgPath = join113(repoRoot, "package.json");
|
|
100473
100980
|
try {
|
|
100474
100981
|
const pkg = JSON.parse(await _generatorDeps.readTextFile(pkgPath));
|
|
100475
100982
|
const ws = pkg.workspaces;
|
|
@@ -100477,7 +100984,7 @@ async function discoverWorkspacePackages2(repoRoot) {
|
|
|
100477
100984
|
if (patterns.length > 0)
|
|
100478
100985
|
await resolveGlobs(patterns);
|
|
100479
100986
|
} catch {}
|
|
100480
|
-
const pnpmPath =
|
|
100987
|
+
const pnpmPath = join113(repoRoot, "pnpm-workspace.yaml");
|
|
100481
100988
|
try {
|
|
100482
100989
|
const raw = await _generatorDeps.readTextFile(pnpmPath);
|
|
100483
100990
|
const lines = raw.split(`
|
|
@@ -100503,7 +101010,7 @@ async function discoverWorkspacePackages2(repoRoot) {
|
|
|
100503
101010
|
async function generateForPackage(packageDir, config, dryRun = false, repoRoot) {
|
|
100504
101011
|
const resolvedRepoRoot = repoRoot ?? packageDir;
|
|
100505
101012
|
const relativePkgPath = relative34(resolvedRepoRoot, packageDir);
|
|
100506
|
-
const contextPath =
|
|
101013
|
+
const contextPath = join113(resolvedRepoRoot, ".nax", "mono", relativePkgPath, "context.md");
|
|
100507
101014
|
if (!_generatorDeps.existsSync(contextPath)) {
|
|
100508
101015
|
return [
|
|
100509
101016
|
{
|
|
@@ -100574,7 +101081,7 @@ var init_generator2 = __esm(() => {
|
|
|
100574
101081
|
|
|
100575
101082
|
// src/cli/generate.ts
|
|
100576
101083
|
import { existsSync as existsSync23 } from "fs";
|
|
100577
|
-
import { join as
|
|
101084
|
+
import { join as join114 } from "path";
|
|
100578
101085
|
async function loadCommandConfig(workdir) {
|
|
100579
101086
|
try {
|
|
100580
101087
|
return await loadConfig(workdir);
|
|
@@ -100625,7 +101132,7 @@ async function runSinglePackage(frame, pkg) {
|
|
|
100625
101132
|
if (!isRelativeAndSafe(pkg)) {
|
|
100626
101133
|
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 });
|
|
100627
101134
|
}
|
|
100628
|
-
const packageDir =
|
|
101135
|
+
const packageDir = join114(frame.workdir, pkg);
|
|
100629
101136
|
printDryRunNotice(frame.dryRun);
|
|
100630
101137
|
console.log(source_default.blue(`\u2192 Generating agent files for package: ${pkg}`));
|
|
100631
101138
|
const pkgResults = await generateForPackage(packageDir, frame.config, frame.dryRun, frame.workdir);
|
|
@@ -100724,8 +101231,8 @@ async function generateFromConfig(frame, genOptions) {
|
|
|
100724
101231
|
await generateDiscoveredPackages(frame);
|
|
100725
101232
|
}
|
|
100726
101233
|
async function runRootGeneration(frame, options) {
|
|
100727
|
-
const contextPath = options.context ?
|
|
100728
|
-
const outputDir = options.output ?
|
|
101234
|
+
const contextPath = options.context ? join114(frame.workdir, options.context) : join114(frame.workdir, ".nax/context.md");
|
|
101235
|
+
const outputDir = options.output ? join114(frame.workdir, options.output) : frame.workdir;
|
|
100729
101236
|
const autoInject = !options.noAutoInject;
|
|
100730
101237
|
validateRootInputs(contextPath, options.agent);
|
|
100731
101238
|
printDryRunNotice(frame.dryRun);
|
|
@@ -100842,8 +101349,8 @@ var init_ignored_nax_paths = __esm(() => {
|
|
|
100842
101349
|
});
|
|
100843
101350
|
|
|
100844
101351
|
// src/cli/init-context.ts
|
|
100845
|
-
import { mkdir as mkdir32, readdir as
|
|
100846
|
-
import { basename as
|
|
101352
|
+
import { mkdir as mkdir32, readdir as readdir10 } from "fs/promises";
|
|
101353
|
+
import { basename as basename21, join as join115, relative as relative36, sep as sep21 } from "path";
|
|
100847
101354
|
async function bunFileExists(path) {
|
|
100848
101355
|
return Bun.file(path).exists();
|
|
100849
101356
|
}
|
|
@@ -100858,7 +101365,7 @@ async function findFiles(dir, maxFiles = 200) {
|
|
|
100858
101365
|
async function walkDir(root, current, out, maxFiles) {
|
|
100859
101366
|
let entries;
|
|
100860
101367
|
try {
|
|
100861
|
-
entries = await
|
|
101368
|
+
entries = await readdir10(current, { withFileTypes: true });
|
|
100862
101369
|
} catch {
|
|
100863
101370
|
return;
|
|
100864
101371
|
}
|
|
@@ -100868,14 +101375,14 @@ async function walkDir(root, current, out, maxFiles) {
|
|
|
100868
101375
|
if (entry.isDirectory()) {
|
|
100869
101376
|
if (EXCLUDED_DIR_NAMES.has(entry.name))
|
|
100870
101377
|
continue;
|
|
100871
|
-
await walkDir(root,
|
|
101378
|
+
await walkDir(root, join115(current, entry.name), out, maxFiles);
|
|
100872
101379
|
} else if (entry.isFile()) {
|
|
100873
|
-
out.push(relative36(root,
|
|
101380
|
+
out.push(relative36(root, join115(current, entry.name)).replaceAll(sep21, "/"));
|
|
100874
101381
|
}
|
|
100875
101382
|
}
|
|
100876
101383
|
}
|
|
100877
101384
|
async function readPackageManifest(projectRoot) {
|
|
100878
|
-
const packageJsonPath =
|
|
101385
|
+
const packageJsonPath = join115(projectRoot, "package.json");
|
|
100879
101386
|
if (!await bunFileExists(packageJsonPath)) {
|
|
100880
101387
|
return null;
|
|
100881
101388
|
}
|
|
@@ -100893,7 +101400,7 @@ async function readPackageManifest(projectRoot) {
|
|
|
100893
101400
|
}
|
|
100894
101401
|
}
|
|
100895
101402
|
async function readReadmeSnippet(projectRoot) {
|
|
100896
|
-
const readmePath =
|
|
101403
|
+
const readmePath = join115(projectRoot, "README.md");
|
|
100897
101404
|
if (!await bunFileExists(readmePath)) {
|
|
100898
101405
|
return null;
|
|
100899
101406
|
}
|
|
@@ -100911,7 +101418,7 @@ async function detectEntryPoints(projectRoot) {
|
|
|
100911
101418
|
const candidates = ["src/index.ts", "src/main.ts", "main.go", "src/lib.rs"];
|
|
100912
101419
|
const found = [];
|
|
100913
101420
|
for (const candidate of candidates) {
|
|
100914
|
-
const path =
|
|
101421
|
+
const path = join115(projectRoot, candidate);
|
|
100915
101422
|
if (await bunFileExists(path)) {
|
|
100916
101423
|
found.push(candidate);
|
|
100917
101424
|
}
|
|
@@ -100922,7 +101429,7 @@ async function detectConfigFiles(projectRoot) {
|
|
|
100922
101429
|
const candidates = ["tsconfig.json", "biome.json", "turbo.json", ".env.example"];
|
|
100923
101430
|
const found = [];
|
|
100924
101431
|
for (const candidate of candidates) {
|
|
100925
|
-
const path =
|
|
101432
|
+
const path = join115(projectRoot, candidate);
|
|
100926
101433
|
if (await bunFileExists(path)) {
|
|
100927
101434
|
found.push(candidate);
|
|
100928
101435
|
}
|
|
@@ -100935,7 +101442,7 @@ async function scanProject(projectRoot) {
|
|
|
100935
101442
|
const readmeSnippet = await readReadmeSnippet(projectRoot);
|
|
100936
101443
|
const entryPoints = await detectEntryPoints(projectRoot);
|
|
100937
101444
|
const configFiles = await detectConfigFiles(projectRoot);
|
|
100938
|
-
const projectName = packageManifest?.name ||
|
|
101445
|
+
const projectName = packageManifest?.name || basename21(projectRoot);
|
|
100939
101446
|
return {
|
|
100940
101447
|
projectName,
|
|
100941
101448
|
fileTree,
|
|
@@ -101053,8 +101560,8 @@ async function initPackage(repoRoot, packagePath, force = false) {
|
|
|
101053
101560
|
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 });
|
|
101054
101561
|
}
|
|
101055
101562
|
const logger = getLogger2();
|
|
101056
|
-
const naxDir =
|
|
101057
|
-
const contextPath =
|
|
101563
|
+
const naxDir = join115(repoRoot, ".nax", "mono", packagePath);
|
|
101564
|
+
const contextPath = join115(naxDir, "context.md");
|
|
101058
101565
|
if (await bunFileExists(contextPath) && !force) {
|
|
101059
101566
|
logger.info("init", "Package context.md already exists (use --force to overwrite)", {
|
|
101060
101567
|
storyId: "init-context",
|
|
@@ -101077,8 +101584,8 @@ async function initPackage(repoRoot, packagePath, force = false) {
|
|
|
101077
101584
|
}
|
|
101078
101585
|
async function initContext(projectRoot, options = {}) {
|
|
101079
101586
|
const logger = getLogger2();
|
|
101080
|
-
const naxDir =
|
|
101081
|
-
const contextPath =
|
|
101587
|
+
const naxDir = join115(projectRoot, ".nax");
|
|
101588
|
+
const contextPath = join115(naxDir, "context.md");
|
|
101082
101589
|
if (await bunFileExists(contextPath) && !options.force) {
|
|
101083
101590
|
logger.info("init", "context.md already exists, skipping (use --force to overwrite)", {
|
|
101084
101591
|
storyId: "init-context",
|
|
@@ -101113,9 +101620,9 @@ var init_init_context = __esm(() => {
|
|
|
101113
101620
|
|
|
101114
101621
|
// src/cli/init-detect.ts
|
|
101115
101622
|
import { existsSync as existsSync24, readFileSync as readFileSync2 } from "fs";
|
|
101116
|
-
import { join as
|
|
101623
|
+
import { join as join116 } from "path";
|
|
101117
101624
|
function readPackageJson(projectRoot) {
|
|
101118
|
-
const pkgPath =
|
|
101625
|
+
const pkgPath = join116(projectRoot, "package.json");
|
|
101119
101626
|
if (!existsSync24(pkgPath))
|
|
101120
101627
|
return;
|
|
101121
101628
|
try {
|
|
@@ -101158,41 +101665,41 @@ function detectStack(projectRoot) {
|
|
|
101158
101665
|
};
|
|
101159
101666
|
}
|
|
101160
101667
|
function detectRuntime(projectRoot) {
|
|
101161
|
-
if (existsSync24(
|
|
101668
|
+
if (existsSync24(join116(projectRoot, "bun.lockb")) || existsSync24(join116(projectRoot, "bunfig.toml"))) {
|
|
101162
101669
|
return "bun";
|
|
101163
101670
|
}
|
|
101164
|
-
if (existsSync24(
|
|
101671
|
+
if (existsSync24(join116(projectRoot, "package-lock.json")) || existsSync24(join116(projectRoot, "yarn.lock")) || existsSync24(join116(projectRoot, "pnpm-lock.yaml"))) {
|
|
101165
101672
|
return "node";
|
|
101166
101673
|
}
|
|
101167
101674
|
return "unknown";
|
|
101168
101675
|
}
|
|
101169
101676
|
function detectLanguage2(projectRoot) {
|
|
101170
|
-
if (existsSync24(
|
|
101677
|
+
if (existsSync24(join116(projectRoot, "tsconfig.json")))
|
|
101171
101678
|
return "typescript";
|
|
101172
|
-
if (existsSync24(
|
|
101679
|
+
if (existsSync24(join116(projectRoot, "pyproject.toml")) || existsSync24(join116(projectRoot, "setup.py"))) {
|
|
101173
101680
|
return "python";
|
|
101174
101681
|
}
|
|
101175
|
-
if (existsSync24(
|
|
101682
|
+
if (existsSync24(join116(projectRoot, "Cargo.toml")))
|
|
101176
101683
|
return "rust";
|
|
101177
|
-
if (existsSync24(
|
|
101684
|
+
if (existsSync24(join116(projectRoot, "go.mod")))
|
|
101178
101685
|
return "go";
|
|
101179
101686
|
return "unknown";
|
|
101180
101687
|
}
|
|
101181
101688
|
function detectLinter(projectRoot) {
|
|
101182
|
-
if (existsSync24(
|
|
101689
|
+
if (existsSync24(join116(projectRoot, "biome.json")) || existsSync24(join116(projectRoot, "biome.jsonc"))) {
|
|
101183
101690
|
return "biome";
|
|
101184
101691
|
}
|
|
101185
|
-
if (existsSync24(
|
|
101692
|
+
if (existsSync24(join116(projectRoot, ".eslintrc.json")) || existsSync24(join116(projectRoot, ".eslintrc.js")) || existsSync24(join116(projectRoot, "eslint.config.js"))) {
|
|
101186
101693
|
return "eslint";
|
|
101187
101694
|
}
|
|
101188
101695
|
return "unknown";
|
|
101189
101696
|
}
|
|
101190
101697
|
function detectMonorepo(projectRoot) {
|
|
101191
|
-
if (existsSync24(
|
|
101698
|
+
if (existsSync24(join116(projectRoot, "turbo.json")))
|
|
101192
101699
|
return "turborepo";
|
|
101193
|
-
if (existsSync24(
|
|
101700
|
+
if (existsSync24(join116(projectRoot, "nx.json")))
|
|
101194
101701
|
return "nx";
|
|
101195
|
-
if (existsSync24(
|
|
101702
|
+
if (existsSync24(join116(projectRoot, "pnpm-workspace.yaml")))
|
|
101196
101703
|
return "pnpm-workspaces";
|
|
101197
101704
|
const pkg = readPackageJson(projectRoot);
|
|
101198
101705
|
if (pkg?.workspaces)
|
|
@@ -101328,7 +101835,7 @@ var init_init_detect = () => {};
|
|
|
101328
101835
|
// src/cli/init.ts
|
|
101329
101836
|
import { existsSync as existsSync25 } from "fs";
|
|
101330
101837
|
import { mkdir as mkdir33 } from "fs/promises";
|
|
101331
|
-
import { join as
|
|
101838
|
+
import { join as join117 } from "path";
|
|
101332
101839
|
function validateProjectName(name) {
|
|
101333
101840
|
if (!name)
|
|
101334
101841
|
return { valid: false, error: "name must be non-empty" };
|
|
@@ -101364,7 +101871,7 @@ async function checkInitCollision(name, currentWorkdir, currentRemote) {
|
|
|
101364
101871
|
}
|
|
101365
101872
|
async function updateGitignore(projectRoot) {
|
|
101366
101873
|
const logger = getLogger2();
|
|
101367
|
-
const gitignorePath =
|
|
101874
|
+
const gitignorePath = join117(projectRoot, ".gitignore");
|
|
101368
101875
|
const result = await patchIgnoreFile(gitignorePath, NAX_GITIGNORE_ENTRIES);
|
|
101369
101876
|
if (result.added.length === 0) {
|
|
101370
101877
|
logger.info("init", ".gitignore already has nax entries", { path: gitignorePath });
|
|
@@ -101378,7 +101885,7 @@ async function updateGitignore(projectRoot) {
|
|
|
101378
101885
|
}
|
|
101379
101886
|
async function updateNaxignore(projectRoot) {
|
|
101380
101887
|
const logger = getLogger2();
|
|
101381
|
-
const naxignorePath =
|
|
101888
|
+
const naxignorePath = join117(projectRoot, ".naxignore");
|
|
101382
101889
|
const result = await patchIgnoreFile(naxignorePath, NAX_NAXIGNORE_ENTRIES, {
|
|
101383
101890
|
header: NAX_NAXIGNORE_HEADER,
|
|
101384
101891
|
footer: NAX_NAXIGNORE_SUGGESTIONS,
|
|
@@ -101464,7 +101971,7 @@ async function initGlobal() {
|
|
|
101464
101971
|
await mkdir33(globalDir, { recursive: true });
|
|
101465
101972
|
logger.info("init", "Created global config directory", { path: globalDir });
|
|
101466
101973
|
}
|
|
101467
|
-
const configPath =
|
|
101974
|
+
const configPath = join117(globalDir, "config.json");
|
|
101468
101975
|
if (!existsSync25(configPath)) {
|
|
101469
101976
|
await Bun.write(configPath, `${JSON.stringify(MINIMAL_GLOBAL_CONFIG, null, 2)}
|
|
101470
101977
|
`);
|
|
@@ -101472,14 +101979,14 @@ async function initGlobal() {
|
|
|
101472
101979
|
} else {
|
|
101473
101980
|
logger.info("init", "Global config already exists", { path: configPath });
|
|
101474
101981
|
}
|
|
101475
|
-
const constitutionPath =
|
|
101982
|
+
const constitutionPath = join117(globalDir, "constitution.md");
|
|
101476
101983
|
if (!existsSync25(constitutionPath)) {
|
|
101477
101984
|
await Bun.write(constitutionPath, buildConstitution({ runtime: "unknown", language: "unknown", linter: "unknown", monorepo: "none" }));
|
|
101478
101985
|
logger.info("init", "Created global constitution", { path: constitutionPath });
|
|
101479
101986
|
} else {
|
|
101480
101987
|
logger.info("init", "Global constitution already exists", { path: constitutionPath });
|
|
101481
101988
|
}
|
|
101482
|
-
const hooksDir =
|
|
101989
|
+
const hooksDir = join117(globalDir, "hooks");
|
|
101483
101990
|
if (!existsSync25(hooksDir)) {
|
|
101484
101991
|
await mkdir33(hooksDir, { recursive: true });
|
|
101485
101992
|
logger.info("init", "Created global hooks directory", { path: hooksDir });
|
|
@@ -101512,7 +102019,7 @@ async function initProject(projectRoot, options) {
|
|
|
101512
102019
|
if (detectedName && !options?.force) {
|
|
101513
102020
|
const collision = await checkInitCollision(detectedName, projectRoot, currentRemote);
|
|
101514
102021
|
if (collision.collision && collision.existing) {
|
|
101515
|
-
const configPath =
|
|
102022
|
+
const configPath = join117(projectDir, "config.json");
|
|
101516
102023
|
throw new NaxError([
|
|
101517
102024
|
`Project name collision: "${detectedName}"`,
|
|
101518
102025
|
` This project: ${projectRoot}`,
|
|
@@ -101540,7 +102047,7 @@ async function initProject(projectRoot, options) {
|
|
|
101540
102047
|
linter: stack.linter,
|
|
101541
102048
|
monorepo: stack.monorepo
|
|
101542
102049
|
});
|
|
101543
|
-
const configPath =
|
|
102050
|
+
const configPath = join117(projectDir, "config.json");
|
|
101544
102051
|
if (!existsSync25(configPath)) {
|
|
101545
102052
|
await Bun.write(configPath, `${JSON.stringify(projectConfig, null, 2)}
|
|
101546
102053
|
`);
|
|
@@ -101549,7 +102056,7 @@ async function initProject(projectRoot, options) {
|
|
|
101549
102056
|
logger.info("init", "Project config already exists", { path: configPath });
|
|
101550
102057
|
}
|
|
101551
102058
|
await initContext(projectRoot, { force: options?.force });
|
|
101552
|
-
const constitutionPath =
|
|
102059
|
+
const constitutionPath = join117(projectDir, "constitution.md");
|
|
101553
102060
|
if (!existsSync25(constitutionPath) || options?.force) {
|
|
101554
102061
|
await Bun.write(constitutionPath, buildConstitution(stack));
|
|
101555
102062
|
logger.info("init", "Created project constitution", { path: constitutionPath });
|
|
@@ -101557,7 +102064,7 @@ async function initProject(projectRoot, options) {
|
|
|
101557
102064
|
logger.info("init", "Project constitution already exists", { path: constitutionPath });
|
|
101558
102065
|
}
|
|
101559
102066
|
for (const [label, dir] of [
|
|
101560
|
-
["hooks",
|
|
102067
|
+
["hooks", join117(projectDir, "hooks")],
|
|
101561
102068
|
["features", featuresDir(projectRoot)]
|
|
101562
102069
|
]) {
|
|
101563
102070
|
if (!existsSync25(dir)) {
|
|
@@ -101697,7 +102204,7 @@ var init_plan_helpers = __esm(() => {
|
|
|
101697
102204
|
});
|
|
101698
102205
|
|
|
101699
102206
|
// src/analyze/scanner.ts
|
|
101700
|
-
import { join as
|
|
102207
|
+
import { join as join118 } from "path";
|
|
101701
102208
|
function resolveFrameworkAndRunner(language, pkg) {
|
|
101702
102209
|
if (language === "go")
|
|
101703
102210
|
return { framework: "", testRunner: "go-test" };
|
|
@@ -101719,7 +102226,7 @@ async function scanSourceRoots(workdir) {
|
|
|
101719
102226
|
});
|
|
101720
102227
|
try {
|
|
101721
102228
|
const language = await deps.detectLanguage(workdir);
|
|
101722
|
-
const pkg = await deps.readPackageJson(
|
|
102229
|
+
const pkg = await deps.readPackageJson(join118(workdir, "package.json"));
|
|
101723
102230
|
const { framework, testRunner } = resolveFrameworkAndRunner(language, pkg);
|
|
101724
102231
|
return [{ path: ".", language, framework, testRunner }];
|
|
101725
102232
|
} catch {
|
|
@@ -101737,9 +102244,9 @@ async function scanSourceRoots(workdir) {
|
|
|
101737
102244
|
packages = packages.slice(0, MAX_SOURCE_ROOTS);
|
|
101738
102245
|
}
|
|
101739
102246
|
return Promise.all(packages.map(async (pkgPath) => {
|
|
101740
|
-
const pkgDir = pkgPath === "." ? workdir :
|
|
102247
|
+
const pkgDir = pkgPath === "." ? workdir : join118(workdir, pkgPath);
|
|
101741
102248
|
const language = await deps.detectLanguage(pkgDir);
|
|
101742
|
-
const pkg = await deps.readPackageJson(
|
|
102249
|
+
const pkg = await deps.readPackageJson(join118(pkgDir, "package.json"));
|
|
101743
102250
|
const { framework, testRunner } = resolveFrameworkAndRunner(language, pkg);
|
|
101744
102251
|
return { path: pkgPath, language, framework, testRunner };
|
|
101745
102252
|
}));
|
|
@@ -102014,7 +102521,7 @@ var init_resume_hydrate = __esm(() => {
|
|
|
102014
102521
|
});
|
|
102015
102522
|
|
|
102016
102523
|
// src/execution/nbf-worth-check.ts
|
|
102017
|
-
import { join as
|
|
102524
|
+
import { join as join119 } from "path";
|
|
102018
102525
|
async function storyDiff(ctx) {
|
|
102019
102526
|
try {
|
|
102020
102527
|
const ref = await _nbfWorthCheckDeps2.resolveEffectiveRef(ctx.packageDir, ctx.story?.storyGitRef, ctx.storyId ?? "");
|
|
@@ -102038,7 +102545,7 @@ async function pendingFeatureStories(ctx) {
|
|
|
102038
102545
|
if (!ctx.featureDir)
|
|
102039
102546
|
return [];
|
|
102040
102547
|
try {
|
|
102041
|
-
const prd = await _nbfWorthCheckDeps2.loadPRD(
|
|
102548
|
+
const prd = await _nbfWorthCheckDeps2.loadPRD(join119(ctx.featureDir, "prd.json"));
|
|
102042
102549
|
return prd.userStories.filter((story) => story.id !== ctx.story?.id && ["pending", "in-progress", "paused"].includes(story.status)).map(({ id, title, acceptanceCriteria }) => ({ id, title, acceptanceCriteria }));
|
|
102043
102550
|
} catch (error) {
|
|
102044
102551
|
getSafeLogger2()?.warn("nbf-worth-check", "worth-check pending stories unavailable \u2014 skipping coverage check", {
|
|
@@ -102104,7 +102611,7 @@ var init_nbf_worth_check2 = __esm(() => {
|
|
|
102104
102611
|
|
|
102105
102612
|
// src/tdd/rollback.ts
|
|
102106
102613
|
import { rm as rm10 } from "fs/promises";
|
|
102107
|
-
import { join as
|
|
102614
|
+
import { join as join120 } from "path";
|
|
102108
102615
|
async function runGitBounded2(args, workdir) {
|
|
102109
102616
|
if (!workdir) {
|
|
102110
102617
|
throw new Error(`Git rollback failed: git ${args.join(" ")} called with an empty workdir`);
|
|
@@ -102178,7 +102685,7 @@ async function rollbackToRef(workdir, ref, untrackedBefore) {
|
|
|
102178
102685
|
const root = await _rollbackDeps.getGitRoot(workdir) ?? workdir;
|
|
102179
102686
|
for (const relPath of appearedSincePhaseStart) {
|
|
102180
102687
|
try {
|
|
102181
|
-
await _rollbackDeps.rm(
|
|
102688
|
+
await _rollbackDeps.rm(join120(root, relPath), { recursive: true, force: true });
|
|
102182
102689
|
} catch (err) {
|
|
102183
102690
|
logger.warn("tdd", "Failed to clean untracked file", {
|
|
102184
102691
|
path: relPath,
|
|
@@ -102231,7 +102738,7 @@ var init_rollback = __esm(() => {
|
|
|
102231
102738
|
});
|
|
102232
102739
|
|
|
102233
102740
|
// src/utils/paths.ts
|
|
102234
|
-
import { join as
|
|
102741
|
+
import { join as join121, relative as relative37, sep as sep22 } from "path";
|
|
102235
102742
|
function packageDirRelative(projectDir, workdir) {
|
|
102236
102743
|
if (!projectDir || !workdir || workdir === projectDir)
|
|
102237
102744
|
return;
|
|
@@ -102241,10 +102748,10 @@ function packageDirRelative(projectDir, workdir) {
|
|
|
102241
102748
|
return rel && rel !== "." ? rel : undefined;
|
|
102242
102749
|
}
|
|
102243
102750
|
function getRunsDir() {
|
|
102244
|
-
return process.env.NAX_RUNS_DIR ??
|
|
102751
|
+
return process.env.NAX_RUNS_DIR ?? join121(globalConfigDir(), "runs");
|
|
102245
102752
|
}
|
|
102246
102753
|
function getEventsRootDir() {
|
|
102247
|
-
return
|
|
102754
|
+
return join121(globalConfigDir(), "events");
|
|
102248
102755
|
}
|
|
102249
102756
|
var init_paths4 = __esm(() => {
|
|
102250
102757
|
init_paths();
|
|
@@ -103403,7 +103910,7 @@ function countOscillationOutcomes(iterations) {
|
|
|
103403
103910
|
}
|
|
103404
103911
|
|
|
103405
103912
|
// src/execution/story-orchestrator/give-up-advice.ts
|
|
103406
|
-
import { join as
|
|
103913
|
+
import { join as join122, relative as relative38 } from "path";
|
|
103407
103914
|
function worstSeverity(findings) {
|
|
103408
103915
|
return [...findings].sort((a, b) => compareSeverity(b.severity, a.severity))[0]?.severity;
|
|
103409
103916
|
}
|
|
@@ -103476,7 +103983,7 @@ function buildGiveUpHook(args) {
|
|
|
103476
103983
|
outputDir: ctx.runtime.outputDir,
|
|
103477
103984
|
feature,
|
|
103478
103985
|
runId: ctx.runtime.runId,
|
|
103479
|
-
specPath: relative38(repoRoot,
|
|
103986
|
+
specPath: relative38(repoRoot, join122(featureDir(repoRoot, feature), "spec.md")),
|
|
103480
103987
|
workdir: ctx.packageDir,
|
|
103481
103988
|
queueHeadsUp: (s, text) => ctx.runtime.advisorHeadsUps.push(s, text)
|
|
103482
103989
|
});
|
|
@@ -105580,7 +106087,7 @@ var init_fix_review_strategy = __esm(() => {
|
|
|
105580
106087
|
});
|
|
105581
106088
|
|
|
105582
106089
|
// src/execution/build-plan-for-strategy.ts
|
|
105583
|
-
import { join as
|
|
106090
|
+
import { join as join123, normalize as normalize7, resolve as resolve43, sep as sep23 } from "path";
|
|
105584
106091
|
function requiresInitialRefCapture(strategy) {
|
|
105585
106092
|
return isThreeSessionStrategy(strategy);
|
|
105586
106093
|
}
|
|
@@ -105596,10 +106103,10 @@ function resolveStoryPathAnchors(ctxPackageDir, storyWorkdir) {
|
|
|
105596
106103
|
return { repoRoot: base, packageDir: base };
|
|
105597
106104
|
}
|
|
105598
106105
|
const candidateRoot = resolve43(base, ...Array(segments.length).fill(".."));
|
|
105599
|
-
if (
|
|
106106
|
+
if (join123(candidateRoot, normalizedRel) === base) {
|
|
105600
106107
|
return { repoRoot: candidateRoot, packageDir: base };
|
|
105601
106108
|
}
|
|
105602
|
-
return { repoRoot: base, packageDir:
|
|
106109
|
+
return { repoRoot: base, packageDir: join123(base, normalizedRel) };
|
|
105603
106110
|
}
|
|
105604
106111
|
function logRejectedDeclarations(diagnostics, ctx) {
|
|
105605
106112
|
if (diagnostics.length === 0)
|
|
@@ -105801,7 +106308,7 @@ var init_build_plan_for_strategy = __esm(() => {
|
|
|
105801
106308
|
});
|
|
105802
106309
|
|
|
105803
106310
|
// src/execution/checkpoint/reader.ts
|
|
105804
|
-
import { join as
|
|
106311
|
+
import { join as join124 } from "path";
|
|
105805
106312
|
function isValidRecord(value) {
|
|
105806
106313
|
if (!value || typeof value !== "object")
|
|
105807
106314
|
return false;
|
|
@@ -105834,7 +106341,7 @@ async function defaultRead(filePath) {
|
|
|
105834
106341
|
return file.text();
|
|
105835
106342
|
}
|
|
105836
106343
|
async function loadCheckpoints(featureDir, options = { _deps: { read: defaultRead } }) {
|
|
105837
|
-
const filePath =
|
|
106344
|
+
const filePath = join124(featureDir, "checkpoint.jsonl");
|
|
105838
106345
|
const deps = options._deps ?? { read: defaultRead };
|
|
105839
106346
|
let content;
|
|
105840
106347
|
try {
|
|
@@ -105952,7 +106459,7 @@ var init_writer = __esm(() => {
|
|
|
105952
106459
|
});
|
|
105953
106460
|
|
|
105954
106461
|
// src/execution/checkpoint/resume-cli.ts
|
|
105955
|
-
import { join as
|
|
106462
|
+
import { join as join125 } from "path";
|
|
105956
106463
|
function applyResumeModeDeps(featureDir, mode = "auto") {
|
|
105957
106464
|
if (mode === "fresh" || mode === "no-resume") {
|
|
105958
106465
|
_storyOrchestratorDeps.loadCheckpoints = async (_fd) => new Map;
|
|
@@ -105962,7 +106469,7 @@ function applyResumeModeDeps(featureDir, mode = "auto") {
|
|
|
105962
106469
|
_storyOrchestratorDeps.loadCheckpoints = async (_fd) => loadCheckpoints(target);
|
|
105963
106470
|
}
|
|
105964
106471
|
function applyRecordGreenDeps(featureDir, runId) {
|
|
105965
|
-
const writer = createCheckpointWriter(
|
|
106472
|
+
const writer = createCheckpointWriter(join125(featureDir, "checkpoint.jsonl"), runId);
|
|
105966
106473
|
_storyOrchestratorDeps.recordGreen = (storyId, phase, tree) => writer.recordGreen(storyId, phase, tree);
|
|
105967
106474
|
}
|
|
105968
106475
|
var _workflowResumeDeps;
|
|
@@ -106560,7 +107067,7 @@ var init_quote_integrity = __esm(() => {
|
|
|
106560
107067
|
|
|
106561
107068
|
// src/execution/progress.ts
|
|
106562
107069
|
import { appendFile as appendFile8, mkdir as mkdir34 } from "fs/promises";
|
|
106563
|
-
import { join as
|
|
107070
|
+
import { join as join126 } from "path";
|
|
106564
107071
|
function getSafeLogger3() {
|
|
106565
107072
|
try {
|
|
106566
107073
|
return getLogger2();
|
|
@@ -106571,7 +107078,7 @@ function getSafeLogger3() {
|
|
|
106571
107078
|
async function appendProgress(featureDir, storyId, status, message) {
|
|
106572
107079
|
try {
|
|
106573
107080
|
await mkdir34(featureDir, { recursive: true });
|
|
106574
|
-
const progressPath =
|
|
107081
|
+
const progressPath = join126(featureDir, "progress.txt");
|
|
106575
107082
|
const timestamp = new Date().toISOString();
|
|
106576
107083
|
const entry = `[${timestamp}] ${storyId} \u2014 ${status.toUpperCase()} \u2014 ${message}
|
|
106577
107084
|
`;
|
|
@@ -107722,7 +108229,7 @@ var init_types13 = __esm(() => {
|
|
|
107722
108229
|
});
|
|
107723
108230
|
|
|
107724
108231
|
// src/worktree/dependencies.ts
|
|
107725
|
-
import { join as
|
|
108232
|
+
import { join as join127 } from "path";
|
|
107726
108233
|
async function prepareWorktreeDependencies(options) {
|
|
107727
108234
|
const mode = options.config.execution.worktreeDependencies.mode;
|
|
107728
108235
|
const resolvedCwd = resolveDependencyCwd(options);
|
|
@@ -107734,7 +108241,7 @@ async function prepareWorktreeDependencies(options) {
|
|
|
107734
108241
|
}
|
|
107735
108242
|
}
|
|
107736
108243
|
function resolveDependencyCwd(options) {
|
|
107737
|
-
return options.storyWorkdir ?
|
|
108244
|
+
return options.storyWorkdir ? join127(options.worktreeRoot, options.storyWorkdir) : options.worktreeRoot;
|
|
107738
108245
|
}
|
|
107739
108246
|
async function provisionDependencies(config, worktreeRoot, resolvedCwd) {
|
|
107740
108247
|
const setupCommand = config.execution.worktreeDependencies.setupCommand;
|
|
@@ -107780,7 +108287,7 @@ var init_nax_orphan_ref = __esm(() => {
|
|
|
107780
108287
|
|
|
107781
108288
|
// src/worktree/worktree-id.ts
|
|
107782
108289
|
import { createHash as createHash23 } from "crypto";
|
|
107783
|
-
import { join as
|
|
108290
|
+
import { join as join128 } from "path";
|
|
107784
108291
|
function sanitize(value) {
|
|
107785
108292
|
return value.replace(/[^a-zA-Z0-9._-]/g, "-").replace(/\.\./g, "-");
|
|
107786
108293
|
}
|
|
@@ -107803,7 +108310,7 @@ function collapse(natural, rawA, rawB) {
|
|
|
107803
108310
|
return natural.slice(0, prefixBudget) + suffix;
|
|
107804
108311
|
}
|
|
107805
108312
|
function storyWorktreePath(projectRoot, worktreeId) {
|
|
107806
|
-
return
|
|
108313
|
+
return join128(projectRoot, ".nax-wt", worktreeId);
|
|
107807
108314
|
}
|
|
107808
108315
|
function storyBranchName(worktreeId) {
|
|
107809
108316
|
return `nax/${worktreeId}`;
|
|
@@ -107815,13 +108322,13 @@ var init_worktree_id = __esm(() => {
|
|
|
107815
108322
|
|
|
107816
108323
|
// src/worktree/manager.ts
|
|
107817
108324
|
import { existsSync as existsSync26, symlinkSync as symlinkSync3 } from "fs";
|
|
107818
|
-
import { mkdir as mkdir36, stat as
|
|
107819
|
-
import { join as
|
|
108325
|
+
import { mkdir as mkdir36, stat as stat12 } from "fs/promises";
|
|
108326
|
+
import { join as join129, resolve as resolve44 } from "path";
|
|
107820
108327
|
async function resolveGitInfoDir(projectRoot) {
|
|
107821
|
-
const dotGit =
|
|
107822
|
-
const isPointerFile = await
|
|
108328
|
+
const dotGit = join129(projectRoot, ".git");
|
|
108329
|
+
const isPointerFile = await stat12(dotGit).then((s) => s.isFile(), () => false);
|
|
107823
108330
|
if (!isPointerFile)
|
|
107824
|
-
return
|
|
108331
|
+
return join129(dotGit, "info");
|
|
107825
108332
|
const { stdout, stderr, exitCode } = await _worktreeManagerDeps.gitWithTimeout(["rev-parse", "--git-common-dir"], projectRoot);
|
|
107826
108333
|
const commonDir = stdout.trim();
|
|
107827
108334
|
if (exitCode !== 0 || commonDir === "") {
|
|
@@ -107831,7 +108338,7 @@ async function resolveGitInfoDir(projectRoot) {
|
|
|
107831
108338
|
stderr
|
|
107832
108339
|
});
|
|
107833
108340
|
}
|
|
107834
|
-
return
|
|
108341
|
+
return join129(resolve44(projectRoot, commonDir), "info");
|
|
107835
108342
|
}
|
|
107836
108343
|
function dropRetiredLines(content, retired) {
|
|
107837
108344
|
const lines = content.split(`
|
|
@@ -107849,7 +108356,7 @@ class WorktreeManager {
|
|
|
107849
108356
|
const logger = getSafeLogger2();
|
|
107850
108357
|
try {
|
|
107851
108358
|
const infoDir = await resolveGitInfoDir(projectRoot);
|
|
107852
|
-
const excludePath =
|
|
108359
|
+
const excludePath = join129(infoDir, "exclude");
|
|
107853
108360
|
await mkdir36(infoDir, { recursive: true });
|
|
107854
108361
|
await Promise.resolve().then(() => init_internal());
|
|
107855
108362
|
await withPathFileLock(excludePath, async () => {
|
|
@@ -109314,7 +109821,7 @@ var init_acceptance_setup = __esm(() => {
|
|
|
109314
109821
|
});
|
|
109315
109822
|
|
|
109316
109823
|
// src/pipeline/stages/completion.ts
|
|
109317
|
-
import { join as
|
|
109824
|
+
import { join as join130 } from "path";
|
|
109318
109825
|
function logHighMemoryCheckpoint(logger, ctx) {
|
|
109319
109826
|
const usage = process.memoryUsage();
|
|
109320
109827
|
if (usage.heapUsed < HIGH_MEMORY_TELEMETRY_BYTES && usage.rss < HIGH_MEMORY_TELEMETRY_BYTES)
|
|
@@ -109470,7 +109977,7 @@ var init_completion = __esm(() => {
|
|
|
109470
109977
|
const sessionSpend = storySpendUsd(ctx.runtime.costAggregator, ctx.story.id, 0);
|
|
109471
109978
|
const sessionCost = sessionSpend.cost;
|
|
109472
109979
|
const persistPrd = ctx.skipPrdPersistence !== true;
|
|
109473
|
-
const prdPath = ctx.prdPath ??
|
|
109980
|
+
const prdPath = ctx.prdPath ?? join130(ctx.featureDir ?? featureDir(ctx.workdir, "unknown"), "prd.json");
|
|
109474
109981
|
const storyStartTime = ctx.storyStartTime || new Date().toISOString();
|
|
109475
109982
|
if (isBatch) {
|
|
109476
109983
|
ctx.storyMetrics = collectBatchMetrics(ctx, storyStartTime);
|
|
@@ -109586,7 +110093,7 @@ var init_completion = __esm(() => {
|
|
|
109586
110093
|
|
|
109587
110094
|
// src/constitution/loader.ts
|
|
109588
110095
|
import { existsSync as existsSync27 } from "fs";
|
|
109589
|
-
import { join as
|
|
110096
|
+
import { join as join131 } from "path";
|
|
109590
110097
|
function truncateToTokens(text, maxTokens) {
|
|
109591
110098
|
const maxChars = maxTokens * 3;
|
|
109592
110099
|
if (text.length <= maxChars) {
|
|
@@ -109608,7 +110115,7 @@ async function loadConstitution(projectDir, config) {
|
|
|
109608
110115
|
}
|
|
109609
110116
|
let combinedContent = "";
|
|
109610
110117
|
if (!config.skipGlobal) {
|
|
109611
|
-
const globalPath =
|
|
110118
|
+
const globalPath = join131(globalConfigDir(), config.path);
|
|
109612
110119
|
if (existsSync27(globalPath)) {
|
|
109613
110120
|
const validatedPath = validateFilePath(globalPath, globalConfigDir());
|
|
109614
110121
|
const globalFile = Bun.file(validatedPath);
|
|
@@ -109618,7 +110125,7 @@ async function loadConstitution(projectDir, config) {
|
|
|
109618
110125
|
}
|
|
109619
110126
|
}
|
|
109620
110127
|
}
|
|
109621
|
-
const projectPath =
|
|
110128
|
+
const projectPath = join131(projectDir, config.path);
|
|
109622
110129
|
if (existsSync27(projectPath)) {
|
|
109623
110130
|
const validatedPath = validateFilePath(projectPath, projectDir);
|
|
109624
110131
|
const projectFile = Bun.file(validatedPath);
|
|
@@ -109666,7 +110173,7 @@ var init_constitution = __esm(() => {
|
|
|
109666
110173
|
});
|
|
109667
110174
|
|
|
109668
110175
|
// src/pipeline/stages/constitution.ts
|
|
109669
|
-
import { dirname as
|
|
110176
|
+
import { dirname as dirname36 } from "path";
|
|
109670
110177
|
var constitutionStage;
|
|
109671
110178
|
var init_constitution2 = __esm(() => {
|
|
109672
110179
|
init_constitution();
|
|
@@ -109676,7 +110183,7 @@ var init_constitution2 = __esm(() => {
|
|
|
109676
110183
|
enabled: (ctx) => ctx.config.constitution.enabled,
|
|
109677
110184
|
async execute(ctx) {
|
|
109678
110185
|
const logger = getLogger2();
|
|
109679
|
-
const ngentDir = ctx.featureDir ?
|
|
110186
|
+
const ngentDir = ctx.featureDir ? dirname36(dirname36(ctx.featureDir)) : `${ctx.workdir}/nax`;
|
|
109680
110187
|
const result = await loadConstitution(ngentDir, ctx.config.constitution);
|
|
109681
110188
|
if (result) {
|
|
109682
110189
|
ctx.constitution = result;
|
|
@@ -109745,7 +110252,7 @@ var init_scope_files = __esm(() => {
|
|
|
109745
110252
|
|
|
109746
110253
|
// src/pipeline/stages/context-session.ts
|
|
109747
110254
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
109748
|
-
import { join as
|
|
110255
|
+
import { join as join132 } from "path";
|
|
109749
110256
|
function allocateStorySession(ctx) {
|
|
109750
110257
|
if (!ctx.sessionScratchDir) {
|
|
109751
110258
|
if (ctx.sessionManager && ctx.prd.feature) {
|
|
@@ -109764,7 +110271,7 @@ function allocateStorySession(ctx) {
|
|
|
109764
110271
|
if (!ctx.sessionId)
|
|
109765
110272
|
ctx.sessionId = sessionId;
|
|
109766
110273
|
const featureId = ctx.featureDir?.replace(/\/$/, "").split("/").pop() ?? "_unattached";
|
|
109767
|
-
ctx.sessionScratchDir =
|
|
110274
|
+
ctx.sessionScratchDir = join132(featureDir(ctx.projectDir, featureId), "sessions", sessionId);
|
|
109768
110275
|
}
|
|
109769
110276
|
}
|
|
109770
110277
|
if (!ctx.contextToolRunCounter) {
|
|
@@ -111031,9 +111538,9 @@ var init_run_log = __esm(() => {
|
|
|
111031
111538
|
|
|
111032
111539
|
// src/workflow/ledger.ts
|
|
111033
111540
|
import { appendFile as appendFile9, mkdir as mkdir37 } from "fs/promises";
|
|
111034
|
-
import { join as
|
|
111541
|
+
import { join as join133 } from "path";
|
|
111035
111542
|
function ledgerFilePath(runDir) {
|
|
111036
|
-
return
|
|
111543
|
+
return join133(runDir, "ledger.md");
|
|
111037
111544
|
}
|
|
111038
111545
|
function oneLine2(text) {
|
|
111039
111546
|
return text.replace(/\s+/g, " ").trim();
|
|
@@ -111074,9 +111581,9 @@ var init_ledger2 = __esm(() => {
|
|
|
111074
111581
|
|
|
111075
111582
|
// src/workflow/preflight.ts
|
|
111076
111583
|
import { rename as rename11 } from "fs/promises";
|
|
111077
|
-
import { join as
|
|
111584
|
+
import { join as join134 } from "path";
|
|
111078
111585
|
function preflightPath(runDir) {
|
|
111079
|
-
return
|
|
111586
|
+
return join134(runDir, "preflight.json");
|
|
111080
111587
|
}
|
|
111081
111588
|
function what(d) {
|
|
111082
111589
|
return d.action.type === "supersede" ? `supersede ${describeTarget(d.action.target)}` : d.action.type;
|
|
@@ -111281,8 +111788,8 @@ var init_open_items = __esm(() => {
|
|
|
111281
111788
|
});
|
|
111282
111789
|
|
|
111283
111790
|
// src/workflow/result.ts
|
|
111284
|
-
import { mkdir as mkdir38, readdir as
|
|
111285
|
-
import { basename as
|
|
111791
|
+
import { mkdir as mkdir38, readdir as readdir11, rename as rename12, stat as stat13 } from "fs/promises";
|
|
111792
|
+
import { basename as basename22, join as join135 } from "path";
|
|
111286
111793
|
function newStoryRecord(storyId, maxRounds, now) {
|
|
111287
111794
|
return {
|
|
111288
111795
|
storyId,
|
|
@@ -111301,7 +111808,7 @@ function newStoryRecord(storyId, maxRounds, now) {
|
|
|
111301
111808
|
};
|
|
111302
111809
|
}
|
|
111303
111810
|
async function readResult(runDir) {
|
|
111304
|
-
const file = Bun.file(
|
|
111811
|
+
const file = Bun.file(join135(runDir, RESULT_FILE));
|
|
111305
111812
|
if (!await file.exists())
|
|
111306
111813
|
return null;
|
|
111307
111814
|
try {
|
|
@@ -111337,7 +111844,7 @@ async function writePreflightTokens(runDir, header, byRole) {
|
|
|
111337
111844
|
}
|
|
111338
111845
|
async function writeResult(runDir, next) {
|
|
111339
111846
|
await _resultDeps.mkdir(runDir, { recursive: true });
|
|
111340
|
-
const path =
|
|
111847
|
+
const path = join135(runDir, RESULT_FILE);
|
|
111341
111848
|
const tmp = `${path}.tmp`;
|
|
111342
111849
|
const text = `${JSON.stringify(next, null, 2)}
|
|
111343
111850
|
`;
|
|
@@ -111348,7 +111855,7 @@ async function writeResult(runDir, next) {
|
|
|
111348
111855
|
}
|
|
111349
111856
|
async function loadPriorStory(featureDir, currentRunId, storyId) {
|
|
111350
111857
|
for (const runDir of await runDirsNewestFirst(featureDir)) {
|
|
111351
|
-
if (
|
|
111858
|
+
if (basename22(runDir) === currentRunId)
|
|
111352
111859
|
continue;
|
|
111353
111860
|
const record = (await readResult(runDir))?.stories[storyId];
|
|
111354
111861
|
if (!record)
|
|
@@ -111366,9 +111873,9 @@ async function runDirsNewestFirst(featureDir) {
|
|
|
111366
111873
|
}
|
|
111367
111874
|
const dated = [];
|
|
111368
111875
|
for (const name of entries) {
|
|
111369
|
-
const runDir =
|
|
111876
|
+
const runDir = join135(featureDir, name);
|
|
111370
111877
|
try {
|
|
111371
|
-
dated.push({ runDir, mtimeMs: (await _resultDeps.stat(
|
|
111878
|
+
dated.push({ runDir, mtimeMs: (await _resultDeps.stat(join135(runDir, RESULT_FILE))).mtimeMs });
|
|
111372
111879
|
} catch {}
|
|
111373
111880
|
}
|
|
111374
111881
|
return [...dated].sort((a, b) => b.mtimeMs - a.mtimeMs).map((d) => d.runDir);
|
|
@@ -111398,11 +111905,11 @@ var _resultDeps, RESULT_FILE = "result.json";
|
|
|
111398
111905
|
var init_result = __esm(() => {
|
|
111399
111906
|
init_store();
|
|
111400
111907
|
init_open_items();
|
|
111401
|
-
_resultDeps = { mkdir: mkdir38, readdir:
|
|
111908
|
+
_resultDeps = { mkdir: mkdir38, readdir: readdir11, rename: rename12, stat: stat13 };
|
|
111402
111909
|
});
|
|
111403
111910
|
|
|
111404
111911
|
// src/workflow/feature-record.ts
|
|
111405
|
-
import { basename as
|
|
111912
|
+
import { basename as basename23 } from "path";
|
|
111406
111913
|
function newFeatureRecord(input) {
|
|
111407
111914
|
return {
|
|
111408
111915
|
step: "repo-gates",
|
|
@@ -111444,7 +111951,7 @@ function isFeatureRecord(v) {
|
|
|
111444
111951
|
}
|
|
111445
111952
|
async function loadPriorFeature(featureDir, currentRunId) {
|
|
111446
111953
|
for (const runDir of await runDirsNewestFirst(featureDir)) {
|
|
111447
|
-
if (
|
|
111954
|
+
if (basename23(runDir) === currentRunId)
|
|
111448
111955
|
continue;
|
|
111449
111956
|
const feature = (await readResult(runDir))?.featureWorkflow;
|
|
111450
111957
|
if (feature === undefined)
|
|
@@ -111621,7 +112128,7 @@ var init_step_context = __esm(() => {
|
|
|
111621
112128
|
|
|
111622
112129
|
// src/workflow/brief.ts
|
|
111623
112130
|
import { mkdir as mkdir39 } from "fs/promises";
|
|
111624
|
-
import { dirname as
|
|
112131
|
+
import { dirname as dirname37, isAbsolute as isAbsolute32, join as join136 } from "path";
|
|
111625
112132
|
function specExcerpts(specText, storyId) {
|
|
111626
112133
|
const sections = specText.split(/^(?=#{1,6} )/m).map((s) => s.trim()).filter(Boolean);
|
|
111627
112134
|
const hits = sections.filter((s) => s.includes(storyId));
|
|
@@ -111648,7 +112155,7 @@ async function loadSpec(sc) {
|
|
|
111648
112155
|
const rel = resolved.specSource?.path;
|
|
111649
112156
|
if (!rel)
|
|
111650
112157
|
return { excerpts: [] };
|
|
111651
|
-
const abs = isAbsolute32(rel) ? rel :
|
|
112158
|
+
const abs = isAbsolute32(rel) ? rel : join136(sc.projectDir, rel);
|
|
111652
112159
|
const file = Bun.file(abs);
|
|
111653
112160
|
return { path: rel, excerpts: await file.exists() ? specExcerpts(await file.text(), sc.story.id) : [] };
|
|
111654
112161
|
} catch {
|
|
@@ -111656,7 +112163,7 @@ async function loadSpec(sc) {
|
|
|
111656
112163
|
}
|
|
111657
112164
|
}
|
|
111658
112165
|
async function redBaseDependencies(sc) {
|
|
111659
|
-
const records = await collectStoryRecords(
|
|
112166
|
+
const records = await collectStoryRecords(dirname37(sc.runDir));
|
|
111660
112167
|
return (sc.story.dependencies ?? []).map((id) => records[id]?.record).filter((r) => r?.state === "complete-gate-open").map((r) => ({ storyId: r?.storyId ?? "", reason: r?.reason ?? "gate red" }));
|
|
111661
112168
|
}
|
|
111662
112169
|
function contextFilePaths(sc) {
|
|
@@ -111729,22 +112236,22 @@ var init_brief = __esm(() => {
|
|
|
111729
112236
|
});
|
|
111730
112237
|
|
|
111731
112238
|
// src/workflow/paths.ts
|
|
111732
|
-
import { join as
|
|
112239
|
+
import { join as join137 } from "path";
|
|
111733
112240
|
function workflowFeatureDir(projectDir, feature) {
|
|
111734
|
-
return
|
|
112241
|
+
return join137(featureDir(projectDir, feature), "workflow");
|
|
111735
112242
|
}
|
|
111736
112243
|
function workflowRunDir(projectDir, feature, runId) {
|
|
111737
|
-
return
|
|
112244
|
+
return join137(workflowFeatureDir(projectDir, feature), runId);
|
|
111738
112245
|
}
|
|
111739
112246
|
function workflowStoryDir(runDir, storyId) {
|
|
111740
|
-
return
|
|
112247
|
+
return join137(runDir, storyId);
|
|
111741
112248
|
}
|
|
111742
112249
|
var init_paths5 = __esm(() => {
|
|
111743
112250
|
init_config();
|
|
111744
112251
|
});
|
|
111745
112252
|
|
|
111746
112253
|
// src/workflow/feature-context.ts
|
|
111747
|
-
import { join as
|
|
112254
|
+
import { join as join138 } from "path";
|
|
111748
112255
|
async function buildFeatureContext(input) {
|
|
111749
112256
|
const storyPackageDirs = input.prd.userStories.map(storyPackageDir);
|
|
111750
112257
|
const dispatchAsk = await _featureContextDeps2.buildRunDispatchAskWiring({
|
|
@@ -111785,8 +112292,8 @@ async function buildFeatureContext(input) {
|
|
|
111785
112292
|
outputDir: input.runtime.outputDir,
|
|
111786
112293
|
runDir,
|
|
111787
112294
|
featureDir: workflowFeatureDir(input.workdir, input.feature),
|
|
111788
|
-
prdPath:
|
|
111789
|
-
reportPath:
|
|
112295
|
+
prdPath: join138(featureDir(input.workdir, input.feature), "prd.json"),
|
|
112296
|
+
reportPath: join138(runDir, "feature-report.md"),
|
|
111790
112297
|
packageDirs: [...new Set(storyPackageDirs.filter((d) => typeof d === "string" && d !== ""))],
|
|
111791
112298
|
...input.abortSignal ? { runSignal: input.abortSignal } : {},
|
|
111792
112299
|
dryRun: input.runtime.dryRun === true
|
|
@@ -111854,7 +112361,7 @@ var init_adjudicate = __esm(() => {
|
|
|
111854
112361
|
|
|
111855
112362
|
// src/workflow/git.ts
|
|
111856
112363
|
import { mkdir as mkdir40 } from "fs/promises";
|
|
111857
|
-
import { dirname as
|
|
112364
|
+
import { dirname as dirname38, relative as relative39 } from "path";
|
|
111858
112365
|
function ledgerCommitMessage(feature) {
|
|
111859
112366
|
return `chore(${feature}): advisor decisions`;
|
|
111860
112367
|
}
|
|
@@ -111967,7 +112474,7 @@ async function writeBranchReviewPackage(projectDir, from, path) {
|
|
|
111967
112474
|
const changedSection = `## Changed files (${records.length})${lines.length > 0 ? `
|
|
111968
112475
|
${lines.join(`
|
|
111969
112476
|
`)}` : ""}`;
|
|
111970
|
-
await mkdir40(
|
|
112477
|
+
await mkdir40(dirname38(path), { recursive: true });
|
|
111971
112478
|
await Bun.write(path, `## Commits (${range})
|
|
111972
112479
|
${log.stdout.trim() || "(none)"}
|
|
111973
112480
|
|
|
@@ -111997,7 +112504,7 @@ async function writeReviewPackage(projectDir, from, path) {
|
|
|
111997
112504
|
}
|
|
111998
112505
|
const body = truncateDiff(diff.stdout, stat.stdout);
|
|
111999
112506
|
const omitted = body === diff.stdout ? "" : omittedFilesSection(names.stdout, body);
|
|
112000
|
-
await mkdir40(
|
|
112507
|
+
await mkdir40(dirname38(path), { recursive: true });
|
|
112001
112508
|
await Bun.write(path, `## Commits (${range})
|
|
112002
112509
|
${log.stdout.trim() || "(none)"}
|
|
112003
112510
|
|
|
@@ -112091,12 +112598,12 @@ var init_branch_fix = __esm(() => {
|
|
|
112091
112598
|
});
|
|
112092
112599
|
|
|
112093
112600
|
// src/workflow/review-coverage.ts
|
|
112094
|
-
function
|
|
112601
|
+
function basename24(path) {
|
|
112095
112602
|
const cut = path.lastIndexOf("/");
|
|
112096
112603
|
return cut === -1 ? path : path.slice(cut + 1);
|
|
112097
112604
|
}
|
|
112098
112605
|
function isNonSource(path) {
|
|
112099
|
-
const base =
|
|
112606
|
+
const base = basename24(path).toLowerCase();
|
|
112100
112607
|
return LOCKFILE_BASENAMES2.has(base) || NON_SOURCE_SUFFIXES.some((suffix) => base.endsWith(suffix));
|
|
112101
112608
|
}
|
|
112102
112609
|
function owningPackage(path, packageDirs) {
|
|
@@ -112165,7 +112672,7 @@ var init_review_coverage = __esm(() => {
|
|
|
112165
112672
|
});
|
|
112166
112673
|
|
|
112167
112674
|
// src/workflow/story-review.ts
|
|
112168
|
-
import { join as
|
|
112675
|
+
import { join as join139 } from "path";
|
|
112169
112676
|
async function underReviewLimit(sc, writePackage, run) {
|
|
112170
112677
|
try {
|
|
112171
112678
|
await writePackage();
|
|
@@ -112189,7 +112696,7 @@ async function underReviewLimit(sc, writePackage, run) {
|
|
|
112189
112696
|
}
|
|
112190
112697
|
async function writeVerdictSafe(sc, file, verdict) {
|
|
112191
112698
|
try {
|
|
112192
|
-
await Bun.write(
|
|
112699
|
+
await Bun.write(join139(sc.storyDir, file), `${JSON.stringify(verdict, null, 2)}
|
|
112193
112700
|
`);
|
|
112194
112701
|
} catch (err) {
|
|
112195
112702
|
getLogger2().warn("workflow", `Could not write ${file}, continuing`, {
|
|
@@ -112209,7 +112716,7 @@ async function appendReviewRules(sc, packagePath, paths) {
|
|
|
112209
112716
|
});
|
|
112210
112717
|
}
|
|
112211
112718
|
async function runStoryReview(sc, concerns, gates = {}) {
|
|
112212
|
-
const packagePath =
|
|
112719
|
+
const packagePath = join139(sc.storyDir, "package-0.diff");
|
|
112213
112720
|
const prompt = buildWorkflowStoryReviewPrompt({
|
|
112214
112721
|
briefPath: sc.briefPath,
|
|
112215
112722
|
reportPath: sc.reportPath,
|
|
@@ -112239,10 +112746,10 @@ var init_story_review = __esm(() => {
|
|
|
112239
112746
|
});
|
|
112240
112747
|
|
|
112241
112748
|
// src/workflow/branch-review.ts
|
|
112242
|
-
import { join as
|
|
112749
|
+
import { join as join140 } from "path";
|
|
112243
112750
|
async function writeFeatureArtifact(fc, name, value) {
|
|
112244
112751
|
try {
|
|
112245
|
-
await Bun.write(
|
|
112752
|
+
await Bun.write(join140(fc.runDir, name), `${JSON.stringify(value, null, 2)}
|
|
112246
112753
|
`);
|
|
112247
112754
|
} catch (err) {
|
|
112248
112755
|
getLogger2().warn("workflow", `Could not write ${name}, continuing`, { storyId: "_run", error: errorMessage(err) });
|
|
@@ -112278,7 +112785,7 @@ async function appendProjectContextOverride(fc, packagePath) {
|
|
|
112278
112785
|
await Bun.write(packagePath, `${prior}${separator}${section}`);
|
|
112279
112786
|
}
|
|
112280
112787
|
async function runBranchReview(fc, input) {
|
|
112281
|
-
const packagePath =
|
|
112788
|
+
const packagePath = join140(fc.runDir, "package-branch.diff");
|
|
112282
112789
|
const range = `${input.seed}..HEAD`;
|
|
112283
112790
|
const prompt = buildWorkflowBranchReviewPrompt({
|
|
112284
112791
|
...input.specPath ? { specPath: input.specPath } : {},
|
|
@@ -112308,7 +112815,7 @@ async function runBranchReview(fc, input) {
|
|
|
112308
112815
|
return unread.length > 0 ? { ran: true, verdict: { ...outcome.verdict, unreadFiles: unread } } : outcome;
|
|
112309
112816
|
}
|
|
112310
112817
|
async function runBranchReReview(fc, input) {
|
|
112311
|
-
const packagePath =
|
|
112818
|
+
const packagePath = join140(fc.runDir, "package-branch-fix.diff");
|
|
112312
112819
|
const prompt = buildWorkflowBranchReReviewPrompt({
|
|
112313
112820
|
...input.specPath ? { specPath: input.specPath } : {},
|
|
112314
112821
|
reportPath: fc.reportPath,
|
|
@@ -112346,12 +112853,12 @@ var init_cost_limit = __esm(() => {
|
|
|
112346
112853
|
});
|
|
112347
112854
|
|
|
112348
112855
|
// src/finish/a3-hints.ts
|
|
112349
|
-
import { join as
|
|
112856
|
+
import { join as join141 } from "path";
|
|
112350
112857
|
async function listJson(dir) {
|
|
112351
112858
|
const glob = new Bun.Glob("*.json");
|
|
112352
112859
|
const out = [];
|
|
112353
112860
|
for await (const name of glob.scan({ cwd: dir, absolute: false }))
|
|
112354
|
-
out.push(
|
|
112861
|
+
out.push(join141(dir, name));
|
|
112355
112862
|
return out.sort((a, b) => a.localeCompare(b));
|
|
112356
112863
|
}
|
|
112357
112864
|
function hintsFromRecord(raw) {
|
|
@@ -112379,7 +112886,7 @@ function hintsFromRecord(raw) {
|
|
|
112379
112886
|
return out;
|
|
112380
112887
|
}
|
|
112381
112888
|
async function readA3Hints(outputDir, feature) {
|
|
112382
|
-
const dir =
|
|
112889
|
+
const dir = join141(outputDir, "nbf-worth-check", feature);
|
|
112383
112890
|
let files;
|
|
112384
112891
|
try {
|
|
112385
112892
|
files = await _a3HintsDeps.listJson(dir);
|
|
@@ -112406,7 +112913,7 @@ var init_a3_hints = __esm(() => {
|
|
|
112406
112913
|
});
|
|
112407
112914
|
|
|
112408
112915
|
// src/finish/acceptance-evidence.ts
|
|
112409
|
-
import { basename as
|
|
112916
|
+
import { basename as basename25, extname, join as join142 } from "path";
|
|
112410
112917
|
function splitAcBlocks(text) {
|
|
112411
112918
|
const lines = text.split(`
|
|
112412
112919
|
`);
|
|
@@ -112434,7 +112941,7 @@ ${f.problem}`.matchAll(BACKTICK))
|
|
|
112434
112941
|
for (const m of f.title.matchAll(CODE_WORD))
|
|
112435
112942
|
ids.add(m[0]);
|
|
112436
112943
|
if (f.file) {
|
|
112437
|
-
const base =
|
|
112944
|
+
const base = basename25(f.file, extname(f.file));
|
|
112438
112945
|
if (!GENERIC_BASENAMES.has(base))
|
|
112439
112946
|
ids.add(base);
|
|
112440
112947
|
}
|
|
@@ -112455,7 +112962,7 @@ function findPinnedAcs(files, f) {
|
|
|
112455
112962
|
return scored.filter((p) => p.score >= 1).sort((a, b) => b.score - a.score).slice(0, MAX_PINNED_BLOCKS);
|
|
112456
112963
|
}
|
|
112457
112964
|
async function loadAcceptanceFiles(workdir, paths) {
|
|
112458
|
-
const texts = await Promise.all(paths.map((p) => _acceptanceEvidenceDeps.readText(
|
|
112965
|
+
const texts = await Promise.all(paths.map((p) => _acceptanceEvidenceDeps.readText(join142(workdir, p))));
|
|
112459
112966
|
return paths.flatMap((path, i) => {
|
|
112460
112967
|
const text = texts[i];
|
|
112461
112968
|
return typeof text === "string" ? [{ path, text }] : [];
|
|
@@ -112474,17 +112981,17 @@ var init_acceptance_evidence = __esm(() => {
|
|
|
112474
112981
|
|
|
112475
112982
|
// src/finish/safe-path.ts
|
|
112476
112983
|
import { realpath as realpath5 } from "fs/promises";
|
|
112477
|
-
import { basename as
|
|
112984
|
+
import { basename as basename26, dirname as dirname39, join as join143, relative as relative40, sep as sep24 } from "path";
|
|
112478
112985
|
async function insideRoot(root, target) {
|
|
112479
112986
|
const realRoot = await realpath5(root).catch(() => null);
|
|
112480
112987
|
if (realRoot === null)
|
|
112481
112988
|
return false;
|
|
112482
|
-
let dir =
|
|
112989
|
+
let dir = dirname39(target);
|
|
112483
112990
|
for (;; ) {
|
|
112484
112991
|
const real = await realpath5(dir).catch(() => null);
|
|
112485
112992
|
if (real !== null)
|
|
112486
112993
|
return real === realRoot || real.startsWith(realRoot + sep24);
|
|
112487
|
-
const up =
|
|
112994
|
+
const up = dirname39(dir);
|
|
112488
112995
|
if (up === dir)
|
|
112489
112996
|
return false;
|
|
112490
112997
|
dir = up;
|
|
@@ -112494,8 +113001,8 @@ async function realpathLoose(target) {
|
|
|
112494
113001
|
const real = await realpath5(target).catch(() => null);
|
|
112495
113002
|
if (real !== null)
|
|
112496
113003
|
return real;
|
|
112497
|
-
const up =
|
|
112498
|
-
return up === target ? target :
|
|
113004
|
+
const up = dirname39(target);
|
|
113005
|
+
return up === target ? target : join143(await realpathLoose(up), basename26(target));
|
|
112499
113006
|
}
|
|
112500
113007
|
async function relativeInsideRoot(root, dir) {
|
|
112501
113008
|
const [realRoot, realDir] = await Promise.all([realpathLoose(root), realpathLoose(dir)]);
|
|
@@ -112647,7 +113154,7 @@ var init_set_aside_git = __esm(() => {
|
|
|
112647
113154
|
});
|
|
112648
113155
|
|
|
112649
113156
|
// src/finish/acceptance-guard.ts
|
|
112650
|
-
import { join as
|
|
113157
|
+
import { join as join144 } from "path";
|
|
112651
113158
|
function acceptancePathsOf(context) {
|
|
112652
113159
|
if (context.acceptanceStatus === "disabled")
|
|
112653
113160
|
return [];
|
|
@@ -112676,7 +113183,7 @@ function changedAcs(before, after) {
|
|
|
112676
113183
|
}
|
|
112677
113184
|
async function acsChangedIn(root, path) {
|
|
112678
113185
|
const head = await gitLiteral(["show", `HEAD:${path}`], root);
|
|
112679
|
-
const after = await _guardDeps.readText(
|
|
113186
|
+
const after = await _guardDeps.readText(join144(root, path));
|
|
112680
113187
|
return changedAcs(head.exitCode === 0 ? head.stdout : "", after ?? "");
|
|
112681
113188
|
}
|
|
112682
113189
|
async function restoreFromHead(root, paths) {
|
|
@@ -113480,15 +113987,15 @@ var init_advise2 = __esm(() => {
|
|
|
113480
113987
|
|
|
113481
113988
|
// src/finish/audit.ts
|
|
113482
113989
|
import { appendFile as appendFile10, mkdir as mkdir41, readFile as readFile11, writeFile as writeFile13 } from "fs/promises";
|
|
113483
|
-
import { join as
|
|
113990
|
+
import { join as join145 } from "path";
|
|
113484
113991
|
function roundsPath(t) {
|
|
113485
|
-
return
|
|
113992
|
+
return join145(t.auditDir, `${t.runId}.jsonl`);
|
|
113486
113993
|
}
|
|
113487
113994
|
function resultPath(t) {
|
|
113488
|
-
return
|
|
113995
|
+
return join145(t.auditDir, `${t.runId}.result.json`);
|
|
113489
113996
|
}
|
|
113490
113997
|
function ledgerPath2(auditDir) {
|
|
113491
|
-
return
|
|
113998
|
+
return join145(auditDir, "last.json");
|
|
113492
113999
|
}
|
|
113493
114000
|
async function updateLedger(t, result) {
|
|
113494
114001
|
if (!result.headSha || !result.branch)
|
|
@@ -113647,13 +114154,13 @@ var init_state = __esm(() => {
|
|
|
113647
114154
|
|
|
113648
114155
|
// src/finish/checkpoint.ts
|
|
113649
114156
|
import { mkdir as mkdir42, rename as rename13, rm as rm11, writeFile as writeFile14 } from "fs/promises";
|
|
113650
|
-
import { join as
|
|
114157
|
+
import { join as join146 } from "path";
|
|
113651
114158
|
function checkpointPath(audit) {
|
|
113652
|
-
return
|
|
114159
|
+
return join146(audit.auditDir, `${audit.runId}.checkpoint.json`);
|
|
113653
114160
|
}
|
|
113654
114161
|
async function writeCheckpoint(audit, state) {
|
|
113655
114162
|
const target = checkpointPath(audit);
|
|
113656
|
-
const tmp =
|
|
114163
|
+
const tmp = join146(audit.auditDir, `${audit.runId}.checkpoint.${_checkpointDeps.uniqueId()}.tmp`);
|
|
113657
114164
|
try {
|
|
113658
114165
|
const text = serializeFinishState(state);
|
|
113659
114166
|
await _checkpointDeps.mkdir(audit.auditDir);
|
|
@@ -114406,13 +114913,13 @@ function settleAll(handoffs, n) {
|
|
|
114406
114913
|
var restorePending = (h) => !h.restored && h.settledBy === undefined, restorePendingNumbers = (handoffs) => handoffs.filter(restorePending).map((h) => h.n);
|
|
114407
114914
|
|
|
114408
114915
|
// src/finish/untracked-snapshot.ts
|
|
114409
|
-
import { chmod as chmod2, copyFile, lstat as
|
|
114410
|
-
import { dirname as
|
|
114916
|
+
import { chmod as chmod2, copyFile, lstat as lstat6, mkdir as mkdir43, realpath as realpath6, rm as rm12, unlink as unlink8 } from "fs/promises";
|
|
114917
|
+
import { dirname as dirname40, join as join148, relative as relative42, resolve as resolve46, sep as sep25 } from "path";
|
|
114411
114918
|
async function copyFileInto(src, dest, ownerOnly = false) {
|
|
114412
114919
|
try {
|
|
114413
|
-
if (!(await
|
|
114920
|
+
if (!(await lstat6(src)).isFile())
|
|
114414
114921
|
return false;
|
|
114415
|
-
await mkdir43(
|
|
114922
|
+
await mkdir43(dirname40(dest), ownerOnly ? { recursive: true, mode: PRIVATE_DIR } : { recursive: true });
|
|
114416
114923
|
await copyFile(src, dest);
|
|
114417
114924
|
if (ownerOnly)
|
|
114418
114925
|
await chmod2(dest, PRIVATE_FILE);
|
|
@@ -114423,9 +114930,9 @@ async function copyFileInto(src, dest, ownerOnly = false) {
|
|
|
114423
114930
|
}
|
|
114424
114931
|
async function privateDirs(top, dir) {
|
|
114425
114932
|
await mkdir43(dir, { recursive: true, mode: PRIVATE_DIR });
|
|
114426
|
-
for (let d = dir;; d =
|
|
114933
|
+
for (let d = dir;; d = dirname40(d)) {
|
|
114427
114934
|
await chmod2(d, PRIVATE_DIR);
|
|
114428
|
-
if (d === top ||
|
|
114935
|
+
if (d === top || dirname40(d) === d)
|
|
114429
114936
|
return;
|
|
114430
114937
|
}
|
|
114431
114938
|
}
|
|
@@ -114452,16 +114959,16 @@ async function snapshotUntracked(workdir, paths, dir) {
|
|
|
114452
114959
|
await rm12(dir, { recursive: true, force: true }).catch(() => {
|
|
114453
114960
|
return;
|
|
114454
114961
|
});
|
|
114455
|
-
await privateDirs(
|
|
114962
|
+
await privateDirs(dirname40(dir), dir);
|
|
114456
114963
|
const { fileMax, totalMax } = _setAsideDeps.limits;
|
|
114457
114964
|
const files = [];
|
|
114458
114965
|
let total = 0;
|
|
114459
114966
|
for (const path of paths) {
|
|
114460
|
-
const st = await
|
|
114967
|
+
const st = await lstat6(join148(root, path)).catch(() => null);
|
|
114461
114968
|
if (!st?.isFile())
|
|
114462
114969
|
continue;
|
|
114463
114970
|
const fits = st.size <= fileMax && total + st.size <= totalMax;
|
|
114464
|
-
const saved = fits && await copyFileInto(
|
|
114971
|
+
const saved = fits && await copyFileInto(join148(root, path), join148(dir, path), true);
|
|
114465
114972
|
if (saved)
|
|
114466
114973
|
total += st.size;
|
|
114467
114974
|
files.push({ path, size: st.size, mtimeMs: st.mtimeMs, mode: st.mode & 511, saved });
|
|
@@ -114475,7 +114982,7 @@ async function putBack(root, from, dest, mode) {
|
|
|
114475
114982
|
try {
|
|
114476
114983
|
if (!await insideRoot(root, dest))
|
|
114477
114984
|
return false;
|
|
114478
|
-
const st = await
|
|
114985
|
+
const st = await lstat6(dest).catch(() => null);
|
|
114479
114986
|
if (st && !st.isFile())
|
|
114480
114987
|
await unlink8(dest);
|
|
114481
114988
|
const copied = await copyFileInto(from, dest);
|
|
@@ -114490,18 +114997,18 @@ async function restoreUntracked(workdir, snapshot, handoffPath) {
|
|
|
114490
114997
|
const out = { restored: [], movedAside: [], failed: [] };
|
|
114491
114998
|
const root = await repoRoot(workdir);
|
|
114492
114999
|
for (const e of snapshot?.files ?? []) {
|
|
114493
|
-
const file =
|
|
115000
|
+
const file = join148(root, e.path);
|
|
114494
115001
|
if (!await insideRoot(root, file)) {
|
|
114495
115002
|
out.failed.push(e.path);
|
|
114496
115003
|
continue;
|
|
114497
115004
|
}
|
|
114498
|
-
const st = await
|
|
115005
|
+
const st = await lstat6(file).catch(() => null);
|
|
114499
115006
|
if (unchanged(st, e))
|
|
114500
115007
|
continue;
|
|
114501
|
-
const kept = !st?.isFile() || await copyFileInto(file,
|
|
115008
|
+
const kept = !st?.isFile() || await copyFileInto(file, join148(handoffPath, "untracked-modified", e.path), true);
|
|
114502
115009
|
if (!kept) {
|
|
114503
115010
|
out.failed.push(e.path);
|
|
114504
|
-
} else if (e.saved && snapshot && await putBack(root,
|
|
115011
|
+
} else if (e.saved && snapshot && await putBack(root, join148(snapshot.dir, e.path), file, e.mode)) {
|
|
114505
115012
|
out.restored.push(e.path);
|
|
114506
115013
|
} else if (!e.saved && st) {
|
|
114507
115014
|
const removed = await _setAsideDeps.remove(file).then(() => true, () => false);
|
|
@@ -114524,10 +115031,10 @@ var init_untracked_snapshot = __esm(() => {
|
|
|
114524
115031
|
});
|
|
114525
115032
|
|
|
114526
115033
|
// src/finish/set-aside.ts
|
|
114527
|
-
import { lstat as
|
|
114528
|
-
import { join as
|
|
115034
|
+
import { lstat as lstat7, mkdir as mkdir44, readFile as readFile12, writeFile as writeFile15 } from "fs/promises";
|
|
115035
|
+
import { join as join149 } from "path";
|
|
114529
115036
|
function handoffDir(audit, n) {
|
|
114530
|
-
return
|
|
115037
|
+
return join149(audit.auditDir, `${audit.runId}.handoff-${n}`);
|
|
114531
115038
|
}
|
|
114532
115039
|
function warn2(message, err) {
|
|
114533
115040
|
getSafeLogger2()?.warn("finish", message, { storyId: "_run", error: errorMessage(err) });
|
|
@@ -114565,7 +115072,7 @@ async function dropIntent(root, created) {
|
|
|
114565
115072
|
async function savePatch(root, dir, baseSha, created) {
|
|
114566
115073
|
await addIntent(root, created);
|
|
114567
115074
|
try {
|
|
114568
|
-
const diff = await git3(["diff", "--binary", "--no-renames", `--output=${
|
|
115075
|
+
const diff = await git3(["diff", "--binary", "--no-renames", `--output=${join149(dir, PATCH)}`, baseSha], root);
|
|
114569
115076
|
return diff.exitCode === 0;
|
|
114570
115077
|
} finally {
|
|
114571
115078
|
await dropIntent(root, created).catch(() => {
|
|
@@ -114582,10 +115089,10 @@ async function restoreKnown(root, baseSha, inBase) {
|
|
|
114582
115089
|
return ok;
|
|
114583
115090
|
}
|
|
114584
115091
|
async function removeEntry(root, rel) {
|
|
114585
|
-
const file =
|
|
115092
|
+
const file = join149(root, rel);
|
|
114586
115093
|
if (!await insideRoot(root, file))
|
|
114587
115094
|
return false;
|
|
114588
|
-
if (!await
|
|
115095
|
+
if (!await lstat7(file).catch(() => null))
|
|
114589
115096
|
return true;
|
|
114590
115097
|
return _setAsideDeps.remove(file).then(() => true, () => false);
|
|
114591
115098
|
}
|
|
@@ -114605,7 +115112,7 @@ async function restorePaths(root, base, tracked, created) {
|
|
|
114605
115112
|
return ok;
|
|
114606
115113
|
}
|
|
114607
115114
|
async function writeMeta(record) {
|
|
114608
|
-
await writeFile15(
|
|
115115
|
+
await writeFile15(join149(record.dir, META), `${JSON.stringify(record, null, 2)}
|
|
114609
115116
|
`, "utf8");
|
|
114610
115117
|
}
|
|
114611
115118
|
function newRecord(args, dir, created, changedPaths) {
|
|
@@ -114634,7 +115141,7 @@ async function saveWork(args, root, record) {
|
|
|
114634
115141
|
try {
|
|
114635
115142
|
await mkdir44(record.dir, { recursive: true });
|
|
114636
115143
|
if (args.note) {
|
|
114637
|
-
await writeFile15(
|
|
115144
|
+
await writeFile15(join149(record.dir, NOTE), `${JSON.stringify(args.note, null, 2)}
|
|
114638
115145
|
`, "utf8");
|
|
114639
115146
|
record.hasNote = true;
|
|
114640
115147
|
}
|
|
@@ -114688,7 +115195,7 @@ async function setAside(input) {
|
|
|
114688
115195
|
async function readHandoffNote(record) {
|
|
114689
115196
|
if (!record.hasNote)
|
|
114690
115197
|
return;
|
|
114691
|
-
const text = await readFile12(
|
|
115198
|
+
const text = await readFile12(join149(record.dir, NOTE), "utf8").catch(() => null);
|
|
114692
115199
|
const parsed = text ? tryParseLLMJson(text) : null;
|
|
114693
115200
|
return isHandoffNote(parsed) ? parsed : undefined;
|
|
114694
115201
|
}
|
|
@@ -114696,7 +115203,7 @@ async function reapplyHandoff(workdir, record) {
|
|
|
114696
115203
|
if (!record.patchSaved)
|
|
114697
115204
|
return { applied: false, files: [] };
|
|
114698
115205
|
const root = await repoRoot(workdir);
|
|
114699
|
-
const patch =
|
|
115206
|
+
const patch = join149(record.dir, PATCH);
|
|
114700
115207
|
const check = await git3(["apply", "--check", "--whitespace=nowarn", patch], root);
|
|
114701
115208
|
if (check.exitCode !== 0)
|
|
114702
115209
|
return { applied: false, files: [] };
|
|
@@ -114793,7 +115300,7 @@ var init_finalize_dirt = __esm(() => {
|
|
|
114793
115300
|
});
|
|
114794
115301
|
|
|
114795
115302
|
// src/finish/fix-step.ts
|
|
114796
|
-
import { join as
|
|
115303
|
+
import { join as join150 } from "path";
|
|
114797
115304
|
function findingIdsOf(findings) {
|
|
114798
115305
|
return (findings ?? []).map(findingId);
|
|
114799
115306
|
}
|
|
@@ -114864,7 +115371,7 @@ async function captureBase(state, deps) {
|
|
|
114864
115371
|
if (!captured) {
|
|
114865
115372
|
return { error: new NaxError("Cannot read the worktree base", "FINISH_FIX_BASE", { stage: "finish" }) };
|
|
114866
115373
|
}
|
|
114867
|
-
const snapshotDir =
|
|
115374
|
+
const snapshotDir = join150(deps.audit.auditDir, `${deps.audit.runId}.fix-base-${state.handoffs.length + 1}`);
|
|
114868
115375
|
return {
|
|
114869
115376
|
...captured,
|
|
114870
115377
|
untrackedSnapshot: await snapshotUntracked(state.workdir, captured.untrackedBefore, snapshotDir)
|
|
@@ -115640,8 +116147,8 @@ var init_gates_loop = __esm(() => {
|
|
|
115640
116147
|
});
|
|
115641
116148
|
|
|
115642
116149
|
// src/finish/review-inputs.ts
|
|
115643
|
-
import { join as
|
|
115644
|
-
function
|
|
116150
|
+
import { join as join151, relative as relative43 } from "path";
|
|
116151
|
+
function isRecord13(value) {
|
|
115645
116152
|
return typeof value === "object" && value !== null;
|
|
115646
116153
|
}
|
|
115647
116154
|
function storiesFromText(text) {
|
|
@@ -115653,13 +116160,13 @@ function storiesFromText(text) {
|
|
|
115653
116160
|
} catch {
|
|
115654
116161
|
return [];
|
|
115655
116162
|
}
|
|
115656
|
-
const rows =
|
|
116163
|
+
const rows = isRecord13(parsed) ? parsed.userStories : undefined;
|
|
115657
116164
|
if (!Array.isArray(rows))
|
|
115658
116165
|
return [];
|
|
115659
|
-
return rows.flatMap((row) =>
|
|
116166
|
+
return rows.flatMap((row) => isRecord13(row) && typeof row.id === "string" && typeof row.title === "string" ? [{ id: row.id, title: row.title }] : []);
|
|
115660
116167
|
}
|
|
115661
116168
|
async function loadReviewInputs(state, outputDir) {
|
|
115662
|
-
const prdAbs =
|
|
116169
|
+
const prdAbs = join151(featureDir(state.workdir, state.feature), "prd.json");
|
|
115663
116170
|
const [changed, hints, prdText] = await Promise.all([
|
|
115664
116171
|
changedFiles(state.workdir, state.base),
|
|
115665
116172
|
outputDir ? readA3Hints(outputDir, state.feature) : Promise.resolve([]),
|
|
@@ -116565,7 +117072,7 @@ var init_narrative = __esm(() => {
|
|
|
116565
117072
|
|
|
116566
117073
|
// src/finish/pr/context.ts
|
|
116567
117074
|
import { readFile as readFile13 } from "fs/promises";
|
|
116568
|
-
import { join as
|
|
117075
|
+
import { join as join152 } from "path";
|
|
116569
117076
|
async function readJson(path) {
|
|
116570
117077
|
let text;
|
|
116571
117078
|
try {
|
|
@@ -116652,8 +117159,8 @@ function fromResolution(state) {
|
|
|
116652
117159
|
async function loadFinishPrContext(args) {
|
|
116653
117160
|
const featureDirPath = featureDir(args.state.workdir, args.state.feature);
|
|
116654
117161
|
const [prd, status, rounds, stat, template, specSummary, advisorDecisions] = await Promise.all([
|
|
116655
|
-
readJson(
|
|
116656
|
-
readJson(
|
|
117162
|
+
readJson(join152(featureDirPath, "prd.json")),
|
|
117163
|
+
readJson(join152(featureDirPath, "status.json")),
|
|
116657
117164
|
readRounds(args.audit),
|
|
116658
117165
|
runDiffstat(args.state.workdir, args.state.base),
|
|
116659
117166
|
loadTemplate(args.state.workdir, args.forge),
|
|
@@ -117629,7 +118136,7 @@ var init_closing_issues = __esm(() => {
|
|
|
117629
118136
|
});
|
|
117630
118137
|
|
|
117631
118138
|
// src/workflow/ci-wait.ts
|
|
117632
|
-
function
|
|
118139
|
+
function isRecord14(v) {
|
|
117633
118140
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
117634
118141
|
}
|
|
117635
118142
|
function parseJson2(stdout) {
|
|
@@ -117644,8 +118151,8 @@ function cliError(r) {
|
|
|
117644
118151
|
}
|
|
117645
118152
|
function ghChecks(value) {
|
|
117646
118153
|
return value.map((c) => ({
|
|
117647
|
-
name:
|
|
117648
|
-
bucket:
|
|
118154
|
+
name: isRecord14(c) && typeof c.name === "string" ? c.name : "",
|
|
118155
|
+
bucket: isRecord14(c) && typeof c.bucket === "string" ? c.bucket : "pending"
|
|
117649
118156
|
}));
|
|
117650
118157
|
}
|
|
117651
118158
|
function ghSummary(checks) {
|
|
@@ -117675,18 +118182,18 @@ function classifyGh(r) {
|
|
|
117675
118182
|
function glabPipelineSha(mr) {
|
|
117676
118183
|
const head = mr.head_pipeline;
|
|
117677
118184
|
const fallback = mr.pipeline;
|
|
117678
|
-
const sha = (
|
|
118185
|
+
const sha = (isRecord14(head) ? head.sha : undefined) ?? (isRecord14(fallback) ? fallback.sha : undefined);
|
|
117679
118186
|
return typeof sha === "string" ? sha : undefined;
|
|
117680
118187
|
}
|
|
117681
118188
|
function classifyGlab(r) {
|
|
117682
118189
|
if (r.exitCode !== 0)
|
|
117683
118190
|
return cliError(r);
|
|
117684
118191
|
const parsed = parseJson2(r.stdout.trim());
|
|
117685
|
-
if (!parsed.ok || !
|
|
118192
|
+
if (!parsed.ok || !isRecord14(parsed.value)) {
|
|
117686
118193
|
return { state: "error", detail: `unparseable glab output: ${r.stdout.slice(0, 200)}` };
|
|
117687
118194
|
}
|
|
117688
118195
|
const pipeline = parsed.value.head_pipeline ?? parsed.value.pipeline;
|
|
117689
|
-
const status =
|
|
118196
|
+
const status = isRecord14(pipeline) && typeof pipeline.status === "string" ? pipeline.status : undefined;
|
|
117690
118197
|
if (status === undefined)
|
|
117691
118198
|
return glabWaiting(parsed.value);
|
|
117692
118199
|
const summary = `CI pipeline: ${status}`;
|
|
@@ -117717,7 +118224,7 @@ async function githubWaiting(poll, prRef, cwd) {
|
|
|
117717
118224
|
if (r.exitCode !== 0)
|
|
117718
118225
|
return poll;
|
|
117719
118226
|
const parsed = parseJson2(r.stdout);
|
|
117720
|
-
if (!parsed.ok || !
|
|
118227
|
+
if (!parsed.ok || !isRecord14(parsed.value))
|
|
117721
118228
|
return poll;
|
|
117722
118229
|
const mr = parsed.value;
|
|
117723
118230
|
if (mr.mergeable === "CONFLICTING" || mr.mergeStateStatus === "DIRTY")
|
|
@@ -118116,7 +118623,7 @@ var init_pr_body = __esm(() => {
|
|
|
118116
118623
|
});
|
|
118117
118624
|
|
|
118118
118625
|
// src/workflow/finalize.ts
|
|
118119
|
-
import { isAbsolute as isAbsolute33, join as
|
|
118626
|
+
import { isAbsolute as isAbsolute33, join as join153 } from "path";
|
|
118120
118627
|
function ciDetailFields(ci) {
|
|
118121
118628
|
return DETAILED_CI_STATES.has(ci.outcome) ? { ciDetail: ci.detail } : {};
|
|
118122
118629
|
}
|
|
@@ -118169,7 +118676,7 @@ async function loadAssumptions(stories) {
|
|
|
118169
118676
|
if (!s.runDir)
|
|
118170
118677
|
continue;
|
|
118171
118678
|
try {
|
|
118172
|
-
const file = Bun.file(
|
|
118679
|
+
const file = Bun.file(join153(workflowStoryDir(s.runDir, s.id), "report.md"));
|
|
118173
118680
|
const text = await file.exists() ? extractAssumptions(await file.text()) : "";
|
|
118174
118681
|
if (text)
|
|
118175
118682
|
out.push({ storyId: s.id, text });
|
|
@@ -118182,7 +118689,7 @@ async function specClosingIssues(fc) {
|
|
|
118182
118689
|
const rel = (await _workflowDeps.resolveFeatureSpec(fc.feature, fc.projectDir)).specSource?.path;
|
|
118183
118690
|
if (!rel)
|
|
118184
118691
|
return;
|
|
118185
|
-
const abs = isAbsolute33(rel) ? rel :
|
|
118692
|
+
const abs = isAbsolute33(rel) ? rel : join153(fc.projectDir, rel);
|
|
118186
118693
|
const closes = parseClosingIssues(await Bun.file(abs).text());
|
|
118187
118694
|
return closes.length > 0 ? closes : undefined;
|
|
118188
118695
|
} catch {
|
|
@@ -118779,8 +119286,8 @@ var init_tokens = __esm(() => {
|
|
|
118779
119286
|
});
|
|
118780
119287
|
|
|
118781
119288
|
// src/workflow/tool-error-outcome.ts
|
|
118782
|
-
import { readdir as
|
|
118783
|
-
import { join as
|
|
119289
|
+
import { readdir as readdir12, readFile as readFile14 } from "fs/promises";
|
|
119290
|
+
import { join as join154 } from "path";
|
|
118784
119291
|
function targetOf(row) {
|
|
118785
119292
|
for (const field of TARGET_FIELDS) {
|
|
118786
119293
|
const value = row.input?.[field];
|
|
@@ -118829,7 +119336,7 @@ async function readToolEntriesSince(scope, sinceMs) {
|
|
|
118829
119336
|
const prefix = `${scope.runId}-`;
|
|
118830
119337
|
let names;
|
|
118831
119338
|
try {
|
|
118832
|
-
names = await
|
|
119339
|
+
names = await readdir12(dir);
|
|
118833
119340
|
} catch {
|
|
118834
119341
|
return [];
|
|
118835
119342
|
}
|
|
@@ -118837,7 +119344,7 @@ async function readToolEntriesSince(scope, sinceMs) {
|
|
|
118837
119344
|
const entries = [];
|
|
118838
119345
|
for (const { name, stamp } of stamped) {
|
|
118839
119346
|
try {
|
|
118840
|
-
const body = JSON.parse(await readFile14(
|
|
119347
|
+
const body = JSON.parse(await readFile14(join154(dir, name), "utf8"));
|
|
118841
119348
|
for (const [index, row] of (body.calls ?? []).entries()) {
|
|
118842
119349
|
entries.push({ key: `${name}#${index}`, row, fileStamp: stamp });
|
|
118843
119350
|
}
|
|
@@ -119028,6 +119535,35 @@ var init_branch_fix_rounds = __esm(() => {
|
|
|
119028
119535
|
NONE4 = { targets: [], notes: [] };
|
|
119029
119536
|
});
|
|
119030
119537
|
|
|
119538
|
+
// src/workflow/gate-timing.ts
|
|
119539
|
+
function isGateTimingItem(text) {
|
|
119540
|
+
const body = text.replace(ZERO_FAIL, "");
|
|
119541
|
+
return NAX_GATE.test(body) && NOT_YET.test(body) && !EVIDENCE2.test(body) && !EVIDENCE_CODES.test(body);
|
|
119542
|
+
}
|
|
119543
|
+
function splitGateTimingItems(items) {
|
|
119544
|
+
return {
|
|
119545
|
+
kept: items.filter((item) => !isGateTimingItem(item)),
|
|
119546
|
+
dropped: items.filter(isGateTimingItem)
|
|
119547
|
+
};
|
|
119548
|
+
}
|
|
119549
|
+
async function ledgerCannotVerify(sink, items) {
|
|
119550
|
+
const { kept, dropped } = splitGateTimingItems(items);
|
|
119551
|
+
for (const item of kept)
|
|
119552
|
+
await sink.ledger(ledgerText.note(`cannot-verify: ${item}`));
|
|
119553
|
+
for (const item of dropped)
|
|
119554
|
+
await sink.ledger(ledgerText.note(`cannot-verify dropped (a nax gate covers it): ${item}`));
|
|
119555
|
+
return kept;
|
|
119556
|
+
}
|
|
119557
|
+
var NAX_GATE, NOT_YET, EVIDENCE2, EVIDENCE_CODES, ZERO_FAIL;
|
|
119558
|
+
var init_gate_timing = __esm(() => {
|
|
119559
|
+
init_ledger2();
|
|
119560
|
+
NAX_GATE = /\b(full(?:[- ]package)?(?:[- ]test)?[- ]suite|repo(?:sitory)?(?:-wide|-level)?[- ]gates?)\b/i;
|
|
119561
|
+
NOT_YET = /\b(after (?:this |the )?review|runs? after|runs? only after|not (?:yet )?(?:been )?run|has(?: not|n't) run|have(?: not|n't) run|had not run|not (?:yet )?(?:been )?reached|never reached|not yet|once every story|after all stories|post-review)\b/i;
|
|
119562
|
+
EVIDENCE2 = /(\bexit(?:ed|s)?(?: code)?\s*[=:]?\s*[1-9]|\bfail|\bneeds?\b|\brequires?\b|\bdepends? on|\bonly (?:on|in|with)\b|\bskip|\btodo\b|\bcredential|\bbrowser|\bsandbox|\bpostgres|\bdocker|\bdatabase|\bdb-|\bintegration\b|\brefused|\berror|\btime(?:d)? ?out|\bpre-existing|\bunrelated|\d+(?:\.\d+)?%|\blive\b|\bnetwork|\bblocked|\babort|coverage)/i;
|
|
119563
|
+
EVIDENCE_CODES = /\b(?:E[A-Z]{3,}|PG|CI)\b/;
|
|
119564
|
+
ZERO_FAIL = /\b0 fail(?:ed|ures?|s)?\b/gi;
|
|
119565
|
+
});
|
|
119566
|
+
|
|
119031
119567
|
// src/workflow/re-review-absorb.ts
|
|
119032
119568
|
function withResidual(finding, residual) {
|
|
119033
119569
|
const { observed: _observed, file, line, suggestion, ...kept } = finding;
|
|
@@ -119194,8 +119730,7 @@ async function branchReviewStep(env, rec) {
|
|
|
119194
119730
|
await env.sink.ledger(ledgerText.reviewSkipped(`branch review: ${out.why}`), NO_MIRROR);
|
|
119195
119731
|
return { reviewRan: false, step: "branch-fix" };
|
|
119196
119732
|
}
|
|
119197
|
-
|
|
119198
|
-
await env.sink.ledger(ledgerText.note(`cannot-verify: ${item}`));
|
|
119733
|
+
const cannotVerify = await ledgerCannotVerify(env.sink, out.verdict.cannotVerify);
|
|
119199
119734
|
const unread = out.verdict.unreadFiles ?? [];
|
|
119200
119735
|
if (unread.length > 0)
|
|
119201
119736
|
await env.sink.ledger(ledgerText.note(describeUnread(unread)));
|
|
@@ -119204,11 +119739,11 @@ async function branchReviewStep(env, rec) {
|
|
|
119204
119739
|
await noteRestated(env, restated.dropped);
|
|
119205
119740
|
const { findings, nextFindingId } = assign(rec, withQualityFloor(out.verdict));
|
|
119206
119741
|
const minors = out.verdict.findings.filter((f) => !isBlocking(f));
|
|
119207
|
-
await env.sink.artifact("branch-review.json", { ...out.verdict, findings: [...findings, ...minors] });
|
|
119742
|
+
await env.sink.artifact("branch-review.json", { ...out.verdict, cannotVerify, findings: [...findings, ...minors] });
|
|
119208
119743
|
log.done(`spec ${out.verdict.spec}, quality ${out.verdict.quality} - ${describeFindings([...findings, ...minors])}`);
|
|
119209
119744
|
return {
|
|
119210
119745
|
reviewRan: true,
|
|
119211
|
-
cannotVerify
|
|
119746
|
+
cannotVerify,
|
|
119212
119747
|
...unread.length > 0 ? { reviewUnread: unread } : {},
|
|
119213
119748
|
reviewOpen: findings,
|
|
119214
119749
|
nextFindingId,
|
|
@@ -119467,6 +120002,7 @@ var init_feature_machine = __esm(() => {
|
|
|
119467
120002
|
init_advisor_live();
|
|
119468
120003
|
init_approval();
|
|
119469
120004
|
init_branch_fix_rounds();
|
|
120005
|
+
init_gate_timing();
|
|
119470
120006
|
init_ledger2();
|
|
119471
120007
|
init_restated_minors();
|
|
119472
120008
|
init_run_log();
|
|
@@ -120150,9 +120686,9 @@ var init_no_work = __esm(() => {
|
|
|
120150
120686
|
});
|
|
120151
120687
|
|
|
120152
120688
|
// src/workflow/re-review.ts
|
|
120153
|
-
import { join as
|
|
120689
|
+
import { join as join155 } from "path";
|
|
120154
120690
|
async function runReReview(sc, round, findings, fixBase) {
|
|
120155
|
-
const packagePath =
|
|
120691
|
+
const packagePath = join155(sc.storyDir, `package-${round}.diff`);
|
|
120156
120692
|
const prompt = buildWorkflowReReviewPrompt({
|
|
120157
120693
|
briefPath: sc.briefPath,
|
|
120158
120694
|
reportPath: sc.reportPath,
|
|
@@ -120289,8 +120825,7 @@ async function review(env, s) {
|
|
|
120289
120825
|
await env.sink.ledger(ledgerText.reviewSkipped(`story review: ${out.why}`), NO_MIRROR2);
|
|
120290
120826
|
return;
|
|
120291
120827
|
}
|
|
120292
|
-
|
|
120293
|
-
await env.sink.ledger(ledgerText.note(`cannot-verify: ${item}`));
|
|
120828
|
+
await ledgerCannotVerify(env.sink, out.verdict.cannotVerify);
|
|
120294
120829
|
await deferMinors(env, s, out.verdict.findings);
|
|
120295
120830
|
s.reviewOpen = s.assign(out.verdict.findings.filter(isBlocking2));
|
|
120296
120831
|
const minors = out.verdict.findings.filter((f) => !isBlocking2(f));
|
|
@@ -120444,6 +120979,7 @@ var WARM_ROUND_CAP = 3, MAX_IMPLEMENTER_QUESTIONS = 2, NO_MIRROR2, isBlocking2 =
|
|
|
120444
120979
|
var init_story_loop = __esm(() => {
|
|
120445
120980
|
init_adjudicate();
|
|
120446
120981
|
init_advisor3();
|
|
120982
|
+
init_gate_timing();
|
|
120447
120983
|
init_ledger2();
|
|
120448
120984
|
init_no_work();
|
|
120449
120985
|
init_run_log();
|
|
@@ -120451,7 +120987,7 @@ var init_story_loop = __esm(() => {
|
|
|
120451
120987
|
});
|
|
120452
120988
|
|
|
120453
120989
|
// src/workflow/stage-env.ts
|
|
120454
|
-
import { join as
|
|
120990
|
+
import { join as join156 } from "path";
|
|
120455
120991
|
function timed(name, add, fn) {
|
|
120456
120992
|
return async (...args) => {
|
|
120457
120993
|
const start = _workflowDeps.now();
|
|
@@ -120485,8 +121021,8 @@ async function buildStoryEnv(ctx, callCtx) {
|
|
|
120485
121021
|
runDir,
|
|
120486
121022
|
outputDir,
|
|
120487
121023
|
storyDir,
|
|
120488
|
-
briefPath:
|
|
120489
|
-
reportPath:
|
|
121024
|
+
briefPath: join156(storyDir, "brief.md"),
|
|
121025
|
+
reportPath: join156(storyDir, "report.md"),
|
|
120490
121026
|
base,
|
|
120491
121027
|
runSignal: ctx.abortSignal,
|
|
120492
121028
|
sessionManager: ctx.sessionManager,
|
|
@@ -120593,10 +121129,10 @@ function resumablePrior(prior, storyId) {
|
|
|
120593
121129
|
}
|
|
120594
121130
|
async function carryOverArtifacts(priorStoryDir, storyDir, storyId) {
|
|
120595
121131
|
for (const name of ["brief.md", "report.md"]) {
|
|
120596
|
-
const src = Bun.file(
|
|
121132
|
+
const src = Bun.file(join156(priorStoryDir, name));
|
|
120597
121133
|
try {
|
|
120598
121134
|
if (await src.exists())
|
|
120599
|
-
await Bun.write(
|
|
121135
|
+
await Bun.write(join156(storyDir, name), src);
|
|
120600
121136
|
} catch (err) {
|
|
120601
121137
|
getLogger2().warn("workflow", `Could not carry ${name} over from the prior run`, {
|
|
120602
121138
|
storyId,
|
|
@@ -121483,7 +122019,7 @@ var init_pipeline_result_handler = __esm(() => {
|
|
|
121483
122019
|
|
|
121484
122020
|
// src/execution/iteration-runner.ts
|
|
121485
122021
|
import { existsSync as existsSync29 } from "fs";
|
|
121486
|
-
import { join as
|
|
122022
|
+
import { join as join157 } from "path";
|
|
121487
122023
|
async function selectPipeline(config) {
|
|
121488
122024
|
const stages = await Promise.resolve().then(() => (init_stages(), {}));
|
|
121489
122025
|
return isWorkflowMode(config) ? getWorkflowPipeline() : defaultPipeline;
|
|
@@ -121546,7 +122082,7 @@ async function runIteration2(ctx, prd, selection, iterations, totalCost, allStor
|
|
|
121546
122082
|
const accumulatedAttemptCost = (story.priorFailures || []).reduce((sum, f) => sum + (f.cost || 0), 0);
|
|
121547
122083
|
const profileOverride = profileOverrideFromConfig(ctx.config);
|
|
121548
122084
|
const storyPkg = storyPackageDir(story);
|
|
121549
|
-
const effectiveConfig = storyPkg ? await _iterationRunnerDeps.loadConfigForWorkdir(
|
|
122085
|
+
const effectiveConfig = storyPkg ? await _iterationRunnerDeps.loadConfigForWorkdir(join157(ctx.workdir, ".nax", "config.json"), storyPkg, profileOverride) : ctx.config;
|
|
121550
122086
|
let dependencyContext;
|
|
121551
122087
|
if (ctx.config.execution.storyIsolation === "worktree") {
|
|
121552
122088
|
try {
|
|
@@ -121717,7 +122253,7 @@ var init_iteration_runner = __esm(() => {
|
|
|
121717
122253
|
});
|
|
121718
122254
|
|
|
121719
122255
|
// src/hooks/runner.ts
|
|
121720
|
-
import { join as
|
|
122256
|
+
import { join as join158 } from "path";
|
|
121721
122257
|
function createDrainDeadline2(deadlineMs) {
|
|
121722
122258
|
let timeoutId;
|
|
121723
122259
|
const promise = new Promise((resolve) => {
|
|
@@ -121736,14 +122272,14 @@ async function loadHooksConfig(projectDir, globalDir) {
|
|
|
121736
122272
|
let globalHooks = { hooks: {} };
|
|
121737
122273
|
let projectHooks = { hooks: {} };
|
|
121738
122274
|
let skipGlobal = false;
|
|
121739
|
-
const projectPath =
|
|
122275
|
+
const projectPath = join158(projectDir, "hooks.json");
|
|
121740
122276
|
const projectData = await loadJsonFile(projectPath, "hooks");
|
|
121741
122277
|
if (projectData) {
|
|
121742
122278
|
projectHooks = projectData;
|
|
121743
122279
|
skipGlobal = projectData.skipGlobal ?? false;
|
|
121744
122280
|
}
|
|
121745
122281
|
if (!skipGlobal && globalDir) {
|
|
121746
|
-
const globalPath =
|
|
122282
|
+
const globalPath = join158(globalDir, "hooks.json");
|
|
121747
122283
|
const globalData = await loadJsonFile(globalPath, "hooks");
|
|
121748
122284
|
if (globalData) {
|
|
121749
122285
|
globalHooks = globalData;
|
|
@@ -122912,11 +123448,11 @@ var init_run_tmp_wipe = __esm(() => {
|
|
|
122912
123448
|
|
|
122913
123449
|
// src/execution/lifecycle/scratchpad-wipe.ts
|
|
122914
123450
|
import { rm as rm14 } from "fs/promises";
|
|
122915
|
-
import { join as
|
|
123451
|
+
import { join as join159 } from "path";
|
|
122916
123452
|
async function wipeScratchpad(workdir, opts = {}) {
|
|
122917
123453
|
if (opts.dryRun)
|
|
122918
123454
|
return;
|
|
122919
|
-
const scratchpad =
|
|
123455
|
+
const scratchpad = join159(workdir, SCRATCHPAD_DIR);
|
|
122920
123456
|
try {
|
|
122921
123457
|
await _scratchpadWipeDeps.remove(scratchpad);
|
|
122922
123458
|
} catch (err) {
|
|
@@ -124269,7 +124805,7 @@ var init_run_completion = __esm(() => {
|
|
|
124269
124805
|
});
|
|
124270
124806
|
|
|
124271
124807
|
// src/context/rules/rule-delivery/index.ts
|
|
124272
|
-
import { isAbsolute as isAbsolute34, join as
|
|
124808
|
+
import { isAbsolute as isAbsolute34, join as join160, posix as posix6, relative as relative44, resolve as resolve47 } from "path";
|
|
124273
124809
|
function createRuleDeliveryHandlers(input) {
|
|
124274
124810
|
const state = createState(input);
|
|
124275
124811
|
const beforeTool = (payload, ctx) => isBeforeToolPayload(payload) ? runBeforeTool(state, payload, ctx) : { kind: "allow" };
|
|
@@ -124414,7 +124950,7 @@ async function loadPackageRuleSet(state, packageRel, rel) {
|
|
|
124414
124950
|
state.seededRules.set(rel, fileRules);
|
|
124415
124951
|
const set = await _ruleDeliveryDeps.resolveRuleSet({
|
|
124416
124952
|
repoRoot,
|
|
124417
|
-
packageDir: packageRel === undefined ? repoRoot :
|
|
124953
|
+
packageDir: packageRel === undefined ? repoRoot : join160(repoRoot, packageRel),
|
|
124418
124954
|
...packageRel !== undefined && { storyWorkdir: packageRel },
|
|
124419
124955
|
...overrideDir !== undefined && { overrideDir },
|
|
124420
124956
|
overrideMode
|
|
@@ -124537,7 +125073,7 @@ var init_rule_delivery = __esm(() => {
|
|
|
124537
125073
|
});
|
|
124538
125074
|
|
|
124539
125075
|
// src/execution/lifecycle/run-rules-setup.ts
|
|
124540
|
-
import { stat as
|
|
125076
|
+
import { stat as stat14 } from "fs/promises";
|
|
124541
125077
|
async function validateProjectContext(config) {
|
|
124542
125078
|
const projectContext = config.context?.projectContext;
|
|
124543
125079
|
if (projectContext?.file === undefined)
|
|
@@ -124584,7 +125120,7 @@ var init_run_rules_setup = __esm(() => {
|
|
|
124584
125120
|
_runRulesSetupDeps = {
|
|
124585
125121
|
dirExists: async (path) => {
|
|
124586
125122
|
try {
|
|
124587
|
-
return (await
|
|
125123
|
+
return (await stat14(path)).isDirectory();
|
|
124588
125124
|
} catch {
|
|
124589
125125
|
return false;
|
|
124590
125126
|
}
|
|
@@ -124793,7 +125329,7 @@ var init_status_file = __esm(() => {
|
|
|
124793
125329
|
});
|
|
124794
125330
|
|
|
124795
125331
|
// src/execution/status-writer.ts
|
|
124796
|
-
import { join as
|
|
125332
|
+
import { join as join161 } from "path";
|
|
124797
125333
|
|
|
124798
125334
|
class StatusWriter {
|
|
124799
125335
|
statusFile;
|
|
@@ -124974,7 +125510,7 @@ class StatusWriter {
|
|
|
124974
125510
|
if (!this._prd)
|
|
124975
125511
|
return;
|
|
124976
125512
|
const safeLogger = getSafeLogger2();
|
|
124977
|
-
const featureStatusPath =
|
|
125513
|
+
const featureStatusPath = join161(featureDir, "status.json");
|
|
124978
125514
|
const write = async () => {
|
|
124979
125515
|
try {
|
|
124980
125516
|
const base = this.getSnapshot(totalCost, iterations);
|
|
@@ -125001,7 +125537,7 @@ var init_status_writer = __esm(() => {
|
|
|
125001
125537
|
});
|
|
125002
125538
|
|
|
125003
125539
|
// src/plugins/builtin/auto-route/index.ts
|
|
125004
|
-
import { join as
|
|
125540
|
+
import { join as join162 } from "path";
|
|
125005
125541
|
function getAutoRouteConfig(context) {
|
|
125006
125542
|
const cfg = context.config;
|
|
125007
125543
|
if (!cfg)
|
|
@@ -125102,7 +125638,7 @@ var init_auto_route = __esm(() => {
|
|
|
125102
125638
|
return { success: true, message: "Auto-route proposal skipped \u2014 no outputDir available" };
|
|
125103
125639
|
}
|
|
125104
125640
|
const proposal = await buildProposal(context, cfg);
|
|
125105
|
-
const target =
|
|
125641
|
+
const target = join162(outputDir, PROPOSAL_FILENAME);
|
|
125106
125642
|
await _autoRouteDeps.writeFile(target, JSON.stringify(buildProposalArtifact(proposal), null, 2));
|
|
125107
125643
|
return {
|
|
125108
125644
|
success: true,
|
|
@@ -128443,7 +128979,7 @@ var init_language_commands = __esm(() => {
|
|
|
128443
128979
|
});
|
|
128444
128980
|
|
|
128445
128981
|
// src/review/scoped-lint.ts
|
|
128446
|
-
import { join as
|
|
128982
|
+
import { join as join166, relative as relative46 } from "path";
|
|
128447
128983
|
function normalizePath3(path) {
|
|
128448
128984
|
return path.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
128449
128985
|
}
|
|
@@ -128480,7 +129016,7 @@ function uniqueFiles(files) {
|
|
|
128480
129016
|
async function filterFilesToScope(files, workdir, projectDir, activePackageDir) {
|
|
128481
129017
|
const inScope = [];
|
|
128482
129018
|
for (const relPath of files) {
|
|
128483
|
-
const absPath =
|
|
129019
|
+
const absPath = join166(workdir, relPath);
|
|
128484
129020
|
const exists = await _scopedLintDeps.fileExists(absPath);
|
|
128485
129021
|
if (!exists)
|
|
128486
129022
|
continue;
|
|
@@ -130809,7 +131345,7 @@ var init_tdd_failure_category = __esm(() => {
|
|
|
130809
131345
|
});
|
|
130810
131346
|
|
|
130811
131347
|
// src/execution/uncategorised-advice.ts
|
|
130812
|
-
import { join as
|
|
131348
|
+
import { join as join167, relative as relative47 } from "path";
|
|
130813
131349
|
function callContextFor(ctx) {
|
|
130814
131350
|
return {
|
|
130815
131351
|
runtime: ctx.runtime,
|
|
@@ -130860,7 +131396,7 @@ async function adviseUncategorised(frame, pauseReason) {
|
|
|
130860
131396
|
outputDir: ctx.runtime.outputDir,
|
|
130861
131397
|
feature,
|
|
130862
131398
|
runId: ctx.runtime.runId,
|
|
130863
|
-
specPath: relative47(repoRoot,
|
|
131399
|
+
specPath: relative47(repoRoot, join167(featureDir(repoRoot, feature), "spec.md")),
|
|
130864
131400
|
workdir: ctx.workdir,
|
|
130865
131401
|
...headsUpChannel(ctx)
|
|
130866
131402
|
});
|
|
@@ -131941,14 +132477,72 @@ var init_runner_completion = __esm(() => {
|
|
|
131941
132477
|
};
|
|
131942
132478
|
});
|
|
131943
132479
|
|
|
132480
|
+
// src/execution/lifecycle/pre-run-steps.ts
|
|
132481
|
+
async function runPreRunSteps(opts) {
|
|
132482
|
+
for (const step of opts.steps) {
|
|
132483
|
+
await _preRunDeps.assertTrusted(opts.workdir, "pre-run");
|
|
132484
|
+
const startedAt = _preRunDeps.now();
|
|
132485
|
+
const result = await _preRunDeps.executeWithTimeout(step.command, step.timeoutSeconds, undefined, {
|
|
132486
|
+
cwd: opts.workdir
|
|
132487
|
+
});
|
|
132488
|
+
const durationMs = _preRunDeps.now() - startedAt;
|
|
132489
|
+
if (result.success) {
|
|
132490
|
+
getSafeLogger2()?.info("execution", "Pre-run step completed", {
|
|
132491
|
+
storyId: RUN_SCOPE_STORY_ID,
|
|
132492
|
+
command: step.command,
|
|
132493
|
+
exitCode: result.exitCode ?? 0,
|
|
132494
|
+
durationMs
|
|
132495
|
+
});
|
|
132496
|
+
continue;
|
|
132497
|
+
}
|
|
132498
|
+
throw failStep(step, result, durationMs);
|
|
132499
|
+
}
|
|
132500
|
+
}
|
|
132501
|
+
function failStep(step, result, durationMs) {
|
|
132502
|
+
const outputTail = (result.output ?? "").slice(-OUTPUT_TAIL_CHARS2);
|
|
132503
|
+
const context = { stage: "execution", command: step.command, exitCode: result.exitCode };
|
|
132504
|
+
if (result.timeout) {
|
|
132505
|
+
getSafeLogger2()?.error("execution", "Pre-run step failed", {
|
|
132506
|
+
storyId: RUN_SCOPE_STORY_ID,
|
|
132507
|
+
command: step.command,
|
|
132508
|
+
timedOut: true,
|
|
132509
|
+
timeoutSeconds: step.timeoutSeconds,
|
|
132510
|
+
durationMs,
|
|
132511
|
+
outputTail
|
|
132512
|
+
});
|
|
132513
|
+
return new NaxError(`Pre-run step failed: ${step.command} (timed out after ${step.timeoutSeconds}s)`, "PRE_RUN_FAILED", context);
|
|
132514
|
+
}
|
|
132515
|
+
getSafeLogger2()?.error("execution", "Pre-run step failed", {
|
|
132516
|
+
storyId: RUN_SCOPE_STORY_ID,
|
|
132517
|
+
command: step.command,
|
|
132518
|
+
exitCode: result.exitCode,
|
|
132519
|
+
timedOut: false,
|
|
132520
|
+
durationMs,
|
|
132521
|
+
outputTail
|
|
132522
|
+
});
|
|
132523
|
+
return new NaxError(`Pre-run step failed: ${step.command} (exit ${result.exitCode ?? "unknown"})`, "PRE_RUN_FAILED", context);
|
|
132524
|
+
}
|
|
132525
|
+
var OUTPUT_TAIL_CHARS2 = 2000, RUN_SCOPE_STORY_ID = "_run", _preRunDeps;
|
|
132526
|
+
var init_pre_run_steps = __esm(() => {
|
|
132527
|
+
init_errors4();
|
|
132528
|
+
init_logger2();
|
|
132529
|
+
init_trust();
|
|
132530
|
+
init_verification();
|
|
132531
|
+
_preRunDeps = {
|
|
132532
|
+
assertTrusted,
|
|
132533
|
+
executeWithTimeout,
|
|
132534
|
+
now: () => Date.now()
|
|
132535
|
+
};
|
|
132536
|
+
});
|
|
132537
|
+
|
|
131944
132538
|
// src/pipeline/subscribers/events-writer.ts
|
|
131945
132539
|
import { appendFile as appendFile13, mkdir as mkdir48 } from "fs/promises";
|
|
131946
|
-
import { basename as
|
|
132540
|
+
import { basename as basename28, join as join168 } from "path";
|
|
131947
132541
|
function wireEventsWriter(bus, feature, runId, workdir) {
|
|
131948
132542
|
const logger = getSafeLogger2();
|
|
131949
|
-
const project =
|
|
131950
|
-
const eventsDir =
|
|
131951
|
-
const eventsFile =
|
|
132543
|
+
const project = basename28(workdir);
|
|
132544
|
+
const eventsDir = join168(getEventsRootDir(), project);
|
|
132545
|
+
const eventsFile = join168(eventsDir, "events.jsonl");
|
|
131952
132546
|
let dirReady = false;
|
|
131953
132547
|
const write = (line) => {
|
|
131954
132548
|
return (async () => {
|
|
@@ -132150,12 +132744,12 @@ var init_interaction4 = __esm(() => {
|
|
|
132150
132744
|
|
|
132151
132745
|
// src/pipeline/subscribers/registry.ts
|
|
132152
132746
|
import { mkdir as mkdir49, writeFile as writeFile18 } from "fs/promises";
|
|
132153
|
-
import { basename as
|
|
132747
|
+
import { basename as basename29, join as join169 } from "path";
|
|
132154
132748
|
function wireRegistry(bus, feature, runId, workdir, outputDir) {
|
|
132155
132749
|
const logger = getSafeLogger2();
|
|
132156
|
-
const project =
|
|
132157
|
-
const runDir =
|
|
132158
|
-
const metaFile =
|
|
132750
|
+
const project = basename29(workdir);
|
|
132751
|
+
const runDir = join169(getRunsDir(), `${project}-${feature}-${runId}`);
|
|
132752
|
+
const metaFile = join169(runDir, "meta.json");
|
|
132159
132753
|
const unsub = bus.on("run:started", (_ev) => {
|
|
132160
132754
|
return (async () => {
|
|
132161
132755
|
try {
|
|
@@ -132165,8 +132759,8 @@ function wireRegistry(bus, feature, runId, workdir, outputDir) {
|
|
|
132165
132759
|
project,
|
|
132166
132760
|
feature,
|
|
132167
132761
|
workdir,
|
|
132168
|
-
statusPath:
|
|
132169
|
-
eventsDir:
|
|
132762
|
+
statusPath: join169(outputDir, "features", feature, "status.json"),
|
|
132763
|
+
eventsDir: join169(outputDir, "features", feature, "runs"),
|
|
132170
132764
|
registeredAt: new Date().toISOString()
|
|
132171
132765
|
};
|
|
132172
132766
|
await writeFile18(metaFile, JSON.stringify(meta, null, 2));
|
|
@@ -133520,6 +134114,17 @@ var init_unified_executor = __esm(() => {
|
|
|
133520
134114
|
});
|
|
133521
134115
|
|
|
133522
134116
|
// src/execution/runner-execution.ts
|
|
134117
|
+
async function runPreRunStepsOrFail(opts) {
|
|
134118
|
+
if (opts.dryRun)
|
|
134119
|
+
return;
|
|
134120
|
+
try {
|
|
134121
|
+
await runPreRunSteps({ steps: opts.config.execution?.preRun ?? [], workdir: opts.workdir });
|
|
134122
|
+
} catch (err) {
|
|
134123
|
+
opts.statusWriter.setRunStatus("failed");
|
|
134124
|
+
await opts.statusWriter.update(0, 0);
|
|
134125
|
+
throw err;
|
|
134126
|
+
}
|
|
134127
|
+
}
|
|
133523
134128
|
async function runExecutionPhase(options, prd, pluginRegistry) {
|
|
133524
134129
|
const logger = getSafeLogger2();
|
|
133525
134130
|
const useBatch = effectiveUseBatch(options.config, options.useBatch, (m) => logger?.warn("execution", m, { storyId: "_run" }));
|
|
@@ -133563,6 +134168,12 @@ async function runExecutionPhase(options, prd, pluginRegistry) {
|
|
|
133563
134168
|
});
|
|
133564
134169
|
}
|
|
133565
134170
|
}
|
|
134171
|
+
await runPreRunStepsOrFail({
|
|
134172
|
+
dryRun: options.dryRun,
|
|
134173
|
+
config: options.config,
|
|
134174
|
+
workdir: options.workdir,
|
|
134175
|
+
statusWriter: options.statusWriter
|
|
134176
|
+
});
|
|
133566
134177
|
if (!options.dryRun) {
|
|
133567
134178
|
try {
|
|
133568
134179
|
await captureRunBaseline({
|
|
@@ -133650,6 +134261,7 @@ var init_runner_execution = __esm(() => {
|
|
|
133650
134261
|
init_session2();
|
|
133651
134262
|
init_ensure_package_dirs();
|
|
133652
134263
|
init_helpers();
|
|
134264
|
+
init_pre_run_steps();
|
|
133653
134265
|
init_test_baseline_capture();
|
|
133654
134266
|
init_new_package_setup();
|
|
133655
134267
|
init_workflow_parallel();
|
|
@@ -135477,7 +136089,7 @@ var init_decompose_mapper = __esm(() => {
|
|
|
135477
136089
|
});
|
|
135478
136090
|
|
|
135479
136091
|
// src/cli/plan-decompose.ts
|
|
135480
|
-
import { join as
|
|
136092
|
+
import { join as join170 } from "path";
|
|
135481
136093
|
function validateDecomposedStoryIds(stories, existingIds) {
|
|
135482
136094
|
const generatedIds = new Set;
|
|
135483
136095
|
for (const story of stories) {
|
|
@@ -135491,7 +136103,7 @@ function validateDecomposedStoryIds(stories, existingIds) {
|
|
|
135491
136103
|
}
|
|
135492
136104
|
}
|
|
135493
136105
|
async function planDecomposeCommand(workdir, config, options) {
|
|
135494
|
-
const prdPath =
|
|
136106
|
+
const prdPath = join170(featureDir(workdir, options.feature), "prd.json");
|
|
135495
136107
|
if (!_planDeps.existsSync(prdPath)) {
|
|
135496
136108
|
throw new NaxError(`PRD not found: ${prdPath}`, "PRD_NOT_FOUND", {
|
|
135497
136109
|
stage: "decompose",
|
|
@@ -135646,7 +136258,7 @@ var init_plan_decompose = __esm(() => {
|
|
|
135646
136258
|
|
|
135647
136259
|
// src/cli/plan-runtime/index.ts
|
|
135648
136260
|
import { existsSync as existsSync34 } from "fs";
|
|
135649
|
-
import { join as
|
|
136261
|
+
import { join as join171 } from "path";
|
|
135650
136262
|
function createPlanRuntime(config, workdir, featureName) {
|
|
135651
136263
|
return _planDeps.createRuntime(config, workdir, featureName);
|
|
135652
136264
|
}
|
|
@@ -135698,7 +136310,7 @@ var init_plan_runtime = __esm(() => {
|
|
|
135698
136310
|
scanSourceRoots: (workdir) => scanSourceRoots(workdir),
|
|
135699
136311
|
createRuntime: (cfg, wd, featureName) => createRuntime(cfg, wd, { featureName }),
|
|
135700
136312
|
claimProjectIdentity,
|
|
135701
|
-
readPackageJson: (workdir) => Bun.file(
|
|
136313
|
+
readPackageJson: (workdir) => Bun.file(join171(workdir, "package.json")).json().catch(() => null),
|
|
135702
136314
|
spawnSync: (cmd, opts) => {
|
|
135703
136315
|
const result = Bun.spawnSync(cmd, opts ? { cwd: opts.cwd, ...opts.env ? { env: opts.env } : {} } : {});
|
|
135704
136316
|
return { stdout: result.stdout, exitCode: result.exitCode };
|
|
@@ -135721,13 +136333,13 @@ var init_plan_runtime = __esm(() => {
|
|
|
135721
136333
|
|
|
135722
136334
|
// src/plan/spec-lint-gate.ts
|
|
135723
136335
|
import { existsSync as existsSync35 } from "fs";
|
|
135724
|
-
import { join as
|
|
136336
|
+
import { join as join172 } from "path";
|
|
135725
136337
|
function assertSpecLintClean(specContent, options) {
|
|
135726
136338
|
if (options.skip === true)
|
|
135727
136339
|
return [];
|
|
135728
136340
|
const findings = lintSpecContent(specContent, {
|
|
135729
136341
|
maxAcCount: options.maxAcCount,
|
|
135730
|
-
fileExists: (path) => existsSync35(
|
|
136342
|
+
fileExists: (path) => existsSync35(join172(options.workdir, path))
|
|
135731
136343
|
});
|
|
135732
136344
|
const blocking = findings.filter((finding) => BLOCKING_SPEC_LINT_CODES.has(finding.code));
|
|
135733
136345
|
if (blocking.length > 0) {
|
|
@@ -135750,9 +136362,9 @@ var init_spec_lint_gate = __esm(() => {
|
|
|
135750
136362
|
});
|
|
135751
136363
|
|
|
135752
136364
|
// src/plan/strategies/context-builder.ts
|
|
135753
|
-
import { join as
|
|
136365
|
+
import { join as join173 } from "path";
|
|
135754
136366
|
async function buildPlanModeContext(workdir, fullConfig, options, deps) {
|
|
135755
|
-
const naxDir =
|
|
136367
|
+
const naxDir = join173(workdir, ".nax");
|
|
135756
136368
|
if (!deps.existsSync(naxDir)) {
|
|
135757
136369
|
throw new NaxError(`.nax directory not found. Run 'nax init' first in ${workdir}`, "PLAN_CONTEXT_NO_NAX_DIR", {
|
|
135758
136370
|
stage: "plan",
|
|
@@ -135760,8 +136372,8 @@ async function buildPlanModeContext(workdir, fullConfig, options, deps) {
|
|
|
135760
136372
|
});
|
|
135761
136373
|
}
|
|
135762
136374
|
validateFeatureName(options.feature);
|
|
135763
|
-
const outputDir =
|
|
135764
|
-
const outputPath =
|
|
136375
|
+
const outputDir = join173(naxDir, "features", options.feature);
|
|
136376
|
+
const outputPath = join173(outputDir, "prd.json");
|
|
135765
136377
|
const [specContent, sourceRoots, pkg] = await Promise.all([
|
|
135766
136378
|
deps.readFile(options.from),
|
|
135767
136379
|
deps.scanSourceRoots(workdir),
|
|
@@ -135790,7 +136402,7 @@ async function buildPlanModeContext(workdir, fullConfig, options, deps) {
|
|
|
135790
136402
|
...new Set(sourceRoots.map((root) => root.path).filter((path) => path !== ".").map((path) => path.startsWith("/") ? path.replace(`${workdir}/`, "") : path))
|
|
135791
136403
|
];
|
|
135792
136404
|
const packageDetails = relativePackages.length === 0 ? [] : await Promise.all(relativePackages.map(async (relativePath) => {
|
|
135793
|
-
const packageJson = await deps.readPackageJsonAt(
|
|
136405
|
+
const packageJson = await deps.readPackageJsonAt(join173(workdir, relativePath, "package.json"));
|
|
135794
136406
|
return buildPackageSummary(relativePath, packageJson);
|
|
135795
136407
|
}));
|
|
135796
136408
|
const projectName = detectProjectName(workdir, pkg);
|
|
@@ -135880,12 +136492,12 @@ var init_finalize_routing = __esm(() => {
|
|
|
135880
136492
|
|
|
135881
136493
|
// src/plan/strategies/persist-prd.ts
|
|
135882
136494
|
import { existsSync as defaultExistsSync, renameSync as defaultRenameSync } from "fs";
|
|
135883
|
-
import { dirname as
|
|
136495
|
+
import { dirname as dirname44, join as join174 } from "path";
|
|
135884
136496
|
function unverifiedStampedStoryIds(prd) {
|
|
135885
136497
|
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);
|
|
135886
136498
|
}
|
|
135887
136499
|
function moveDraftAside(outputPath) {
|
|
135888
|
-
const rejectedPath =
|
|
136500
|
+
const rejectedPath = join174(dirname44(outputPath), "prd.rejected.json");
|
|
135889
136501
|
if (!_persistPrdDeps.existsSync(outputPath)) {
|
|
135890
136502
|
return { phrase: `no draft was on disk at ${outputPath}` };
|
|
135891
136503
|
}
|
|
@@ -135945,7 +136557,7 @@ async function finalizeAndWritePrd(args) {
|
|
|
135945
136557
|
respelled: result.respelled
|
|
135946
136558
|
});
|
|
135947
136559
|
}
|
|
135948
|
-
if (result.defaulted.length > 0 && _persistPrdDeps.existsSync(
|
|
136560
|
+
if (result.defaulted.length > 0 && _persistPrdDeps.existsSync(join174(args.repoRoot, ".nax", "mono"))) {
|
|
135949
136561
|
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 });
|
|
135950
136562
|
}
|
|
135951
136563
|
} catch (err) {
|
|
@@ -136195,7 +136807,7 @@ var init_strategies = __esm(() => {
|
|
|
136195
136807
|
});
|
|
136196
136808
|
|
|
136197
136809
|
// src/cli/plan-command.ts
|
|
136198
|
-
import { basename as
|
|
136810
|
+
import { basename as basename30 } from "path";
|
|
136199
136811
|
function resolvePlanMode(config) {
|
|
136200
136812
|
const explicit = config?.plan?.mode;
|
|
136201
136813
|
if (explicit)
|
|
@@ -136210,7 +136822,7 @@ async function claimPlanIdentity(workdir, config) {
|
|
|
136210
136822
|
remoteUrl = gitResult.stdout.toString().trim() || null;
|
|
136211
136823
|
}
|
|
136212
136824
|
} catch {}
|
|
136213
|
-
const projectKey = config.name?.trim() ||
|
|
136825
|
+
const projectKey = config.name?.trim() || basename30(workdir);
|
|
136214
136826
|
try {
|
|
136215
136827
|
await _planDeps.claimProjectIdentity(projectKey, workdir, remoteUrl);
|
|
136216
136828
|
} catch (err) {
|
|
@@ -136355,12 +136967,12 @@ var init_prompts_export = __esm(() => {
|
|
|
136355
136967
|
|
|
136356
136968
|
// src/cli/prompts-init.ts
|
|
136357
136969
|
import { existsSync as existsSync36, mkdirSync as mkdirSync9 } from "fs";
|
|
136358
|
-
import { join as
|
|
136970
|
+
import { join as join176 } from "path";
|
|
136359
136971
|
async function promptsInitCommand(options) {
|
|
136360
136972
|
const { workdir, force = false, autoWireConfig = true } = options;
|
|
136361
|
-
const templatesDir =
|
|
136973
|
+
const templatesDir = join176(workdir, ".nax", "templates");
|
|
136362
136974
|
mkdirSync9(templatesDir, { recursive: true });
|
|
136363
|
-
const existingFiles = TEMPLATE_ROLES.map((t) => t.file).filter((f) => existsSync36(
|
|
136975
|
+
const existingFiles = TEMPLATE_ROLES.map((t) => t.file).filter((f) => existsSync36(join176(templatesDir, f)));
|
|
136364
136976
|
if (existingFiles.length > 0 && !force) {
|
|
136365
136977
|
_promptsInitDeps.warn(`[WARN] .nax/templates/ already contains files: ${existingFiles.join(", ")}. No files overwritten.
|
|
136366
136978
|
Pass --force to overwrite existing templates.`);
|
|
@@ -136368,7 +136980,7 @@ async function promptsInitCommand(options) {
|
|
|
136368
136980
|
}
|
|
136369
136981
|
const written = [];
|
|
136370
136982
|
for (const template of TEMPLATE_ROLES) {
|
|
136371
|
-
const filePath =
|
|
136983
|
+
const filePath = join176(templatesDir, template.file);
|
|
136372
136984
|
const roleBody = unwrapProtocolRegions(template.role === "implementer" ? buildRoleTaskSection(template.role, template.variant) : buildRoleTaskSection(template.role));
|
|
136373
136985
|
const content = TEMPLATE_HEADER + roleBody;
|
|
136374
136986
|
await Bun.write(filePath, content);
|
|
@@ -136384,7 +136996,7 @@ async function promptsInitCommand(options) {
|
|
|
136384
136996
|
return written;
|
|
136385
136997
|
}
|
|
136386
136998
|
async function autoWirePromptsConfig(workdir) {
|
|
136387
|
-
const configPath =
|
|
136999
|
+
const configPath = join176(projectConfigDir(workdir), "config.json");
|
|
136388
137000
|
if (!existsSync36(configPath)) {
|
|
136389
137001
|
const exampleConfig = JSON.stringify({
|
|
136390
137002
|
prompts: {
|
|
@@ -136514,7 +137126,7 @@ function buildFrontmatter(story, ctx, role) {
|
|
|
136514
137126
|
}
|
|
136515
137127
|
|
|
136516
137128
|
// src/cli/prompts-tdd.ts
|
|
136517
|
-
import { join as
|
|
137129
|
+
import { join as join177 } from "path";
|
|
136518
137130
|
async function handleThreeSessionTddPrompts(story, ctx, outputDir, logger) {
|
|
136519
137131
|
const scopedTestCommand = commandSpecIncludes(ctx.config.quality?.commands?.testScoped, "{{files}}") ? "testScoped" : undefined;
|
|
136520
137132
|
const [testWriterPrompt, implementerPrompt, verifierPrompt] = await Promise.all([
|
|
@@ -136534,7 +137146,7 @@ ${frontmatter}---
|
|
|
136534
137146
|
|
|
136535
137147
|
${session.prompt}`;
|
|
136536
137148
|
if (outputDir) {
|
|
136537
|
-
const promptFile =
|
|
137149
|
+
const promptFile = join177(outputDir, `${story.id}.${session.role}.md`);
|
|
136538
137150
|
await Bun.write(promptFile, fullOutput);
|
|
136539
137151
|
logger.info("cli", "Written TDD prompt file", {
|
|
136540
137152
|
storyId: story.id,
|
|
@@ -136550,7 +137162,7 @@ ${"=".repeat(80)}`);
|
|
|
136550
137162
|
}
|
|
136551
137163
|
}
|
|
136552
137164
|
if (outputDir && ctx.contextMarkdown) {
|
|
136553
|
-
const contextFile =
|
|
137165
|
+
const contextFile = join177(outputDir, `${story.id}.context.md`);
|
|
136554
137166
|
const frontmatter = buildFrontmatter(story, ctx);
|
|
136555
137167
|
const contextOutput = `---
|
|
136556
137168
|
${frontmatter}---
|
|
@@ -136566,19 +137178,19 @@ var init_prompts_tdd = __esm(() => {
|
|
|
136566
137178
|
|
|
136567
137179
|
// src/cli/prompts-main.ts
|
|
136568
137180
|
import { existsSync as existsSync37, mkdirSync as mkdirSync10 } from "fs";
|
|
136569
|
-
import { join as
|
|
137181
|
+
import { join as join178 } from "path";
|
|
136570
137182
|
async function promptsCommand(options) {
|
|
136571
137183
|
const logger = getLogger2();
|
|
136572
137184
|
const { feature, workdir, config, storyId, outputDir } = options;
|
|
136573
|
-
const naxDir =
|
|
137185
|
+
const naxDir = join178(workdir, ".nax");
|
|
136574
137186
|
if (!existsSync37(naxDir)) {
|
|
136575
137187
|
throw new NaxError(`.nax directory not found. Run 'nax init' first in ${workdir}`, "NAX_DIR_NOT_FOUND", {
|
|
136576
137188
|
stage: "cli",
|
|
136577
137189
|
workdir
|
|
136578
137190
|
});
|
|
136579
137191
|
}
|
|
136580
|
-
const featureDir =
|
|
136581
|
-
const prdPath =
|
|
137192
|
+
const featureDir = join178(naxDir, "features", feature);
|
|
137193
|
+
const prdPath = join178(featureDir, "prd.json");
|
|
136582
137194
|
if (!existsSync37(prdPath)) {
|
|
136583
137195
|
throw new NaxError(`Feature "${feature}" not found or missing prd.json`, "FEATURE_PRD_NOT_FOUND", {
|
|
136584
137196
|
stage: "cli",
|
|
@@ -136649,10 +137261,10 @@ ${frontmatter}---
|
|
|
136649
137261
|
|
|
136650
137262
|
${ctx.prompt}`;
|
|
136651
137263
|
if (outputDir) {
|
|
136652
|
-
const promptFile =
|
|
137264
|
+
const promptFile = join178(outputDir, `${story.id}.prompt.md`);
|
|
136653
137265
|
await Bun.write(promptFile, fullOutput);
|
|
136654
137266
|
if (ctx.contextMarkdown) {
|
|
136655
|
-
const contextFile =
|
|
137267
|
+
const contextFile = join178(outputDir, `${story.id}.context.md`);
|
|
136656
137268
|
const contextOutput = `---
|
|
136657
137269
|
${frontmatter}---
|
|
136658
137270
|
|
|
@@ -136700,42 +137312,9 @@ var init_prompts2 = __esm(() => {
|
|
|
136700
137312
|
init_prompts_tdd();
|
|
136701
137313
|
});
|
|
136702
137314
|
|
|
136703
|
-
// src/cli/resolve-run-profile.ts
|
|
136704
|
-
async function resolveRunProfileOverride(opts) {
|
|
136705
|
-
const cliChain = parseProfileList(opts.cliProfile);
|
|
136706
|
-
if (cliChain.length > 0)
|
|
136707
|
-
return cliChain;
|
|
136708
|
-
if (opts.envProfile)
|
|
136709
|
-
return;
|
|
136710
|
-
const readJson = opts._readJson ?? (async (path) => {
|
|
136711
|
-
const file = Bun.file(path);
|
|
136712
|
-
if (!await file.exists())
|
|
136713
|
-
return;
|
|
136714
|
-
return file.json();
|
|
136715
|
-
});
|
|
136716
|
-
try {
|
|
136717
|
-
const prd = await readJson(opts.prdPath);
|
|
136718
|
-
const rp = prd?.routingProfile;
|
|
136719
|
-
const prdChain = parseProfileList(typeof rp === "string" || Array.isArray(rp) ? rp : undefined);
|
|
136720
|
-
if (prdChain.length > 0) {
|
|
136721
|
-
const listNames = opts._listProfileNames ?? (async () => (await listProfiles(opts.projectRoot)).map((p) => p.name));
|
|
136722
|
-
const available = await listNames();
|
|
136723
|
-
const missing = prdChain.filter((name) => name !== "default" && !available.includes(name));
|
|
136724
|
-
if (missing.length === 0)
|
|
136725
|
-
return prdChain;
|
|
136726
|
-
getSafeLogger2()?.warn("run", `PRD was planned with config profile(s) "${prdChain.join(",")}" but ${missing.join(", ")} not found \u2014 continuing with current config resolution`, { storyId: "prd", plannedProfile: prdChain.join(","), missing });
|
|
136727
|
-
}
|
|
136728
|
-
} catch {}
|
|
136729
|
-
return;
|
|
136730
|
-
}
|
|
136731
|
-
var init_resolve_run_profile = __esm(() => {
|
|
136732
|
-
init_config();
|
|
136733
|
-
init_logger2();
|
|
136734
|
-
});
|
|
136735
|
-
|
|
136736
137315
|
// src/cli/routing-calibrate.ts
|
|
136737
137316
|
import { mkdirSync as mkdirSync11 } from "fs";
|
|
136738
|
-
import { basename as
|
|
137317
|
+
import { basename as basename32, join as join179 } from "path";
|
|
136739
137318
|
function resolveProjectConfigDir(workdir) {
|
|
136740
137319
|
return findProjectDir(workdir) ?? projectInputDir(workdir);
|
|
136741
137320
|
}
|
|
@@ -136778,7 +137357,7 @@ async function runRoutingCalibrateCli(options, deps = _routingCalibrateDeps) {
|
|
|
136778
137357
|
function resolveOutputDir(workdir, override, prior) {
|
|
136779
137358
|
if (override)
|
|
136780
137359
|
return override;
|
|
136781
|
-
const key = prior?.name?.trim() ||
|
|
137360
|
+
const key = prior?.name?.trim() || basename32(workdir);
|
|
136782
137361
|
return projectOutputDir(key, prior?.outputDir);
|
|
136783
137362
|
}
|
|
136784
137363
|
function mergeComplexityRouting(prior, adjustments) {
|
|
@@ -136867,7 +137446,7 @@ var init_routing_calibrate = __esm(() => {
|
|
|
136867
137446
|
loadRunMetrics: (outputDir) => loadRunMetrics(outputDir),
|
|
136868
137447
|
readConfig: (workdir) => loadConfig(workdir),
|
|
136869
137448
|
readProjectConfig: async (workdir) => {
|
|
136870
|
-
const filePath =
|
|
137449
|
+
const filePath = join179(resolveProjectConfigDir(workdir), "config.json");
|
|
136871
137450
|
const configFile = Bun.file(filePath);
|
|
136872
137451
|
if (!await configFile.exists())
|
|
136873
137452
|
return {};
|
|
@@ -136876,7 +137455,7 @@ var init_routing_calibrate = __esm(() => {
|
|
|
136876
137455
|
writeConfig: async (workdir, config) => {
|
|
136877
137456
|
const dir = resolveProjectConfigDir(workdir);
|
|
136878
137457
|
mkdirSync11(dir, { recursive: true });
|
|
136879
|
-
const filePath =
|
|
137458
|
+
const filePath = join179(dir, "config.json");
|
|
136880
137459
|
await saveJsonFile(filePath, config, "routing-calibrate");
|
|
136881
137460
|
},
|
|
136882
137461
|
stdout: (msg) => {
|
|
@@ -136892,7 +137471,7 @@ var init_routing_calibrate = __esm(() => {
|
|
|
136892
137471
|
|
|
136893
137472
|
// src/cli/rules-lint.ts
|
|
136894
137473
|
import { statSync as statSync15 } from "fs";
|
|
136895
|
-
import { join as
|
|
137474
|
+
import { join as join180 } from "path";
|
|
136896
137475
|
function classifyPattern(normalizedPattern) {
|
|
136897
137476
|
const segments = normalizedPattern.split("/");
|
|
136898
137477
|
const literal = [];
|
|
@@ -136911,7 +137490,7 @@ function matchLiteralPath(literalPath, cwd) {
|
|
|
136911
137490
|
if (!isRelativeAndSafe(literalPath))
|
|
136912
137491
|
return "no-match";
|
|
136913
137492
|
try {
|
|
136914
|
-
return statSync15(
|
|
137493
|
+
return statSync15(join180(cwd, literalPath)).isFile() ? "match" : "no-match";
|
|
136915
137494
|
} catch {
|
|
136916
137495
|
return "no-match";
|
|
136917
137496
|
}
|
|
@@ -136951,7 +137530,7 @@ function collectCanonicalRuleRoots(workdir, globCanonicalRuleFiles = _rulesLintD
|
|
|
136951
137530
|
const packageRel = normalized.slice(0, idx);
|
|
136952
137531
|
if (!packageRel)
|
|
136953
137532
|
continue;
|
|
136954
|
-
roots.add(
|
|
137533
|
+
roots.add(join180(workdir, packageRel));
|
|
136955
137534
|
}
|
|
136956
137535
|
return [...roots].sort();
|
|
136957
137536
|
}
|
|
@@ -137008,7 +137587,7 @@ function lintRulesForRoot(rules, root, isSinglePackageRepo, deps, logger) {
|
|
|
137008
137587
|
if (isSinglePackageRepo && rule.paths && rule.paths.length > 0) {
|
|
137009
137588
|
warningCount++;
|
|
137010
137589
|
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.", {
|
|
137011
|
-
file:
|
|
137590
|
+
file: join180(root, CANONICAL_RULES_DIR, rule.path ?? rule.fileName),
|
|
137012
137591
|
code: "INERT_PATHS",
|
|
137013
137592
|
paths: rule.paths,
|
|
137014
137593
|
root,
|
|
@@ -137106,7 +137685,7 @@ var init_rules_lint = __esm(() => {
|
|
|
137106
137685
|
return matchLiteralPath(shape.path, cwd);
|
|
137107
137686
|
const regex = globToRegex3(normalizedPattern);
|
|
137108
137687
|
if (shape.kind === "prefixed")
|
|
137109
|
-
return scanTreeForMatch(
|
|
137688
|
+
return scanTreeForMatch(join180(cwd, shape.prefix), shape.prefix, regex);
|
|
137110
137689
|
return scanTreeForMatch(cwd, "", regex);
|
|
137111
137690
|
} catch {
|
|
137112
137691
|
return "no-match";
|
|
@@ -137120,7 +137699,7 @@ var init_rules_lint = __esm(() => {
|
|
|
137120
137699
|
|
|
137121
137700
|
// src/cli/rules-cli-deps.ts
|
|
137122
137701
|
import { mkdir as mkdir50 } from "fs/promises";
|
|
137123
|
-
import { join as
|
|
137702
|
+
import { join as join181 } from "path";
|
|
137124
137703
|
var _rulesCLIDeps;
|
|
137125
137704
|
var init_rules_cli_deps = __esm(() => {
|
|
137126
137705
|
init_canonical_loader();
|
|
@@ -137134,7 +137713,7 @@ var init_rules_cli_deps = __esm(() => {
|
|
|
137134
137713
|
fileExists: async (path) => Bun.file(path).exists(),
|
|
137135
137714
|
globInDir: (dir) => {
|
|
137136
137715
|
try {
|
|
137137
|
-
return [...new Bun.Glob("*.md").scanSync({ cwd: dir })].sort().map((f) =>
|
|
137716
|
+
return [...new Bun.Glob("*.md").scanSync({ cwd: dir })].sort().map((f) => join181(dir, f));
|
|
137138
137717
|
} catch {
|
|
137139
137718
|
return [];
|
|
137140
137719
|
}
|
|
@@ -137175,7 +137754,7 @@ var init_rules_migrate_plan = __esm(() => {
|
|
|
137175
137754
|
});
|
|
137176
137755
|
|
|
137177
137756
|
// src/cli/rules-migrate.ts
|
|
137178
|
-
import { basename as
|
|
137757
|
+
import { basename as basename33, join as join182 } from "path";
|
|
137179
137758
|
function neutralizeContent(content) {
|
|
137180
137759
|
let result = content;
|
|
137181
137760
|
let replacements = 0;
|
|
@@ -137224,13 +137803,13 @@ function withReviewNotice(content, replacements) {
|
|
|
137224
137803
|
}
|
|
137225
137804
|
async function collectMigrationSources(workdir) {
|
|
137226
137805
|
const sources = [];
|
|
137227
|
-
const rulesDir =
|
|
137806
|
+
const rulesDir = join182(workdir, ".claude", "rules");
|
|
137228
137807
|
const ruleFiles = _rulesCLIDeps.globInDir(rulesDir);
|
|
137229
137808
|
for (const filePath of ruleFiles) {
|
|
137230
137809
|
try {
|
|
137231
137810
|
const content = await _rulesCLIDeps.readFile(filePath);
|
|
137232
137811
|
if (content.trim()) {
|
|
137233
|
-
sources.push({ sourcePath: filePath, targetFileName:
|
|
137812
|
+
sources.push({ sourcePath: filePath, targetFileName: basename33(filePath), content });
|
|
137234
137813
|
}
|
|
137235
137814
|
} catch {}
|
|
137236
137815
|
}
|
|
@@ -137246,11 +137825,11 @@ async function rulesMigrateCommand(options) {
|
|
|
137246
137825
|
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.");
|
|
137247
137826
|
return { written: [], skipped: [] };
|
|
137248
137827
|
}
|
|
137249
|
-
const targetDir =
|
|
137828
|
+
const targetDir = join182(workdir, CANONICAL_RULES_DIR);
|
|
137250
137829
|
const planEntries = sources.map((source) => ({
|
|
137251
137830
|
sourcePath: source.sourcePath,
|
|
137252
137831
|
targetFileName: source.targetFileName,
|
|
137253
|
-
targetPath:
|
|
137832
|
+
targetPath: join182(targetDir, source.targetFileName),
|
|
137254
137833
|
content: source.content
|
|
137255
137834
|
}));
|
|
137256
137835
|
const plan = await planMigration(planEntries, {
|
|
@@ -137300,7 +137879,7 @@ var init_rules_migrate = __esm(() => {
|
|
|
137300
137879
|
});
|
|
137301
137880
|
|
|
137302
137881
|
// src/cli/rules.ts
|
|
137303
|
-
import { join as
|
|
137882
|
+
import { join as join183, resolve as resolve51, sep as sep27 } from "path";
|
|
137304
137883
|
async function rulesLintCommand2(options) {
|
|
137305
137884
|
return rulesLintCommand(options, {
|
|
137306
137885
|
globCanonicalRuleFiles: _rulesCLIDeps.globCanonicalRuleFiles,
|
|
@@ -137373,7 +137952,7 @@ async function exportRuleDirectory(input) {
|
|
|
137373
137952
|
await _rulesCLIDeps.writeFile(target, content);
|
|
137374
137953
|
}
|
|
137375
137954
|
const expected = new Set(rules.map((r) => resolve51(workdir, ruleDir, r.path ?? r.fileName)));
|
|
137376
|
-
for (const existing of _rulesCLIDeps.globInDir(
|
|
137955
|
+
for (const existing of _rulesCLIDeps.globInDir(join183(workdir, ruleDir))) {
|
|
137377
137956
|
if (!expected.has(resolve51(existing))) {
|
|
137378
137957
|
_rulesCLIDeps.getLogger().warn("rules-export", "Generated rules dir contains a file with no canonical source", {
|
|
137379
137958
|
file: existing,
|
|
@@ -137429,7 +138008,7 @@ ${r.content}`).join(`
|
|
|
137429
138008
|
`);
|
|
137430
138009
|
const shimContent = `${header + body}
|
|
137431
138010
|
`;
|
|
137432
|
-
const shimPath =
|
|
138011
|
+
const shimPath = join183(workdir, shimFileName);
|
|
137433
138012
|
if (options.dryRun) {
|
|
137434
138013
|
console.log(`[dry-run] Would write ${shimPath} (${shimContent.length} bytes)`);
|
|
137435
138014
|
return;
|
|
@@ -137459,12 +138038,12 @@ var init_rules = __esm(() => {
|
|
|
137459
138038
|
|
|
137460
138039
|
// src/cli/runs.ts
|
|
137461
138040
|
import { existsSync as existsSync38, readdirSync as readdirSync5 } from "fs";
|
|
137462
|
-
import { basename as
|
|
138041
|
+
import { basename as basename34, join as join184 } from "path";
|
|
137463
138042
|
async function resolveOutputDir2(workdir, override) {
|
|
137464
138043
|
if (override)
|
|
137465
138044
|
return override;
|
|
137466
138045
|
const config = await loadConfig(workdir).catch(() => null);
|
|
137467
|
-
const projectKey = config?.name?.trim() ||
|
|
138046
|
+
const projectKey = config?.name?.trim() || basename34(workdir);
|
|
137468
138047
|
return projectOutputDir(projectKey, config?.outputDir);
|
|
137469
138048
|
}
|
|
137470
138049
|
async function parseRunLog(logPath) {
|
|
@@ -137503,7 +138082,7 @@ async function runsListCommand(options) {
|
|
|
137503
138082
|
const logger = getLogger2();
|
|
137504
138083
|
const { feature, workdir } = options;
|
|
137505
138084
|
const outputDir = await resolveOutputDir2(workdir, options.outputDir);
|
|
137506
|
-
const runsDir =
|
|
138085
|
+
const runsDir = join184(outputDir, "features", feature, "runs");
|
|
137507
138086
|
if (!existsSync38(runsDir)) {
|
|
137508
138087
|
logger.info("cli", "No runs found for feature", { feature, hint: `Directory not found: ${runsDir}` });
|
|
137509
138088
|
return;
|
|
@@ -137515,7 +138094,7 @@ async function runsListCommand(options) {
|
|
|
137515
138094
|
}
|
|
137516
138095
|
logger.info("cli", `Runs for ${feature}`, { count: files.length });
|
|
137517
138096
|
for (const file of files.sort().reverse()) {
|
|
137518
|
-
const logPath =
|
|
138097
|
+
const logPath = join184(runsDir, file);
|
|
137519
138098
|
const entries = await parseRunLog(logPath);
|
|
137520
138099
|
const startEvent = findRunStart(entries);
|
|
137521
138100
|
const completeEvent = findRunSummary(entries);
|
|
@@ -137542,7 +138121,7 @@ async function runsShowCommand(options) {
|
|
|
137542
138121
|
const logger = getLogger2();
|
|
137543
138122
|
const { runId, feature, workdir } = options;
|
|
137544
138123
|
const outputDir = await resolveOutputDir2(workdir, options.outputDir);
|
|
137545
|
-
const logPath =
|
|
138124
|
+
const logPath = join184(outputDir, "features", feature, "runs", `${runId}.jsonl`);
|
|
137546
138125
|
if (!existsSync38(logPath)) {
|
|
137547
138126
|
logger.error("cli", "Run not found", { runId, feature, logPath });
|
|
137548
138127
|
throw new NaxError("Run not found", "RUN_NOT_FOUND", { runId, feature, logPath });
|
|
@@ -137713,36 +138292,36 @@ var init_sandbox_probe = __esm(() => {
|
|
|
137713
138292
|
});
|
|
137714
138293
|
|
|
137715
138294
|
// src/cli/setup-analyze.ts
|
|
137716
|
-
import { join as
|
|
138295
|
+
import { join as join185 } from "path";
|
|
137717
138296
|
async function detectPackageManager(workdir) {
|
|
137718
138297
|
const { fileExists } = _analyzeRepoDeps;
|
|
137719
|
-
if (await fileExists(
|
|
138298
|
+
if (await fileExists(join185(workdir, "bun.lock")))
|
|
137720
138299
|
return { pmRunPrefix: "bun run", pmDlx: "bunx" };
|
|
137721
|
-
if (await fileExists(
|
|
138300
|
+
if (await fileExists(join185(workdir, "bun.lockb")))
|
|
137722
138301
|
return { pmRunPrefix: "bun run", pmDlx: "bunx" };
|
|
137723
|
-
if (await fileExists(
|
|
138302
|
+
if (await fileExists(join185(workdir, "package-lock.json")))
|
|
137724
138303
|
return { pmRunPrefix: "npm run", pmDlx: "npx" };
|
|
137725
|
-
if (await fileExists(
|
|
138304
|
+
if (await fileExists(join185(workdir, "yarn.lock")))
|
|
137726
138305
|
return { pmRunPrefix: "yarn", pmDlx: "yarn dlx" };
|
|
137727
|
-
if (await fileExists(
|
|
138306
|
+
if (await fileExists(join185(workdir, "pnpm-lock.yaml")))
|
|
137728
138307
|
return { pmRunPrefix: "pnpm run", pmDlx: "pnpx" };
|
|
137729
138308
|
return { pmRunPrefix: "npm run", pmDlx: "npx" };
|
|
137730
138309
|
}
|
|
137731
138310
|
async function detectOrchestrator(workdir) {
|
|
137732
138311
|
const { fileExists } = _analyzeRepoDeps;
|
|
137733
|
-
if (await fileExists(
|
|
138312
|
+
if (await fileExists(join185(workdir, "turbo.json")))
|
|
137734
138313
|
return "turbo";
|
|
137735
|
-
if (await fileExists(
|
|
138314
|
+
if (await fileExists(join185(workdir, "nx.json")))
|
|
137736
138315
|
return "nx";
|
|
137737
138316
|
return "none";
|
|
137738
138317
|
}
|
|
137739
138318
|
async function getMissingScripts(packageDir) {
|
|
137740
|
-
const pkg = await _analyzeRepoDeps.readJson(
|
|
138319
|
+
const pkg = await _analyzeRepoDeps.readJson(join185(packageDir, "package.json"));
|
|
137741
138320
|
const scripts = pkg?.scripts ?? {};
|
|
137742
138321
|
return CANONICAL_SCRIPTS.filter((s) => !(s in scripts));
|
|
137743
138322
|
}
|
|
137744
138323
|
async function buildPackageFacts(workdir, relativeDir, testPatternMap) {
|
|
137745
|
-
const packageDir = relativeDir === "" ? workdir :
|
|
138324
|
+
const packageDir = relativeDir === "" ? workdir : join185(workdir, relativeDir);
|
|
137746
138325
|
const [profile, missingScripts] = await Promise.all([
|
|
137747
138326
|
_analyzeRepoDeps.detectProjectProfile(packageDir, {}),
|
|
137748
138327
|
getMissingScripts(packageDir)
|
|
@@ -137803,7 +138382,7 @@ var init_setup_analyze = __esm(() => {
|
|
|
137803
138382
|
});
|
|
137804
138383
|
|
|
137805
138384
|
// src/cli/setup-fill.ts
|
|
137806
|
-
import { join as
|
|
138385
|
+
import { join as join186 } from "path";
|
|
137807
138386
|
async function addScriptToPackageJson(pkgJsonPath, key, value) {
|
|
137808
138387
|
const pkg = await _fillScriptsDeps.readJson(pkgJsonPath) ?? {};
|
|
137809
138388
|
const scripts = pkg.scripts ?? {};
|
|
@@ -137826,18 +138405,18 @@ async function fillScripts(workdir, analysis) {
|
|
|
137826
138405
|
if (shape === "single") {
|
|
137827
138406
|
const rootPkg = packages[0];
|
|
137828
138407
|
if (rootPkg?.missingScripts.includes(TYPE_CHECK_KEY)) {
|
|
137829
|
-
await addScriptToPackageJson(
|
|
138408
|
+
await addScriptToPackageJson(join186(workdir, "package.json"), TYPE_CHECK_KEY, TYPE_CHECK_SCRIPT);
|
|
137830
138409
|
}
|
|
137831
138410
|
return;
|
|
137832
138411
|
}
|
|
137833
138412
|
for (const pkg of packages) {
|
|
137834
138413
|
if (!pkg.missingScripts.includes(TYPE_CHECK_KEY))
|
|
137835
138414
|
continue;
|
|
137836
|
-
await addScriptToPackageJson(
|
|
138415
|
+
await addScriptToPackageJson(join186(workdir, pkg.relativeDir, "package.json"), TYPE_CHECK_KEY, TYPE_CHECK_SCRIPT);
|
|
137837
138416
|
}
|
|
137838
138417
|
if (orchestrator === "turbo" && packages.some((p) => p.missingScripts.includes(TYPE_CHECK_KEY))) {
|
|
137839
|
-
await addTurboTask(
|
|
137840
|
-
await addScriptToPackageJson(
|
|
138418
|
+
await addTurboTask(join186(workdir, "turbo.json"), TYPE_CHECK_KEY);
|
|
138419
|
+
await addScriptToPackageJson(join186(workdir, "package.json"), TYPE_CHECK_KEY, TYPE_CHECK_TURBO_PASSTHROUGH);
|
|
137841
138420
|
}
|
|
137842
138421
|
}
|
|
137843
138422
|
var TYPE_CHECK_KEY = "type-check", TYPE_CHECK_SCRIPT = "tsc --noEmit -p tsconfig.json", TYPE_CHECK_TURBO_PASSTHROUGH = "turbo run type-check", _fillScriptsDeps;
|
|
@@ -137892,17 +138471,17 @@ var init_setup_verify = __esm(() => {
|
|
|
137892
138471
|
});
|
|
137893
138472
|
|
|
137894
138473
|
// src/cli/setup-write.ts
|
|
137895
|
-
import { join as
|
|
138474
|
+
import { join as join187 } from "path";
|
|
137896
138475
|
async function writeSetupConfig(workdir, config, monoConfigs, _opts, deps = _writeSetupDeps) {
|
|
137897
|
-
const naxDir =
|
|
137898
|
-
const naxConfigPath =
|
|
138476
|
+
const naxDir = join187(workdir, ".nax");
|
|
138477
|
+
const naxConfigPath = join187(naxDir, "config.json");
|
|
137899
138478
|
const written = [];
|
|
137900
138479
|
await deps.mkdir(naxDir);
|
|
137901
138480
|
await deps.writeFile(naxConfigPath, JSON.stringify(config, null, 2));
|
|
137902
138481
|
written.push(naxConfigPath);
|
|
137903
138482
|
for (const mc of monoConfigs) {
|
|
137904
|
-
const monoDir =
|
|
137905
|
-
const monoConfigPath =
|
|
138483
|
+
const monoDir = join187(naxDir, "mono", mc.relativeDir);
|
|
138484
|
+
const monoConfigPath = join187(monoDir, "config.json");
|
|
137906
138485
|
await deps.mkdir(monoDir);
|
|
137907
138486
|
await deps.writeFile(monoConfigPath, JSON.stringify(mc.config, null, 2));
|
|
137908
138487
|
written.push(monoConfigPath);
|
|
@@ -137921,11 +138500,11 @@ var init_setup_write = __esm(() => {
|
|
|
137921
138500
|
});
|
|
137922
138501
|
|
|
137923
138502
|
// src/cli/setup.ts
|
|
137924
|
-
import { join as
|
|
138503
|
+
import { join as join188 } from "path";
|
|
137925
138504
|
async function setupCommand(options = {}) {
|
|
137926
138505
|
const workdir = options.dir ?? process.cwd();
|
|
137927
|
-
const naxDir =
|
|
137928
|
-
const naxConfigPath =
|
|
138506
|
+
const naxDir = join188(workdir, ".nax");
|
|
138507
|
+
const naxConfigPath = join188(naxDir, "config.json");
|
|
137929
138508
|
const exists = await _setupDeps.fileExists(naxConfigPath);
|
|
137930
138509
|
if (exists && !options.force) {
|
|
137931
138510
|
_setupDeps.stderr("[setup] .nax/config.json already exists. Use --force to overwrite.");
|
|
@@ -138008,7 +138587,7 @@ var init_setup = __esm(() => {
|
|
|
138008
138587
|
|
|
138009
138588
|
// src/cli/spec-lint-command.ts
|
|
138010
138589
|
import { existsSync as existsSync39 } from "fs";
|
|
138011
|
-
import { join as
|
|
138590
|
+
import { join as join189 } from "path";
|
|
138012
138591
|
async function resolveSpecPaths(options, deps) {
|
|
138013
138592
|
const explicit = (options.paths ?? []).filter((path) => path.trim().length > 0);
|
|
138014
138593
|
if (explicit.length > 0)
|
|
@@ -138024,7 +138603,7 @@ async function resolveSpecPaths(options, deps) {
|
|
|
138024
138603
|
message: `${options.feature} resolved to ${resolved.specSource.path}; a prd.json has no spec sections to lint. Pass the markdown spec explicitly.`
|
|
138025
138604
|
};
|
|
138026
138605
|
}
|
|
138027
|
-
return [
|
|
138606
|
+
return [join189(options.dir, resolved.specSource.path)];
|
|
138028
138607
|
}
|
|
138029
138608
|
async function lintOne(specPath, options, deps) {
|
|
138030
138609
|
if (!deps.fileExists(specPath)) {
|
|
@@ -138038,7 +138617,7 @@ async function lintOne(specPath, options, deps) {
|
|
|
138038
138617
|
}
|
|
138039
138618
|
const findings = lintSpecContent(content, {
|
|
138040
138619
|
maxAcCount: options.maxAcCount,
|
|
138041
|
-
fileExists: (path) => deps.fileExists(
|
|
138620
|
+
fileExists: (path) => deps.fileExists(join189(options.dir, path))
|
|
138042
138621
|
});
|
|
138043
138622
|
return {
|
|
138044
138623
|
specPath,
|
|
@@ -138114,10 +138693,10 @@ var init_spec_lint_command = __esm(() => {
|
|
|
138114
138693
|
});
|
|
138115
138694
|
|
|
138116
138695
|
// src/cli/status-cost.ts
|
|
138117
|
-
import { basename as
|
|
138696
|
+
import { basename as basename35 } from "path";
|
|
138118
138697
|
async function resolveProject(workdir) {
|
|
138119
138698
|
const config = await loadConfig(workdir).catch(() => null);
|
|
138120
|
-
const project = config?.name?.trim() ||
|
|
138699
|
+
const project = config?.name?.trim() || basename35(workdir);
|
|
138121
138700
|
const outputDir = projectOutputDir(project, config?.outputDir);
|
|
138122
138701
|
return { project, outputDir };
|
|
138123
138702
|
}
|
|
@@ -138250,7 +138829,7 @@ var init_status_cost = __esm(() => {
|
|
|
138250
138829
|
|
|
138251
138830
|
// src/commands/common.ts
|
|
138252
138831
|
import { existsSync as existsSync40, readdirSync as readdirSync6, realpathSync as realpathSync6 } from "fs";
|
|
138253
|
-
import { join as
|
|
138832
|
+
import { join as join190, resolve as resolve52 } from "path";
|
|
138254
138833
|
function resolveProject2(options = {}) {
|
|
138255
138834
|
const { dir, feature } = options;
|
|
138256
138835
|
let projectRoot;
|
|
@@ -138258,12 +138837,12 @@ function resolveProject2(options = {}) {
|
|
|
138258
138837
|
let configPath;
|
|
138259
138838
|
if (dir) {
|
|
138260
138839
|
projectRoot = realpathSync6(resolve52(dir));
|
|
138261
|
-
naxDir =
|
|
138840
|
+
naxDir = join190(projectRoot, ".nax");
|
|
138262
138841
|
if (!existsSync40(naxDir)) {
|
|
138263
138842
|
throw new NaxError(`Directory does not contain a nax project: ${projectRoot}
|
|
138264
138843
|
Expected to find: ${naxDir}`, "NAX_DIR_NOT_FOUND", { projectRoot, naxDir });
|
|
138265
138844
|
}
|
|
138266
|
-
configPath =
|
|
138845
|
+
configPath = join190(naxDir, "config.json");
|
|
138267
138846
|
if (!existsSync40(configPath)) {
|
|
138268
138847
|
throw new NaxError(`.nax directory found but config.json is missing: ${naxDir}
|
|
138269
138848
|
Expected to find: ${configPath}`, "CONFIG_NOT_FOUND", { naxDir, configPath });
|
|
@@ -138271,17 +138850,17 @@ Expected to find: ${configPath}`, "CONFIG_NOT_FOUND", { naxDir, configPath });
|
|
|
138271
138850
|
} else {
|
|
138272
138851
|
const found = findProjectRoot(process.cwd());
|
|
138273
138852
|
if (!found) {
|
|
138274
|
-
const cwdNaxDir =
|
|
138853
|
+
const cwdNaxDir = join190(process.cwd(), ".nax");
|
|
138275
138854
|
if (existsSync40(cwdNaxDir)) {
|
|
138276
|
-
const cwdConfigPath =
|
|
138855
|
+
const cwdConfigPath = join190(cwdNaxDir, "config.json");
|
|
138277
138856
|
throw new NaxError(`.nax directory found but config.json is missing: ${cwdNaxDir}
|
|
138278
138857
|
Expected to find: ${cwdConfigPath}`, "CONFIG_NOT_FOUND", { naxDir: cwdNaxDir, configPath: cwdConfigPath });
|
|
138279
138858
|
}
|
|
138280
138859
|
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() });
|
|
138281
138860
|
}
|
|
138282
138861
|
projectRoot = found;
|
|
138283
|
-
naxDir =
|
|
138284
|
-
configPath =
|
|
138862
|
+
naxDir = join190(projectRoot, ".nax");
|
|
138863
|
+
configPath = join190(naxDir, "config.json");
|
|
138285
138864
|
}
|
|
138286
138865
|
let featureDir;
|
|
138287
138866
|
if (feature) {
|
|
@@ -138290,8 +138869,8 @@ Expected to find: ${cwdConfigPath}`, "CONFIG_NOT_FOUND", { naxDir: cwdNaxDir, co
|
|
|
138290
138869
|
} catch (error) {
|
|
138291
138870
|
throw new NaxError(error.message, "FEATURE_INVALID", { feature });
|
|
138292
138871
|
}
|
|
138293
|
-
const featuresDir =
|
|
138294
|
-
featureDir =
|
|
138872
|
+
const featuresDir = join190(naxDir, "features");
|
|
138873
|
+
featureDir = join190(featuresDir, feature);
|
|
138295
138874
|
if (!existsSync40(featureDir)) {
|
|
138296
138875
|
const availableFeatures = existsSync40(featuresDir) ? readdirSync6(featuresDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name) : [];
|
|
138297
138876
|
const availableMsg = availableFeatures.length > 0 ? `
|
|
@@ -138315,7 +138894,7 @@ No features found in this project.`;
|
|
|
138315
138894
|
};
|
|
138316
138895
|
}
|
|
138317
138896
|
function resolveSingleFeature(naxDir, remediationHint = "pass -f <name>") {
|
|
138318
|
-
const featuresDir =
|
|
138897
|
+
const featuresDir = join190(naxDir, "features");
|
|
138319
138898
|
const available = existsSync40(featuresDir) ? readdirSync6(featuresDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort() : [];
|
|
138320
138899
|
if (available.length === 1)
|
|
138321
138900
|
return available[0];
|
|
@@ -138340,7 +138919,7 @@ async function resolveProjectAsync(options = {}) {
|
|
|
138340
138919
|
}
|
|
138341
138920
|
const isPlainName = !dir.includes("/") && !dir.includes("\\");
|
|
138342
138921
|
if (isPlainName) {
|
|
138343
|
-
const registryIdentityPath =
|
|
138922
|
+
const registryIdentityPath = join190(globalConfigDir(), dir, ".identity");
|
|
138344
138923
|
const identityFile = Bun.file(registryIdentityPath);
|
|
138345
138924
|
if (await identityFile.exists()) {
|
|
138346
138925
|
try {
|
|
@@ -138372,12 +138951,12 @@ function findProjectRoot(startDir) {
|
|
|
138372
138951
|
let current = resolve52(startDir);
|
|
138373
138952
|
let depth = 0;
|
|
138374
138953
|
while (depth < MAX_DIRECTORY_DEPTH) {
|
|
138375
|
-
const naxDir =
|
|
138376
|
-
const configPath =
|
|
138954
|
+
const naxDir = join190(current, ".nax");
|
|
138955
|
+
const configPath = join190(naxDir, "config.json");
|
|
138377
138956
|
if (existsSync40(configPath)) {
|
|
138378
138957
|
return realpathSync6(current);
|
|
138379
138958
|
}
|
|
138380
|
-
const parent =
|
|
138959
|
+
const parent = join190(current, "..");
|
|
138381
138960
|
if (parent === current) {
|
|
138382
138961
|
break;
|
|
138383
138962
|
}
|
|
@@ -138512,9 +139091,9 @@ var init_status_features_details = __esm(() => {
|
|
|
138512
139091
|
|
|
138513
139092
|
// src/cli/status-features.ts
|
|
138514
139093
|
import { existsSync as existsSync41, readdirSync as readdirSync7 } from "fs";
|
|
138515
|
-
import { basename as
|
|
139094
|
+
import { basename as basename36, join as join191, resolve as resolve53 } from "path";
|
|
138516
139095
|
async function loadStatusFile(featureDir) {
|
|
138517
|
-
const statusPath =
|
|
139096
|
+
const statusPath = join191(featureDir, "status.json");
|
|
138518
139097
|
if (!existsSync41(statusPath)) {
|
|
138519
139098
|
return null;
|
|
138520
139099
|
}
|
|
@@ -138528,9 +139107,9 @@ async function loadStatusFile(featureDir) {
|
|
|
138528
139107
|
}
|
|
138529
139108
|
async function loadProjectStatusFile(projectDir) {
|
|
138530
139109
|
const config = await _statusFeaturesDeps.loadConfig(projectDir).catch(() => null);
|
|
138531
|
-
const projectKey = config?.name?.trim() ||
|
|
139110
|
+
const projectKey = config?.name?.trim() || basename36(projectDir);
|
|
138532
139111
|
const outputDir = _statusFeaturesDeps.projectOutputDir(projectKey, config?.outputDir);
|
|
138533
|
-
const statusPath =
|
|
139112
|
+
const statusPath = join191(outputDir, "status.json");
|
|
138534
139113
|
if (!existsSync41(statusPath)) {
|
|
138535
139114
|
return null;
|
|
138536
139115
|
}
|
|
@@ -138572,7 +139151,7 @@ function isUsableStatusFile(value) {
|
|
|
138572
139151
|
return true;
|
|
138573
139152
|
}
|
|
138574
139153
|
async function getFeatureSummary(featureName, featureDir, runsDir) {
|
|
138575
|
-
const prdPath =
|
|
139154
|
+
const prdPath = join191(featureDir, "prd.json");
|
|
138576
139155
|
if (!existsSync41(prdPath)) {
|
|
138577
139156
|
return {
|
|
138578
139157
|
name: featureName,
|
|
@@ -138631,7 +139210,7 @@ async function getFeatureSummary(featureName, featureDir, runsDir) {
|
|
|
138631
139210
|
}
|
|
138632
139211
|
async function displayAllFeatures(projectRoot) {
|
|
138633
139212
|
const config = await _statusFeaturesDeps.loadConfig(projectRoot).catch(() => null);
|
|
138634
|
-
const projectKey = config?.name?.trim() ||
|
|
139213
|
+
const projectKey = config?.name?.trim() || basename36(projectRoot);
|
|
138635
139214
|
const outputDir = _statusFeaturesDeps.projectOutputDir(projectKey, config?.outputDir);
|
|
138636
139215
|
const featuresRepoDir = featuresDir(projectRoot);
|
|
138637
139216
|
if (!existsSync41(featuresRepoDir)) {
|
|
@@ -138689,7 +139268,7 @@ async function displayAllFeatures(projectRoot) {
|
|
|
138689
139268
|
console.log();
|
|
138690
139269
|
}
|
|
138691
139270
|
}
|
|
138692
|
-
const summaries = await Promise.all(features.map((name) => getFeatureSummary(name, featureDir(projectRoot, name),
|
|
139271
|
+
const summaries = await Promise.all(features.map((name) => getFeatureSummary(name, featureDir(projectRoot, name), join191(outputDir, "features", name, "runs"))));
|
|
138693
139272
|
console.log(source_default.bold(`\uD83D\uDCCA Features
|
|
138694
139273
|
`));
|
|
138695
139274
|
const header = ` ${"Feature".padEnd(25)} ${"Done".padEnd(6)} ${"Failed".padEnd(8)} ${"Pending".padEnd(9)} ${"Last Run".padEnd(22)} ${"Cost".padEnd(10)} Status`;
|
|
@@ -138717,7 +139296,7 @@ async function displayAllFeatures(projectRoot) {
|
|
|
138717
139296
|
console.log();
|
|
138718
139297
|
}
|
|
138719
139298
|
async function displayFeatureDetails(featureName, featureDir) {
|
|
138720
|
-
const prdPath =
|
|
139299
|
+
const prdPath = join191(featureDir, "prd.json");
|
|
138721
139300
|
if (!existsSync41(prdPath)) {
|
|
138722
139301
|
displayNoPrdNotice(featureName);
|
|
138723
139302
|
return;
|
|
@@ -138741,7 +139320,7 @@ async function displayFeatureDetails(featureName, featureDir) {
|
|
|
138741
139320
|
function resolveRootFromDir(dir) {
|
|
138742
139321
|
const resolved = resolve53(dir);
|
|
138743
139322
|
const naxDir = _statusFeaturesDeps.findProjectDir(resolved);
|
|
138744
|
-
return naxDir ?
|
|
139323
|
+
return naxDir ? join191(naxDir, "..") : resolved;
|
|
138745
139324
|
}
|
|
138746
139325
|
async function displayFeatureStatus(options = {}) {
|
|
138747
139326
|
if (options.feature) {
|
|
@@ -139077,12 +139656,12 @@ var init_supplementary_items = __esm(() => {
|
|
|
139077
139656
|
});
|
|
139078
139657
|
|
|
139079
139658
|
// src/workflow/run-verdict.ts
|
|
139080
|
-
import { basename as
|
|
139659
|
+
import { basename as basename37 } from "path";
|
|
139081
139660
|
async function newestResult(dir, feature) {
|
|
139082
139661
|
for (const runDir of await runDirsNewestFirst(workflowFeatureDir(dir, feature))) {
|
|
139083
139662
|
const result = await readResult(runDir);
|
|
139084
139663
|
if (result)
|
|
139085
|
-
return { runId:
|
|
139664
|
+
return { runId: basename37(runDir), runDir, result };
|
|
139086
139665
|
}
|
|
139087
139666
|
return null;
|
|
139088
139667
|
}
|
|
@@ -139129,7 +139708,7 @@ var init_run_verdict = __esm(() => {
|
|
|
139129
139708
|
});
|
|
139130
139709
|
|
|
139131
139710
|
// src/cli/workflow-forge.ts
|
|
139132
|
-
import { basename as
|
|
139711
|
+
import { basename as basename38 } from "path";
|
|
139133
139712
|
var _workflowForgeDeps;
|
|
139134
139713
|
var init_workflow_forge = __esm(() => {
|
|
139135
139714
|
init_config();
|
|
@@ -139142,14 +139721,14 @@ var init_workflow_forge = __esm(() => {
|
|
|
139142
139721
|
waitForChecks,
|
|
139143
139722
|
resolveOutputDir: async (dir) => {
|
|
139144
139723
|
const config = await loadConfig(dir).catch(() => null);
|
|
139145
|
-
return projectOutputDir(config?.name?.trim() ||
|
|
139724
|
+
return projectOutputDir(config?.name?.trim() || basename38(dir), config?.outputDir);
|
|
139146
139725
|
}
|
|
139147
139726
|
};
|
|
139148
139727
|
});
|
|
139149
139728
|
|
|
139150
139729
|
// src/workflow/decisions-sidecar.ts
|
|
139151
|
-
import { mkdir as mkdir51, readdir as
|
|
139152
|
-
import { dirname as
|
|
139730
|
+
import { mkdir as mkdir51, readdir as readdir14, rename as rename17, unlink as unlink12 } from "fs/promises";
|
|
139731
|
+
import { dirname as dirname45, join as join192 } from "path";
|
|
139153
139732
|
function invalid(message) {
|
|
139154
139733
|
return new NaxError(message, DECISIONS_INVALID, { stage: "workflow" });
|
|
139155
139734
|
}
|
|
@@ -139292,7 +139871,7 @@ async function newestSidecar(runDir) {
|
|
|
139292
139871
|
const newest = (await sidecarNames(runDir))[0];
|
|
139293
139872
|
if (newest === undefined)
|
|
139294
139873
|
return null;
|
|
139295
|
-
const path =
|
|
139874
|
+
const path = join192(runDir, newest);
|
|
139296
139875
|
return { path, sidecar: await readSidecar(path) };
|
|
139297
139876
|
}
|
|
139298
139877
|
async function discard2(path) {
|
|
@@ -139301,7 +139880,7 @@ async function discard2(path) {
|
|
|
139301
139880
|
} catch {}
|
|
139302
139881
|
}
|
|
139303
139882
|
async function writeSidecar(path, sidecar) {
|
|
139304
|
-
await _sidecarDeps.mkdir(
|
|
139883
|
+
await _sidecarDeps.mkdir(dirname45(path), { recursive: true });
|
|
139305
139884
|
const tmp = tempSibling(path);
|
|
139306
139885
|
try {
|
|
139307
139886
|
await Bun.write(tmp, `${JSON.stringify(sidecar, null, 2)}
|
|
@@ -139316,7 +139895,7 @@ var _sidecarDeps, DISPOSITIONS, SIDECAR_OUTCOMES, SIDECAR_KINDS, DECISIONS_INVAL
|
|
|
139316
139895
|
var init_decisions_sidecar = __esm(() => {
|
|
139317
139896
|
init_internal();
|
|
139318
139897
|
init_errors4();
|
|
139319
|
-
_sidecarDeps = { mkdir: mkdir51, readdir:
|
|
139898
|
+
_sidecarDeps = { mkdir: mkdir51, readdir: readdir14, rename: rename17, unlink: unlink12 };
|
|
139320
139899
|
DISPOSITIONS = ["fixed", "waived", "confirmed", "overridden", "verified"];
|
|
139321
139900
|
SIDECAR_OUTCOMES = ["pending", "promoted", "verified-ready", "abandoned"];
|
|
139322
139901
|
SIDECAR_KINDS = ["finding", "advisor", "gate", "ci", "story", "cannot-verify", "minor", "reason"];
|
|
@@ -139327,7 +139906,7 @@ var init_decisions_sidecar = __esm(() => {
|
|
|
139327
139906
|
});
|
|
139328
139907
|
|
|
139329
139908
|
// src/workflow/pr-state.ts
|
|
139330
|
-
function
|
|
139909
|
+
function isRecord15(value) {
|
|
139331
139910
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
139332
139911
|
}
|
|
139333
139912
|
function readFailed(prRef, detail, context) {
|
|
@@ -139356,7 +139935,7 @@ function parseOutput(stdout, prRef, forge) {
|
|
|
139356
139935
|
parsed = undefined;
|
|
139357
139936
|
}
|
|
139358
139937
|
}
|
|
139359
|
-
if (!
|
|
139938
|
+
if (!isRecord15(parsed)) {
|
|
139360
139939
|
const detail = out === "" ? "empty output" : `unparseable output: ${out.slice(0, DETAIL_SLICE)}`;
|
|
139361
139940
|
throw readFailed(prRef, detail, { forge });
|
|
139362
139941
|
}
|
|
@@ -139454,7 +140033,7 @@ var init_promote = __esm(() => {
|
|
|
139454
140033
|
});
|
|
139455
140034
|
|
|
139456
140035
|
// src/cli/workflow-promote.ts
|
|
139457
|
-
import { join as
|
|
140036
|
+
import { join as join193 } from "path";
|
|
139458
140037
|
function invalid2(message, context = {}) {
|
|
139459
140038
|
return new NaxError(message, PROMOTE_INVALID, { stage: "workflow", ...context });
|
|
139460
140039
|
}
|
|
@@ -139543,7 +140122,7 @@ function promotedSidecar(target, now) {
|
|
|
139543
140122
|
async function recordAction(target) {
|
|
139544
140123
|
const now = target.forgeDeps.now();
|
|
139545
140124
|
const found = target.found;
|
|
139546
|
-
const path = found?.path ??
|
|
140125
|
+
const path = found?.path ?? join193(target.loaded.runDir, sidecarFileName(now));
|
|
139547
140126
|
const sidecar = found ? { ...found.sidecar, outcome: "promoted", url: target.url } : promotedSidecar(target, now);
|
|
139548
140127
|
await writeSidecar(path, sidecar);
|
|
139549
140128
|
return { name: "record", status: "done" };
|
|
@@ -139627,7 +140206,7 @@ var init_workflow_promote = __esm(() => {
|
|
|
139627
140206
|
});
|
|
139628
140207
|
|
|
139629
140208
|
// src/cli/workflow-record.ts
|
|
139630
|
-
import { join as
|
|
140209
|
+
import { join as join194, relative as relative48 } from "path";
|
|
139631
140210
|
function invalid3(message, context = {}) {
|
|
139632
140211
|
return new NaxError(message, RECORD_INVALID, { stage: "workflow", ...context });
|
|
139633
140212
|
}
|
|
@@ -139699,7 +140278,7 @@ async function writeRecorded(input) {
|
|
|
139699
140278
|
if (input.opts.decisions === undefined) {
|
|
139700
140279
|
throw invalid3(`no decisions sidecar for run ${input.loaded.runId}; pass --decisions`);
|
|
139701
140280
|
}
|
|
139702
|
-
const path =
|
|
140281
|
+
const path = join194(input.loaded.runDir, sidecarFileName(input.now));
|
|
139703
140282
|
const sidecar = newSidecar(input);
|
|
139704
140283
|
await writeSidecar(path, sidecar);
|
|
139705
140284
|
return { path, sidecar };
|
|
@@ -139869,6 +140448,8 @@ var init_cli2 = __esm(() => {
|
|
|
139869
140448
|
init_confirm();
|
|
139870
140449
|
init_context2();
|
|
139871
140450
|
init_context_fragments();
|
|
140451
|
+
init_cost3();
|
|
140452
|
+
init_cost_ledger_query();
|
|
139872
140453
|
init_features_acceptance();
|
|
139873
140454
|
init_features_resolve();
|
|
139874
140455
|
init_gates();
|
|
@@ -152469,7 +153050,7 @@ var init_worktree_id2 = __esm(() => {
|
|
|
152469
153050
|
});
|
|
152470
153051
|
|
|
152471
153052
|
// src/bakeoff/contestant.ts
|
|
152472
|
-
import { basename as
|
|
153053
|
+
import { basename as basename42, join as join207 } from "path";
|
|
152473
153054
|
function aggregateTotals(metrics) {
|
|
152474
153055
|
let costUsd = 0;
|
|
152475
153056
|
let wallTimeMs = 0;
|
|
@@ -152499,8 +153080,8 @@ async function runContestant(agent, options, deps) {
|
|
|
152499
153080
|
}
|
|
152500
153081
|
};
|
|
152501
153082
|
const worktree = storyWorktreePath(options.projectRoot, storyId);
|
|
152502
|
-
const projectKey = options.config.name?.trim() ||
|
|
152503
|
-
const outputDir =
|
|
153083
|
+
const projectKey = options.config.name?.trim() || basename42(options.projectRoot);
|
|
153084
|
+
const outputDir = join207(projectOutputDir(projectKey, options.outputDir), "bakeoff", feature, agent);
|
|
152504
153085
|
const context = {
|
|
152505
153086
|
profile: agent,
|
|
152506
153087
|
config: { ...pinnedConfig, outputDir },
|
|
@@ -152557,7 +153138,7 @@ var init_contestant = __esm(() => {
|
|
|
152557
153138
|
});
|
|
152558
153139
|
|
|
152559
153140
|
// src/bakeoff/pipeline-adapter.ts
|
|
152560
|
-
import { join as
|
|
153141
|
+
import { join as join208 } from "path";
|
|
152561
153142
|
function toResults(runs, result) {
|
|
152562
153143
|
const latest = runs.at(-1);
|
|
152563
153144
|
if (latest && latest.stories.length > 0) {
|
|
@@ -152583,8 +153164,8 @@ async function pipeline2(ctx) {
|
|
|
152583
153164
|
validateFeatureName(ctx.feature);
|
|
152584
153165
|
const hooks = await _pipelineAdapterDeps.loadHooksConfig(ctx.worktree, globalConfigDir());
|
|
152585
153166
|
const contestantFeatureDir = featureDir(ctx.worktree, ctx.feature);
|
|
152586
|
-
const prdPath =
|
|
152587
|
-
const statusFile =
|
|
153167
|
+
const prdPath = join208(contestantFeatureDir, "prd.json");
|
|
153168
|
+
const statusFile = join208(ctx.outputDir, "status.json");
|
|
152588
153169
|
const result = await _pipelineAdapterDeps.run({
|
|
152589
153170
|
prdPath,
|
|
152590
153171
|
workdir: ctx.worktree,
|
|
@@ -152631,9 +153212,9 @@ var init_ranking = __esm(() => {
|
|
|
152631
153212
|
});
|
|
152632
153213
|
|
|
152633
153214
|
// src/bakeoff/coordinator.ts
|
|
152634
|
-
import { join as
|
|
153215
|
+
import { join as join209 } from "path";
|
|
152635
153216
|
async function persistBakeoffResult(result, outputDir) {
|
|
152636
|
-
const filePath =
|
|
153217
|
+
const filePath = join209(outputDir, "bakeoff", result.feature, "bakeoff.json");
|
|
152637
153218
|
await Bun.write(filePath, JSON.stringify(result, null, 2));
|
|
152638
153219
|
}
|
|
152639
153220
|
async function runBakeoff(options, deps = {}) {
|
|
@@ -152675,7 +153256,7 @@ async function handleRunAction(options, deps = _bakeoffCliDeps) {
|
|
|
152675
153256
|
if (compareList.length === 0) {
|
|
152676
153257
|
return deps.runSingleAgent(options);
|
|
152677
153258
|
}
|
|
152678
|
-
const prdPath =
|
|
153259
|
+
const prdPath = join209(featureDir(options.projectRoot, options.feature), "prd.json");
|
|
152679
153260
|
await deps.assertPrdCommitted(prdPath, options.projectRoot);
|
|
152680
153261
|
const agents = options.agents ?? compareList;
|
|
152681
153262
|
return deps.runBakeoff({
|
|
@@ -152883,7 +153464,7 @@ var init_migrate = __esm(() => {
|
|
|
152883
153464
|
});
|
|
152884
153465
|
|
|
152885
153466
|
// src/cli/mcp.ts
|
|
152886
|
-
async function runMcpLockCommand(workdir) {
|
|
153467
|
+
async function runMcpLockCommand(workdir, opts) {
|
|
152887
153468
|
const config = await loadConfig(workdir);
|
|
152888
153469
|
const servers = config.mcp?.servers ?? {};
|
|
152889
153470
|
const enabled = Object.entries(servers).filter(([, server]) => server.enabled);
|
|
@@ -152891,6 +153472,7 @@ async function runMcpLockCommand(workdir) {
|
|
|
152891
153472
|
console.log("No enabled MCP servers configured; nothing to lock.");
|
|
152892
153473
|
return;
|
|
152893
153474
|
}
|
|
153475
|
+
const target = opts?.global === true ? globalMcpLockPath() : mcpLockPath(workdir);
|
|
152894
153476
|
const pool = createMcpPool({ servers });
|
|
152895
153477
|
try {
|
|
152896
153478
|
const locked = {};
|
|
@@ -152901,8 +153483,12 @@ async function runMcpLockCommand(workdir) {
|
|
|
152901
153483
|
if (tools.length === 0)
|
|
152902
153484
|
console.log(` (server advertised nothing - check \`${servers[id]?.command}\` runs)`);
|
|
152903
153485
|
}
|
|
152904
|
-
|
|
152905
|
-
|
|
153486
|
+
const lock = { version: 1, servers: locked };
|
|
153487
|
+
if (opts?.global === true)
|
|
153488
|
+
await writeMcpLockAt(target, lock);
|
|
153489
|
+
else
|
|
153490
|
+
await writeMcpLock(workdir, lock);
|
|
153491
|
+
console.log(`Wrote ${target}`);
|
|
152906
153492
|
} finally {
|
|
152907
153493
|
await pool.close();
|
|
152908
153494
|
}
|
|
@@ -152915,7 +153501,7 @@ var init_mcp3 = __esm(() => {
|
|
|
152915
153501
|
// src/commands/curator.ts
|
|
152916
153502
|
import { readdirSync as readdirSync10 } from "fs";
|
|
152917
153503
|
import { unlink as unlink14 } from "fs/promises";
|
|
152918
|
-
import { join as
|
|
153504
|
+
import { join as join211, resolve as resolve55, sep as sep28 } from "path";
|
|
152919
153505
|
function openInEditor(filePath) {
|
|
152920
153506
|
const [editor, ...args] = parseCommandToArgv(process.env.EDITOR ?? process.env.VISUAL ?? "vi");
|
|
152921
153507
|
if (!editor)
|
|
@@ -153021,7 +153607,7 @@ async function curatorStatus(options) {
|
|
|
153021
153607
|
const config = await _curatorCmdDeps.loadConfig(resolved.projectDir);
|
|
153022
153608
|
const projectKey = getProjectKey(config, resolved.projectDir);
|
|
153023
153609
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
153024
|
-
const runsDir =
|
|
153610
|
+
const runsDir = join211(outputDir, "runs");
|
|
153025
153611
|
const runIds = listRunIds(runsDir);
|
|
153026
153612
|
let runId;
|
|
153027
153613
|
if (options.run) {
|
|
@@ -153038,8 +153624,8 @@ async function curatorStatus(options) {
|
|
|
153038
153624
|
runId = runIds[runIds.length - 1];
|
|
153039
153625
|
}
|
|
153040
153626
|
console.log(`Run: ${runId}`);
|
|
153041
|
-
const runDir =
|
|
153042
|
-
const observationsPath =
|
|
153627
|
+
const runDir = join211(runsDir, runId);
|
|
153628
|
+
const observationsPath = join211(runDir, "observations.jsonl");
|
|
153043
153629
|
const observations = await parseObservations(observationsPath);
|
|
153044
153630
|
const counts = new Map;
|
|
153045
153631
|
for (const obs of observations) {
|
|
@@ -153049,7 +153635,7 @@ async function curatorStatus(options) {
|
|
|
153049
153635
|
for (const [kind, count] of counts.entries()) {
|
|
153050
153636
|
console.log(` ${kind}: ${count}`);
|
|
153051
153637
|
}
|
|
153052
|
-
const proposalsPath =
|
|
153638
|
+
const proposalsPath = join211(runDir, "curator-proposals.md");
|
|
153053
153639
|
const proposalText = await _curatorCmdDeps.readFile(proposalsPath).catch(() => null);
|
|
153054
153640
|
if (proposalText !== null) {
|
|
153055
153641
|
console.log("");
|
|
@@ -153078,8 +153664,8 @@ async function curatorCommit(options) {
|
|
|
153078
153664
|
const config = await _curatorCmdDeps.loadConfig(resolved.projectDir);
|
|
153079
153665
|
const projectKey = getProjectKey(config, resolved.projectDir);
|
|
153080
153666
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
153081
|
-
const runDir =
|
|
153082
|
-
const proposalsPath =
|
|
153667
|
+
const runDir = join211(outputDir, "runs", options.runId);
|
|
153668
|
+
const proposalsPath = join211(runDir, "curator-proposals.md");
|
|
153083
153669
|
const proposalText = await _curatorCmdDeps.readFile(proposalsPath).catch(() => null);
|
|
153084
153670
|
if (proposalText === null) {
|
|
153085
153671
|
console.log(`curator-proposals.md not found for run ${options.runId}.`);
|
|
@@ -153209,7 +153795,7 @@ async function curatorDryrun(options) {
|
|
|
153209
153795
|
const config = await _curatorCmdDeps.loadConfig(resolved.projectDir);
|
|
153210
153796
|
const projectKey = getProjectKey(config, resolved.projectDir);
|
|
153211
153797
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
153212
|
-
const runsDir =
|
|
153798
|
+
const runsDir = join211(outputDir, "runs");
|
|
153213
153799
|
const runIds = listRunIds(runsDir);
|
|
153214
153800
|
if (runIds.length === 0) {
|
|
153215
153801
|
console.log("No runs found.");
|
|
@@ -153220,7 +153806,7 @@ async function curatorDryrun(options) {
|
|
|
153220
153806
|
console.log(`Run ${options.run} not found in ${runsDir}.`);
|
|
153221
153807
|
return;
|
|
153222
153808
|
}
|
|
153223
|
-
const observationsPath =
|
|
153809
|
+
const observationsPath = join211(runsDir, runId, "observations.jsonl");
|
|
153224
153810
|
const observations = await parseObservations(observationsPath);
|
|
153225
153811
|
const thresholds = getThresholds(config);
|
|
153226
153812
|
const proposals = runHeuristics(observations, thresholds);
|
|
@@ -153252,12 +153838,12 @@ async function curatorGc(options) {
|
|
|
153252
153838
|
dropUnattributed: sweep
|
|
153253
153839
|
});
|
|
153254
153840
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
153255
|
-
const perRunsDir =
|
|
153841
|
+
const perRunsDir = join211(outputDir, "runs");
|
|
153256
153842
|
for (const runId of uniqueRunIds) {
|
|
153257
153843
|
if (!keepSet.has(runId)) {
|
|
153258
|
-
const runDir =
|
|
153259
|
-
await _curatorCmdDeps.removeFile(
|
|
153260
|
-
await _curatorCmdDeps.removeFile(
|
|
153844
|
+
const runDir = join211(perRunsDir, runId);
|
|
153845
|
+
await _curatorCmdDeps.removeFile(join211(runDir, "observations.jsonl"));
|
|
153846
|
+
await _curatorCmdDeps.removeFile(join211(runDir, "curator-proposals.md"));
|
|
153261
153847
|
}
|
|
153262
153848
|
}
|
|
153263
153849
|
const droppedRuns = Math.max(0, uniqueRunIds.length - keepSet.size);
|
|
@@ -153382,7 +153968,7 @@ init_src();
|
|
|
153382
153968
|
init_source();
|
|
153383
153969
|
import { existsSync as existsSync50, mkdirSync as mkdirSync13, symlinkSync as symlinkSync4, unlinkSync } from "fs";
|
|
153384
153970
|
import { homedir as homedir9 } from "os";
|
|
153385
|
-
import { join as
|
|
153971
|
+
import { join as join212 } from "path";
|
|
153386
153972
|
|
|
153387
153973
|
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/index.js
|
|
153388
153974
|
var { Argument } = require_argument();
|
|
@@ -153432,7 +154018,7 @@ init_config();
|
|
|
153432
154018
|
init_logger2();
|
|
153433
154019
|
init_detect();
|
|
153434
154020
|
init_common();
|
|
153435
|
-
import { join as
|
|
154021
|
+
import { join as join195 } from "path";
|
|
153436
154022
|
function resolveEffective(detected, configPatterns) {
|
|
153437
154023
|
if (configPatterns !== undefined)
|
|
153438
154024
|
return "config";
|
|
@@ -153517,7 +154103,7 @@ async function detectCommand(options) {
|
|
|
153517
154103
|
const rootDetected = detectionMap[""] ?? { patterns: [], confidence: "empty", sources: [] };
|
|
153518
154104
|
const pkgEntries = await Promise.all(packageDirs.map(async (dir) => {
|
|
153519
154105
|
const det = detectionMap[dir] ?? { patterns: [], confidence: "empty", sources: [] };
|
|
153520
|
-
const pkgConfigPath =
|
|
154106
|
+
const pkgConfigPath = join195(workdir, ".nax", "mono", dir, "config.json");
|
|
153521
154107
|
const pkgRaw = await loadRawConfig(pkgConfigPath);
|
|
153522
154108
|
const pkgPatterns = deepGet(pkgRaw, TEST_PATTERNS_KEY);
|
|
153523
154109
|
const effective = Array.isArray(pkgPatterns) ? pkgPatterns : undefined;
|
|
@@ -153571,13 +154157,13 @@ async function detectCommand(options) {
|
|
|
153571
154157
|
if (rootDetected.confidence === "empty") {
|
|
153572
154158
|
console.log(source_default.yellow(" root: skipped (empty detection)"));
|
|
153573
154159
|
} else {
|
|
153574
|
-
const rootConfigPath =
|
|
154160
|
+
const rootConfigPath = join195(workdir, ".nax", "config.json");
|
|
153575
154161
|
try {
|
|
153576
154162
|
const status = await applyToConfig(rootConfigPath, rootDetected.patterns, options.force ?? false);
|
|
153577
154163
|
if (status === "skipped") {
|
|
153578
154164
|
console.log(source_default.dim(" root: skipped (testFilePatterns already set; use --force to overwrite)"));
|
|
153579
154165
|
} else {
|
|
153580
|
-
console.log(source_default.green(` root: ${status} \u2192 ${
|
|
154166
|
+
console.log(source_default.green(` root: ${status} \u2192 ${join195(".nax", "config.json")}`));
|
|
153581
154167
|
}
|
|
153582
154168
|
} catch (err) {
|
|
153583
154169
|
console.error(source_default.red(` root: write failed \u2014 ${err.message}`));
|
|
@@ -153590,13 +154176,13 @@ async function detectCommand(options) {
|
|
|
153590
154176
|
console.log(source_default.dim(` ${dir}: skipped (empty detection)`));
|
|
153591
154177
|
continue;
|
|
153592
154178
|
}
|
|
153593
|
-
const pkgConfigPath =
|
|
154179
|
+
const pkgConfigPath = join195(workdir, ".nax", "mono", dir, "config.json");
|
|
153594
154180
|
try {
|
|
153595
154181
|
const status = await applyToConfig(pkgConfigPath, det.patterns, options.force ?? false);
|
|
153596
154182
|
if (status === "skipped") {
|
|
153597
154183
|
console.log(source_default.dim(` ${dir}: skipped (already set)`));
|
|
153598
154184
|
} else {
|
|
153599
|
-
console.log(source_default.green(` ${dir}: ${status} \u2192 ${
|
|
154185
|
+
console.log(source_default.green(` ${dir}: ${status} \u2192 ${join195(".nax", "mono", dir, "config.json")}`));
|
|
153600
154186
|
}
|
|
153601
154187
|
} catch (err) {
|
|
153602
154188
|
console.error(source_default.red(` ${dir}: write failed \u2014 ${err.message}`));
|
|
@@ -153621,7 +154207,7 @@ init_prd();
|
|
|
153621
154207
|
init_precheck();
|
|
153622
154208
|
init_common();
|
|
153623
154209
|
import { existsSync as existsSync42 } from "fs";
|
|
153624
|
-
import { join as
|
|
154210
|
+
import { join as join196 } from "path";
|
|
153625
154211
|
async function precheckCommand(options) {
|
|
153626
154212
|
const resolved = resolveProject2({
|
|
153627
154213
|
dir: options.dir,
|
|
@@ -153634,7 +154220,7 @@ async function precheckCommand(options) {
|
|
|
153634
154220
|
process.exit(result.passed ? EXIT_CODES.SUCCESS : EXIT_CODES.BLOCKER);
|
|
153635
154221
|
return;
|
|
153636
154222
|
}
|
|
153637
|
-
const naxDir =
|
|
154223
|
+
const naxDir = join196(resolved.projectDir, ".nax");
|
|
153638
154224
|
let featureName = options.feature;
|
|
153639
154225
|
if (!featureName) {
|
|
153640
154226
|
try {
|
|
@@ -153644,8 +154230,8 @@ async function precheckCommand(options) {
|
|
|
153644
154230
|
process.exit(1);
|
|
153645
154231
|
}
|
|
153646
154232
|
}
|
|
153647
|
-
const featureDir =
|
|
153648
|
-
const prdPath =
|
|
154233
|
+
const featureDir = join196(naxDir, "features", featureName);
|
|
154234
|
+
const prdPath = join196(featureDir, "prd.json");
|
|
153649
154235
|
if (!existsSync42(featureDir)) {
|
|
153650
154236
|
console.error(source_default.red(`Feature not found: ${featureName}`));
|
|
153651
154237
|
process.exit(1);
|
|
@@ -153675,7 +154261,7 @@ async function doctorCommand(options) {
|
|
|
153675
154261
|
init_errors4();
|
|
153676
154262
|
init_common();
|
|
153677
154263
|
import { existsSync as existsSync44 } from "fs";
|
|
153678
|
-
import { join as
|
|
154264
|
+
import { join as join199 } from "path";
|
|
153679
154265
|
|
|
153680
154266
|
// src/commands/logs-formatter.ts
|
|
153681
154267
|
init_source();
|
|
@@ -153683,14 +154269,14 @@ init_formatter();
|
|
|
153683
154269
|
init_summary();
|
|
153684
154270
|
init_bun_deps();
|
|
153685
154271
|
import { readdirSync as readdirSync9 } from "fs";
|
|
153686
|
-
import { join as
|
|
154272
|
+
import { join as join198 } from "path";
|
|
153687
154273
|
|
|
153688
154274
|
// src/commands/logs-reader.ts
|
|
153689
154275
|
init_errors4();
|
|
153690
154276
|
init_paths4();
|
|
153691
154277
|
import { existsSync as existsSync43, readdirSync as readdirSync8 } from "fs";
|
|
153692
|
-
import { readdir as
|
|
153693
|
-
import { join as
|
|
154278
|
+
import { readdir as readdir15 } from "fs/promises";
|
|
154279
|
+
import { join as join197 } from "path";
|
|
153694
154280
|
var _logsReaderDeps = {
|
|
153695
154281
|
getRunsDir
|
|
153696
154282
|
};
|
|
@@ -153698,14 +154284,14 @@ async function resolveRunFileFromRegistry(runId) {
|
|
|
153698
154284
|
const runsDir = _logsReaderDeps.getRunsDir();
|
|
153699
154285
|
let entries;
|
|
153700
154286
|
try {
|
|
153701
|
-
entries = await
|
|
154287
|
+
entries = await readdir15(runsDir);
|
|
153702
154288
|
} catch {
|
|
153703
154289
|
throw new NaxError(`Run not found in registry: ${runId}`, "RUN_NOT_FOUND", { stage: "logs", runId });
|
|
153704
154290
|
}
|
|
153705
154291
|
let exactMatch = null;
|
|
153706
154292
|
const prefixMatches = [];
|
|
153707
154293
|
for (const entry of entries) {
|
|
153708
|
-
const metaPath =
|
|
154294
|
+
const metaPath = join197(runsDir, entry, "meta.json");
|
|
153709
154295
|
try {
|
|
153710
154296
|
const meta = await Bun.file(metaPath).json();
|
|
153711
154297
|
if (meta.runId === runId) {
|
|
@@ -153741,14 +154327,14 @@ async function resolveRunFileFromRegistry(runId) {
|
|
|
153741
154327
|
return null;
|
|
153742
154328
|
}
|
|
153743
154329
|
const specificFile = files.find((f) => f === `${matched.runId}.jsonl`);
|
|
153744
|
-
return
|
|
154330
|
+
return join197(matched.eventsDir, specificFile ?? files[0]);
|
|
153745
154331
|
}
|
|
153746
154332
|
async function selectRunFile(runsDir) {
|
|
153747
154333
|
const files = readdirSync8(runsDir).filter((f) => f.endsWith(".jsonl") && f !== "latest.jsonl").sort().reverse();
|
|
153748
154334
|
if (files.length === 0) {
|
|
153749
154335
|
return null;
|
|
153750
154336
|
}
|
|
153751
|
-
return
|
|
154337
|
+
return join197(runsDir, files[0]);
|
|
153752
154338
|
}
|
|
153753
154339
|
async function extractRunSummary(filePath) {
|
|
153754
154340
|
const file = Bun.file(filePath);
|
|
@@ -153834,7 +154420,7 @@ Runs:
|
|
|
153834
154420
|
console.log(source_default.gray(" Timestamp Stories Duration Cost Status"));
|
|
153835
154421
|
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"));
|
|
153836
154422
|
for (const file of files) {
|
|
153837
|
-
const filePath =
|
|
154423
|
+
const filePath = join198(runsDir, file);
|
|
153838
154424
|
const summary = await extractRunSummary(filePath);
|
|
153839
154425
|
const timestamp = file.replace(".jsonl", "");
|
|
153840
154426
|
const stories = summary ? `${summary.passed}/${summary.total}` : "?/?";
|
|
@@ -153967,10 +154553,10 @@ async function logsCommand(options) {
|
|
|
153967
154553
|
return;
|
|
153968
154554
|
}
|
|
153969
154555
|
const resolved = resolveProject2({ dir: options.dir });
|
|
153970
|
-
const naxDir =
|
|
154556
|
+
const naxDir = join199(resolved.projectDir, ".nax");
|
|
153971
154557
|
const featureName = resolveSingleFeature(naxDir, "pass -r <runId> (see `nax runs list`)");
|
|
153972
|
-
const featureDir =
|
|
153973
|
-
const runsDir =
|
|
154558
|
+
const featureDir = join199(naxDir, "features", featureName);
|
|
154559
|
+
const runsDir = join199(featureDir, "runs");
|
|
153974
154560
|
if (!existsSync44(runsDir)) {
|
|
153975
154561
|
throw new NaxError(`No runs directory found for feature: ${featureName}`, "LOGS_RUNS_DIR_NOT_FOUND", {
|
|
153976
154562
|
stage: "logs",
|
|
@@ -153996,27 +154582,27 @@ async function logsCommand(options) {
|
|
|
153996
154582
|
init_errors4();
|
|
153997
154583
|
init_metrics();
|
|
153998
154584
|
import { existsSync as existsSync45 } from "fs";
|
|
153999
|
-
import { dirname as
|
|
154585
|
+
import { dirname as dirname46 } from "path";
|
|
154000
154586
|
|
|
154001
154587
|
// src/replay/discovery.ts
|
|
154002
154588
|
init_errors4();
|
|
154003
154589
|
init_paths4();
|
|
154004
|
-
import { readdir as
|
|
154005
|
-
import { join as
|
|
154590
|
+
import { readdir as readdir16 } from "fs/promises";
|
|
154591
|
+
import { join as join200 } from "path";
|
|
154006
154592
|
var _discoveryDeps = {
|
|
154007
154593
|
getRunsDir
|
|
154008
154594
|
};
|
|
154009
154595
|
async function loadMetas(runsDir) {
|
|
154010
154596
|
let entries;
|
|
154011
154597
|
try {
|
|
154012
|
-
entries = await
|
|
154598
|
+
entries = await readdir16(runsDir);
|
|
154013
154599
|
} catch {
|
|
154014
154600
|
return [];
|
|
154015
154601
|
}
|
|
154016
154602
|
const metas = [];
|
|
154017
154603
|
for (const entry of entries) {
|
|
154018
154604
|
try {
|
|
154019
|
-
const meta = await Bun.file(
|
|
154605
|
+
const meta = await Bun.file(join200(runsDir, entry, "meta.json")).json();
|
|
154020
154606
|
metas.push(meta);
|
|
154021
154607
|
} catch {}
|
|
154022
154608
|
}
|
|
@@ -154033,7 +154619,7 @@ async function discoverRun(query, depsArg = _discoveryDeps) {
|
|
|
154033
154619
|
throw new NaxError("No runs registered", "RUN_NOT_FOUND", { runsDir });
|
|
154034
154620
|
}
|
|
154035
154621
|
const latest = metas.reduce((acc, m) => m.runId > acc.runId ? m : acc);
|
|
154036
|
-
return { meta: latest, jsonlPath:
|
|
154622
|
+
return { meta: latest, jsonlPath: join200(latest.eventsDir, `${latest.runId}.jsonl`) };
|
|
154037
154623
|
}
|
|
154038
154624
|
const matched = metas.filter((m) => matches(m, query));
|
|
154039
154625
|
if (matched.length === 0) {
|
|
@@ -154050,7 +154636,7 @@ async function discoverRun(query, depsArg = _discoveryDeps) {
|
|
|
154050
154636
|
});
|
|
154051
154637
|
}
|
|
154052
154638
|
const meta = matched[0];
|
|
154053
|
-
return { meta, jsonlPath:
|
|
154639
|
+
return { meta, jsonlPath: join200(meta.eventsDir, `${meta.runId}.jsonl`) };
|
|
154054
154640
|
}
|
|
154055
154641
|
|
|
154056
154642
|
// src/replay/json.ts
|
|
@@ -154265,7 +154851,7 @@ function renderStoryBlock(story, expandPhases) {
|
|
|
154265
154851
|
});
|
|
154266
154852
|
return lines;
|
|
154267
154853
|
}
|
|
154268
|
-
function
|
|
154854
|
+
function renderReport2(timeline, options = {}) {
|
|
154269
154855
|
const stories = options.story ? timeline.stories.filter((s) => s.storyId === options.story) : timeline.stories;
|
|
154270
154856
|
const lines = [];
|
|
154271
154857
|
lines.push(...renderHeader(timeline, stories));
|
|
@@ -154309,7 +154895,7 @@ async function readJsonOrUndefined(path) {
|
|
|
154309
154895
|
}
|
|
154310
154896
|
async function readMetricsFromProject(meta) {
|
|
154311
154897
|
await Promise.resolve().then(() => init_tracker());
|
|
154312
|
-
const outputDir =
|
|
154898
|
+
const outputDir = dirname46(dirname46(dirname46(meta.eventsDir)));
|
|
154313
154899
|
const all = await loadRunMetrics(outputDir);
|
|
154314
154900
|
return all.find((m) => m.runId === meta.runId);
|
|
154315
154901
|
}
|
|
@@ -154319,7 +154905,7 @@ var _replayCmdDeps = {
|
|
|
154319
154905
|
readMetrics: readMetricsFromProject,
|
|
154320
154906
|
readStatus: async (statusPath) => readJsonOrUndefined(statusPath),
|
|
154321
154907
|
reconstructTimeline,
|
|
154322
|
-
renderReport,
|
|
154908
|
+
renderReport: renderReport2,
|
|
154323
154909
|
toReplayJson,
|
|
154324
154910
|
stdout: (text) => process.stdout.write(text),
|
|
154325
154911
|
stderr: (text) => process.stderr.write(text)
|
|
@@ -154393,11 +154979,11 @@ init_checkpoint();
|
|
|
154393
154979
|
init_runtime3();
|
|
154394
154980
|
init_feature_name();
|
|
154395
154981
|
import { existsSync as existsSync46 } from "fs";
|
|
154396
|
-
import { basename as
|
|
154982
|
+
import { basename as basename39, join as join201 } from "path";
|
|
154397
154983
|
async function defaultCheckpointExists(featureDir) {
|
|
154398
154984
|
if (!featureDir || !existsSync46(featureDir))
|
|
154399
154985
|
return false;
|
|
154400
|
-
return existsSync46(
|
|
154986
|
+
return existsSync46(join201(featureDir, "checkpoint.jsonl"));
|
|
154401
154987
|
}
|
|
154402
154988
|
async function defaultLoadCheckpoints(featureDir) {
|
|
154403
154989
|
return loadCheckpoints(featureDir);
|
|
@@ -154475,12 +155061,12 @@ function registerResumeCommand(program) {
|
|
|
154475
155061
|
`);
|
|
154476
155062
|
process.exit(1);
|
|
154477
155063
|
}
|
|
154478
|
-
const featureDir =
|
|
155064
|
+
const featureDir = join201(naxDir, "features", cmdOpts.feature);
|
|
154479
155065
|
const deps = {
|
|
154480
155066
|
..._resumeCmdDeps,
|
|
154481
155067
|
runInvocation: async (feature, opts) => {
|
|
154482
155068
|
const config = await loadConfig(naxDir ?? undefined);
|
|
154483
|
-
const prdPath =
|
|
155069
|
+
const prdPath = join201(opts.featureDir ?? "", "prd.json");
|
|
154484
155070
|
if (!existsSync(prdPath)) {
|
|
154485
155071
|
process.stderr.write(`Feature "${feature}" not found or missing prd.json
|
|
154486
155072
|
`);
|
|
@@ -154490,13 +155076,13 @@ function registerResumeCommand(program) {
|
|
|
154490
155076
|
const globalNaxDir = globalConfigDir();
|
|
154491
155077
|
const hooks = await loadHooksConfig(naxDir, globalNaxDir);
|
|
154492
155078
|
applyResumeModeDeps(opts.featureDir ?? "", "auto");
|
|
154493
|
-
const projectKey = config.name?.trim() ||
|
|
155079
|
+
const projectKey = config.name?.trim() || basename39(dir);
|
|
154494
155080
|
const outputDir = projectOutputDir(projectKey, config.outputDir);
|
|
154495
|
-
const statusFilePath =
|
|
154496
|
-
const runsDir =
|
|
155081
|
+
const statusFilePath = join201(outputDir, "status.json");
|
|
155082
|
+
const runsDir = join201(outputDir, "features", feature, "runs");
|
|
154497
155083
|
mkdirSync(runsDir, { recursive: true });
|
|
154498
155084
|
const runId = buildRunId(dir, new Date);
|
|
154499
|
-
const logFilePath =
|
|
155085
|
+
const logFilePath = join201(runsDir, `${runId}.jsonl`);
|
|
154500
155086
|
initLogger({ level: "info", filePath: logFilePath, useChalk: true, headless: true, suppressConsole: false });
|
|
154501
155087
|
const result = await run({
|
|
154502
155088
|
prdPath,
|
|
@@ -154532,8 +155118,8 @@ function registerResumeCommand(program) {
|
|
|
154532
155118
|
// src/commands/runs.ts
|
|
154533
155119
|
init_source();
|
|
154534
155120
|
init_paths4();
|
|
154535
|
-
import { readdir as
|
|
154536
|
-
import { join as
|
|
155121
|
+
import { readdir as readdir17 } from "fs/promises";
|
|
155122
|
+
import { join as join202 } from "path";
|
|
154537
155123
|
var DEFAULT_LIMIT = 20;
|
|
154538
155124
|
var _runsCmdDeps = {
|
|
154539
155125
|
getRunsDir
|
|
@@ -154583,14 +155169,14 @@ async function runsCommand(options = {}) {
|
|
|
154583
155169
|
const runsDir = _runsCmdDeps.getRunsDir();
|
|
154584
155170
|
let entries;
|
|
154585
155171
|
try {
|
|
154586
|
-
entries = await
|
|
155172
|
+
entries = await readdir17(runsDir);
|
|
154587
155173
|
} catch {
|
|
154588
155174
|
console.log("No runs found.");
|
|
154589
155175
|
return;
|
|
154590
155176
|
}
|
|
154591
155177
|
const rows = [];
|
|
154592
155178
|
for (const entry of entries) {
|
|
154593
|
-
const metaPath =
|
|
155179
|
+
const metaPath = join202(runsDir, entry, "meta.json");
|
|
154594
155180
|
let meta;
|
|
154595
155181
|
try {
|
|
154596
155182
|
meta = await Bun.file(metaPath).json();
|
|
@@ -154672,7 +155258,7 @@ init_execution2();
|
|
|
154672
155258
|
init_logger2();
|
|
154673
155259
|
init_runtime3();
|
|
154674
155260
|
import { mkdir as mkdir52, unlink as unlink13 } from "fs/promises";
|
|
154675
|
-
import { basename as
|
|
155261
|
+
import { basename as basename40, join as join203 } from "path";
|
|
154676
155262
|
var _unlockDeps = {
|
|
154677
155263
|
findProjectDir,
|
|
154678
155264
|
loadConfig,
|
|
@@ -154703,7 +155289,7 @@ function parseFeatureLockRecord(raw) {
|
|
|
154703
155289
|
async function resolveOutputDir3(workdir) {
|
|
154704
155290
|
const naxDir = _unlockDeps.findProjectDir(workdir);
|
|
154705
155291
|
const config = await _unlockDeps.loadConfig(naxDir ?? undefined);
|
|
154706
|
-
const projectKey = config.name?.trim() ||
|
|
155292
|
+
const projectKey = config.name?.trim() || basename40(workdir);
|
|
154707
155293
|
const outputDir = _unlockDeps.projectOutputDir(projectKey, config.outputDir);
|
|
154708
155294
|
return { outputDir, naxDir };
|
|
154709
155295
|
}
|
|
@@ -154736,7 +155322,7 @@ async function tryRemoveFeatureLock(outputDir, feature, force) {
|
|
|
154736
155322
|
return "removed";
|
|
154737
155323
|
}
|
|
154738
155324
|
async function listFeatureLockFeatures(outputDir) {
|
|
154739
|
-
const featuresRoot =
|
|
155325
|
+
const featuresRoot = join203(outputDir, "features");
|
|
154740
155326
|
let paths;
|
|
154741
155327
|
try {
|
|
154742
155328
|
paths = await Array.fromAsync(new Bun.Glob("*/nax.lock").scan({ cwd: featuresRoot, onlyFiles: true }));
|
|
@@ -154753,7 +155339,7 @@ async function unlockCommand(options) {
|
|
|
154753
155339
|
const workdir = options.dir ?? process.cwd();
|
|
154754
155340
|
if (options.feature !== undefined && options.feature.length > 0) {
|
|
154755
155341
|
const { outputDir } = await resolveOutputDir3(workdir);
|
|
154756
|
-
await mkdir52(
|
|
155342
|
+
await mkdir52(join203(outputDir, "features"), { recursive: true });
|
|
154757
155343
|
const outcome = await tryRemoveFeatureLock(outputDir, options.feature, options.force ?? false);
|
|
154758
155344
|
if (outcome === "skipped" || outcome === "parse-error") {
|
|
154759
155345
|
process.exit(1);
|
|
@@ -154761,7 +155347,7 @@ async function unlockCommand(options) {
|
|
|
154761
155347
|
logUnlockInfo("Feature lock removed");
|
|
154762
155348
|
process.exit(0);
|
|
154763
155349
|
}
|
|
154764
|
-
const checkoutLockPath =
|
|
155350
|
+
const checkoutLockPath = join203(workdir, "nax.lock");
|
|
154765
155351
|
let checkoutAborted = false;
|
|
154766
155352
|
const lockFile = Bun.file(checkoutLockPath);
|
|
154767
155353
|
const exists = await lockFile.exists();
|
|
@@ -162515,12 +163101,12 @@ init_version();
|
|
|
162515
163101
|
init_source();
|
|
162516
163102
|
init_cli2();
|
|
162517
163103
|
import { existsSync as existsSync48, mkdirSync as mkdirSync12 } from "fs";
|
|
162518
|
-
import { basename as
|
|
163104
|
+
import { basename as basename41, join as join206 } from "path";
|
|
162519
163105
|
|
|
162520
163106
|
// src/cli/run-context-overrides.ts
|
|
162521
|
-
import { isAbsolute as isAbsolute38, join as
|
|
163107
|
+
import { isAbsolute as isAbsolute38, join as join205 } from "path";
|
|
162522
163108
|
function resolveCliOverridePath(workdir, value) {
|
|
162523
|
-
return isAbsolute38(value) || value.startsWith("~/") ? value :
|
|
163109
|
+
return isAbsolute38(value) || value.startsWith("~/") ? value : join205(workdir, value);
|
|
162524
163110
|
}
|
|
162525
163111
|
function resolveContextCliOverrides(workdir, options) {
|
|
162526
163112
|
const overrides = {};
|
|
@@ -162816,7 +163402,7 @@ async function resolveRunProjectContext(workdir, options) {
|
|
|
162816
163402
|
const cliOverrides = {};
|
|
162817
163403
|
const cliProfiles = options.profile ?? [];
|
|
162818
163404
|
const profileOverride = naxDir ? await resolveRunProfileOverride({
|
|
162819
|
-
prdPath:
|
|
163405
|
+
prdPath: join206(naxDir, "features", options.feature, "prd.json"),
|
|
162820
163406
|
projectRoot: workdir,
|
|
162821
163407
|
cliProfile: cliProfiles,
|
|
162822
163408
|
envProfile: process.env.NAX_PROFILE
|
|
@@ -162863,10 +163449,10 @@ async function maybeRunPlanPhase(params) {
|
|
|
162863
163449
|
}
|
|
162864
163450
|
async function runPlanningPhase(params) {
|
|
162865
163451
|
const { options, from, config, workdir, projectRoot, featureDir } = params;
|
|
162866
|
-
const planLogDir =
|
|
163452
|
+
const planLogDir = join206(featureDir, "plan");
|
|
162867
163453
|
mkdirSync12(planLogDir, { recursive: true });
|
|
162868
163454
|
const planLogId = new Date().toISOString().replace(/:/g, "-").replace(/\..+/, "");
|
|
162869
|
-
const planLogPath =
|
|
163455
|
+
const planLogPath = join206(planLogDir, `${planLogId}.jsonl`);
|
|
162870
163456
|
initLogger({ level: "info", filePath: planLogPath, useChalk: false, headless: true });
|
|
162871
163457
|
console.log(source_default.dim(` [Plan log: ${planLogPath}]`));
|
|
162872
163458
|
console.log(source_default.dim(" [Planning phase: generating PRD from spec]"));
|
|
@@ -162908,12 +163494,12 @@ async function displayPlanConfirmation(prd, options) {
|
|
|
162908
163494
|
}
|
|
162909
163495
|
function initRunLogging(params) {
|
|
162910
163496
|
const { options, config, workdir, isTTY, logLevel, formatterMode } = params;
|
|
162911
|
-
const projectKey = config.name?.trim() ||
|
|
163497
|
+
const projectKey = config.name?.trim() || basename41(workdir);
|
|
162912
163498
|
const outputDir = projectOutputDir(projectKey, config.outputDir);
|
|
162913
|
-
const runsDir =
|
|
163499
|
+
const runsDir = join206(outputDir, "features", options.feature, "runs");
|
|
162914
163500
|
mkdirSync12(runsDir, { recursive: true });
|
|
162915
163501
|
const runId = new Date().toISOString().replace(/:/g, "-").replace(/\..+/, "");
|
|
162916
|
-
const logFilePath =
|
|
163502
|
+
const logFilePath = join206(runsDir, `${runId}.jsonl`);
|
|
162917
163503
|
const headlessFlag = options.headless ?? false;
|
|
162918
163504
|
const headlessEnv = process.env.NAX_HEADLESS === "1";
|
|
162919
163505
|
const useHeadless = resolveUseHeadless({ isTTY, headlessFlag, headlessEnv, formatterMode });
|
|
@@ -162947,7 +163533,7 @@ function applyRunCliOverrides(config, options, maxIterationsFlag) {
|
|
|
162947
163533
|
// bin/run-action-execute.ts
|
|
162948
163534
|
init_source();
|
|
162949
163535
|
init_execution2();
|
|
162950
|
-
import { join as
|
|
163536
|
+
import { join as join210 } from "path";
|
|
162951
163537
|
init_version();
|
|
162952
163538
|
function mountRunTui(params) {
|
|
162953
163539
|
const initialStories = params.prd.userStories.map((story) => ({
|
|
@@ -162962,7 +163548,7 @@ function mountRunTui(params) {
|
|
|
162962
163548
|
stories: initialStories,
|
|
162963
163549
|
events: params.eventEmitter,
|
|
162964
163550
|
agentStreamEvents: params.agentStreamEvents,
|
|
162965
|
-
queueFilePath:
|
|
163551
|
+
queueFilePath: join210(params.workdir, ".queue.txt")
|
|
162966
163552
|
});
|
|
162967
163553
|
}
|
|
162968
163554
|
async function waitForScheduledRun(params) {
|
|
@@ -163127,9 +163713,9 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
163127
163713
|
process.exit(1);
|
|
163128
163714
|
}
|
|
163129
163715
|
await runTrustGate(workdir);
|
|
163130
|
-
const projectRoot =
|
|
163131
|
-
const featureDir =
|
|
163132
|
-
const prdPath =
|
|
163716
|
+
const projectRoot = join212(naxDir, "..");
|
|
163717
|
+
const featureDir = join212(naxDir, "features", options.feature);
|
|
163718
|
+
const prdPath = join212(featureDir, "prd.json");
|
|
163133
163719
|
await maybeRunPlanPhase({ options, config, workdir, projectRoot, featureDir, prdPath });
|
|
163134
163720
|
if (!existsSync50(prdPath)) {
|
|
163135
163721
|
console.error(source_default.red(`Feature "${options.feature}" not found or missing prd.json`));
|
|
@@ -163147,7 +163733,7 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
163147
163733
|
formatterMode
|
|
163148
163734
|
});
|
|
163149
163735
|
config = applyRunCliOverrides(config, options, maxIterationsFlag);
|
|
163150
|
-
const globalNaxDir =
|
|
163736
|
+
const globalNaxDir = join212(homedir9(), ".nax");
|
|
163151
163737
|
const hooks = await loadHooksConfig(naxDir, globalNaxDir);
|
|
163152
163738
|
const eventEmitter = new PipelineEventEmitter;
|
|
163153
163739
|
const agentStreamEvents = useHeadless ? undefined : new AgentStreamEventBus;
|
|
@@ -163164,7 +163750,7 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
163164
163750
|
} else {
|
|
163165
163751
|
console.log(source_default.dim(" [Headless mode \u2014 pipe output]"));
|
|
163166
163752
|
}
|
|
163167
|
-
const statusFilePath =
|
|
163753
|
+
const statusFilePath = join212(outputDir, "status.json");
|
|
163168
163754
|
await waitForScheduledRun({ scheduleGate, feature: options.feature, formatterMode, isTTY, tuiInstance });
|
|
163169
163755
|
if (options.compare) {
|
|
163170
163756
|
await runBakeoffMode({ options, workdir, outputDir, config, tuiInstance });
|
|
@@ -163185,7 +163771,7 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
163185
163771
|
agentStreamEvents,
|
|
163186
163772
|
tuiInstance
|
|
163187
163773
|
});
|
|
163188
|
-
const latestSymlink =
|
|
163774
|
+
const latestSymlink = join212(runsDir, "latest.jsonl");
|
|
163189
163775
|
try {
|
|
163190
163776
|
if (existsSync50(latestSymlink)) {
|
|
163191
163777
|
unlinkSync(latestSymlink);
|
|
@@ -163279,9 +163865,9 @@ features.command("create <name>").description("Create a new feature").option("-d
|
|
|
163279
163865
|
console.error(source_default.red("nax not initialized. Run: nax init"));
|
|
163280
163866
|
process.exit(1);
|
|
163281
163867
|
}
|
|
163282
|
-
const featureDir =
|
|
163868
|
+
const featureDir = join212(naxDir, "features", name);
|
|
163283
163869
|
mkdirSync13(featureDir, { recursive: true });
|
|
163284
|
-
await Bun.write(
|
|
163870
|
+
await Bun.write(join212(featureDir, "spec.md"), `# Feature: ${name}
|
|
163285
163871
|
|
|
163286
163872
|
## Overview
|
|
163287
163873
|
|
|
@@ -163314,7 +163900,7 @@ features.command("create <name>").description("Create a new feature").option("-d
|
|
|
163314
163900
|
|
|
163315
163901
|
<!-- What this feature explicitly does NOT cover. -->
|
|
163316
163902
|
`);
|
|
163317
|
-
await Bun.write(
|
|
163903
|
+
await Bun.write(join212(featureDir, "progress.txt"), `# Progress: ${name}
|
|
163318
163904
|
|
|
163319
163905
|
Created: ${new Date().toISOString()}
|
|
163320
163906
|
|
|
@@ -163340,7 +163926,7 @@ features.command("list").description("List all features").option("-d, --dir <pat
|
|
|
163340
163926
|
console.error(source_default.red("nax not initialized."));
|
|
163341
163927
|
process.exit(1);
|
|
163342
163928
|
}
|
|
163343
|
-
const featuresDir =
|
|
163929
|
+
const featuresDir = join212(naxDir, "features");
|
|
163344
163930
|
if (!existsSync50(featuresDir)) {
|
|
163345
163931
|
console.log(source_default.dim("No features yet."));
|
|
163346
163932
|
return;
|
|
@@ -163355,7 +163941,7 @@ features.command("list").description("List all features").option("-d, --dir <pat
|
|
|
163355
163941
|
Features:
|
|
163356
163942
|
`));
|
|
163357
163943
|
for (const name of entries) {
|
|
163358
|
-
const prdPath =
|
|
163944
|
+
const prdPath = join212(featuresDir, name, "prd.json");
|
|
163359
163945
|
if (existsSync50(prdPath)) {
|
|
163360
163946
|
try {
|
|
163361
163947
|
const prd = await loadPRD(prdPath);
|
|
@@ -163370,7 +163956,7 @@ Features:
|
|
|
163370
163956
|
}
|
|
163371
163957
|
console.log();
|
|
163372
163958
|
});
|
|
163373
|
-
features.command("resolve [name]").description("Resolve feature name and spec source deterministically").option("--json", "Emit machine-readable JSON to stdout").option("-d, --dir <path>", "Project directory", process.cwd()).action(async (name, options) => {
|
|
163959
|
+
features.command("resolve [name]").description("Resolve feature name and spec source deterministically").option("--json", "Emit machine-readable JSON to stdout").option("-d, --dir <path>", "Project directory", process.cwd()).option("--profile <name>", "Profile(s) to overlay (comma-separated or repeated; later overrides earlier)", collectProfile, []).action(async (name, options) => {
|
|
163374
163960
|
let workdir;
|
|
163375
163961
|
try {
|
|
163376
163962
|
workdir = validateDirectory(options.dir);
|
|
@@ -163384,7 +163970,7 @@ features.command("resolve [name]").description("Resolve feature name and spec so
|
|
|
163384
163970
|
}
|
|
163385
163971
|
let result;
|
|
163386
163972
|
try {
|
|
163387
|
-
result = await resolveFeatureSpec(name, workdir);
|
|
163973
|
+
result = await resolveFeatureSpec(name, workdir, { profile: options.profile });
|
|
163388
163974
|
} catch (err) {
|
|
163389
163975
|
const msg = err.message ?? "unexpected error";
|
|
163390
163976
|
if (options.json) {
|
|
@@ -163427,17 +164013,17 @@ Use: nax plan -f <feature> --from <spec>`));
|
|
|
163427
164013
|
console.error(source_default.red("nax not initialized. Run: nax init"));
|
|
163428
164014
|
process.exit(1);
|
|
163429
164015
|
}
|
|
163430
|
-
const projectRoot =
|
|
164016
|
+
const projectRoot = join212(naxDir, "..");
|
|
163431
164017
|
const cliOverrides = {};
|
|
163432
164018
|
const cliProfiles = options.profile ?? [];
|
|
163433
164019
|
if (cliProfiles.length > 0) {
|
|
163434
164020
|
cliOverrides.profile = cliProfiles;
|
|
163435
164021
|
}
|
|
163436
164022
|
const config = await loadConfig(projectRoot, cliOverrides);
|
|
163437
|
-
const featureLogDir =
|
|
164023
|
+
const featureLogDir = join212(naxDir, "features", options.feature, "plan");
|
|
163438
164024
|
mkdirSync13(featureLogDir, { recursive: true });
|
|
163439
164025
|
const planLogId = new Date().toISOString().replace(/:/g, "-").replace(/\..+/, "");
|
|
163440
|
-
const planLogPath =
|
|
164026
|
+
const planLogPath = join212(featureLogDir, `${planLogId}.jsonl`);
|
|
163441
164027
|
initLogger({ level: "info", filePath: planLogPath, useChalk: false, headless: true });
|
|
163442
164028
|
console.log(source_default.dim(` [Plan log: ${planLogPath}]`));
|
|
163443
164029
|
try {
|
|
@@ -163599,11 +164185,12 @@ registerAdvisorCommand(program2).hook("preAction", (_group, action) => {
|
|
|
163599
164185
|
registerTrustCommand(program2);
|
|
163600
164186
|
registerWorkflowCommand(program2);
|
|
163601
164187
|
registerGatesCommand(program2);
|
|
164188
|
+
registerCostCommand(program2);
|
|
163602
164189
|
var mcpCmd = program2.command("mcp").description("Manage MCP servers the native agent may call tools on");
|
|
163603
|
-
mcpCmd.command("lock").description("Refresh .nax/mcp-lock.json from what each configured server advertises").action(async () => {
|
|
164190
|
+
mcpCmd.command("lock").description("Refresh .nax/mcp-lock.json from what each configured server advertises").option("--global", "Write the lock to the global config dir instead of the project", false).action(async (options) => {
|
|
163604
164191
|
await runTrustGate(process.cwd());
|
|
163605
164192
|
await Promise.resolve().then(() => init_mcp3());
|
|
163606
|
-
await runMcpLockCommand(process.cwd());
|
|
164193
|
+
await runMcpLockCommand(process.cwd(), { global: options.global === true });
|
|
163607
164194
|
});
|
|
163608
164195
|
var routingCmd = program2.command("routing").description("Routing calibration helpers");
|
|
163609
164196
|
routingCmd.command("calibrate").description("Propose complexity\u2192tier mapping adjustments from run history").option("-d, --dir <path>", "Project directory", process.cwd()).option("--apply", "Write the proposed mapping into .nax/config.json", false).option("--json", "Emit the proposal as JSON", false).option("--min-samples <n>", "Override the per-band sample floor for this invocation").action(async (options) => {
|
|
@@ -163964,7 +164551,7 @@ spec.command("lint [paths...]").description("Check a spec's machine-extracted se
|
|
|
163964
164551
|
return;
|
|
163965
164552
|
}
|
|
163966
164553
|
const naxDir = findProjectDir(workdir);
|
|
163967
|
-
const projectRoot = naxDir ?
|
|
164554
|
+
const projectRoot = naxDir ? join212(naxDir, "..") : workdir;
|
|
163968
164555
|
let maxAcCount;
|
|
163969
164556
|
if (naxDir) {
|
|
163970
164557
|
const config = await loadConfig(projectRoot);
|