@nathapp/nax 0.91.8-canary.6 → 0.91.8-canary.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nax.js +878 -519
- package/package.json +2 -2
package/dist/nax.js
CHANGED
|
@@ -263,6 +263,9 @@ var init_redact = __esm(() => {
|
|
|
263
263
|
{ kind: "github-pat", re: /github_pat_[A-Za-z0-9_]{20,}/g },
|
|
264
264
|
{ kind: "npm", re: /npm_[A-Za-z0-9]{8,}/g },
|
|
265
265
|
{ kind: "aws", re: /AKIA[0-9A-Z]{16}/g },
|
|
266
|
+
{ kind: "gitlab", re: /glpat-[A-Za-z0-9_-]{20,}/g },
|
|
267
|
+
{ kind: "google", re: /AIza[0-9A-Za-z_-]{35}/g },
|
|
268
|
+
{ kind: "stripe", re: /\b[sr]k_live_[0-9A-Za-z]{16,}/g },
|
|
266
269
|
{ kind: "slack", re: /xox[baprs]-[A-Za-z0-9-]{10,}/g },
|
|
267
270
|
{ kind: "telegram", re: /\b\d{6,}:[A-Za-z0-9_-]{30,}\b/g },
|
|
268
271
|
{ kind: "assignment", re: /(?:SECRET|TOKEN|API_?KEY|PASSWORD|PRIVATE_?KEY|ACCESS_?KEY|WEBHOOK)=[^\s"',]+/gi },
|
|
@@ -10140,7 +10143,7 @@ function createSessionStorage(deps) {
|
|
|
10140
10143
|
try {
|
|
10141
10144
|
const temp = join9(tempDir, "metadata.tmp");
|
|
10142
10145
|
await writeFile2(temp, `${JSON.stringify(meta, null, 2)}
|
|
10143
|
-
|
|
10146
|
+
`, { mode: 384 });
|
|
10144
10147
|
await rename2(temp, path);
|
|
10145
10148
|
} finally {
|
|
10146
10149
|
await rm2(tempDir, { recursive: true, force: true });
|
|
@@ -13517,7 +13520,7 @@ function extension(mimeType) {
|
|
|
13517
13520
|
async function publishImageOnce(path, bytes) {
|
|
13518
13521
|
const staged = `${path}.${randomUUID8()}.tmp`;
|
|
13519
13522
|
try {
|
|
13520
|
-
await _transcriptImagesDeps.writeFileAtomic(staged, bytes);
|
|
13523
|
+
await _transcriptImagesDeps.writeFileAtomic(staged, bytes, { mode: 384 });
|
|
13521
13524
|
try {
|
|
13522
13525
|
await _transcriptImagesDeps.link(staged, path);
|
|
13523
13526
|
} catch (error) {
|
|
@@ -13758,7 +13761,7 @@ async function writeTranscriptDoc(dir, sessionName, doc) {
|
|
|
13758
13761
|
const path = transcriptPath(dir, sessionName);
|
|
13759
13762
|
const stored = await splitTranscriptImages(path, doc);
|
|
13760
13763
|
await mkdir9(dir, { recursive: true });
|
|
13761
|
-
await writeFileAtomic(path, JSON.stringify(stored, null, 2));
|
|
13764
|
+
await writeFileAtomic(path, JSON.stringify(stored, null, 2), { mode: 384 });
|
|
13762
13765
|
}
|
|
13763
13766
|
function createFileTranscriptStore(dir) {
|
|
13764
13767
|
return {
|
|
@@ -14458,10 +14461,24 @@ var init_instruction_file_name = __esm(() => {
|
|
|
14458
14461
|
});
|
|
14459
14462
|
|
|
14460
14463
|
// ../nax-agent/src/internal/bounded-io.ts
|
|
14461
|
-
import {
|
|
14464
|
+
import { constants as constants6 } from "fs";
|
|
14465
|
+
import { open as open5, stat as stat8 } from "fs/promises";
|
|
14466
|
+
function notRegularFileError(path) {
|
|
14467
|
+
return new NaxError(`"${path}" is not a regular file`, "READ_NOT_REGULAR_FILE", { stage: "read", path });
|
|
14468
|
+
}
|
|
14462
14469
|
async function readPrefix(path, maxBytes) {
|
|
14463
|
-
|
|
14470
|
+
let handle;
|
|
14464
14471
|
try {
|
|
14472
|
+
handle = await open5(path, constants6.O_RDONLY | (constants6.O_NONBLOCK ?? 0));
|
|
14473
|
+
} catch (error) {
|
|
14474
|
+
const pathIsNonRegular = await stat8(path).then((info) => !info.isFile(), () => false);
|
|
14475
|
+
if (pathIsNonRegular)
|
|
14476
|
+
throw notRegularFileError(path);
|
|
14477
|
+
throw error;
|
|
14478
|
+
}
|
|
14479
|
+
try {
|
|
14480
|
+
if (!(await handle.stat()).isFile())
|
|
14481
|
+
throw notRegularFileError(path);
|
|
14465
14482
|
const buffer = Buffer.alloc(maxBytes + 1);
|
|
14466
14483
|
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
14467
14484
|
return buffer.subarray(0, bytesRead).toString("utf8");
|
|
@@ -14485,7 +14502,9 @@ async function drainBounded(stream, maxBytes) {
|
|
|
14485
14502
|
await reader.cancel().catch(() => {});
|
|
14486
14503
|
}
|
|
14487
14504
|
}
|
|
14488
|
-
var init_bounded_io = () => {
|
|
14505
|
+
var init_bounded_io = __esm(() => {
|
|
14506
|
+
init_infra();
|
|
14507
|
+
});
|
|
14489
14508
|
|
|
14490
14509
|
// ../nax-agent/src/tools/deny-paths.ts
|
|
14491
14510
|
function globToRegExp(pattern) {
|
|
@@ -14742,7 +14761,7 @@ async function archiveTranscript(store, sessionId, archive) {
|
|
|
14742
14761
|
return;
|
|
14743
14762
|
const stamp = _transcriptArchiveDeps.now().toISOString().replace(/[:.]/g, "-");
|
|
14744
14763
|
await mkdir10(archive.dir, { recursive: true });
|
|
14745
|
-
await writeFileAtomic(join18(archive.dir, `${sessionId}.transcript.${stamp}.json`), JSON.stringify(redactSecrets(doc), null, 2));
|
|
14764
|
+
await writeFileAtomic(join18(archive.dir, `${sessionId}.transcript.${stamp}.json`), JSON.stringify(redactSecrets(doc), null, 2), { mode: 384 });
|
|
14746
14765
|
await pruneRetainedTranscripts(archive.dir, archive.maxRetained);
|
|
14747
14766
|
} catch (err) {
|
|
14748
14767
|
getLogger().warn("native-session", "Transcript archive failed; close continues unchanged", {
|
|
@@ -17179,7 +17198,7 @@ async function sessionSandboxFrom(launcher, root, writeExemption) {
|
|
|
17179
17198
|
var init_session_sandbox = () => {};
|
|
17180
17199
|
|
|
17181
17200
|
// ../nax-agent/src/sandbox/session-tmp.ts
|
|
17182
|
-
import { accessSync as accessSync2, constants as
|
|
17201
|
+
import { accessSync as accessSync2, constants as constants7, lstatSync as lstatSync3 } from "fs";
|
|
17183
17202
|
function isUsableSharedParent() {
|
|
17184
17203
|
try {
|
|
17185
17204
|
const stats = _sessionTmpDeps.lstat(SHARED_TMP_PARENT);
|
|
@@ -17191,7 +17210,7 @@ function isUsableSharedParent() {
|
|
|
17191
17210
|
return err.code === "ENOENT";
|
|
17192
17211
|
}
|
|
17193
17212
|
try {
|
|
17194
|
-
_sessionTmpDeps.access(SHARED_TMP_PARENT,
|
|
17213
|
+
_sessionTmpDeps.access(SHARED_TMP_PARENT, constants7.W_OK | constants7.X_OK);
|
|
17195
17214
|
return true;
|
|
17196
17215
|
} catch {
|
|
17197
17216
|
return false;
|
|
@@ -17802,7 +17821,7 @@ var init_edit_region = __esm(() => {
|
|
|
17802
17821
|
});
|
|
17803
17822
|
|
|
17804
17823
|
// ../nax-agent/src/tools/edit.ts
|
|
17805
|
-
import { readFile as readFile10, stat as
|
|
17824
|
+
import { readFile as readFile10, stat as stat9, writeFile as writeFile4 } from "fs/promises";
|
|
17806
17825
|
function countOccurrences(haystack, needle) {
|
|
17807
17826
|
if (needle === "")
|
|
17808
17827
|
return 0;
|
|
@@ -17818,7 +17837,7 @@ var _editDeps, editTool;
|
|
|
17818
17837
|
var init_edit = __esm(() => {
|
|
17819
17838
|
init_edit_region();
|
|
17820
17839
|
_editDeps = {
|
|
17821
|
-
stat: (path) =>
|
|
17840
|
+
stat: (path) => stat9(path),
|
|
17822
17841
|
readFile: (path, encoding) => readFile10(path, encoding),
|
|
17823
17842
|
writeFile: (path, data, encoding) => writeFile4(path, data, encoding)
|
|
17824
17843
|
};
|
|
@@ -20500,7 +20519,7 @@ function buildGrepArgv(binary, pattern, path, patternType = "literal") {
|
|
|
20500
20519
|
return ["rg", ...flags, "--", pattern, target];
|
|
20501
20520
|
}
|
|
20502
20521
|
const modeFlag = patternType === "literal" ? "-F" : "-E";
|
|
20503
|
-
return ["grep", "-r", "-n", modeFlag, "--", pattern, target];
|
|
20522
|
+
return ["grep", "-r", "-n", "--exclude-dir=.git", modeFlag, "--", pattern, target];
|
|
20504
20523
|
}
|
|
20505
20524
|
var GREP_TIMEOUT_MS = 15000, REGEX_METACHARACTERS, _grepDeps, grepTool;
|
|
20506
20525
|
var init_grep = __esm(() => {
|
|
@@ -24465,7 +24484,7 @@ var init_native = __esm(() => {
|
|
|
24465
24484
|
|
|
24466
24485
|
// ../nax-agent/src/session/agent-session-deps.ts
|
|
24467
24486
|
import { randomUUID as randomUUID13 } from "crypto";
|
|
24468
|
-
import { mkdtemp as mkdtemp2, rm as rm8, stat as
|
|
24487
|
+
import { mkdtemp as mkdtemp2, rm as rm8, stat as stat10 } from "fs/promises";
|
|
24469
24488
|
import { tmpdir as tmpdir4 } from "os";
|
|
24470
24489
|
import { join as join32 } from "path";
|
|
24471
24490
|
var MAX_UNDELIVERED_CONTROL_EVENTS = 1000, _agentSessionDeps;
|
|
@@ -24477,7 +24496,7 @@ var init_agent_session_deps = __esm(() => {
|
|
|
24477
24496
|
randomUUID: () => randomUUID13(),
|
|
24478
24497
|
isDirectory: async (path) => {
|
|
24479
24498
|
try {
|
|
24480
|
-
return (await
|
|
24499
|
+
return (await stat10(path)).isDirectory();
|
|
24481
24500
|
} catch {
|
|
24482
24501
|
return false;
|
|
24483
24502
|
}
|
|
@@ -30409,6 +30428,9 @@ var GIT_NO_SUCH_OBJECT_EXIT = 128;
|
|
|
30409
30428
|
var init_nax_path_restore = () => {};
|
|
30410
30429
|
|
|
30411
30430
|
// src/utils/git.ts
|
|
30431
|
+
function isPublishableBranch(branch, defaultBranch) {
|
|
30432
|
+
return !PROTECTED_BRANCHES.has(branch) && branch !== defaultBranch;
|
|
30433
|
+
}
|
|
30412
30434
|
async function captureGitRef(workdir) {
|
|
30413
30435
|
try {
|
|
30414
30436
|
const { stdout, exitCode } = await gitWithTimeout(["rev-parse", "HEAD"], workdir);
|
|
@@ -30610,11 +30632,12 @@ async function captureDiffSummary(workdir, baseRef, scopePrefix) {
|
|
|
30610
30632
|
return "";
|
|
30611
30633
|
}
|
|
30612
30634
|
}
|
|
30613
|
-
var AUTO_COMMIT_GIT_TIMEOUT_MS = 30000, beforeAutoCommitHooks;
|
|
30635
|
+
var PROTECTED_BRANCHES, AUTO_COMMIT_GIT_TIMEOUT_MS = 30000, beforeAutoCommitHooks;
|
|
30614
30636
|
var init_git2 = __esm(() => {
|
|
30615
30637
|
init_internal();
|
|
30616
30638
|
init_nax_path_restore();
|
|
30617
30639
|
init_internal();
|
|
30640
|
+
PROTECTED_BRANCHES = new Set(["", "main", "master"]);
|
|
30618
30641
|
beforeAutoCommitHooks = new Set;
|
|
30619
30642
|
});
|
|
30620
30643
|
|
|
@@ -31510,11 +31533,22 @@ function findProjectDir(startDir) {
|
|
|
31510
31533
|
}
|
|
31511
31534
|
return null;
|
|
31512
31535
|
}
|
|
31513
|
-
var GLOBAL_CONFIG_DIR_ENV = "NAX_GLOBAL_CONFIG_DIR", FEATURE_ID_PATTERN, PROJECT_NAX_DIR = ".nax", PROJECT_FEATURES_DIR, GLOBAL_LOCAL_CONFIG_FILE = "config.local.json";
|
|
31536
|
+
var GLOBAL_CONFIG_DIR_ENV = "NAX_GLOBAL_CONFIG_DIR", FEATURE_ID_PATTERN, RESERVED_PROJECT_NAMES, PROJECT_NAX_DIR = ".nax", PROJECT_FEATURES_DIR, GLOBAL_LOCAL_CONFIG_FILE = "config.local.json";
|
|
31514
31537
|
var init_paths = __esm(() => {
|
|
31515
31538
|
init_errors4();
|
|
31516
31539
|
init_path_security();
|
|
31517
31540
|
FEATURE_ID_PATTERN = /^[a-zA-Z0-9_][a-zA-Z0-9._-]{0,63}$/;
|
|
31541
|
+
RESERVED_PROJECT_NAMES = [
|
|
31542
|
+
"global",
|
|
31543
|
+
"profiles",
|
|
31544
|
+
"runs",
|
|
31545
|
+
"events",
|
|
31546
|
+
"plugins",
|
|
31547
|
+
"acp",
|
|
31548
|
+
"memory",
|
|
31549
|
+
"hooks",
|
|
31550
|
+
"_archive"
|
|
31551
|
+
];
|
|
31518
31552
|
PROJECT_FEATURES_DIR = `${PROJECT_NAX_DIR}/features`;
|
|
31519
31553
|
});
|
|
31520
31554
|
|
|
@@ -32763,136 +32797,6 @@ var init_config_guards = __esm(() => {
|
|
|
32763
32797
|
};
|
|
32764
32798
|
});
|
|
32765
32799
|
|
|
32766
|
-
// src/config/dotenv.ts
|
|
32767
|
-
function parseQuotedValue(raw, quote) {
|
|
32768
|
-
let value = "";
|
|
32769
|
-
for (let i = 1;i < raw.length; i++) {
|
|
32770
|
-
const c = raw[i];
|
|
32771
|
-
if (quote === '"' && c === "\\" && i + 1 < raw.length) {
|
|
32772
|
-
const next = raw[i + 1];
|
|
32773
|
-
if (next === "n") {
|
|
32774
|
-
value += `
|
|
32775
|
-
`;
|
|
32776
|
-
i++;
|
|
32777
|
-
continue;
|
|
32778
|
-
}
|
|
32779
|
-
if (next === '"' || next === "\\") {
|
|
32780
|
-
value += next;
|
|
32781
|
-
i++;
|
|
32782
|
-
continue;
|
|
32783
|
-
}
|
|
32784
|
-
value += c;
|
|
32785
|
-
continue;
|
|
32786
|
-
}
|
|
32787
|
-
if (c === quote) {
|
|
32788
|
-
return value;
|
|
32789
|
-
}
|
|
32790
|
-
value += c;
|
|
32791
|
-
}
|
|
32792
|
-
return value;
|
|
32793
|
-
}
|
|
32794
|
-
function stripInlineComment(raw) {
|
|
32795
|
-
for (let i = 0;i < raw.length; i++) {
|
|
32796
|
-
if (raw[i] === "#" && (i === 0 || /\s/.test(raw[i - 1] ?? ""))) {
|
|
32797
|
-
return raw.slice(0, i);
|
|
32798
|
-
}
|
|
32799
|
-
}
|
|
32800
|
-
return raw;
|
|
32801
|
-
}
|
|
32802
|
-
function parseDotenv(content) {
|
|
32803
|
-
if (!content)
|
|
32804
|
-
return {};
|
|
32805
|
-
const result = {};
|
|
32806
|
-
for (const rawLine of content.split(`
|
|
32807
|
-
`)) {
|
|
32808
|
-
let line = rawLine.trim();
|
|
32809
|
-
if (!line || line.startsWith("#"))
|
|
32810
|
-
continue;
|
|
32811
|
-
if (line.startsWith("export ")) {
|
|
32812
|
-
line = line.slice(7).trim();
|
|
32813
|
-
if (line.length >= 2 && (line[0] === '"' || line[0] === "'") && line.endsWith(line[0])) {
|
|
32814
|
-
line = line.slice(1, -1);
|
|
32815
|
-
}
|
|
32816
|
-
}
|
|
32817
|
-
const eqIndex = line.indexOf("=");
|
|
32818
|
-
if (eqIndex === -1)
|
|
32819
|
-
continue;
|
|
32820
|
-
const key = line.slice(0, eqIndex).trim();
|
|
32821
|
-
const rawValue = line.slice(eqIndex + 1).trim();
|
|
32822
|
-
let value;
|
|
32823
|
-
if (rawValue.startsWith('"') || rawValue.startsWith("'")) {
|
|
32824
|
-
value = parseQuotedValue(rawValue, rawValue[0]);
|
|
32825
|
-
} else {
|
|
32826
|
-
value = stripInlineComment(rawValue).trim();
|
|
32827
|
-
}
|
|
32828
|
-
result[key] = value;
|
|
32829
|
-
}
|
|
32830
|
-
return result;
|
|
32831
|
-
}
|
|
32832
|
-
function copyLiteral(config) {
|
|
32833
|
-
if (config === null || typeof config !== "object" || Array.isArray(config))
|
|
32834
|
-
return config;
|
|
32835
|
-
const result = {};
|
|
32836
|
-
for (const [key, value] of Object.entries(config)) {
|
|
32837
|
-
if (!DANGEROUS_MERGE_KEYS.has(key))
|
|
32838
|
-
result[key] = value;
|
|
32839
|
-
}
|
|
32840
|
-
return result;
|
|
32841
|
-
}
|
|
32842
|
-
function isLiteralSubtree(path) {
|
|
32843
|
-
return LITERAL_SUBTREE_PATHS.some((literal) => literal.length === path.length && literal.every((segment, i) => segment === path[i]));
|
|
32844
|
-
}
|
|
32845
|
-
function resolveEnvVars(config, env, path = []) {
|
|
32846
|
-
if (isLiteralSubtree(path))
|
|
32847
|
-
return copyLiteral(config);
|
|
32848
|
-
if (typeof config === "string") {
|
|
32849
|
-
return resolveString(config, env, path);
|
|
32850
|
-
}
|
|
32851
|
-
if (Array.isArray(config)) {
|
|
32852
|
-
return config.map((item, i) => resolveEnvVars(item, env, [...path, String(i)]));
|
|
32853
|
-
}
|
|
32854
|
-
if (config !== null && typeof config === "object") {
|
|
32855
|
-
const result = {};
|
|
32856
|
-
for (const [key, value] of Object.entries(config)) {
|
|
32857
|
-
if (DANGEROUS_MERGE_KEYS.has(key)) {
|
|
32858
|
-
continue;
|
|
32859
|
-
}
|
|
32860
|
-
result[key] = resolveEnvVars(value, env, [...path, key]);
|
|
32861
|
-
}
|
|
32862
|
-
return result;
|
|
32863
|
-
}
|
|
32864
|
-
return config;
|
|
32865
|
-
}
|
|
32866
|
-
function resolveString(str, env, path) {
|
|
32867
|
-
const resolveOne = (varName) => {
|
|
32868
|
-
if (!(varName in env)) {
|
|
32869
|
-
throw new UnresolvedEnvVarError(varName, path);
|
|
32870
|
-
}
|
|
32871
|
-
return env[varName];
|
|
32872
|
-
};
|
|
32873
|
-
return str.replace(DOUBLE_DOLLAR_PROTECT_RE, `$$$${DOUBLE_DOLLAR_PLACEHOLDER}$1`).replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_match, varName) => resolveOne(varName)).replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g, (_match, varName) => resolveOne(varName)).replace(DOUBLE_DOLLAR_RESTORE_RE, (_match, varName) => `$${varName}`);
|
|
32874
|
-
}
|
|
32875
|
-
var LITERAL_SUBTREE_PATHS, UnresolvedEnvVarError, DOUBLE_DOLLAR_PLACEHOLDER = "\x00__DOLLAR_ESCAPE__\x00", DOUBLE_DOLLAR_PROTECT_RE, DOUBLE_DOLLAR_RESTORE_RE;
|
|
32876
|
-
var init_dotenv = __esm(() => {
|
|
32877
|
-
init_merger();
|
|
32878
|
-
LITERAL_SUBTREE_PATHS = [
|
|
32879
|
-
["mcp", "servers"],
|
|
32880
|
-
["memory", "koda", "headers"]
|
|
32881
|
-
];
|
|
32882
|
-
UnresolvedEnvVarError = class UnresolvedEnvVarError extends Error {
|
|
32883
|
-
varName;
|
|
32884
|
-
path;
|
|
32885
|
-
constructor(varName, path) {
|
|
32886
|
-
super(`Environment variable $${varName} is not defined (at config path "${path.join(".") || "(root)"}")`);
|
|
32887
|
-
this.varName = varName;
|
|
32888
|
-
this.path = path;
|
|
32889
|
-
this.name = "UnresolvedEnvVarError";
|
|
32890
|
-
}
|
|
32891
|
-
};
|
|
32892
|
-
DOUBLE_DOLLAR_PROTECT_RE = /\$\$(\{[A-Za-z_][A-Za-z0-9_]*\}|[A-Za-z_][A-Za-z0-9_]*)/g;
|
|
32893
|
-
DOUBLE_DOLLAR_RESTORE_RE = /\$\$\x00__DOLLAR_ESCAPE__\x00(\{[A-Za-z_][A-Za-z0-9_]*\}|[A-Za-z_][A-Za-z0-9_]*)/g;
|
|
32894
|
-
});
|
|
32895
|
-
|
|
32896
32800
|
// src/config/merge.ts
|
|
32897
32801
|
function mergeTranscriptAudit(root, override) {
|
|
32898
32802
|
const dir = override?.dir ?? root?.dir;
|
|
@@ -33032,6 +32936,136 @@ var init_package_config_cache = __esm(() => {
|
|
|
33032
32936
|
};
|
|
33033
32937
|
});
|
|
33034
32938
|
|
|
32939
|
+
// src/config/dotenv.ts
|
|
32940
|
+
function parseQuotedValue(raw, quote) {
|
|
32941
|
+
let value = "";
|
|
32942
|
+
for (let i = 1;i < raw.length; i++) {
|
|
32943
|
+
const c = raw[i];
|
|
32944
|
+
if (quote === '"' && c === "\\" && i + 1 < raw.length) {
|
|
32945
|
+
const next = raw[i + 1];
|
|
32946
|
+
if (next === "n") {
|
|
32947
|
+
value += `
|
|
32948
|
+
`;
|
|
32949
|
+
i++;
|
|
32950
|
+
continue;
|
|
32951
|
+
}
|
|
32952
|
+
if (next === '"' || next === "\\") {
|
|
32953
|
+
value += next;
|
|
32954
|
+
i++;
|
|
32955
|
+
continue;
|
|
32956
|
+
}
|
|
32957
|
+
value += c;
|
|
32958
|
+
continue;
|
|
32959
|
+
}
|
|
32960
|
+
if (c === quote) {
|
|
32961
|
+
return value;
|
|
32962
|
+
}
|
|
32963
|
+
value += c;
|
|
32964
|
+
}
|
|
32965
|
+
return value;
|
|
32966
|
+
}
|
|
32967
|
+
function stripInlineComment(raw) {
|
|
32968
|
+
for (let i = 0;i < raw.length; i++) {
|
|
32969
|
+
if (raw[i] === "#" && (i === 0 || /\s/.test(raw[i - 1] ?? ""))) {
|
|
32970
|
+
return raw.slice(0, i);
|
|
32971
|
+
}
|
|
32972
|
+
}
|
|
32973
|
+
return raw;
|
|
32974
|
+
}
|
|
32975
|
+
function parseDotenv(content) {
|
|
32976
|
+
if (!content)
|
|
32977
|
+
return {};
|
|
32978
|
+
const result = {};
|
|
32979
|
+
for (const rawLine of content.split(`
|
|
32980
|
+
`)) {
|
|
32981
|
+
let line = rawLine.trim();
|
|
32982
|
+
if (!line || line.startsWith("#"))
|
|
32983
|
+
continue;
|
|
32984
|
+
if (line.startsWith("export ")) {
|
|
32985
|
+
line = line.slice(7).trim();
|
|
32986
|
+
if (line.length >= 2 && (line[0] === '"' || line[0] === "'") && line.endsWith(line[0])) {
|
|
32987
|
+
line = line.slice(1, -1);
|
|
32988
|
+
}
|
|
32989
|
+
}
|
|
32990
|
+
const eqIndex = line.indexOf("=");
|
|
32991
|
+
if (eqIndex === -1)
|
|
32992
|
+
continue;
|
|
32993
|
+
const key = line.slice(0, eqIndex).trim();
|
|
32994
|
+
const rawValue = line.slice(eqIndex + 1).trim();
|
|
32995
|
+
let value;
|
|
32996
|
+
if (rawValue.startsWith('"') || rawValue.startsWith("'")) {
|
|
32997
|
+
value = parseQuotedValue(rawValue, rawValue[0]);
|
|
32998
|
+
} else {
|
|
32999
|
+
value = stripInlineComment(rawValue).trim();
|
|
33000
|
+
}
|
|
33001
|
+
result[key] = value;
|
|
33002
|
+
}
|
|
33003
|
+
return result;
|
|
33004
|
+
}
|
|
33005
|
+
function copyLiteral(config) {
|
|
33006
|
+
if (config === null || typeof config !== "object" || Array.isArray(config))
|
|
33007
|
+
return config;
|
|
33008
|
+
const result = {};
|
|
33009
|
+
for (const [key, value] of Object.entries(config)) {
|
|
33010
|
+
if (!DANGEROUS_MERGE_KEYS.has(key))
|
|
33011
|
+
result[key] = value;
|
|
33012
|
+
}
|
|
33013
|
+
return result;
|
|
33014
|
+
}
|
|
33015
|
+
function isLiteralSubtree(path) {
|
|
33016
|
+
return LITERAL_SUBTREE_PATHS.some((literal) => literal.length === path.length && literal.every((segment, i) => segment === path[i]));
|
|
33017
|
+
}
|
|
33018
|
+
function resolveEnvVars(config, env, path = []) {
|
|
33019
|
+
if (isLiteralSubtree(path))
|
|
33020
|
+
return copyLiteral(config);
|
|
33021
|
+
if (typeof config === "string") {
|
|
33022
|
+
return resolveString(config, env, path);
|
|
33023
|
+
}
|
|
33024
|
+
if (Array.isArray(config)) {
|
|
33025
|
+
return config.map((item, i) => resolveEnvVars(item, env, [...path, String(i)]));
|
|
33026
|
+
}
|
|
33027
|
+
if (config !== null && typeof config === "object") {
|
|
33028
|
+
const result = {};
|
|
33029
|
+
for (const [key, value] of Object.entries(config)) {
|
|
33030
|
+
if (DANGEROUS_MERGE_KEYS.has(key)) {
|
|
33031
|
+
continue;
|
|
33032
|
+
}
|
|
33033
|
+
result[key] = resolveEnvVars(value, env, [...path, key]);
|
|
33034
|
+
}
|
|
33035
|
+
return result;
|
|
33036
|
+
}
|
|
33037
|
+
return config;
|
|
33038
|
+
}
|
|
33039
|
+
function resolveString(str, env, path) {
|
|
33040
|
+
const resolveOne = (varName) => {
|
|
33041
|
+
if (!(varName in env)) {
|
|
33042
|
+
throw new UnresolvedEnvVarError(varName, path);
|
|
33043
|
+
}
|
|
33044
|
+
return env[varName];
|
|
33045
|
+
};
|
|
33046
|
+
return str.replace(DOUBLE_DOLLAR_PROTECT_RE, `$$$${DOUBLE_DOLLAR_PLACEHOLDER}$1`).replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_match, bracedName, bareName) => resolveOne(bracedName ?? bareName ?? "")).replace(DOUBLE_DOLLAR_RESTORE_RE, (_match, varName) => `$${varName}`);
|
|
33047
|
+
}
|
|
33048
|
+
var LITERAL_SUBTREE_PATHS, UnresolvedEnvVarError, DOUBLE_DOLLAR_PLACEHOLDER = "\x00__DOLLAR_ESCAPE__\x00", DOUBLE_DOLLAR_PROTECT_RE, DOUBLE_DOLLAR_RESTORE_RE;
|
|
33049
|
+
var init_dotenv = __esm(() => {
|
|
33050
|
+
init_merger();
|
|
33051
|
+
LITERAL_SUBTREE_PATHS = [
|
|
33052
|
+
["mcp", "servers"],
|
|
33053
|
+
["memory", "koda", "headers"]
|
|
33054
|
+
];
|
|
33055
|
+
UnresolvedEnvVarError = class UnresolvedEnvVarError extends Error {
|
|
33056
|
+
varName;
|
|
33057
|
+
path;
|
|
33058
|
+
constructor(varName, path) {
|
|
33059
|
+
super(`Environment variable $${varName} is not defined (at config path "${path.join(".") || "(root)"}")`);
|
|
33060
|
+
this.varName = varName;
|
|
33061
|
+
this.path = path;
|
|
33062
|
+
this.name = "UnresolvedEnvVarError";
|
|
33063
|
+
}
|
|
33064
|
+
};
|
|
33065
|
+
DOUBLE_DOLLAR_PROTECT_RE = /\$\$(\{[A-Za-z_][A-Za-z0-9_]*\}|[A-Za-z_][A-Za-z0-9_]*)/g;
|
|
33066
|
+
DOUBLE_DOLLAR_RESTORE_RE = /\$\$\x00__DOLLAR_ESCAPE__\x00(\{[A-Za-z_][A-Za-z0-9_]*\}|[A-Za-z_][A-Za-z0-9_]*)/g;
|
|
33067
|
+
});
|
|
33068
|
+
|
|
33035
33069
|
// src/config/profile.ts
|
|
33036
33070
|
import { readdirSync as readdirSync3 } from "fs";
|
|
33037
33071
|
import { join as join37 } from "path";
|
|
@@ -33210,34 +33244,6 @@ var init_profile = __esm(() => {
|
|
|
33210
33244
|
SENSITIVE_ENV_KEY_PATTERN = /key|token|secret|password|credential|auth|session|cookie|private|dsn|url/i;
|
|
33211
33245
|
});
|
|
33212
33246
|
|
|
33213
|
-
// src/config/package-profile.ts
|
|
33214
|
-
import { join as join38 } from "path";
|
|
33215
|
-
async function loadPackageProfileLayers({
|
|
33216
|
-
profile,
|
|
33217
|
-
repoRoot,
|
|
33218
|
-
packageDir,
|
|
33219
|
-
logger,
|
|
33220
|
-
warnDedupe
|
|
33221
|
-
}) {
|
|
33222
|
-
const chain = parseProfileList(profile).filter((name) => name && name !== "default");
|
|
33223
|
-
const layers = [];
|
|
33224
|
-
const packageRoot = join38(repoRoot, packageDir);
|
|
33225
|
-
for (const name of chain) {
|
|
33226
|
-
const profileData = await loadProfile(name, packageRoot);
|
|
33227
|
-
const resolvedProfileData = await resolveProfileEnvVars(name, packageRoot, profileData, `Per-package profile "${name}" (${packageDir})`, { packageDir });
|
|
33228
|
-
const layer = applyConfigCompatShims(resolvedProfileData, logger, warnDedupe);
|
|
33229
|
-
rejectPipelineModeKeys(layer, `per-package profile "${name}" (${packageDir})`);
|
|
33230
|
-
warnQualityCommandChains(layer, warnDedupe.warn);
|
|
33231
|
-
layers.push(layer);
|
|
33232
|
-
}
|
|
33233
|
-
return { chain, layers };
|
|
33234
|
-
}
|
|
33235
|
-
var init_package_profile = __esm(() => {
|
|
33236
|
-
init_compat_shims();
|
|
33237
|
-
init_config_guards();
|
|
33238
|
-
init_profile();
|
|
33239
|
-
});
|
|
33240
|
-
|
|
33241
33247
|
// src/config/removed-stage-names.ts
|
|
33242
33248
|
function isRecord3(value) {
|
|
33243
33249
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -33329,86 +33335,6 @@ var init_removed_stage_names = __esm(() => {
|
|
|
33329
33335
|
REMOVED_STAGE_SET = new Set(REMOVED_STAGE_NAMES);
|
|
33330
33336
|
});
|
|
33331
33337
|
|
|
33332
|
-
// src/config/root-only-keys.ts
|
|
33333
|
-
function pinRootOnlyKeys(merged, root) {
|
|
33334
|
-
const { auth: _packageAuth, advisor: _packageAdvisor, workflow: _packageWorkflow, ...rootOnlyMerged } = merged;
|
|
33335
|
-
return {
|
|
33336
|
-
...rootOnlyMerged,
|
|
33337
|
-
...root.auth === undefined ? {} : { auth: root.auth },
|
|
33338
|
-
...root.advisor === undefined ? {} : { advisor: root.advisor },
|
|
33339
|
-
...root.workflow === undefined ? {} : { workflow: root.workflow },
|
|
33340
|
-
context: {
|
|
33341
|
-
...merged.context,
|
|
33342
|
-
rules: root.context.rules,
|
|
33343
|
-
projectContext: root.context.projectContext
|
|
33344
|
-
},
|
|
33345
|
-
execution: {
|
|
33346
|
-
...merged.execution,
|
|
33347
|
-
mode: root.execution.mode,
|
|
33348
|
-
bashApproval: root.execution.bashApproval,
|
|
33349
|
-
approvalTimeout: root.execution.approvalTimeout,
|
|
33350
|
-
sandbox: root.execution.sandbox,
|
|
33351
|
-
commandSafety: root.execution.commandSafety
|
|
33352
|
-
}
|
|
33353
|
-
};
|
|
33354
|
-
}
|
|
33355
|
-
function isRecord4(value) {
|
|
33356
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33357
|
-
}
|
|
33358
|
-
function pinRootOnlyKeysRaw(raw, root, packageDir, onIgnored) {
|
|
33359
|
-
const { auth: _packageAuth, advisor: _packageAdvisor, workflow: _packageWorkflow, ...rawWithoutAuth } = raw;
|
|
33360
|
-
const execution = isRecord4(raw.execution) ? raw.execution : {};
|
|
33361
|
-
const rootExecution = { ...root.execution };
|
|
33362
|
-
for (const key of ROOT_ONLY_EXECUTION_KEYS) {
|
|
33363
|
-
if (key in execution && !Bun.deepEquals(execution[key], rootExecution[key])) {
|
|
33364
|
-
onIgnored(`execution.${key} is root-only (ADR-031); the value set for package "${packageDir}" is ignored`);
|
|
33365
|
-
}
|
|
33366
|
-
}
|
|
33367
|
-
const rest = Object.fromEntries(Object.entries(execution).filter(([k]) => !ROOT_ONLY.has(k)));
|
|
33368
|
-
const pinned = Object.fromEntries(ROOT_ONLY_EXECUTION_KEYS.flatMap((k) => rootExecution[k] === undefined ? [] : [[k, rootExecution[k]]]));
|
|
33369
|
-
const rawContext = isRecord4(raw.context) ? raw.context : null;
|
|
33370
|
-
const rootContextValues = {
|
|
33371
|
-
rules: root.context.rules,
|
|
33372
|
-
projectContext: root.context.projectContext
|
|
33373
|
-
};
|
|
33374
|
-
const pinnedContext = {};
|
|
33375
|
-
for (const key of ROOT_ONLY_CONTEXT_KEYS) {
|
|
33376
|
-
if (rawContext !== null && key in rawContext && !Bun.deepEquals(rawContext[key], rootContextValues[key])) {
|
|
33377
|
-
onIgnored(`context.${key} is root-only; the value set for package "${packageDir}" is ignored`);
|
|
33378
|
-
pinnedContext[key] = rootContextValues[key];
|
|
33379
|
-
}
|
|
33380
|
-
}
|
|
33381
|
-
if (Object.hasOwn(raw, "auth") && !Bun.deepEquals(raw.auth, root.auth)) {
|
|
33382
|
-
onIgnored(`auth is root-only; the value set for package "${packageDir}" is ignored`);
|
|
33383
|
-
}
|
|
33384
|
-
if (Object.hasOwn(raw, "advisor") && !Bun.deepEquals(raw.advisor, root.advisor)) {
|
|
33385
|
-
onIgnored(`advisor is root-only; the value set for package "${packageDir}" is ignored`);
|
|
33386
|
-
}
|
|
33387
|
-
if (Object.hasOwn(raw, "workflow") && !Bun.deepEquals(raw.workflow, root.workflow)) {
|
|
33388
|
-
onIgnored(`workflow is root-only; the value set for package "${packageDir}" is ignored`);
|
|
33389
|
-
}
|
|
33390
|
-
return {
|
|
33391
|
-
...rawWithoutAuth,
|
|
33392
|
-
...root.auth === undefined ? {} : { auth: root.auth },
|
|
33393
|
-
...root.advisor === undefined ? {} : { advisor: root.advisor },
|
|
33394
|
-
...root.workflow === undefined ? {} : { workflow: root.workflow },
|
|
33395
|
-
...rawContext === null ? {} : { context: { ...rawContext, ...pinnedContext } },
|
|
33396
|
-
execution: { ...rest, ...pinned }
|
|
33397
|
-
};
|
|
33398
|
-
}
|
|
33399
|
-
var ROOT_ONLY_EXECUTION_KEYS, ROOT_ONLY, ROOT_ONLY_CONTEXT_KEYS;
|
|
33400
|
-
var init_root_only_keys = __esm(() => {
|
|
33401
|
-
ROOT_ONLY_EXECUTION_KEYS = [
|
|
33402
|
-
"bashApproval",
|
|
33403
|
-
"approvalTimeout",
|
|
33404
|
-
"sandbox",
|
|
33405
|
-
"commandSafety",
|
|
33406
|
-
"mode"
|
|
33407
|
-
];
|
|
33408
|
-
ROOT_ONLY = new Set(ROOT_ONLY_EXECUTION_KEYS);
|
|
33409
|
-
ROOT_ONLY_CONTEXT_KEYS = ["rules", "projectContext"];
|
|
33410
|
-
});
|
|
33411
|
-
|
|
33412
33338
|
// src/config/schema-types.ts
|
|
33413
33339
|
function toPricing(config) {
|
|
33414
33340
|
return {
|
|
@@ -33765,13 +33691,13 @@ var init_schemas_bot = __esm(() => {
|
|
|
33765
33691
|
|
|
33766
33692
|
// src/config/schemas-context.ts
|
|
33767
33693
|
import { homedir as homedir5 } from "os";
|
|
33768
|
-
import { isAbsolute as isAbsolute11, join as
|
|
33694
|
+
import { isAbsolute as isAbsolute11, join as join38 } from "path";
|
|
33769
33695
|
var OverridePathSchema, RulesOverrideConfigBase, RulesOverrideConfigSchema, ProjectContextConfigBase, ProjectContextConfigSchema, TestCoverageConfigBase, TestCoverageConfigSchema, ContextAutoDetectConfigBase, ContextAutoDetectConfigSchema, FeatureContextEngineConfigSchema, ContextV2PullConfigSchema, ContextV2FragmentsConfigSchema, ContextV2RulesConfigSchema, ContextPluginProviderConfigSchema, ContextV2StageOverrideSchema, ContextV2ConfigBase, ContextV2ConfigSchema, ContextConfigSchema;
|
|
33770
33696
|
var init_schemas_context = __esm(() => {
|
|
33771
33697
|
init_zod();
|
|
33772
33698
|
OverridePathSchema = string2().min(1).refine((value) => isAbsolute11(value) || value.startsWith("~/"), {
|
|
33773
33699
|
message: "must be an absolute path or start with '~/'"
|
|
33774
|
-
}).transform((value) => value.startsWith("~/") ?
|
|
33700
|
+
}).transform((value) => value.startsWith("~/") ? join38(homedir5(), value.slice(2)) : value);
|
|
33775
33701
|
RulesOverrideConfigBase = object({
|
|
33776
33702
|
delivery: _enum(["index", "push"]).default("index"),
|
|
33777
33703
|
overrideDir: OverridePathSchema.optional(),
|
|
@@ -34861,6 +34787,7 @@ var init_schemas3 = __esm(() => {
|
|
|
34861
34787
|
init_internal();
|
|
34862
34788
|
init_zod();
|
|
34863
34789
|
init_agent_defaults();
|
|
34790
|
+
init_paths();
|
|
34864
34791
|
init_schema_types();
|
|
34865
34792
|
init_schemas_acp_agents();
|
|
34866
34793
|
init_schemas_advisor();
|
|
@@ -34888,8 +34815,10 @@ var init_schemas3 = __esm(() => {
|
|
|
34888
34815
|
message: "name must contain only lowercase letters, digits, hyphens, and underscores"
|
|
34889
34816
|
}).refine((v) => v === "" || !v.startsWith(".") && !v.startsWith("_"), {
|
|
34890
34817
|
message: "name must not start with '.' or '_'"
|
|
34891
|
-
}).
|
|
34892
|
-
|
|
34818
|
+
}).superRefine((v, ctx) => {
|
|
34819
|
+
if (RESERVED_PROJECT_NAMES.includes(v)) {
|
|
34820
|
+
ctx.addIssue({ code: "custom", message: `name '${v}' is reserved` });
|
|
34821
|
+
}
|
|
34893
34822
|
}).refine((v) => v === "" || v.length <= 64, {
|
|
34894
34823
|
message: "name must be at most 64 characters"
|
|
34895
34824
|
}),
|
|
@@ -35224,15 +35153,7 @@ var init_schema = __esm(() => {
|
|
|
35224
35153
|
init_types5();
|
|
35225
35154
|
});
|
|
35226
35155
|
|
|
35227
|
-
// src/config/
|
|
35228
|
-
function applyWorkflowMode(config) {
|
|
35229
|
-
if (config.advisor === undefined || config.advisor.enabled)
|
|
35230
|
-
return config;
|
|
35231
|
-
return { ...config, advisor: { ...config.advisor, enabled: true } };
|
|
35232
|
-
}
|
|
35233
|
-
|
|
35234
|
-
// src/config/loader.ts
|
|
35235
|
-
import { basename as basename7, dirname as dirname15, join as join40, resolve as resolve26 } from "path";
|
|
35156
|
+
// src/config/package-layer.ts
|
|
35236
35157
|
function rejectResolvedPipelineMode(config, source) {
|
|
35237
35158
|
const execution = config.execution;
|
|
35238
35159
|
if (!execution || typeof execution !== "object" || Array.isArray(execution))
|
|
@@ -35262,6 +35183,163 @@ function resolveEnvVarsWarnOnFailure(config, logger, layerName) {
|
|
|
35262
35183
|
throw err;
|
|
35263
35184
|
}
|
|
35264
35185
|
}
|
|
35186
|
+
function preparePackageLayer(fields, packageDir, logger, warnDedupe) {
|
|
35187
|
+
const layerName = `per-package config "${packageDir}"`;
|
|
35188
|
+
const envResolved = resolveEnvVarsWarnOnFailure(fields, logger, layerName);
|
|
35189
|
+
const shimmed = applyConfigCompatShims(envResolved, logger, warnDedupe);
|
|
35190
|
+
rejectPipelineModeKeys(shimmed, layerName);
|
|
35191
|
+
warnQualityCommandChains(shimmed, warnDedupe.warn);
|
|
35192
|
+
rejectLegacyRectificationKeys(shimmed);
|
|
35193
|
+
rejectDeadQualityFlags(shimmed);
|
|
35194
|
+
return stripRemovedConfig(shimmed, warnDedupe.warn);
|
|
35195
|
+
}
|
|
35196
|
+
function validatePackageConfig(rawMerged, packageDir, profileChain, warnDedupe) {
|
|
35197
|
+
rejectLegacyAgentKeys(rawMerged);
|
|
35198
|
+
rejectLegacyRectificationKeys(rawMerged);
|
|
35199
|
+
rejectDeadQualityFlags(rawMerged);
|
|
35200
|
+
rejectRemovedPlanModes(rawMerged);
|
|
35201
|
+
validatePermissionsBlock(rawMerged);
|
|
35202
|
+
const stripped = stripRemovedConfig(rawMerged, warnDedupe.warn);
|
|
35203
|
+
const result = NaxConfigSchema.safeParse(stripped);
|
|
35204
|
+
if (!result.success) {
|
|
35205
|
+
const errors = result.error.issues.map((err) => {
|
|
35206
|
+
const path = String(err.path.join("."));
|
|
35207
|
+
return path ? `${path}: ${err.message}` : err.message;
|
|
35208
|
+
});
|
|
35209
|
+
const label = profileChain.length > 0 ? `profile "${profileChain.join("+")}"` : "override";
|
|
35210
|
+
throw new NaxError(`Per-package config ${label} produced an invalid config for package "${packageDir}":
|
|
35211
|
+
${errors.join(`
|
|
35212
|
+
`)}`, "PER_PACKAGE_PROFILE_INVALID", { stage: "config", packageDir, profileChain: [...profileChain] });
|
|
35213
|
+
}
|
|
35214
|
+
return result.data;
|
|
35215
|
+
}
|
|
35216
|
+
var init_package_layer = __esm(() => {
|
|
35217
|
+
init_errors4();
|
|
35218
|
+
init_compat_shims();
|
|
35219
|
+
init_config_guards();
|
|
35220
|
+
init_dotenv();
|
|
35221
|
+
init_profile();
|
|
35222
|
+
init_removed_stage_names();
|
|
35223
|
+
init_schema();
|
|
35224
|
+
});
|
|
35225
|
+
|
|
35226
|
+
// src/config/package-profile.ts
|
|
35227
|
+
import { join as join39 } from "path";
|
|
35228
|
+
async function loadPackageProfileLayers({
|
|
35229
|
+
profile,
|
|
35230
|
+
repoRoot,
|
|
35231
|
+
packageDir,
|
|
35232
|
+
logger,
|
|
35233
|
+
warnDedupe
|
|
35234
|
+
}) {
|
|
35235
|
+
const chain = parseProfileList(profile).filter((name) => name && name !== "default");
|
|
35236
|
+
const layers = [];
|
|
35237
|
+
const packageRoot = join39(repoRoot, packageDir);
|
|
35238
|
+
for (const name of chain) {
|
|
35239
|
+
const profileData = await loadProfile(name, packageRoot);
|
|
35240
|
+
const resolvedProfileData = await resolveProfileEnvVars(name, packageRoot, profileData, `Per-package profile "${name}" (${packageDir})`, { packageDir });
|
|
35241
|
+
const layer = applyConfigCompatShims(resolvedProfileData, logger, warnDedupe);
|
|
35242
|
+
rejectPipelineModeKeys(layer, `per-package profile "${name}" (${packageDir})`);
|
|
35243
|
+
warnQualityCommandChains(layer, warnDedupe.warn);
|
|
35244
|
+
layers.push(layer);
|
|
35245
|
+
}
|
|
35246
|
+
return { chain, layers };
|
|
35247
|
+
}
|
|
35248
|
+
var init_package_profile = __esm(() => {
|
|
35249
|
+
init_compat_shims();
|
|
35250
|
+
init_config_guards();
|
|
35251
|
+
init_profile();
|
|
35252
|
+
});
|
|
35253
|
+
|
|
35254
|
+
// src/config/root-only-keys.ts
|
|
35255
|
+
function pinRootOnlyKeys(merged, root) {
|
|
35256
|
+
const { auth: _packageAuth, advisor: _packageAdvisor, workflow: _packageWorkflow, ...rootOnlyMerged } = merged;
|
|
35257
|
+
return {
|
|
35258
|
+
...rootOnlyMerged,
|
|
35259
|
+
...root.auth === undefined ? {} : { auth: root.auth },
|
|
35260
|
+
...root.advisor === undefined ? {} : { advisor: root.advisor },
|
|
35261
|
+
...root.workflow === undefined ? {} : { workflow: root.workflow },
|
|
35262
|
+
context: {
|
|
35263
|
+
...merged.context,
|
|
35264
|
+
rules: root.context.rules,
|
|
35265
|
+
projectContext: root.context.projectContext
|
|
35266
|
+
},
|
|
35267
|
+
execution: {
|
|
35268
|
+
...merged.execution,
|
|
35269
|
+
mode: root.execution.mode,
|
|
35270
|
+
bashApproval: root.execution.bashApproval,
|
|
35271
|
+
approvalTimeout: root.execution.approvalTimeout,
|
|
35272
|
+
sandbox: root.execution.sandbox,
|
|
35273
|
+
commandSafety: root.execution.commandSafety
|
|
35274
|
+
}
|
|
35275
|
+
};
|
|
35276
|
+
}
|
|
35277
|
+
function isRecord4(value) {
|
|
35278
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35279
|
+
}
|
|
35280
|
+
function pinRootOnlyKeysRaw(raw, root, packageDir, onIgnored) {
|
|
35281
|
+
const { auth: _packageAuth, advisor: _packageAdvisor, workflow: _packageWorkflow, ...rawWithoutAuth } = raw;
|
|
35282
|
+
const execution = isRecord4(raw.execution) ? raw.execution : {};
|
|
35283
|
+
const rootExecution = { ...root.execution };
|
|
35284
|
+
for (const key of ROOT_ONLY_EXECUTION_KEYS) {
|
|
35285
|
+
if (key in execution && !Bun.deepEquals(execution[key], rootExecution[key])) {
|
|
35286
|
+
onIgnored(`execution.${key} is root-only (ADR-031); the value set for package "${packageDir}" is ignored`);
|
|
35287
|
+
}
|
|
35288
|
+
}
|
|
35289
|
+
const rest = Object.fromEntries(Object.entries(execution).filter(([k]) => !ROOT_ONLY.has(k)));
|
|
35290
|
+
const pinned = Object.fromEntries(ROOT_ONLY_EXECUTION_KEYS.flatMap((k) => rootExecution[k] === undefined ? [] : [[k, rootExecution[k]]]));
|
|
35291
|
+
const rawContext = isRecord4(raw.context) ? raw.context : null;
|
|
35292
|
+
const rootContextValues = {
|
|
35293
|
+
rules: root.context.rules,
|
|
35294
|
+
projectContext: root.context.projectContext
|
|
35295
|
+
};
|
|
35296
|
+
const pinnedContext = {};
|
|
35297
|
+
for (const key of ROOT_ONLY_CONTEXT_KEYS) {
|
|
35298
|
+
if (rawContext !== null && key in rawContext && !Bun.deepEquals(rawContext[key], rootContextValues[key])) {
|
|
35299
|
+
onIgnored(`context.${key} is root-only; the value set for package "${packageDir}" is ignored`);
|
|
35300
|
+
pinnedContext[key] = rootContextValues[key];
|
|
35301
|
+
}
|
|
35302
|
+
}
|
|
35303
|
+
if (Object.hasOwn(raw, "auth") && !Bun.deepEquals(raw.auth, root.auth)) {
|
|
35304
|
+
onIgnored(`auth is root-only; the value set for package "${packageDir}" is ignored`);
|
|
35305
|
+
}
|
|
35306
|
+
if (Object.hasOwn(raw, "advisor") && !Bun.deepEquals(raw.advisor, root.advisor)) {
|
|
35307
|
+
onIgnored(`advisor is root-only; the value set for package "${packageDir}" is ignored`);
|
|
35308
|
+
}
|
|
35309
|
+
if (Object.hasOwn(raw, "workflow") && !Bun.deepEquals(raw.workflow, root.workflow)) {
|
|
35310
|
+
onIgnored(`workflow is root-only; the value set for package "${packageDir}" is ignored`);
|
|
35311
|
+
}
|
|
35312
|
+
return {
|
|
35313
|
+
...rawWithoutAuth,
|
|
35314
|
+
...root.auth === undefined ? {} : { auth: root.auth },
|
|
35315
|
+
...root.advisor === undefined ? {} : { advisor: root.advisor },
|
|
35316
|
+
...root.workflow === undefined ? {} : { workflow: root.workflow },
|
|
35317
|
+
...rawContext === null ? {} : { context: { ...rawContext, ...pinnedContext } },
|
|
35318
|
+
execution: { ...rest, ...pinned }
|
|
35319
|
+
};
|
|
35320
|
+
}
|
|
35321
|
+
var ROOT_ONLY_EXECUTION_KEYS, ROOT_ONLY, ROOT_ONLY_CONTEXT_KEYS;
|
|
35322
|
+
var init_root_only_keys = __esm(() => {
|
|
35323
|
+
ROOT_ONLY_EXECUTION_KEYS = [
|
|
35324
|
+
"bashApproval",
|
|
35325
|
+
"approvalTimeout",
|
|
35326
|
+
"sandbox",
|
|
35327
|
+
"commandSafety",
|
|
35328
|
+
"mode"
|
|
35329
|
+
];
|
|
35330
|
+
ROOT_ONLY = new Set(ROOT_ONLY_EXECUTION_KEYS);
|
|
35331
|
+
ROOT_ONLY_CONTEXT_KEYS = ["rules", "projectContext"];
|
|
35332
|
+
});
|
|
35333
|
+
|
|
35334
|
+
// src/config/workflow-mode.ts
|
|
35335
|
+
function applyWorkflowMode(config) {
|
|
35336
|
+
if (config.advisor === undefined || config.advisor.enabled)
|
|
35337
|
+
return config;
|
|
35338
|
+
return { ...config, advisor: { ...config.advisor, enabled: true } };
|
|
35339
|
+
}
|
|
35340
|
+
|
|
35341
|
+
// src/config/loader.ts
|
|
35342
|
+
import { basename as basename7, dirname as dirname15, join as join40, resolve as resolve26 } from "path";
|
|
35265
35343
|
function globalConfigPath() {
|
|
35266
35344
|
return join40(globalConfigDir(), "config.json");
|
|
35267
35345
|
}
|
|
@@ -35378,20 +35456,20 @@ async function loadConfig(startDir, cliOverrides) {
|
|
|
35378
35456
|
}
|
|
35379
35457
|
return finalizeAndValidateRootConfig(rawConfig);
|
|
35380
35458
|
}
|
|
35381
|
-
async function loadPackageOverrideData(repoRoot, packageDir) {
|
|
35459
|
+
async function loadPackageOverrideData(repoRoot, packageDir, warnDedupe) {
|
|
35382
35460
|
const packageConfigPath = join40(repoRoot, PROJECT_NAX_DIR, "mono", packageDir, "config.json");
|
|
35383
35461
|
const override = await loadJsonFileStrict(packageConfigPath, "config");
|
|
35384
35462
|
if (!override)
|
|
35385
35463
|
return null;
|
|
35386
35464
|
const { profile, ...fields } = rejectGlobalOnlyKeys(override, `package:${packageDir}`);
|
|
35387
|
-
const { layers } = await loadPackageProfileLayers({
|
|
35465
|
+
const { chain, layers } = await loadPackageProfileLayers({
|
|
35388
35466
|
profile,
|
|
35389
35467
|
repoRoot,
|
|
35390
35468
|
packageDir,
|
|
35391
35469
|
logger: getLogger2(),
|
|
35392
|
-
warnDedupe
|
|
35470
|
+
warnDedupe
|
|
35393
35471
|
});
|
|
35394
|
-
return { fields, layers };
|
|
35472
|
+
return { fields, layers, chain };
|
|
35395
35473
|
}
|
|
35396
35474
|
function applyPackageProfileLayers(base, layers) {
|
|
35397
35475
|
let merged = base;
|
|
@@ -35401,18 +35479,23 @@ function applyPackageProfileLayers(base, layers) {
|
|
|
35401
35479
|
return resolvedFields;
|
|
35402
35480
|
}
|
|
35403
35481
|
async function loadPackageOverride(repoRoot, packageDir) {
|
|
35404
|
-
const data = await loadPackageOverrideData(repoRoot, packageDir);
|
|
35482
|
+
const data = await loadPackageOverrideData(repoRoot, packageDir, createConfigWarnDedupe());
|
|
35405
35483
|
return data ? applyPackageProfileLayers(data.fields, data.layers) : null;
|
|
35406
35484
|
}
|
|
35407
35485
|
async function loadPackageOverrideWithConfig(options) {
|
|
35408
35486
|
const { repoRoot, packageDir, rootConfig } = options;
|
|
35409
|
-
const
|
|
35487
|
+
const warnDedupe = createConfigWarnDedupe();
|
|
35488
|
+
const logger = getLogger2();
|
|
35489
|
+
const data = await loadPackageOverrideData(repoRoot, packageDir, warnDedupe);
|
|
35410
35490
|
if (!data)
|
|
35411
35491
|
return null;
|
|
35412
|
-
const
|
|
35413
|
-
const
|
|
35492
|
+
const prepared = preparePackageLayer(data.fields, packageDir, logger, warnDedupe);
|
|
35493
|
+
const overlay = applyPackageProfileLayers(prepared, data.layers);
|
|
35494
|
+
const base = mergePackageConfig(rootConfig, prepared);
|
|
35414
35495
|
const resolved = applyPackageProfileLayers(base, data.layers);
|
|
35415
|
-
const
|
|
35496
|
+
const merged = mergePackageConfig(rootConfig, resolved);
|
|
35497
|
+
const pinned = pinRootOnlyKeysRaw(merged, rootConfig, packageDir, warnDedupe.warn);
|
|
35498
|
+
const config = validatePackageConfig(pinned, packageDir, data.chain, warnDedupe);
|
|
35416
35499
|
config.review.commands = mergePackageConfig(rootConfig, overlay).review.commands;
|
|
35417
35500
|
return { overlay, config };
|
|
35418
35501
|
}
|
|
@@ -35456,13 +35539,7 @@ async function loadConfigForWorkdir(rootConfigPath, packageDir, cliOverrides) {
|
|
|
35456
35539
|
logger.debug("config", "Per-package config loaded", { packageConfigPath, packageDir });
|
|
35457
35540
|
const { profile: packageProfile, ...packageFields } = rejectGlobalOnlyKeys(packageOverride, `package:${packageDir}`);
|
|
35458
35541
|
const warnDedupe = createConfigWarnDedupe();
|
|
35459
|
-
const
|
|
35460
|
-
const shimmedPackageFields = applyConfigCompatShims(envResolvedPackageFields, logger, warnDedupe);
|
|
35461
|
-
rejectPipelineModeKeys(shimmedPackageFields, `per-package config "${packageDir}"`);
|
|
35462
|
-
warnQualityCommandChains(shimmedPackageFields, warnDedupe.warn);
|
|
35463
|
-
rejectLegacyRectificationKeys(shimmedPackageFields);
|
|
35464
|
-
rejectDeadQualityFlags(shimmedPackageFields);
|
|
35465
|
-
const packageLayer = stripRemovedConfig(shimmedPackageFields, warnDedupe.warn);
|
|
35542
|
+
const packageLayer = preparePackageLayer(packageFields, packageDir, logger, warnDedupe);
|
|
35466
35543
|
let merged = mergePackageConfig(rootConfig, packageLayer);
|
|
35467
35544
|
merged = stripRemovedConfig(merged, warnDedupe.warn);
|
|
35468
35545
|
const { chain: packageChain, layers } = await loadPackageProfileLayers({
|
|
@@ -35479,24 +35556,8 @@ async function loadConfigForWorkdir(rootConfigPath, packageDir, cliOverrides) {
|
|
|
35479
35556
|
rawMerged.profileChain = packageChain;
|
|
35480
35557
|
}
|
|
35481
35558
|
rawMerged = pinRootOnlyKeysRaw(rawMerged, rootConfig, packageDir, warnDedupe.warn);
|
|
35482
|
-
|
|
35483
|
-
|
|
35484
|
-
rejectDeadQualityFlags(rawMerged);
|
|
35485
|
-
rejectRemovedPlanModes(rawMerged);
|
|
35486
|
-
validatePermissionsBlock(rawMerged);
|
|
35487
|
-
rawMerged = stripRemovedConfig(rawMerged, warnDedupe.warn);
|
|
35488
|
-
const result = NaxConfigSchema.safeParse(rawMerged);
|
|
35489
|
-
if (!result.success) {
|
|
35490
|
-
const errors = result.error.issues.map((err) => {
|
|
35491
|
-
const path = String(err.path.join("."));
|
|
35492
|
-
return path ? `${path}: ${err.message}` : err.message;
|
|
35493
|
-
});
|
|
35494
|
-
const label = packageChain.length > 0 ? `profile "${packageChain.join("+")}"` : "override";
|
|
35495
|
-
throw new NaxError(`Per-package config ${label} produced an invalid config for package "${packageDir}":
|
|
35496
|
-
${errors.join(`
|
|
35497
|
-
`)}`, "PER_PACKAGE_PROFILE_INVALID", { stage: "config", packageDir, profileChain: packageChain });
|
|
35498
|
-
}
|
|
35499
|
-
merged = applyWorkflowMode(result.data);
|
|
35559
|
+
const validated = validatePackageConfig(rawMerged, packageDir, packageChain, warnDedupe);
|
|
35560
|
+
merged = applyWorkflowMode(validated);
|
|
35500
35561
|
return packageConfigCache.set(resolvedRootConfigPath, packageDir, profileKey, merged);
|
|
35501
35562
|
}
|
|
35502
35563
|
var ROOT_CONFIG_CACHE_MAX = 20, _rootConfigCache;
|
|
@@ -35506,11 +35567,11 @@ var init_loader = __esm(() => {
|
|
|
35506
35567
|
init_json_file();
|
|
35507
35568
|
init_compat_shims();
|
|
35508
35569
|
init_config_guards();
|
|
35509
|
-
init_dotenv();
|
|
35510
35570
|
init_global_files();
|
|
35511
35571
|
init_global_only_keys();
|
|
35512
35572
|
init_merger();
|
|
35513
35573
|
init_package_config_cache();
|
|
35574
|
+
init_package_layer();
|
|
35514
35575
|
init_package_profile();
|
|
35515
35576
|
init_paths();
|
|
35516
35577
|
init_profile();
|
|
@@ -36896,32 +36957,99 @@ var init_path_frame = () => {};
|
|
|
36896
36957
|
function normalizePath2(path) {
|
|
36897
36958
|
return path.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
36898
36959
|
}
|
|
36899
|
-
function
|
|
36900
|
-
|
|
36901
|
-
|
|
36902
|
-
|
|
36960
|
+
function bracesBalanced(pattern) {
|
|
36961
|
+
let depth = 0;
|
|
36962
|
+
for (const c of pattern) {
|
|
36963
|
+
if (c === "{") {
|
|
36964
|
+
depth++;
|
|
36965
|
+
} else if (c === "}") {
|
|
36966
|
+
if (depth === 0)
|
|
36967
|
+
return false;
|
|
36968
|
+
depth--;
|
|
36969
|
+
}
|
|
36970
|
+
}
|
|
36971
|
+
return depth === 0;
|
|
36972
|
+
}
|
|
36973
|
+
function findBraceGroupEnd(text, start) {
|
|
36974
|
+
let depth = 0;
|
|
36975
|
+
for (let i = start;i < text.length; i++) {
|
|
36976
|
+
if (text[i] === "{") {
|
|
36977
|
+
depth++;
|
|
36978
|
+
} else if (text[i] === "}") {
|
|
36979
|
+
depth--;
|
|
36980
|
+
if (depth === 0)
|
|
36981
|
+
return i;
|
|
36982
|
+
}
|
|
36983
|
+
}
|
|
36984
|
+
return -1;
|
|
36985
|
+
}
|
|
36986
|
+
function splitTopLevelAlternatives(content) {
|
|
36987
|
+
const alternatives = [];
|
|
36988
|
+
let depth = 0;
|
|
36989
|
+
let current = "";
|
|
36990
|
+
for (const c of content) {
|
|
36991
|
+
if (c === "{") {
|
|
36992
|
+
depth++;
|
|
36993
|
+
} else if (c === "}") {
|
|
36994
|
+
depth--;
|
|
36995
|
+
}
|
|
36996
|
+
if (c === "," && depth === 0) {
|
|
36997
|
+
alternatives.push(current);
|
|
36998
|
+
current = "";
|
|
36999
|
+
continue;
|
|
37000
|
+
}
|
|
37001
|
+
current += c;
|
|
37002
|
+
}
|
|
37003
|
+
alternatives.push(current);
|
|
37004
|
+
return alternatives;
|
|
37005
|
+
}
|
|
37006
|
+
function translateStars(text, start, follower) {
|
|
37007
|
+
if (text[start + 1] !== "*")
|
|
37008
|
+
return { regex: "[^/]*", next: start + 1, absorbed: false };
|
|
37009
|
+
if (text[start + 2] === "/")
|
|
37010
|
+
return { regex: GLOBSTAR_DIR, next: start + 3, absorbed: false };
|
|
37011
|
+
if (start + 2 === text.length && follower.startsWith("/")) {
|
|
37012
|
+
return { regex: GLOBSTAR_DIR, next: start + 2, absorbed: true };
|
|
37013
|
+
}
|
|
37014
|
+
return { regex: ".*", next: start + 2, absorbed: false };
|
|
37015
|
+
}
|
|
37016
|
+
function translateBraceGroup(content, follower) {
|
|
37017
|
+
const alternatives = splitTopLevelAlternatives(content);
|
|
37018
|
+
if (alternatives.length < 2) {
|
|
37019
|
+
const inner = translateGlobText(content, true, `}${follower}`);
|
|
37020
|
+
return { regex: `\\{${inner.regex}\\}`, absorbed: inner.absorbed };
|
|
37021
|
+
}
|
|
37022
|
+
const parts = alternatives.map((alternative) => translateGlobText(alternative, true, follower));
|
|
37023
|
+
const anyAbsorbed = parts.some((part) => part.absorbed);
|
|
37024
|
+
const body = parts.map((part) => anyAbsorbed && !part.absorbed ? `${part.regex}\\/` : part.regex).join("|");
|
|
37025
|
+
return { regex: `(?:${body})`, absorbed: anyAbsorbed };
|
|
37026
|
+
}
|
|
37027
|
+
function translateGlobText(text, expandBraces, follower = "") {
|
|
36903
37028
|
let regex = "";
|
|
36904
37029
|
let i = 0;
|
|
36905
|
-
|
|
36906
|
-
|
|
36907
|
-
|
|
36908
|
-
|
|
36909
|
-
|
|
36910
|
-
|
|
36911
|
-
|
|
36912
|
-
|
|
36913
|
-
|
|
36914
|
-
|
|
36915
|
-
|
|
36916
|
-
i += 3;
|
|
37030
|
+
let absorbed = false;
|
|
37031
|
+
while (i < text.length) {
|
|
37032
|
+
const c = text[i];
|
|
37033
|
+
if (c === "{" && expandBraces) {
|
|
37034
|
+
const end = findBraceGroupEnd(text, i);
|
|
37035
|
+
if (end !== -1) {
|
|
37036
|
+
const rest = text.slice(end + 1);
|
|
37037
|
+
const group = translateBraceGroup(text.slice(i + 1, end), rest + follower);
|
|
37038
|
+
regex += group.regex;
|
|
37039
|
+
if (group.absorbed && rest.length > 0) {
|
|
37040
|
+
i = end + 2;
|
|
36917
37041
|
} else {
|
|
36918
|
-
|
|
36919
|
-
i
|
|
37042
|
+
absorbed = absorbed || group.absorbed;
|
|
37043
|
+
i = end + 1;
|
|
36920
37044
|
}
|
|
36921
37045
|
continue;
|
|
36922
37046
|
}
|
|
36923
|
-
|
|
36924
|
-
|
|
37047
|
+
}
|
|
37048
|
+
if (c === "*") {
|
|
37049
|
+
const star = translateStars(text, i, follower);
|
|
37050
|
+
regex += star.regex;
|
|
37051
|
+
absorbed = absorbed || star.absorbed;
|
|
37052
|
+
i = star.next;
|
|
36925
37053
|
continue;
|
|
36926
37054
|
}
|
|
36927
37055
|
if (c === "?") {
|
|
@@ -36929,14 +37057,16 @@ function globToRegex2(pattern) {
|
|
|
36929
37057
|
i++;
|
|
36930
37058
|
continue;
|
|
36931
37059
|
}
|
|
36932
|
-
|
|
36933
|
-
regex += `\\${c}`;
|
|
36934
|
-
} else {
|
|
36935
|
-
regex += c;
|
|
36936
|
-
}
|
|
37060
|
+
regex += REGEX_META_CHARS.includes(c) ? `\\${c}` : c;
|
|
36937
37061
|
i++;
|
|
36938
37062
|
}
|
|
36939
|
-
|
|
37063
|
+
return { regex, absorbed };
|
|
37064
|
+
}
|
|
37065
|
+
function globToRegex2(pattern) {
|
|
37066
|
+
const cached = GLOB_REGEX_CACHE.get(pattern);
|
|
37067
|
+
if (cached !== undefined)
|
|
37068
|
+
return cached;
|
|
37069
|
+
const compiled = new RegExp(`(?:^|/)${translateGlobText(pattern, bracesBalanced(pattern)).regex}$`);
|
|
36940
37070
|
if (GLOB_REGEX_CACHE.size < MAX_GLOB_REGEX_CACHE_ENTRIES) {
|
|
36941
37071
|
GLOB_REGEX_CACHE.set(pattern, compiled);
|
|
36942
37072
|
}
|
|
@@ -36973,7 +37103,7 @@ function ruleMatchesPackage(paths, repoRoot, packageDir, storyWorkdir) {
|
|
|
36973
37103
|
const patterns = paths.map((p) => globToRegex2(normalizePath2(p)));
|
|
36974
37104
|
return patterns.some((pattern) => pattern.test(rel) || pattern.test(`${rel}/`));
|
|
36975
37105
|
}
|
|
36976
|
-
var SCOPE_GLOB_META, MAX_GLOB_REGEX_CACHE_ENTRIES = 1024, GLOB_REGEX_CACHE;
|
|
37106
|
+
var SCOPE_GLOB_META, MAX_GLOB_REGEX_CACHE_ENTRIES = 1024, GLOB_REGEX_CACHE, REGEX_META_CHARS = `.+^\${}()|[]\\`, GLOBSTAR_DIR = "(?:.*\\/)?";
|
|
36977
37107
|
var init_scope_path_match = __esm(() => {
|
|
36978
37108
|
init_path_frame();
|
|
36979
37109
|
SCOPE_GLOB_META = /[*?[{]/;
|
|
@@ -37603,12 +37733,10 @@ async function parseVitestConfig(workdir) {
|
|
|
37603
37733
|
const text = await _frameworkConfigDeps.readText(path);
|
|
37604
37734
|
if (!text)
|
|
37605
37735
|
continue;
|
|
37606
|
-
const
|
|
37607
|
-
|
|
37608
|
-
|
|
37609
|
-
|
|
37610
|
-
return { type: "framework-config", framework: "vitest", path, patterns: normalize2(patterns) };
|
|
37611
|
-
}
|
|
37736
|
+
const testBlock = extractBalancedBlock(text, TEST_BLOCK_ANCHOR);
|
|
37737
|
+
const patterns = testBlock ? extractTopLevelInclude(testBlock) : null;
|
|
37738
|
+
if (patterns && patterns.length > 0) {
|
|
37739
|
+
return { type: "framework-config", framework: "vitest", path, patterns: normalize2(patterns) };
|
|
37612
37740
|
}
|
|
37613
37741
|
return { type: "framework-config", framework: "vitest", path, patterns: [] };
|
|
37614
37742
|
}
|
|
@@ -37758,17 +37886,12 @@ async function parseViteConfig(workdir) {
|
|
|
37758
37886
|
const text = await _frameworkConfigDeps.readText(path);
|
|
37759
37887
|
if (!text)
|
|
37760
37888
|
continue;
|
|
37761
|
-
if (
|
|
37889
|
+
if (!TEST_BLOCK_ANCHOR.test(text))
|
|
37762
37890
|
continue;
|
|
37763
|
-
const testBlock = extractBalancedBlock(text,
|
|
37764
|
-
|
|
37765
|
-
|
|
37766
|
-
|
|
37767
|
-
const patterns = extractStringLiterals(includeMatch[1]);
|
|
37768
|
-
if (patterns.length > 0) {
|
|
37769
|
-
return { type: "framework-config", framework: "vitest", path, patterns: normalize2(patterns) };
|
|
37770
|
-
}
|
|
37771
|
-
}
|
|
37891
|
+
const testBlock = extractBalancedBlock(text, TEST_BLOCK_ANCHOR);
|
|
37892
|
+
const patterns = testBlock ? extractTopLevelInclude(testBlock) : null;
|
|
37893
|
+
if (patterns && patterns.length > 0) {
|
|
37894
|
+
return { type: "framework-config", framework: "vitest", path, patterns: normalize2(patterns) };
|
|
37772
37895
|
}
|
|
37773
37896
|
return { type: "framework-config", framework: "vitest", path, patterns: [] };
|
|
37774
37897
|
}
|
|
@@ -37818,6 +37941,27 @@ function extractBalancedBlock(text, anchor) {
|
|
|
37818
37941
|
}
|
|
37819
37942
|
return null;
|
|
37820
37943
|
}
|
|
37944
|
+
function extractTopLevelInclude(block) {
|
|
37945
|
+
const keyRe = /\binclude\b\s*:/g;
|
|
37946
|
+
let depth = 0;
|
|
37947
|
+
let scanned = 0;
|
|
37948
|
+
for (const match of block.matchAll(keyRe)) {
|
|
37949
|
+
for (let i = scanned;i < match.index; i++) {
|
|
37950
|
+
if (block[i] === "{")
|
|
37951
|
+
depth++;
|
|
37952
|
+
else if (block[i] === "}")
|
|
37953
|
+
depth--;
|
|
37954
|
+
}
|
|
37955
|
+
scanned = match.index + match[0].length;
|
|
37956
|
+
if (depth !== 0)
|
|
37957
|
+
continue;
|
|
37958
|
+
const array = block.slice(match.index + match[0].length).match(/^\s*\[([^\]]*)\]/);
|
|
37959
|
+
if (!array)
|
|
37960
|
+
continue;
|
|
37961
|
+
return extractStringLiterals(array[1]);
|
|
37962
|
+
}
|
|
37963
|
+
return null;
|
|
37964
|
+
}
|
|
37821
37965
|
async function detectFromFrameworkConfigs(workdir) {
|
|
37822
37966
|
const results = await Promise.all([
|
|
37823
37967
|
parseVitestConfig(workdir),
|
|
@@ -37832,13 +37976,14 @@ async function detectFromFrameworkConfigs(workdir) {
|
|
|
37832
37976
|
]);
|
|
37833
37977
|
return results.filter((r) => r !== null);
|
|
37834
37978
|
}
|
|
37835
|
-
var EXCLUDE_DIRS2;
|
|
37979
|
+
var EXCLUDE_DIRS2, TEST_BLOCK_ANCHOR;
|
|
37836
37980
|
var init_framework_configs = __esm(() => {
|
|
37837
37981
|
init_extglob();
|
|
37838
37982
|
init_framework_configs_deps();
|
|
37839
37983
|
init_framework_configs_python();
|
|
37840
37984
|
init_framework_configs_deps();
|
|
37841
37985
|
EXCLUDE_DIRS2 = ["node_modules", "dist", "build", ".nax", "coverage", ".git"];
|
|
37986
|
+
TEST_BLOCK_ANCHOR = /\btest\s*:\s*\{/;
|
|
37842
37987
|
});
|
|
37843
37988
|
|
|
37844
37989
|
// src/test-runners/detect/framework-defaults.ts
|
|
@@ -38857,20 +39002,18 @@ async function importGrepFallback(sourceFiles, workdir, testFilePatterns, maxSca
|
|
|
38857
39002
|
if (sourceFiles.length === 0 || testFilePatterns.length === 0)
|
|
38858
39003
|
return [];
|
|
38859
39004
|
const searchTerms = sourceFiles.flatMap(extractSearchTerms);
|
|
39005
|
+
const cap = maxScanFiles;
|
|
38860
39006
|
const testFilePaths = [];
|
|
38861
|
-
|
|
38862
|
-
|
|
38863
|
-
|
|
38864
|
-
|
|
38865
|
-
|
|
38866
|
-
|
|
38867
|
-
|
|
38868
|
-
cap: maxScanFiles
|
|
38869
|
-
});
|
|
38870
|
-
break outer;
|
|
38871
|
-
}
|
|
39007
|
+
for (const pattern of testFilePatterns) {
|
|
39008
|
+
const g = _bunDeps.glob(pattern);
|
|
39009
|
+
for await (const file of g.scan({ cwd: workdir, absolute: false })) {
|
|
39010
|
+
testFilePaths.push(`${workdir}/${file}`);
|
|
39011
|
+
if (testFilePaths.length > cap) {
|
|
39012
|
+
getSafeLogger2()?.warn("smart-runner", `import-grep over cap ${cap} \u2014 escalating to full suite`, { cap });
|
|
39013
|
+
return [];
|
|
38872
39014
|
}
|
|
38873
39015
|
}
|
|
39016
|
+
}
|
|
38874
39017
|
const results = await Promise.all(testFilePaths.map(async (testFile) => {
|
|
38875
39018
|
try {
|
|
38876
39019
|
const content = await _bunDeps.file(testFile).text();
|
|
@@ -42576,6 +42719,17 @@ var init_schema2 = __esm(() => {
|
|
|
42576
42719
|
|
|
42577
42720
|
// src/prd/index.ts
|
|
42578
42721
|
import { existsSync as existsSync9, statSync as statSync7 } from "fs";
|
|
42722
|
+
function assertObjectStories(stories, path) {
|
|
42723
|
+
for (const [index, story] of stories.entries()) {
|
|
42724
|
+
if (story === null || typeof story !== "object" || Array.isArray(story)) {
|
|
42725
|
+
throw new NaxError(`PRD file has a non-object story at userStories[${index}]: ${path}`, "PRD_INVALID", {
|
|
42726
|
+
stage: "prd",
|
|
42727
|
+
path,
|
|
42728
|
+
index
|
|
42729
|
+
});
|
|
42730
|
+
}
|
|
42731
|
+
}
|
|
42732
|
+
}
|
|
42579
42733
|
async function loadPRD(path) {
|
|
42580
42734
|
if (!existsSync9(path)) {
|
|
42581
42735
|
throw new NaxError(`PRD file not found: ${path}`, "PRD_NOT_FOUND", { stage: "prd", path });
|
|
@@ -42598,6 +42752,7 @@ async function loadPRD(path) {
|
|
|
42598
42752
|
path
|
|
42599
42753
|
});
|
|
42600
42754
|
}
|
|
42755
|
+
assertObjectStories(prd.userStories, path);
|
|
42601
42756
|
for (const story of prd.userStories) {
|
|
42602
42757
|
story.attempts = story.attempts ?? 0;
|
|
42603
42758
|
story.priorErrors = story.priorErrors ?? [];
|
|
@@ -43561,11 +43716,16 @@ function formatCheckErrors(checks, opts) {
|
|
|
43561
43716
|
|
|
43562
43717
|
`);
|
|
43563
43718
|
}
|
|
43564
|
-
function
|
|
43719
|
+
function capTail(value, maxChars) {
|
|
43565
43720
|
if (value.length <= maxChars)
|
|
43566
43721
|
return value;
|
|
43567
|
-
|
|
43568
|
-
|
|
43722
|
+
let kept = value.slice(Math.max(0, value.length - Math.max(0, maxChars)));
|
|
43723
|
+
const newline = kept.indexOf(`
|
|
43724
|
+
`);
|
|
43725
|
+
if (newline >= 0 && newline < kept.length - 1)
|
|
43726
|
+
kept = kept.slice(newline + 1);
|
|
43727
|
+
return `... (truncated \u2014 ${value.length} chars total; showing the last ${kept.length})
|
|
43728
|
+
${kept}`;
|
|
43569
43729
|
}
|
|
43570
43730
|
function formatFindingLine(finding) {
|
|
43571
43731
|
const location = typeof finding.line === "number" ? `${finding.file}:${finding.line}` : finding.file;
|
|
@@ -43587,13 +43747,13 @@ function formatCheckError(check, opts) {
|
|
|
43587
43747
|
lines.push("");
|
|
43588
43748
|
lines.push("Raw output excerpt:");
|
|
43589
43749
|
lines.push("```");
|
|
43590
|
-
lines.push(
|
|
43750
|
+
lines.push(capTail(check.output, RAW_WITH_FINDINGS_LIMIT));
|
|
43591
43751
|
lines.push("```");
|
|
43592
43752
|
return lines.join(`
|
|
43593
43753
|
`);
|
|
43594
43754
|
}
|
|
43595
43755
|
lines.push("```");
|
|
43596
|
-
lines.push(
|
|
43756
|
+
lines.push(capTail(check.output, RAW_FALLBACK_LIMIT));
|
|
43597
43757
|
lines.push("```");
|
|
43598
43758
|
return lines.join(`
|
|
43599
43759
|
`);
|
|
@@ -43885,9 +44045,7 @@ function assertNever(value) {
|
|
|
43885
44045
|
}
|
|
43886
44046
|
function renderCheckBlock(check, opts) {
|
|
43887
44047
|
const parts = [];
|
|
43888
|
-
const
|
|
43889
|
-
const output = truncated ? `${check.output.slice(0, 4000)}
|
|
43890
|
-
... (truncated \u2014 ${check.output.length} chars total)` : check.output;
|
|
44048
|
+
const output = capTail(check.output, 4000);
|
|
43891
44049
|
parts.push(`### ${check.check} (exit ${check.exitCode})
|
|
43892
44050
|
`, `\`\`\`
|
|
43893
44051
|
${output}
|
|
@@ -44095,9 +44253,7 @@ Commit your fixes when done.${scopeConstraint}`;
|
|
|
44095
44253
|
for (const check of failedChecks) {
|
|
44096
44254
|
parts.push(`### ${check.check} (exit ${check.exitCode})
|
|
44097
44255
|
`);
|
|
44098
|
-
const
|
|
44099
|
-
const output = truncated ? `${check.output.slice(0, 4000)}
|
|
44100
|
-
... (truncated \u2014 ${check.output.length} chars total)` : check.output;
|
|
44256
|
+
const output = capTail(check.output, 4000);
|
|
44101
44257
|
parts.push(`\`\`\`
|
|
44102
44258
|
${output}
|
|
44103
44259
|
\`\`\`
|
|
@@ -48755,7 +48911,7 @@ class SessionManager {
|
|
|
48755
48911
|
const reuse = decideReuse(liveHandle, this._findByName(name), opts);
|
|
48756
48912
|
if (liveHandle && reuse === "reuse")
|
|
48757
48913
|
return liveHandle;
|
|
48758
|
-
if (liveHandle && reuse
|
|
48914
|
+
if (liveHandle && (reuse !== "reopen" || this._cancelledSessions.has(name)))
|
|
48759
48915
|
await this.closeSession(liveHandle, true);
|
|
48760
48916
|
else if (liveHandle)
|
|
48761
48917
|
this._liveHandles.delete(name);
|
|
@@ -49084,7 +49240,7 @@ var init_session2 = __esm(() => {
|
|
|
49084
49240
|
var DEFAULT_MAX_TOKENS_PER_CALL = 2048;
|
|
49085
49241
|
|
|
49086
49242
|
// src/context/fragments/store.ts
|
|
49087
|
-
import { mkdir as mkdir23, rm as rm10, stat as
|
|
49243
|
+
import { mkdir as mkdir23, rm as rm10, stat as stat11 } from "fs/promises";
|
|
49088
49244
|
import { dirname as dirname21, join as join59 } from "path";
|
|
49089
49245
|
function fragmentPath(projectDir, featureId, storyId) {
|
|
49090
49246
|
validatePathSegment(storyId, "storyId");
|
|
@@ -49183,7 +49339,7 @@ var init_store3 = __esm(() => {
|
|
|
49183
49339
|
fileExists: (path) => Bun.file(path).exists(),
|
|
49184
49340
|
directoryExists: async (path) => {
|
|
49185
49341
|
try {
|
|
49186
|
-
return (await
|
|
49342
|
+
return (await stat11(path)).isDirectory();
|
|
49187
49343
|
} catch {
|
|
49188
49344
|
return false;
|
|
49189
49345
|
}
|
|
@@ -53078,7 +53234,7 @@ var package_default;
|
|
|
53078
53234
|
var init_package = __esm(() => {
|
|
53079
53235
|
package_default = {
|
|
53080
53236
|
name: "@nathapp/nax",
|
|
53081
|
-
version: "0.91.8-canary.
|
|
53237
|
+
version: "0.91.8-canary.7",
|
|
53082
53238
|
description: "AI Coding Agent Orchestrator \u2014 loops until done",
|
|
53083
53239
|
type: "module",
|
|
53084
53240
|
bin: {
|
|
@@ -53164,7 +53320,7 @@ var init_package = __esm(() => {
|
|
|
53164
53320
|
"@agentclientprotocol/sdk": "~1.7.0",
|
|
53165
53321
|
"@anthropic-ai/sandbox-runtime": "0.0.77",
|
|
53166
53322
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
53167
|
-
"@nathapp/nax-ai": "0.91.8-canary.
|
|
53323
|
+
"@nathapp/nax-ai": "0.91.8-canary.7",
|
|
53168
53324
|
chalk: "^5.6.2",
|
|
53169
53325
|
commander: "^13.1.0",
|
|
53170
53326
|
"highlight.js": "^11.12.0",
|
|
@@ -60626,7 +60782,7 @@ var init_cursor_sandbox = __esm(() => {
|
|
|
60626
60782
|
});
|
|
60627
60783
|
|
|
60628
60784
|
// ../nax-agent-acp/src/client/opencode-sandbox.ts
|
|
60629
|
-
import { readFile as readFile11, stat as
|
|
60785
|
+
import { readFile as readFile11, stat as stat12 } from "fs/promises";
|
|
60630
60786
|
import { dirname as dirname29, join as join74 } from "path";
|
|
60631
60787
|
function opencodeSandboxPluginSource(prefix) {
|
|
60632
60788
|
return `${sandboxWrapSnippet(prefix)}
|
|
@@ -60715,7 +60871,7 @@ var init_opencode_sandbox = __esm(() => {
|
|
|
60715
60871
|
init_errors6();
|
|
60716
60872
|
init_policy_files();
|
|
60717
60873
|
init_shell_sandbox();
|
|
60718
|
-
_opencodeSandboxDeps = { readFile: readFile11, stat:
|
|
60874
|
+
_opencodeSandboxDeps = { readFile: readFile11, stat: stat12 };
|
|
60719
60875
|
});
|
|
60720
60876
|
|
|
60721
60877
|
// ../nax-agent-acp/src/client/shell-rules.ts
|
|
@@ -61400,14 +61556,14 @@ function race(promise, opts) {
|
|
|
61400
61556
|
|
|
61401
61557
|
// ../nax-agent-acp/src/client/launch.ts
|
|
61402
61558
|
import { spawn as spawn4 } from "child_process";
|
|
61403
|
-
import { accessSync as accessSync3, constants as
|
|
61559
|
+
import { accessSync as accessSync3, constants as constants8, statSync as statSync11 } from "fs";
|
|
61404
61560
|
import { delimiter as delimiter2, isAbsolute as isAbsolute23, join as join75 } from "path";
|
|
61405
61561
|
import { Readable as Readable2, Writable } from "stream";
|
|
61406
61562
|
function isExecutableFile2(path) {
|
|
61407
61563
|
try {
|
|
61408
61564
|
if (!statSync11(path).isFile())
|
|
61409
61565
|
return false;
|
|
61410
|
-
accessSync3(path,
|
|
61566
|
+
accessSync3(path, constants8.X_OK);
|
|
61411
61567
|
return true;
|
|
61412
61568
|
} catch {
|
|
61413
61569
|
return false;
|
|
@@ -71913,7 +72069,7 @@ var init_websocket = () => {};
|
|
|
71913
72069
|
|
|
71914
72070
|
// ../../node_modules/.bun/@hono+node-server@2.1.3+e7800e0fd2b1569d/node_modules/@hono/node-server/dist/index.mjs
|
|
71915
72071
|
import { STATUS_CODES, ServerResponse, createServer } from "http";
|
|
71916
|
-
import { Http2ServerRequest, constants as
|
|
72072
|
+
import { Http2ServerRequest, constants as constants9 } from "http2";
|
|
71917
72073
|
import { Readable as Readable3 } from "stream";
|
|
71918
72074
|
async function readWithoutBlocking(readPromise) {
|
|
71919
72075
|
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(undefined))]);
|
|
@@ -72328,7 +72484,7 @@ var RequestError2, nonJoinedHeaders, validHeaderName, isHttpWhitespace = (code)
|
|
|
72328
72484
|
incomingWithDrainState[incomingDraining] = true;
|
|
72329
72485
|
if (incoming instanceof Http2ServerRequest) {
|
|
72330
72486
|
try {
|
|
72331
|
-
incoming.stream?.close?.(
|
|
72487
|
+
incoming.stream?.close?.(constants9.NGHTTP2_NO_ERROR);
|
|
72332
72488
|
} catch {}
|
|
72333
72489
|
return;
|
|
72334
72490
|
}
|
|
@@ -75176,7 +75332,7 @@ var init_turn_slot = __esm(() => {
|
|
|
75176
75332
|
});
|
|
75177
75333
|
|
|
75178
75334
|
// src/agents/acp/session.ts
|
|
75179
|
-
import { stat as
|
|
75335
|
+
import { stat as stat13 } from "fs/promises";
|
|
75180
75336
|
function errorText(err) {
|
|
75181
75337
|
return err instanceof Error ? err.message : String(err);
|
|
75182
75338
|
}
|
|
@@ -75402,7 +75558,7 @@ var init_session3 = __esm(() => {
|
|
|
75402
75558
|
delay: (ms, signal) => cancellableDelay(ms, signal),
|
|
75403
75559
|
async cwdExists(dir) {
|
|
75404
75560
|
try {
|
|
75405
|
-
return (await
|
|
75561
|
+
return (await stat13(dir)).isDirectory();
|
|
75406
75562
|
} catch {
|
|
75407
75563
|
return false;
|
|
75408
75564
|
}
|
|
@@ -75699,6 +75855,8 @@ async function runLoop(loop) {
|
|
|
75699
75855
|
break;
|
|
75700
75856
|
}
|
|
75701
75857
|
state.output = outcome.output;
|
|
75858
|
+
if (used(state) >= loop.max)
|
|
75859
|
+
break;
|
|
75702
75860
|
const next = await nextPrompt(loop, outcome.output);
|
|
75703
75861
|
if (next === undefined)
|
|
75704
75862
|
break;
|
|
@@ -78398,7 +78556,7 @@ var init_registry7 = __esm(() => {
|
|
|
78398
78556
|
|
|
78399
78557
|
// src/trust/store.ts
|
|
78400
78558
|
import { randomUUID as randomUUID20 } from "crypto";
|
|
78401
|
-
import { mkdir as mkdir27, rename as rename9, stat as
|
|
78559
|
+
import { mkdir as mkdir27, rename as rename9, stat as stat14, unlink as unlink5, writeFile as writeFile10 } from "fs/promises";
|
|
78402
78560
|
import { dirname as dirname31, isAbsolute as isAbsolute25, join as join79 } from "path";
|
|
78403
78561
|
function trustStorePath() {
|
|
78404
78562
|
return join79(globalConfigDir(), "trust.json");
|
|
@@ -78481,7 +78639,7 @@ async function writeTrustStore(storePath, file) {
|
|
|
78481
78639
|
}
|
|
78482
78640
|
async function directoryExists2(dir) {
|
|
78483
78641
|
try {
|
|
78484
|
-
return (await
|
|
78642
|
+
return (await stat14(dir)).isDirectory();
|
|
78485
78643
|
} catch {
|
|
78486
78644
|
return false;
|
|
78487
78645
|
}
|
|
@@ -80072,19 +80230,42 @@ ${r.output}`).join(""),
|
|
|
80072
80230
|
|
|
80073
80231
|
// src/quality/runner.ts
|
|
80074
80232
|
var {spawn: spawn5 } = globalThis.Bun;
|
|
80075
|
-
function
|
|
80233
|
+
function collectStream2(stream) {
|
|
80234
|
+
const reader = stream.getReader();
|
|
80235
|
+
const decoder = new TextDecoder;
|
|
80236
|
+
let output = "";
|
|
80237
|
+
const done = (async () => {
|
|
80238
|
+
try {
|
|
80239
|
+
while (true) {
|
|
80240
|
+
const next = await reader.read();
|
|
80241
|
+
if (next.done)
|
|
80242
|
+
break;
|
|
80243
|
+
output += decoder.decode(next.value, { stream: true });
|
|
80244
|
+
}
|
|
80245
|
+
output += decoder.decode();
|
|
80246
|
+
} catch {}
|
|
80247
|
+
})();
|
|
80248
|
+
return { done, text: () => output, cancel: () => reader.cancel() };
|
|
80249
|
+
}
|
|
80250
|
+
async function drainStream(collector) {
|
|
80076
80251
|
let timeoutId;
|
|
80077
|
-
const
|
|
80078
|
-
timeoutId = setTimeout(() => resolve(
|
|
80252
|
+
const deadline = new Promise((resolve) => {
|
|
80253
|
+
timeoutId = _qualityRunnerDeps.setTimeout(() => resolve(true), STREAM_DRAIN_TIMEOUT_MS);
|
|
80079
80254
|
});
|
|
80080
|
-
|
|
80081
|
-
|
|
80082
|
-
|
|
80083
|
-
|
|
80084
|
-
|
|
80085
|
-
|
|
80086
|
-
|
|
80087
|
-
|
|
80255
|
+
const timedOut = await Promise.race([collector.done.then(() => false), deadline]);
|
|
80256
|
+
if (timeoutId !== undefined)
|
|
80257
|
+
_qualityRunnerDeps.clearTimeout(timeoutId);
|
|
80258
|
+
if (timedOut) {
|
|
80259
|
+
collector.cancel().catch(() => {});
|
|
80260
|
+
}
|
|
80261
|
+
return { output: collector.text(), timedOut };
|
|
80262
|
+
}
|
|
80263
|
+
async function drainOutputStreams(opts) {
|
|
80264
|
+
const [stdout, stderr] = await Promise.all([drainStream(opts.stdout), drainStream(opts.stderr)]);
|
|
80265
|
+
if (!opts.timedOut && (stdout.timedOut || stderr.timedOut)) {
|
|
80266
|
+
_qualityRunnerDeps.killProcessGroup(opts.pid, "SIGTERM", { singleProcessFallback: false });
|
|
80267
|
+
}
|
|
80268
|
+
return [stdout.output, stderr.output];
|
|
80088
80269
|
}
|
|
80089
80270
|
function timedOutOutput(commandName, timeoutMs, partial) {
|
|
80090
80271
|
const notice = `[nax] ${commandName} timed out after ${timeoutMs / 1000}s`;
|
|
@@ -80157,23 +80338,20 @@ async function runSingleCommand(opts) {
|
|
|
80157
80338
|
}, SIGKILL_GRACE_PERIOD_MS);
|
|
80158
80339
|
});
|
|
80159
80340
|
}, timeoutMs);
|
|
80160
|
-
const
|
|
80161
|
-
const
|
|
80341
|
+
const stdoutCollector = collectStream2(proc.stdout);
|
|
80342
|
+
const stderrCollector = collectStream2(proc.stderr);
|
|
80162
80343
|
const exitCode = await proc.exited;
|
|
80163
|
-
|
|
80164
|
-
|
|
80165
|
-
|
|
80166
|
-
|
|
80167
|
-
|
|
80168
|
-
|
|
80169
|
-
|
|
80170
|
-
|
|
80171
|
-
|
|
80172
|
-
|
|
80173
|
-
|
|
80174
|
-
}
|
|
80175
|
-
})() : await Promise.all([stdoutPromise, stderrPromise]);
|
|
80176
|
-
_qualityRunnerDeps.clearTimeout(killTimer);
|
|
80344
|
+
leaderExited = true;
|
|
80345
|
+
if (!timedOut)
|
|
80346
|
+
_qualityRunnerDeps.clearTimeout(killTimer);
|
|
80347
|
+
const [stdout, stderr] = await drainOutputStreams({
|
|
80348
|
+
stdout: stdoutCollector,
|
|
80349
|
+
stderr: stderrCollector,
|
|
80350
|
+
pid: proc.pid,
|
|
80351
|
+
timedOut
|
|
80352
|
+
});
|
|
80353
|
+
if (timedOut)
|
|
80354
|
+
_qualityRunnerDeps.clearTimeout(killTimer);
|
|
80177
80355
|
if (sigkillTimer !== undefined) {
|
|
80178
80356
|
const membersLeft = !sigkillFired && _qualityRunnerDeps.killProcessGroup(proc.pid, 0, { singleProcessFallback: false });
|
|
80179
80357
|
if (membersLeft)
|
|
@@ -80367,7 +80545,21 @@ function createPackageRegistry(loader, repoRoot) {
|
|
|
80367
80545
|
cache.set(key, view);
|
|
80368
80546
|
return view;
|
|
80369
80547
|
}
|
|
80548
|
+
async function hydratePackage(dir, loadOverride) {
|
|
80549
|
+
const rootConfig = loader.current();
|
|
80550
|
+
const resolved = await resolvePackageOverride({ repoRoot, packageDir: dir, rootConfig, loadOverride });
|
|
80551
|
+
if (resolved === null)
|
|
80552
|
+
return;
|
|
80553
|
+
overlays.set(dir, resolved.overlay);
|
|
80554
|
+
const merged = pinRootOnlyKeys(resolved.config, rootConfig);
|
|
80555
|
+
mergedConfigs.set(dir, applyWorkflowMode(merged));
|
|
80556
|
+
for (const key of cache.keys()) {
|
|
80557
|
+
if (toOverrideKey(key) === dir)
|
|
80558
|
+
cache.delete(key);
|
|
80559
|
+
}
|
|
80560
|
+
}
|
|
80370
80561
|
async function hydrate(packageDirs, loadOverride) {
|
|
80562
|
+
let firstError = null;
|
|
80371
80563
|
for (const dir of packageDirs) {
|
|
80372
80564
|
if (!dir) {
|
|
80373
80565
|
continue;
|
|
@@ -80376,19 +80568,22 @@ function createPackageRegistry(loader, repoRoot) {
|
|
|
80376
80568
|
if (mergedConfigs.has(dir)) {
|
|
80377
80569
|
continue;
|
|
80378
80570
|
}
|
|
80379
|
-
|
|
80380
|
-
|
|
80381
|
-
|
|
80382
|
-
|
|
80383
|
-
|
|
80384
|
-
|
|
80385
|
-
for (const key of cache.keys()) {
|
|
80386
|
-
if (toOverrideKey(key) === dir)
|
|
80387
|
-
cache.delete(key);
|
|
80571
|
+
try {
|
|
80572
|
+
await hydratePackage(dir, loadOverride);
|
|
80573
|
+
} catch (err) {
|
|
80574
|
+
if (firstError === null) {
|
|
80575
|
+
firstError = err;
|
|
80576
|
+
continue;
|
|
80388
80577
|
}
|
|
80578
|
+
_packagesDeps.getSafeLogger()?.warn("packages", "Per-package config hydration failed \u2014 using root config", {
|
|
80579
|
+
packageDir: dir,
|
|
80580
|
+
error: errorMessage(err)
|
|
80581
|
+
});
|
|
80389
80582
|
}
|
|
80390
80583
|
}
|
|
80391
80584
|
hydrated = true;
|
|
80585
|
+
if (firstError !== null)
|
|
80586
|
+
throw firstError;
|
|
80392
80587
|
}
|
|
80393
80588
|
return {
|
|
80394
80589
|
all() {
|
|
@@ -80414,6 +80609,7 @@ function storyExecRoot(view) {
|
|
|
80414
80609
|
}
|
|
80415
80610
|
var _packagesDeps;
|
|
80416
80611
|
var init_packages = __esm(() => {
|
|
80612
|
+
init_internal();
|
|
80417
80613
|
init_config();
|
|
80418
80614
|
init_logger2();
|
|
80419
80615
|
_packagesDeps = { getSafeLogger: getSafeLogger2 };
|
|
@@ -84908,8 +85104,8 @@ var init_version = __esm(() => {
|
|
|
84908
85104
|
NAX_AI_VERSION = CATALOG_VERSION;
|
|
84909
85105
|
NAX_COMMIT = (() => {
|
|
84910
85106
|
try {
|
|
84911
|
-
if (/^[0-9a-f]{6,10}$/.test("
|
|
84912
|
-
return "
|
|
85107
|
+
if (/^[0-9a-f]{6,10}$/.test("0b2d3d4"))
|
|
85108
|
+
return "0b2d3d4";
|
|
84913
85109
|
} catch {}
|
|
84914
85110
|
try {
|
|
84915
85111
|
const result = Bun.spawnSync(["git", "rev-parse", "--short", "HEAD"], {
|
|
@@ -87249,7 +87445,7 @@ class PidRegistry {
|
|
|
87249
87445
|
});
|
|
87250
87446
|
return;
|
|
87251
87447
|
}
|
|
87252
|
-
if (current.
|
|
87448
|
+
if (current.startedAt !== proc.startedAt) {
|
|
87253
87449
|
getSafeLogger2()?.warn("pid-registry", `Skipping SIG${signal} for PID ${proc.pid} after identity changed`, {
|
|
87254
87450
|
pid: proc.pid,
|
|
87255
87451
|
signal,
|
|
@@ -91312,7 +91508,7 @@ var init_parse_skill = __esm(() => {
|
|
|
91312
91508
|
});
|
|
91313
91509
|
|
|
91314
91510
|
// src/resources/scan-dirs.ts
|
|
91315
|
-
import { stat as
|
|
91511
|
+
import { stat as stat15 } from "fs/promises";
|
|
91316
91512
|
import { join as join98 } from "path";
|
|
91317
91513
|
function scanAgentsDir(dir, origin) {
|
|
91318
91514
|
return scanDir({ dir, origin, pattern: "*.md", parse: parseAgentFile });
|
|
@@ -91366,7 +91562,7 @@ var init_scan_dirs = __esm(() => {
|
|
|
91366
91562
|
init_parse_skill();
|
|
91367
91563
|
_resourceFsDeps = {
|
|
91368
91564
|
async isDirectory(path) {
|
|
91369
|
-
return (await
|
|
91565
|
+
return (await stat15(path)).isDirectory();
|
|
91370
91566
|
},
|
|
91371
91567
|
async listFiles(dir, pattern) {
|
|
91372
91568
|
return Array.fromAsync(new Bun.Glob(pattern).scan({ cwd: dir, onlyFiles: true, dot: false }));
|
|
@@ -92006,7 +92202,7 @@ var init_nax_plugin_packages = __esm(() => {
|
|
|
92006
92202
|
});
|
|
92007
92203
|
|
|
92008
92204
|
// src/resources/skills-provider.ts
|
|
92009
|
-
import { realpath as realpath6, stat as
|
|
92205
|
+
import { realpath as realpath6, stat as stat16 } from "fs/promises";
|
|
92010
92206
|
import { isAbsolute as isAbsolute29, join as join100, relative as relative28, sep as sep19 } from "path";
|
|
92011
92207
|
function failure5(content) {
|
|
92012
92208
|
return { content, isError: true };
|
|
@@ -92094,7 +92290,7 @@ var init_skills_provider = __esm(() => {
|
|
|
92094
92290
|
init_internal();
|
|
92095
92291
|
_skillsProviderDeps = {
|
|
92096
92292
|
realpath: realpath6,
|
|
92097
|
-
stat:
|
|
92293
|
+
stat: stat16,
|
|
92098
92294
|
async readFile(path) {
|
|
92099
92295
|
return new Uint8Array(await Bun.file(path).slice(0, MAX_SKILL_FILE_BYTES + 1).arrayBuffer());
|
|
92100
92296
|
}
|
|
@@ -96954,7 +97150,7 @@ var init_paths4 = __esm(() => {
|
|
|
96954
97150
|
});
|
|
96955
97151
|
|
|
96956
97152
|
// src/memory/repo-notes.ts
|
|
96957
|
-
import { constants as
|
|
97153
|
+
import { constants as constants10 } from "fs";
|
|
96958
97154
|
import { lstat as lstat7, open as open8, readdir as readdir9 } from "fs/promises";
|
|
96959
97155
|
import { join as join114 } from "path";
|
|
96960
97156
|
function unsafeCandidate(path, problem) {
|
|
@@ -97141,7 +97337,7 @@ var init_repo_notes = __esm(() => {
|
|
|
97141
97337
|
init_internal();
|
|
97142
97338
|
init_config();
|
|
97143
97339
|
init_errors4();
|
|
97144
|
-
READ_FLAGS3 =
|
|
97340
|
+
READ_FLAGS3 = constants10.O_RDONLY | (constants10.O_NOFOLLOW ?? 0) | constants10.O_NONBLOCK;
|
|
97145
97341
|
_repoNotesDeps = {
|
|
97146
97342
|
lstat: (path) => lstat7(path),
|
|
97147
97343
|
readdir: (path) => readdir9(path),
|
|
@@ -100640,6 +100836,9 @@ class WebhookInteractionPlugin {
|
|
|
100640
100836
|
try {
|
|
100641
100837
|
const parsed = JSON.parse(body);
|
|
100642
100838
|
const response = InteractionResponseSchema.parse(parsed);
|
|
100839
|
+
if (response.requestId !== requestId) {
|
|
100840
|
+
return new Response("Bad Request: requestId mismatch", { status: 400 });
|
|
100841
|
+
}
|
|
100643
100842
|
deliveryResult = this.deliverResponse(requestId, response);
|
|
100644
100843
|
} catch {
|
|
100645
100844
|
return new Response("Bad Request: Invalid response format", { status: 400 });
|
|
@@ -103627,6 +103826,20 @@ var init_task_types = __esm(() => {
|
|
|
103627
103826
|
// src/chat/background/task-registry.ts
|
|
103628
103827
|
import { appendFileSync as appendFileSync4, mkdirSync as mkdirSync12 } from "fs";
|
|
103629
103828
|
import { join as join123 } from "path";
|
|
103829
|
+
async function readLogTail(path) {
|
|
103830
|
+
const file = Bun.file(path);
|
|
103831
|
+
if (file.size <= TASK_LOG_TAIL_BYTES)
|
|
103832
|
+
return file.text();
|
|
103833
|
+
const start = file.size - TASK_LOG_TAIL_BYTES;
|
|
103834
|
+
const previous = new Uint8Array(await file.slice(start - 1, start).arrayBuffer());
|
|
103835
|
+
let tail = new Uint8Array(await file.slice(start).arrayBuffer());
|
|
103836
|
+
if (previous[0] !== NEWLINE_BYTE) {
|
|
103837
|
+
const newline = tail.indexOf(NEWLINE_BYTE);
|
|
103838
|
+
if (newline !== -1)
|
|
103839
|
+
tail = tail.slice(newline + 1);
|
|
103840
|
+
}
|
|
103841
|
+
return new TextDecoder().decode(tail);
|
|
103842
|
+
}
|
|
103630
103843
|
function terminalState(end) {
|
|
103631
103844
|
if (end.aborted)
|
|
103632
103845
|
return "stopped";
|
|
@@ -103852,13 +104065,14 @@ class BackgroundTasks {
|
|
|
103852
104065
|
function createBackgroundTasks(options) {
|
|
103853
104066
|
return new BackgroundTasks(options);
|
|
103854
104067
|
}
|
|
103855
|
-
var TASK_LOG_MAX_BYTES, TASK_OUTPUT_MAX_LINES = 500, TASK_OUTPUT_DEFAULT_LINES = 40, RANDOM_HEX_LENGTH3 = 8, ID_ATTEMPTS = 16, LOG_LIMIT_LINE = "[nax] log limit reached; further output dropped", encoder, NEWLINE_BYTE = 10, _backgroundTaskDeps;
|
|
104068
|
+
var TASK_LOG_MAX_BYTES, TASK_LOG_TAIL_BYTES, TASK_OUTPUT_MAX_LINES = 500, TASK_OUTPUT_DEFAULT_LINES = 40, RANDOM_HEX_LENGTH3 = 8, ID_ATTEMPTS = 16, LOG_LIMIT_LINE = "[nax] log limit reached; further output dropped", encoder, NEWLINE_BYTE = 10, _backgroundTaskDeps;
|
|
103856
104069
|
var init_task_registry = __esm(() => {
|
|
103857
104070
|
init_internal();
|
|
103858
104071
|
init_errors4();
|
|
103859
104072
|
init_prompts();
|
|
103860
104073
|
init_task_types();
|
|
103861
104074
|
TASK_LOG_MAX_BYTES = 50 * 1024 * 1024;
|
|
104075
|
+
TASK_LOG_TAIL_BYTES = 2 * 1024 * 1024;
|
|
103862
104076
|
encoder = new TextEncoder;
|
|
103863
104077
|
_backgroundTaskDeps = {
|
|
103864
104078
|
randomHex: () => crypto.randomUUID().slice(0, RANDOM_HEX_LENGTH3),
|
|
@@ -103868,7 +104082,7 @@ var init_task_registry = __esm(() => {
|
|
|
103868
104082
|
appendLog: async (path, chunk) => {
|
|
103869
104083
|
appendFileSync4(path, chunk);
|
|
103870
104084
|
},
|
|
103871
|
-
readLog:
|
|
104085
|
+
readLog: readLogTail
|
|
103872
104086
|
};
|
|
103873
104087
|
});
|
|
103874
104088
|
|
|
@@ -106490,7 +106704,7 @@ var init_types12 = __esm(() => {
|
|
|
106490
106704
|
});
|
|
106491
106705
|
|
|
106492
106706
|
// src/chat/mentions/mention-expand.ts
|
|
106493
|
-
import { readdir as readdir10, realpath as realpath8, stat as
|
|
106707
|
+
import { readdir as readdir10, realpath as realpath8, stat as stat17 } from "fs/promises";
|
|
106494
106708
|
import { relative as relative32, resolve as resolve44, sep as sep21 } from "path";
|
|
106495
106709
|
async function expandChatMentions(text, where) {
|
|
106496
106710
|
const ctx = {
|
|
@@ -106567,6 +106781,8 @@ async function targetIgnoredRefusal(located, ctx) {
|
|
|
106567
106781
|
}
|
|
106568
106782
|
async function contentRecord(located, ctx) {
|
|
106569
106783
|
const info = await _mentionExpandDeps.stat(located.realPath);
|
|
106784
|
+
if (info.special)
|
|
106785
|
+
return pathOnly(located.path, PATH_ONLY_NOT_REGULAR_FILE);
|
|
106570
106786
|
if (info.isDirectory)
|
|
106571
106787
|
return folderRecord(located, ctx);
|
|
106572
106788
|
if (info.size > MENTION_READ_MAX_BYTES)
|
|
@@ -106677,7 +106893,7 @@ async function realPathOrUndefined(path) {
|
|
|
106677
106893
|
return;
|
|
106678
106894
|
}
|
|
106679
106895
|
}
|
|
106680
|
-
var _mentionExpandDeps, REFUSAL_PREFIX = "not attached: ", OUTSIDE_REPO = "outside the repo", INSIDE_GIT_DIR = "inside .git", GIT_TIMED_OUT = "git timed out", IGNORED_BY_GIT = "ignored by git", GIT_DIR_SEGMENT = ".git", CHECK_IGNORE_ARGS, LS_FILES_ARGS, ROOT_PATHSPEC = ".", PATH_ONLY_FILE_TOO_LARGE = "path only: file too large", PATH_ONLY_BINARY = "path only: binary", PATH_ONLY_MESSAGE_TOO_LARGE = "path only: message too large", PATH_ONLY_NO_IMAGES = "path only: model cannot read images", PATH_ONLY_PREFIX = "path only: ", IMAGE_NOTE_LEAD = "image \xB7 ", NEWLINE = `
|
|
106896
|
+
var _mentionExpandDeps, REFUSAL_PREFIX = "not attached: ", OUTSIDE_REPO = "outside the repo", INSIDE_GIT_DIR = "inside .git", GIT_TIMED_OUT = "git timed out", IGNORED_BY_GIT = "ignored by git", GIT_DIR_SEGMENT = ".git", CHECK_IGNORE_ARGS, LS_FILES_ARGS, ROOT_PATHSPEC = ".", PATH_ONLY_FILE_TOO_LARGE = "path only: file too large", PATH_ONLY_NOT_REGULAR_FILE = "path only: not a regular file", PATH_ONLY_BINARY = "path only: binary", PATH_ONLY_MESSAGE_TOO_LARGE = "path only: message too large", PATH_ONLY_NO_IMAGES = "path only: model cannot read images", PATH_ONLY_PREFIX = "path only: ", IMAGE_NOTE_LEAD = "image \xB7 ", NEWLINE = `
|
|
106681
106897
|
`, PATH_SEPARATOR = "/", FOLDER_SUFFIX = "/", NUL2 = "\x00", TRAILING_PUNCTUATION2;
|
|
106682
106898
|
var init_mention_expand = __esm(() => {
|
|
106683
106899
|
init_internal();
|
|
@@ -106690,8 +106906,13 @@ var init_mention_expand = __esm(() => {
|
|
|
106690
106906
|
return realpath8(path);
|
|
106691
106907
|
},
|
|
106692
106908
|
async stat(path) {
|
|
106693
|
-
const info = await
|
|
106694
|
-
|
|
106909
|
+
const info = await stat17(path);
|
|
106910
|
+
const isDirectory = info.isDirectory();
|
|
106911
|
+
return {
|
|
106912
|
+
isDirectory,
|
|
106913
|
+
size: info.size,
|
|
106914
|
+
...!info.isFile() && !isDirectory ? { special: true } : {}
|
|
106915
|
+
};
|
|
106695
106916
|
},
|
|
106696
106917
|
async readBytes(path) {
|
|
106697
106918
|
return new Uint8Array(await Bun.file(path).arrayBuffer());
|
|
@@ -107079,7 +107300,7 @@ var init_paths5 = __esm(() => {
|
|
|
107079
107300
|
});
|
|
107080
107301
|
|
|
107081
107302
|
// src/workflow/result.ts
|
|
107082
|
-
import { mkdir as mkdir35, readdir as readdir11, rename as rename13, stat as
|
|
107303
|
+
import { mkdir as mkdir35, readdir as readdir11, rename as rename13, stat as stat18 } from "fs/promises";
|
|
107083
107304
|
import { basename as basename22, join as join129 } from "path";
|
|
107084
107305
|
function newStoryRecord(storyId, maxRounds, now) {
|
|
107085
107306
|
return {
|
|
@@ -107196,7 +107417,7 @@ var _resultDeps, RESULT_FILE = "result.json";
|
|
|
107196
107417
|
var init_result = __esm(() => {
|
|
107197
107418
|
init_store2();
|
|
107198
107419
|
init_open_items();
|
|
107199
|
-
_resultDeps = { mkdir: mkdir35, readdir: readdir11, rename: rename13, stat:
|
|
107420
|
+
_resultDeps = { mkdir: mkdir35, readdir: readdir11, rename: rename13, stat: stat18 };
|
|
107200
107421
|
});
|
|
107201
107422
|
|
|
107202
107423
|
// src/workflow/advisor-live.ts
|
|
@@ -110917,12 +111138,12 @@ var init_worktree_id = __esm(() => {
|
|
|
110917
111138
|
});
|
|
110918
111139
|
|
|
110919
111140
|
// src/worktree/manager.ts
|
|
110920
|
-
import { existsSync as existsSync15, symlinkSync as symlinkSync3 } from "fs";
|
|
110921
|
-
import { mkdir as mkdir37, stat as
|
|
111141
|
+
import { existsSync as existsSync15, lstatSync as lstatSync8, symlinkSync as symlinkSync3 } from "fs";
|
|
111142
|
+
import { mkdir as mkdir37, stat as stat19 } from "fs/promises";
|
|
110922
111143
|
import { join as join136, resolve as resolve47 } from "path";
|
|
110923
111144
|
async function resolveGitInfoDir(projectRoot) {
|
|
110924
111145
|
const dotGit = join136(projectRoot, ".git");
|
|
110925
|
-
const isPointerFile = await
|
|
111146
|
+
const isPointerFile = await stat19(dotGit).then((s) => s.isFile(), () => false);
|
|
110926
111147
|
if (!isPointerFile)
|
|
110927
111148
|
return join136(dotGit, "info");
|
|
110928
111149
|
const { stdout, stderr, exitCode } = await _worktreeManagerDeps.gitWithTimeout(["rev-parse", "--git-common-dir"], projectRoot);
|
|
@@ -110936,6 +111157,40 @@ async function resolveGitInfoDir(projectRoot) {
|
|
|
110936
111157
|
}
|
|
110937
111158
|
return join136(resolve47(projectRoot, commonDir), "info");
|
|
110938
111159
|
}
|
|
111160
|
+
async function preserveWorktreeEnv(options) {
|
|
111161
|
+
const envSource = join136(options.projectRoot, ".env");
|
|
111162
|
+
if (!existsSync15(envSource))
|
|
111163
|
+
return;
|
|
111164
|
+
const envTarget = join136(options.worktreePath, ".env");
|
|
111165
|
+
try {
|
|
111166
|
+
_worktreeManagerDeps.lstatSync(envTarget);
|
|
111167
|
+
getSafeLogger2()?.debug("worktree", ".env is tracked; the worktree keeps the checked-out copy", {
|
|
111168
|
+
worktreeId: options.worktreeId
|
|
111169
|
+
});
|
|
111170
|
+
return;
|
|
111171
|
+
} catch (error) {
|
|
111172
|
+
if (error.code !== "ENOENT") {
|
|
111173
|
+
await options.removeWorktree();
|
|
111174
|
+
throw new NaxError(`Failed to inspect worktree .env: ${errorMessage(error)}`, "WORKTREE_ERROR", {
|
|
111175
|
+
stage: "worktree",
|
|
111176
|
+
worktreeId: options.worktreeId,
|
|
111177
|
+
envTarget,
|
|
111178
|
+
cause: error
|
|
111179
|
+
});
|
|
111180
|
+
}
|
|
111181
|
+
}
|
|
111182
|
+
try {
|
|
111183
|
+
symlinkSync3(envSource, envTarget, "file");
|
|
111184
|
+
} catch (error) {
|
|
111185
|
+
await options.removeWorktree();
|
|
111186
|
+
throw new NaxError(`Failed to symlink .env: ${errorMessage(error)}`, "WORKTREE_ERROR", {
|
|
111187
|
+
stage: "worktree",
|
|
111188
|
+
worktreeId: options.worktreeId,
|
|
111189
|
+
envSource,
|
|
111190
|
+
envTarget
|
|
111191
|
+
});
|
|
111192
|
+
}
|
|
111193
|
+
}
|
|
110939
111194
|
function dropRetiredLines(content, retired) {
|
|
110940
111195
|
const lines = content.split(`
|
|
110941
111196
|
`).filter((line) => !retired.has(line.trim()));
|
|
@@ -111096,21 +111351,12 @@ ${missing.join(`
|
|
|
111096
111351
|
projectRoot
|
|
111097
111352
|
});
|
|
111098
111353
|
}
|
|
111099
|
-
|
|
111100
|
-
|
|
111101
|
-
|
|
111102
|
-
|
|
111103
|
-
|
|
111104
|
-
|
|
111105
|
-
await this.remove(projectRoot, worktreeId);
|
|
111106
|
-
throw new NaxError(`Failed to symlink .env: ${errorMessage(error)}`, "WORKTREE_ERROR", {
|
|
111107
|
-
stage: "worktree",
|
|
111108
|
-
worktreeId,
|
|
111109
|
-
envSource,
|
|
111110
|
-
envTarget
|
|
111111
|
-
});
|
|
111112
|
-
}
|
|
111113
|
-
}
|
|
111354
|
+
await preserveWorktreeEnv({
|
|
111355
|
+
projectRoot,
|
|
111356
|
+
worktreePath,
|
|
111357
|
+
worktreeId,
|
|
111358
|
+
removeWorktree: () => this.remove(projectRoot, worktreeId)
|
|
111359
|
+
});
|
|
111114
111360
|
}
|
|
111115
111361
|
async remove(projectRoot, worktreeId) {
|
|
111116
111362
|
const worktreePath = storyWorktreePath(projectRoot, worktreeId);
|
|
@@ -111213,7 +111459,8 @@ var init_manager3 = __esm(() => {
|
|
|
111213
111459
|
init_nax_orphan_ref();
|
|
111214
111460
|
init_worktree_id();
|
|
111215
111461
|
_worktreeManagerDeps = {
|
|
111216
|
-
gitWithTimeout
|
|
111462
|
+
gitWithTimeout,
|
|
111463
|
+
lstatSync: (path) => lstatSync8(path)
|
|
111217
111464
|
};
|
|
111218
111465
|
});
|
|
111219
111466
|
|
|
@@ -111854,34 +112101,47 @@ var init_escape = __esm(() => {
|
|
|
111854
112101
|
function parseView(stdout, forge) {
|
|
111855
112102
|
try {
|
|
111856
112103
|
const parsed = JSON.parse(stdout);
|
|
112104
|
+
const closed = forge === "github" ? parsed.state === "CLOSED" || parsed.state === "MERGED" : parsed.state === "closed" || parsed.state === "merged";
|
|
111857
112105
|
if (forge === "github") {
|
|
111858
|
-
return {
|
|
112106
|
+
return {
|
|
112107
|
+
isDraft: parsed.isDraft === true,
|
|
112108
|
+
url: typeof parsed.url === "string" ? parsed.url : undefined,
|
|
112109
|
+
closed
|
|
112110
|
+
};
|
|
111859
112111
|
}
|
|
111860
112112
|
const isDraft = parsed.isDraft === true || parsed.draft === true || parsed.work_in_progress === true;
|
|
111861
|
-
return { isDraft, url: extractUrl(stdout) };
|
|
112113
|
+
return { isDraft, url: extractUrl(stdout), closed };
|
|
111862
112114
|
} catch {
|
|
111863
|
-
return { isDraft: false, url: extractUrl(stdout) };
|
|
112115
|
+
return { isDraft: false, url: extractUrl(stdout), closed: false };
|
|
111864
112116
|
}
|
|
111865
112117
|
}
|
|
111866
|
-
async function
|
|
111867
|
-
if (view.exitCode === 0) {
|
|
111868
|
-
const before = parseView(view.stdout, args.forge);
|
|
111869
|
-
await updatePrBody({ ...args, keepDraft: before.isDraft }, deps);
|
|
111870
|
-
const reView = await deps.run(viewArgv(args.forge, args.branch, "isDraft,url"), { cwd: args.workdir });
|
|
111871
|
-
const after = reView.exitCode === 0 ? parseView(reView.stdout, args.forge) : before;
|
|
111872
|
-
return { status: after.isDraft ? "draft" : "already-ready", url: after.url ?? before.url };
|
|
111873
|
-
}
|
|
112118
|
+
async function createDraftPr(args, deps) {
|
|
111874
112119
|
const created = await openPr(args.forge, { title: args.title, body: args.body, branch: args.branch, draft: true }, deps, args.workdir);
|
|
111875
112120
|
if (!created.success) {
|
|
111876
112121
|
throw new NaxError(`Failed to create draft PR/MR for "${args.branch}": ${created.message}`, "FINISH_PR_CREATE_FAILED", { stage: "finish-pr", branch: args.branch });
|
|
111877
112122
|
}
|
|
111878
112123
|
return { status: "draft", url: created.url };
|
|
111879
112124
|
}
|
|
112125
|
+
async function keepDraftPr(args, view, deps) {
|
|
112126
|
+
if (view.exitCode === 0) {
|
|
112127
|
+
const before = parseView(view.stdout, args.forge);
|
|
112128
|
+
if (!before.closed) {
|
|
112129
|
+
await updatePrBody({ ...args, keepDraft: before.isDraft }, deps);
|
|
112130
|
+
const reView = await deps.run(viewArgv(args.forge, args.branch, "isDraft,url,state"), { cwd: args.workdir });
|
|
112131
|
+
const after = reView.exitCode === 0 ? parseView(reView.stdout, args.forge) : before;
|
|
112132
|
+
if (!after.closed) {
|
|
112133
|
+
return { status: after.isDraft ? "draft" : "already-ready", url: after.url ?? before.url };
|
|
112134
|
+
}
|
|
112135
|
+
}
|
|
112136
|
+
}
|
|
112137
|
+
return createDraftPr(args, deps);
|
|
112138
|
+
}
|
|
111880
112139
|
async function openOrPromotePr(args, deps) {
|
|
111881
|
-
const view = await deps.run(viewArgv(args.forge, args.branch, "isDraft,url"), { cwd: args.workdir });
|
|
112140
|
+
const view = await deps.run(viewArgv(args.forge, args.branch, "isDraft,url,state"), { cwd: args.workdir });
|
|
111882
112141
|
if (args.keepDraft)
|
|
111883
112142
|
return keepDraftPr(args, view, deps);
|
|
111884
|
-
|
|
112143
|
+
const parsedView = view.exitCode === 0 ? parseView(view.stdout, args.forge) : undefined;
|
|
112144
|
+
if (!parsedView || parsedView.closed) {
|
|
111885
112145
|
const createCmd = args.forge === "github" ? ["gh", "pr", "create", "--title", args.title, "--body", args.body, "--head", args.branch] : ["glab", "mr", "create", "--title", args.title, "--description", args.body, "--source-branch", args.branch];
|
|
111886
112146
|
const create = await deps.run(createCmd, { cwd: args.workdir });
|
|
111887
112147
|
if (create.exitCode !== 0) {
|
|
@@ -111889,7 +112149,7 @@ async function openOrPromotePr(args, deps) {
|
|
|
111889
112149
|
}
|
|
111890
112150
|
return { status: "opened", url: extractUrl(create.stdout) };
|
|
111891
112151
|
}
|
|
111892
|
-
const { isDraft, url } =
|
|
112152
|
+
const { isDraft, url } = parsedView;
|
|
111893
112153
|
if (isDraft) {
|
|
111894
112154
|
const readyCmd = args.forge === "github" ? ["gh", "pr", "ready", args.branch] : ["glab", "mr", "update", args.branch, "--ready"];
|
|
111895
112155
|
const ready = await deps.run(readyCmd, { cwd: args.workdir });
|
|
@@ -113836,12 +114096,12 @@ function progressLog(onInfo) {
|
|
|
113836
114096
|
}
|
|
113837
114097
|
};
|
|
113838
114098
|
}
|
|
113839
|
-
async function waitWithHeartbeat(ms, startedAt, progress) {
|
|
114099
|
+
async function waitWithHeartbeat(ms, startedAt, progress, signal) {
|
|
113840
114100
|
let remaining = ms;
|
|
113841
|
-
while (remaining > 0) {
|
|
114101
|
+
while (remaining > 0 && !signal?.aborted) {
|
|
113842
114102
|
const untilBeat = Math.max(1, CI_WAIT_HEARTBEAT_MS - progress.sinceLastInfo());
|
|
113843
114103
|
const slice = Math.min(remaining, untilBeat);
|
|
113844
|
-
await _ciWaitDeps.sleep(slice);
|
|
114104
|
+
await _ciWaitDeps.sleep(slice, signal);
|
|
113845
114105
|
remaining -= slice;
|
|
113846
114106
|
progress.heartbeatIfDue(startedAt);
|
|
113847
114107
|
}
|
|
@@ -113955,7 +114215,7 @@ async function waitForChecks(forge, prRef, opts) {
|
|
|
113955
114215
|
return end(timeout.outcome, timeout.detail);
|
|
113956
114216
|
}
|
|
113957
114217
|
progress.heartbeatIfDue(startedAt);
|
|
113958
|
-
await waitWithHeartbeat(opts.pollMs, startedAt, progress);
|
|
114218
|
+
await waitWithHeartbeat(opts.pollMs, startedAt, progress, opts.signal);
|
|
113959
114219
|
progress.heartbeatIfDue(startedAt);
|
|
113960
114220
|
}
|
|
113961
114221
|
} finally {
|
|
@@ -114007,9 +114267,12 @@ var init_ci_wait = __esm(() => {
|
|
|
114007
114267
|
init_forge();
|
|
114008
114268
|
init_log_format();
|
|
114009
114269
|
init_logger2();
|
|
114270
|
+
init_bun_deps();
|
|
114010
114271
|
_ciWaitDeps = {
|
|
114011
114272
|
run: (cmd, opts) => defaultForgeDeps.run(cmd, opts),
|
|
114012
|
-
sleep: (ms) =>
|
|
114273
|
+
sleep: (ms, signal) => cancellableDelay(ms, signal).catch(() => {
|
|
114274
|
+
return;
|
|
114275
|
+
}),
|
|
114013
114276
|
now: () => Date.now(),
|
|
114014
114277
|
schedule: (fn, ms) => {
|
|
114015
114278
|
const timer = setInterval(fn, ms);
|
|
@@ -117929,7 +118192,7 @@ var init_hooks = __esm(() => {
|
|
|
117929
118192
|
});
|
|
117930
118193
|
|
|
117931
118194
|
// src/execution/lifecycle/run-rules-setup.ts
|
|
117932
|
-
import { stat as
|
|
118195
|
+
import { stat as stat20 } from "fs/promises";
|
|
117933
118196
|
async function validateProjectContext(config) {
|
|
117934
118197
|
const projectContext = config.context?.projectContext;
|
|
117935
118198
|
if (projectContext?.file === undefined)
|
|
@@ -117982,7 +118245,7 @@ var init_run_rules_setup = __esm(() => {
|
|
|
117982
118245
|
_runRulesSetupDeps = {
|
|
117983
118246
|
dirExists: async (path) => {
|
|
117984
118247
|
try {
|
|
117985
|
-
return (await
|
|
118248
|
+
return (await stat20(path)).isDirectory();
|
|
117986
118249
|
} catch {
|
|
117987
118250
|
return false;
|
|
117988
118251
|
}
|
|
@@ -118354,6 +118617,15 @@ async function clearHiddenNaxIndexFlags(ctx) {
|
|
|
118354
118617
|
clearTimeout(timer);
|
|
118355
118618
|
}
|
|
118356
118619
|
}
|
|
118620
|
+
async function releaseOwnedLocks(ctx) {
|
|
118621
|
+
try {
|
|
118622
|
+
await ctx.releaseLocks?.();
|
|
118623
|
+
} catch (error) {
|
|
118624
|
+
getSafeLogger2()?.warn("crash-recovery", "Failed to release run locks during fatal teardown", {
|
|
118625
|
+
error: error instanceof Error ? error.message : String(error)
|
|
118626
|
+
});
|
|
118627
|
+
}
|
|
118628
|
+
}
|
|
118357
118629
|
function getSignalNumber(signal) {
|
|
118358
118630
|
const signalMap = {
|
|
118359
118631
|
SIGTERM: 15,
|
|
@@ -118378,6 +118650,7 @@ function createSignalHandler(ctx, state) {
|
|
|
118378
118650
|
await writeRunComplete(ctx, signal.toLowerCase());
|
|
118379
118651
|
await updateStatusToCrashed(ctx.statusWriter, ctx.getTotalCost(), ctx.getIterations(), signal, ctx.featureDir);
|
|
118380
118652
|
await clearHiddenNaxIndexFlags(ctx);
|
|
118653
|
+
await releaseOwnedLocks(ctx);
|
|
118381
118654
|
cancelDeadline();
|
|
118382
118655
|
_crashSignalsDeps.exit(128 + getSignalNumber(signal));
|
|
118383
118656
|
};
|
|
@@ -118404,6 +118677,7 @@ ${error.stack ?? ""}
|
|
|
118404
118677
|
await writeFatalLog(ctx.jsonlFilePath, "uncaughtException", error);
|
|
118405
118678
|
await updateStatusToCrashed(ctx.statusWriter, ctx.getTotalCost(), ctx.getIterations(), "uncaughtException", ctx.featureDir);
|
|
118406
118679
|
await clearHiddenNaxIndexFlags(ctx);
|
|
118680
|
+
await releaseOwnedLocks(ctx);
|
|
118407
118681
|
cancelDeadline();
|
|
118408
118682
|
_crashSignalsDeps.exit(1);
|
|
118409
118683
|
};
|
|
@@ -118431,6 +118705,7 @@ ${error.stack ?? ""}
|
|
|
118431
118705
|
await writeFatalLog(ctx.jsonlFilePath, "unhandledRejection", error);
|
|
118432
118706
|
await updateStatusToCrashed(ctx.statusWriter, ctx.getTotalCost(), ctx.getIterations(), "unhandledRejection", ctx.featureDir);
|
|
118433
118707
|
await clearHiddenNaxIndexFlags(ctx);
|
|
118708
|
+
await releaseOwnedLocks(ctx);
|
|
118434
118709
|
cancelDeadline();
|
|
118435
118710
|
_crashSignalsDeps.exit(1);
|
|
118436
118711
|
};
|
|
@@ -122382,12 +122657,14 @@ var init_feature_context3 = __esm(() => {
|
|
|
122382
122657
|
});
|
|
122383
122658
|
|
|
122384
122659
|
// src/workflow/adjudicate.ts
|
|
122385
|
-
async function adjudicateResidual(advisor, req, ledger) {
|
|
122660
|
+
async function adjudicateResidual(advisor, req, ledger, aborted) {
|
|
122386
122661
|
let answer = { rulings: [], diagnoses: {} };
|
|
122387
122662
|
if (req.items.length > 0 || req.redGates.length > 0) {
|
|
122388
122663
|
try {
|
|
122389
122664
|
answer = await advisor.ruleResidual(req);
|
|
122390
122665
|
} catch (err) {
|
|
122666
|
+
if (aborted?.())
|
|
122667
|
+
throw err;
|
|
122391
122668
|
getLogger2().warn("workflow", "Residual advisor call failed \u2014 default hold", {
|
|
122392
122669
|
storyId: req.storyId,
|
|
122393
122670
|
error: errorMessage(err)
|
|
@@ -122854,9 +123131,6 @@ import { isAbsolute as isAbsolute37, join as join164 } from "path";
|
|
|
122854
123131
|
function ciDetailFields(ci) {
|
|
122855
123132
|
return DETAILED_CI_STATES.has(ci.outcome) ? { ciDetail: ci.detail } : {};
|
|
122856
123133
|
}
|
|
122857
|
-
function isPublishableBranch(branch, defaultBranch) {
|
|
122858
|
-
return !PROTECTED_BRANCHES.has(branch) && branch !== defaultBranch;
|
|
122859
|
-
}
|
|
122860
123134
|
function workflowPrTitle(fc) {
|
|
122861
123135
|
const raw = `feat(${fc.feature}): ${fc.prd.userStories.length} stories (nax workflow)`;
|
|
122862
123136
|
return sanitizeTitle(raw) ?? raw;
|
|
@@ -123173,12 +123447,13 @@ async function publish(fc, input) {
|
|
|
123173
123447
|
const plan = { fc, forge: target.forge, facts, dirty, base };
|
|
123174
123448
|
return mode === "push" ? pushMode(plan) : prMode(plan, input);
|
|
123175
123449
|
}
|
|
123176
|
-
var DETAILED_CI_STATES,
|
|
123450
|
+
var DETAILED_CI_STATES, MAX_EVIDENCE_FILES = 300, NO_BASE_COMMIT = "no base commit was resolved", NO_SEED_LINE = "Base commit: unresolved. Establish the diff base from the pull request itself, never from a local branch.", CI_NOT_RUN = "CI: not run yet. It runs on the pushed head after this ruling, and the PR is ready only when it is green.", DIRTY_REASON = "uncommitted changes after the branch fix", ALREADY_READY_REASON = "a human already marked the PR ready; nax left it as is", PUBLISH_DISABLED_REASON = "publish disabled (workflow.publish: none)", DEFAULT_PUBLISH_MODE = "pr";
|
|
123177
123451
|
var init_finalize = __esm(() => {
|
|
123178
123452
|
init_internal();
|
|
123179
123453
|
init_errors4();
|
|
123180
123454
|
init_finish();
|
|
123181
123455
|
init_logger2();
|
|
123456
|
+
init_git2();
|
|
123182
123457
|
init_approval();
|
|
123183
123458
|
init_closing_issues();
|
|
123184
123459
|
init_feature_deps();
|
|
@@ -123193,7 +123468,6 @@ var init_finalize = __esm(() => {
|
|
|
123193
123468
|
"no-checks",
|
|
123194
123469
|
"unavailable"
|
|
123195
123470
|
]);
|
|
123196
|
-
PROTECTED_BRANCHES = new Set(["", "main", "master"]);
|
|
123197
123471
|
});
|
|
123198
123472
|
|
|
123199
123473
|
// src/workflow/item-threads-index.ts
|
|
@@ -123891,7 +124165,7 @@ function buildFeatureEnv(fc, input, ctx) {
|
|
|
123891
124165
|
...opts?.prUrl ? { toolProviders: [forgeReadProviderForUrl(opts.prUrl, _featureDeps.forge, fc.projectDir)] } : {}
|
|
123892
124166
|
})),
|
|
123893
124167
|
branchReReview: (findings, fixBase) => toolErrors("branch-rereview", () => runBranchReReview(fc, { ...spec, findings, fixBase })),
|
|
123894
|
-
adjudicate: (items) => adjudicateResidual(live, { storyId: FEATURE_SCOPE, items, redGates: [] }, ledger),
|
|
124168
|
+
adjudicate: (items) => adjudicateResidual(live, { storyId: FEATURE_SCOPE, items, redGates: [] }, ledger, () => fc.runSignal?.aborted === true),
|
|
123895
124169
|
publish: (record) => publish(fc, {
|
|
123896
124170
|
record,
|
|
123897
124171
|
stories: ctx.stories,
|
|
@@ -125949,7 +126223,7 @@ async function residualStep(env, state) {
|
|
|
125949
126223
|
if (!s.gates?.red && !s.suiteThisIteration)
|
|
125950
126224
|
s.suite = await env.steps.fullSuite();
|
|
125951
126225
|
const items = state.open.filter((f) => f.kind !== "gate");
|
|
125952
|
-
const rulings = await adjudicateResidual(env.advisor, { storyId: env.storyId, items, redGates: redGateNames(s) }, env.sink.ledger);
|
|
126226
|
+
const rulings = await adjudicateResidual(env.advisor, { storyId: env.storyId, items, redGates: redGateNames(s) }, env.sink.ledger, env.aborted);
|
|
125953
126227
|
return { patch: { suite: s.suite, rulings } };
|
|
125954
126228
|
}
|
|
125955
126229
|
async function fixStep2(env, state) {
|
|
@@ -126218,6 +126492,7 @@ async function buildStoryEnv(ctx, callCtx) {
|
|
|
126218
126492
|
storyId: ctx.story.id,
|
|
126219
126493
|
dependents: dependentsOf(ctx.prd, ctx.story.id)
|
|
126220
126494
|
}),
|
|
126495
|
+
aborted: () => ctx.abortSignal?.aborted === true,
|
|
126221
126496
|
sink: {
|
|
126222
126497
|
update: async (patch) => {
|
|
126223
126498
|
reportStoryPhase(ctx, patch);
|
|
@@ -126853,7 +127128,7 @@ var init_headless_formatter = __esm(() => {
|
|
|
126853
127128
|
});
|
|
126854
127129
|
|
|
126855
127130
|
// src/execution/lifecycle/run-tmp-wipe.ts
|
|
126856
|
-
import { lstatSync as
|
|
127131
|
+
import { lstatSync as lstatSync9 } from "fs";
|
|
126857
127132
|
import { rm as rm16 } from "fs/promises";
|
|
126858
127133
|
function inspect(path) {
|
|
126859
127134
|
try {
|
|
@@ -126897,7 +127172,7 @@ var init_run_tmp_wipe = __esm(() => {
|
|
|
126897
127172
|
remove: (path) => rm16(path, { recursive: true, force: true }),
|
|
126898
127173
|
exists: (path) => {
|
|
126899
127174
|
try {
|
|
126900
|
-
|
|
127175
|
+
lstatSync9(path);
|
|
126901
127176
|
return true;
|
|
126902
127177
|
} catch (err) {
|
|
126903
127178
|
if (err.code !== "ENOENT")
|
|
@@ -129246,6 +129521,17 @@ async function defaultGetRemoteUrl(workdir) {
|
|
|
129246
129521
|
const trimmed = result.stdout.trim();
|
|
129247
129522
|
return trimmed.length > 0 ? trimmed : null;
|
|
129248
129523
|
}
|
|
129524
|
+
async function defaultReadDefaultBranch(workdir) {
|
|
129525
|
+
try {
|
|
129526
|
+
const result = await _autoPrDeps.run([...GIT_DEFAULT_BRANCH_CMD], { cwd: workdir });
|
|
129527
|
+
if (result.exitCode !== 0)
|
|
129528
|
+
return;
|
|
129529
|
+
const branch = result.stdout.trim().replace(/^origin\//, "");
|
|
129530
|
+
return branch.length > 0 ? branch : undefined;
|
|
129531
|
+
} catch {
|
|
129532
|
+
return;
|
|
129533
|
+
}
|
|
129534
|
+
}
|
|
129249
129535
|
function getAutoPrConfig(context) {
|
|
129250
129536
|
const cfg = context.config;
|
|
129251
129537
|
if (!cfg)
|
|
@@ -129281,12 +129567,20 @@ function toPrBodyContext(context) {
|
|
|
129281
129567
|
stories: context.stories
|
|
129282
129568
|
};
|
|
129283
129569
|
}
|
|
129284
|
-
var PLUGIN_NAME2 = "nax-auto-pr", PLUGIN_VERSION2 = "0.1.0", GIT_REMOTE_CMD, DEFAULT_SUBPROCESS_TIMEOUT_MS2 = 30000, _autoPrDeps, autoPrAction, autoPrPlugin;
|
|
129570
|
+
var PLUGIN_NAME2 = "nax-auto-pr", PLUGIN_VERSION2 = "0.1.0", GIT_REMOTE_CMD, GIT_DEFAULT_BRANCH_CMD, DEFAULT_SUBPROCESS_TIMEOUT_MS2 = 30000, _autoPrDeps, autoPrAction, autoPrPlugin;
|
|
129285
129571
|
var init_auto_pr = __esm(() => {
|
|
129286
129572
|
init_internal();
|
|
129287
129573
|
init_forge();
|
|
129574
|
+
init_git2();
|
|
129288
129575
|
init_pr_body2();
|
|
129289
129576
|
GIT_REMOTE_CMD = ["git", "remote", "get-url", "origin"];
|
|
129577
|
+
GIT_DEFAULT_BRANCH_CMD = [
|
|
129578
|
+
"git",
|
|
129579
|
+
"symbolic-ref",
|
|
129580
|
+
"--quiet",
|
|
129581
|
+
"--short",
|
|
129582
|
+
"refs/remotes/origin/HEAD"
|
|
129583
|
+
];
|
|
129290
129584
|
_autoPrDeps = {
|
|
129291
129585
|
run: defaultRun2,
|
|
129292
129586
|
readText: defaultReadText3,
|
|
@@ -129294,7 +129588,8 @@ var init_auto_pr = __esm(() => {
|
|
|
129294
129588
|
detectForge: forgeFromRemoteUrl,
|
|
129295
129589
|
hasOpenPr,
|
|
129296
129590
|
openDraft: openPr,
|
|
129297
|
-
findPrTemplate
|
|
129591
|
+
findPrTemplate,
|
|
129592
|
+
readDefaultBranch: defaultReadDefaultBranch
|
|
129298
129593
|
};
|
|
129299
129594
|
autoPrAction = {
|
|
129300
129595
|
name: PLUGIN_NAME2,
|
|
@@ -129310,6 +129605,13 @@ var init_auto_pr = __esm(() => {
|
|
|
129310
129605
|
return false;
|
|
129311
129606
|
if (summary.paused > 0)
|
|
129312
129607
|
return false;
|
|
129608
|
+
const defaultBranch = await _autoPrDeps.readDefaultBranch(context.workdir);
|
|
129609
|
+
if (!isPublishableBranch(context.branch, defaultBranch)) {
|
|
129610
|
+
context.logger.warn("Skipping auto-PR \u2014 the run's branch is protected", {
|
|
129611
|
+
branch: context.branch
|
|
129612
|
+
});
|
|
129613
|
+
return false;
|
|
129614
|
+
}
|
|
129313
129615
|
const remoteUrl = await _autoPrDeps.getRemoteUrl(context.workdir);
|
|
129314
129616
|
if (!remoteUrl)
|
|
129315
129617
|
return false;
|
|
@@ -129331,6 +129633,13 @@ var init_auto_pr = __esm(() => {
|
|
|
129331
129633
|
},
|
|
129332
129634
|
async execute(context) {
|
|
129333
129635
|
try {
|
|
129636
|
+
const defaultBranch = await _autoPrDeps.readDefaultBranch(context.workdir);
|
|
129637
|
+
if (!isPublishableBranch(context.branch, defaultBranch)) {
|
|
129638
|
+
return {
|
|
129639
|
+
success: false,
|
|
129640
|
+
message: `Auto-PR skipped: branch "${context.branch || "(empty)"}" is not a feature branch`
|
|
129641
|
+
};
|
|
129642
|
+
}
|
|
129334
129643
|
const cfg = getAutoPrConfig(context);
|
|
129335
129644
|
const remoteUrl = await _autoPrDeps.getRemoteUrl(context.workdir);
|
|
129336
129645
|
if (!remoteUrl) {
|
|
@@ -132449,6 +132758,7 @@ async function setupRun(options) {
|
|
|
132449
132758
|
await runtime.pidRegistry.cleanupStale();
|
|
132450
132759
|
let cleanupCrashHandlers;
|
|
132451
132760
|
let sealApprovals;
|
|
132761
|
+
let releaseRunLocks;
|
|
132452
132762
|
try {
|
|
132453
132763
|
cleanupCrashHandlers = _runSetupDeps.installCrashHandlers({
|
|
132454
132764
|
statusWriter,
|
|
@@ -132470,6 +132780,9 @@ async function setupRun(options) {
|
|
|
132470
132780
|
sealApprovals: async () => {
|
|
132471
132781
|
await sealApprovals?.();
|
|
132472
132782
|
},
|
|
132783
|
+
releaseLocks: async () => {
|
|
132784
|
+
await releaseRunLocks?.();
|
|
132785
|
+
},
|
|
132473
132786
|
onShutdown: async (abortSignal) => {
|
|
132474
132787
|
await closeAllRunSessions(sessionManager, options.agentGetFn, { force: true, signal: abortSignal });
|
|
132475
132788
|
await runtime.close().catch((err) => {
|
|
@@ -132556,6 +132869,10 @@ async function setupRun(options) {
|
|
|
132556
132869
|
holderWorkdir: featureLock.holder.workdir
|
|
132557
132870
|
});
|
|
132558
132871
|
}
|
|
132872
|
+
releaseRunLocks = async () => {
|
|
132873
|
+
await releaseFeatureLock({ outputDir: runtime.outputDir, feature, runId });
|
|
132874
|
+
await releaseLock(workdir);
|
|
132875
|
+
};
|
|
132559
132876
|
const initResult = await initializeAfterLock({
|
|
132560
132877
|
config,
|
|
132561
132878
|
workdir,
|
|
@@ -133322,27 +133639,36 @@ async function spawnGitWithDeadline(args, workdir) {
|
|
|
133322
133639
|
} catch {}
|
|
133323
133640
|
}, GIT_TIMEOUT_MS);
|
|
133324
133641
|
const stdoutPromise = new Response(proc.stdout).text().catch(() => "");
|
|
133325
|
-
|
|
133326
|
-
|
|
133327
|
-
|
|
133328
|
-
|
|
133329
|
-
|
|
133642
|
+
const stderrPromise = new Response(proc.stderr).text().catch(() => "");
|
|
133643
|
+
try {
|
|
133644
|
+
const exitCode = await proc.exited;
|
|
133645
|
+
clearTimeout(timerId);
|
|
133646
|
+
const [stdout] = await Promise.all([stdoutPromise, stderrPromise]);
|
|
133647
|
+
return { stdout, exitCode, timedOut };
|
|
133648
|
+
} finally {
|
|
133649
|
+
clearTimeout(timerId);
|
|
133650
|
+
}
|
|
133330
133651
|
}
|
|
133331
133652
|
async function captureRunStartRef(workdir) {
|
|
133332
133653
|
try {
|
|
133333
|
-
const
|
|
133334
|
-
return stdout.trim();
|
|
133654
|
+
const result = await spawnGitWithDeadline(["rev-parse", "HEAD"], workdir);
|
|
133655
|
+
return result.exitCode === 0 && !result.timedOut ? result.stdout.trim() : "";
|
|
133335
133656
|
} catch {
|
|
133336
133657
|
return "";
|
|
133337
133658
|
}
|
|
133338
133659
|
}
|
|
133339
133660
|
async function getChangedFilesForDeferred(workdir, baseRef) {
|
|
133340
133661
|
try {
|
|
133341
|
-
const
|
|
133342
|
-
|
|
133343
|
-
|
|
133344
|
-
|
|
133345
|
-
|
|
133662
|
+
const result = await spawnGitWithDeadline(["diff", "--name-only", `${baseRef}...HEAD`], workdir);
|
|
133663
|
+
if (result.timedOut)
|
|
133664
|
+
return { ok: false, error: "[deferred-review] git diff timed out" };
|
|
133665
|
+
if (result.exitCode !== 0) {
|
|
133666
|
+
return { ok: false, error: `[deferred-review] git diff exited with code ${result.exitCode}` };
|
|
133667
|
+
}
|
|
133668
|
+
return { ok: true, files: result.stdout.trim().split(`
|
|
133669
|
+
`).filter(Boolean) };
|
|
133670
|
+
} catch (error) {
|
|
133671
|
+
return { ok: false, error: `[deferred-review] git diff failed: ${errorMessage(error)}` };
|
|
133346
133672
|
}
|
|
133347
133673
|
}
|
|
133348
133674
|
async function runDeferredReview(workdir, _reviewConfig, plugins, runStartRef, naxIgnoreIndex) {
|
|
@@ -133350,9 +133676,22 @@ async function runDeferredReview(workdir, _reviewConfig, plugins, runStartRef, n
|
|
|
133350
133676
|
if (reviewers.length === 0) {
|
|
133351
133677
|
return;
|
|
133352
133678
|
}
|
|
133353
|
-
const
|
|
133679
|
+
const changedFilesResult = await getChangedFilesForDeferred(workdir, runStartRef);
|
|
133680
|
+
if (!changedFilesResult.ok) {
|
|
133681
|
+
return {
|
|
133682
|
+
runStartRef,
|
|
133683
|
+
changedFiles: [],
|
|
133684
|
+
reviewerResults: reviewers.map((reviewer) => ({
|
|
133685
|
+
name: reviewer.name,
|
|
133686
|
+
passed: false,
|
|
133687
|
+
output: "",
|
|
133688
|
+
error: changedFilesResult.error
|
|
133689
|
+
})),
|
|
133690
|
+
anyFailed: true
|
|
133691
|
+
};
|
|
133692
|
+
}
|
|
133354
133693
|
const ignoreMatchers = naxIgnoreIndex?.getMatchers() ?? await resolveNaxIgnorePatterns(workdir);
|
|
133355
|
-
const changedFiles = filterNaxInternalPaths(
|
|
133694
|
+
const changedFiles = filterNaxInternalPaths(changedFilesResult.files, ignoreMatchers);
|
|
133356
133695
|
const reviewerResults = [];
|
|
133357
133696
|
let anyFailed = false;
|
|
133358
133697
|
for (const reviewer of reviewers) {
|
|
@@ -140264,7 +140603,7 @@ var init_yoga_wasm_base64_esm = __esm(() => {
|
|
|
140264
140603
|
});
|
|
140265
140604
|
|
|
140266
140605
|
// ../../node_modules/.bun/yoga-layout@3.2.1/node_modules/yoga-layout/dist/src/generated/YGEnums.js
|
|
140267
|
-
var Align, BoxSizing, Dimension, Direction, Display, Edge, Errata, ExperimentalFeature, FlexDirection, Gutter, Justify, LogLevel, MeasureMode, NodeType, Overflow, PositionType, Unit, Wrap,
|
|
140606
|
+
var Align, BoxSizing, Dimension, Direction, Display, Edge, Errata, ExperimentalFeature, FlexDirection, Gutter, Justify, LogLevel, MeasureMode, NodeType, Overflow, PositionType, Unit, Wrap, constants11, YGEnums_default;
|
|
140268
140607
|
var init_YGEnums = __esm(() => {
|
|
140269
140608
|
Align = /* @__PURE__ */ function(Align) {
|
|
140270
140609
|
Align[Align["Auto"] = 0] = "Auto";
|
|
@@ -140392,7 +140731,7 @@ var init_YGEnums = __esm(() => {
|
|
|
140392
140731
|
Wrap[Wrap["WrapReverse"] = 2] = "WrapReverse";
|
|
140393
140732
|
return Wrap;
|
|
140394
140733
|
}({});
|
|
140395
|
-
|
|
140734
|
+
constants11 = {
|
|
140396
140735
|
ALIGN_AUTO: Align.Auto,
|
|
140397
140736
|
ALIGN_FLEX_START: Align.FlexStart,
|
|
140398
140737
|
ALIGN_CENTER: Align.Center,
|
|
@@ -140466,7 +140805,7 @@ var init_YGEnums = __esm(() => {
|
|
|
140466
140805
|
WRAP_WRAP: Wrap.Wrap,
|
|
140467
140806
|
WRAP_WRAP_REVERSE: Wrap.WrapReverse
|
|
140468
140807
|
};
|
|
140469
|
-
YGEnums_default =
|
|
140808
|
+
YGEnums_default = constants11;
|
|
140470
140809
|
});
|
|
140471
140810
|
|
|
140472
140811
|
// ../../node_modules/.bun/yoga-layout@3.2.1/node_modules/yoga-layout/dist/src/wrapAssembly.js
|
|
@@ -168193,8 +168532,8 @@ async function loadGlobalConfig() {
|
|
|
168193
168532
|
const withGlobal = globalConf ? deepMergeConfig(defaults, globalConf) : defaults;
|
|
168194
168533
|
return localConf ? deepMergeConfig(withGlobal, localConf) : withGlobal;
|
|
168195
168534
|
}
|
|
168196
|
-
async function loadProjectConfig() {
|
|
168197
|
-
const projectDir = findProjectDir(process.cwd());
|
|
168535
|
+
async function loadProjectConfig(startDir) {
|
|
168536
|
+
const projectDir = findProjectDir(startDir ?? process.cwd());
|
|
168198
168537
|
if (!projectDir)
|
|
168199
168538
|
return null;
|
|
168200
168539
|
const projectPath = join185(projectDir, "config.json");
|
|
@@ -168363,9 +168702,9 @@ async function configCommand(config, options = {}) {
|
|
|
168363
168702
|
console.error("Error: --explain and --diff are mutually exclusive");
|
|
168364
168703
|
process.exit(1);
|
|
168365
168704
|
}
|
|
168366
|
-
const sources = determineConfigSources();
|
|
168705
|
+
const sources = determineConfigSources(options.dir);
|
|
168367
168706
|
if (diff) {
|
|
168368
|
-
const projectConf = await loadProjectConfig();
|
|
168707
|
+
const projectConf = await loadProjectConfig(options.dir);
|
|
168369
168708
|
if (!projectConf) {
|
|
168370
168709
|
console.log("No project config found \u2014 using global defaults");
|
|
168371
168710
|
return;
|
|
@@ -168612,6 +168951,22 @@ var init_config3 = __esm(() => {
|
|
|
168612
168951
|
init_config_profile();
|
|
168613
168952
|
});
|
|
168614
168953
|
|
|
168954
|
+
// src/cli/config-display-action.ts
|
|
168955
|
+
async function configDisplayAction(options) {
|
|
168956
|
+
const projectDir = findProjectDir(options.dir);
|
|
168957
|
+
const config = await loadConfig(projectDir ?? options.dir, { profile: options.profile });
|
|
168958
|
+
await configCommand(config, {
|
|
168959
|
+
explain: options.explain,
|
|
168960
|
+
diff: options.diff,
|
|
168961
|
+
profile: options.profile,
|
|
168962
|
+
dir: options.dir
|
|
168963
|
+
});
|
|
168964
|
+
}
|
|
168965
|
+
var init_config_display_action = __esm(() => {
|
|
168966
|
+
init_config();
|
|
168967
|
+
init_config3();
|
|
168968
|
+
});
|
|
168969
|
+
|
|
168615
168970
|
// src/context/engine/effectiveness-eval.ts
|
|
168616
168971
|
function loadLabelSet(json) {
|
|
168617
168972
|
let parsed;
|
|
@@ -169127,7 +169482,7 @@ var init_context_fragments = __esm(() => {
|
|
|
169127
169482
|
});
|
|
169128
169483
|
|
|
169129
169484
|
// src/cli/cost-ledger-query.ts
|
|
169130
|
-
import { readdir as readdir17, stat as
|
|
169485
|
+
import { readdir as readdir17, stat as stat21 } from "fs/promises";
|
|
169131
169486
|
import { basename as basename35, dirname as dirname53, join as join189 } from "path";
|
|
169132
169487
|
function errorCode3(err) {
|
|
169133
169488
|
return typeof err === "object" && err !== null ? Reflect.get(err, "code") : undefined;
|
|
@@ -169151,7 +169506,7 @@ async function readEntries(dir) {
|
|
|
169151
169506
|
}
|
|
169152
169507
|
async function isDirectory2(path) {
|
|
169153
169508
|
try {
|
|
169154
|
-
return (await
|
|
169509
|
+
return (await stat21(path)).isDirectory();
|
|
169155
169510
|
} catch (err) {
|
|
169156
169511
|
if (isAbsentOrNotDir(err))
|
|
169157
169512
|
return false;
|
|
@@ -170967,7 +171322,7 @@ function validateProjectName(name) {
|
|
|
170967
171322
|
valid: false,
|
|
170968
171323
|
error: "name must contain only lowercase letters, digits, hyphens, and underscores"
|
|
170969
171324
|
};
|
|
170970
|
-
if (
|
|
171325
|
+
if (RESERVED_PROJECT_NAMES.includes(name))
|
|
170971
171326
|
return { valid: false, error: `name '${name}' is reserved` };
|
|
170972
171327
|
if (name.startsWith(".") || name.startsWith("_"))
|
|
170973
171328
|
return { valid: false, error: "name must not start with '.' or '_'" };
|
|
@@ -173349,7 +173704,7 @@ function classifyPattern(normalizedPattern) {
|
|
|
173349
173704
|
const segments = normalizedPattern.split("/");
|
|
173350
173705
|
const literal = [];
|
|
173351
173706
|
for (const segment of segments) {
|
|
173352
|
-
if (/[*?]/.test(segment))
|
|
173707
|
+
if (/[*?{]/.test(segment))
|
|
173353
173708
|
break;
|
|
173354
173709
|
literal.push(segment);
|
|
173355
173710
|
}
|
|
@@ -174053,7 +174408,7 @@ var init_runs = __esm(() => {
|
|
|
174053
174408
|
|
|
174054
174409
|
// src/cli/sandbox-exec.ts
|
|
174055
174410
|
import { randomUUID as randomUUID25 } from "crypto";
|
|
174056
|
-
import { constants as
|
|
174411
|
+
import { constants as constants12 } from "os";
|
|
174057
174412
|
function childEnv(file) {
|
|
174058
174413
|
const env = Object.fromEntries(Object.entries(_sandboxExecDeps.env()).filter((entry) => entry[1] !== undefined && !file.stripEnv.includes(entry[0])));
|
|
174059
174414
|
if (file.home !== undefined)
|
|
@@ -174068,7 +174423,7 @@ async function runChild(argv, opts, backend) {
|
|
|
174068
174423
|
_sandboxExecDeps.onSignal("SIGINT", interrupt);
|
|
174069
174424
|
_sandboxExecDeps.onSignal("SIGTERM", terminate);
|
|
174070
174425
|
const result = await child.exited;
|
|
174071
|
-
return result.signal ? SIGNAL_EXIT_BASE + (
|
|
174426
|
+
return result.signal ? SIGNAL_EXIT_BASE + (constants12.signals[result.signal] ?? 0) : result.exitCode ?? REFUSED_EXIT;
|
|
174072
174427
|
} finally {
|
|
174073
174428
|
process.removeListener("SIGINT", interrupt);
|
|
174074
174429
|
process.removeListener("SIGTERM", terminate);
|
|
@@ -176122,6 +176477,7 @@ var init_cli2 = __esm(async () => {
|
|
|
176122
176477
|
init_bot2();
|
|
176123
176478
|
init_config3();
|
|
176124
176479
|
init_config_descriptions();
|
|
176480
|
+
init_config_display_action();
|
|
176125
176481
|
init_confirm();
|
|
176126
176482
|
init_context3();
|
|
176127
176483
|
init_context_fragments();
|
|
@@ -180505,6 +180861,10 @@ function parseRunPreconditionFlags(options) {
|
|
|
180505
180861
|
console.error(source_default.red("nax run --no-batch was removed: workflow mode runs stories one at a time"));
|
|
180506
180862
|
process.exit(1);
|
|
180507
180863
|
}
|
|
180864
|
+
if (options.context === false) {
|
|
180865
|
+
console.error(source_default.red("nax run --no-context was removed: workflow mode builds each prompt's context itself"));
|
|
180866
|
+
process.exit(1);
|
|
180867
|
+
}
|
|
180508
180868
|
const chatAsksFlag = parseChatAsksFlag(options.chatAsks);
|
|
180509
180869
|
if (!chatAsksFlag.ok) {
|
|
180510
180870
|
console.error(source_default.red(chatAsksFlag.message));
|
|
@@ -180895,7 +181255,7 @@ program2.command("setup").description("Analyze repo and generate .nax/config.jso
|
|
|
180895
181255
|
});
|
|
180896
181256
|
process.exit(exitCode);
|
|
180897
181257
|
});
|
|
180898
|
-
program2.command("run").description("Run the orchestration loop for a feature").requiredOption("-f, --feature <name>", "Feature name").option("-a, --agent <name>", "Force a specific agent").option("-m, --max-iterations <n>", "Removed: workflow mode sets its own limits").option("--max-cost <usd>", "Override cost limit (USD) for this run \u2014 aborts execution when exceeded").option("--dry-run", "Show plan without executing", false).option("--no-context", "
|
|
181258
|
+
program2.command("run").description("Run the orchestration loop for a feature").requiredOption("-f, --feature <name>", "Feature name").option("-a, --agent <name>", "Force a specific agent").option("-m, --max-iterations <n>", "Removed: workflow mode sets its own limits").option("--max-cost <usd>", "Override cost limit (USD) for this run \u2014 aborts execution when exceeded").option("--dry-run", "Show plan without executing", false).option("--no-context", "Removed: workflow mode builds its own prompt context").option("--rules-dir <path>", "Override rules directory (absolute, ~/\u2026 , or relative to the workdir)").option("--context-file <path>", "Project-context override file (absolute, ~/\u2026 , or relative to the workdir)").option("--no-batch", "Removed: workflow mode runs stories one at a time").option("--parallel <n>", "Removed: workflow mode sets its own limits").option("--plan", "Run plan phase first before execution", false).option("--from <spec-path>", "Path to spec file (required when --plan is used)").option("--no-spec-lint", "Plan even when the spec declares sections that extract to nothing").option("--one-shot", "Skip interactive planning Q&A, use single LLM call (ACP only)", false).option("--force", "Force overwrite existing prd.json when using --plan", false).option("--headless", "Force headless mode (disable TUI, use pipe mode)", false).addOption(new Option2("--chat-asks <dir>").hideHelp()).option("--verbose", "Enable verbose logging (debug level)", false).option("--quiet", "Quiet mode (warnings and errors only)", false).option("--silent", "Silent mode (errors only)", false).option("--json", "JSON mode (raw JSONL output to stdout)", false).option("-d, --dir <path>", "Working directory", process.cwd()).option("--skip-precheck", "Skip precheck validations (advanced users only)", false).option("--profile <name>", "Profile(s) to overlay (comma-separated or repeated; later overrides earlier)", collectProfile2, []).option("--schedule <when>", "Defer run start until <when> (e.g. 30m, 1h30m, 17:00, 2026-07-02T02:00)").option("--compare <agents>", "Bake-off mode: comma-separated list of contestant agents (e.g. claude,codex)").option("--publish-only", "Rerun only the workflow's publish step for a finished feature that has no PR (needs every story passed)", false).option("--fresh", "Ignore any existing checkpoint.jsonl and re-run every incomplete story from scratch", false).addOption(new Option2("--no-resume", "Alias for --fresh: never auto-resume from a prior checkpoint").default("__UNSET__")).action(async (options) => {
|
|
180899
181259
|
const workdir = resolveRunWorkdir(options);
|
|
180900
181260
|
const { chatAsksDir } = parseRunPreconditionFlags(options);
|
|
180901
181261
|
await validateBakeoffPreflight(options, workdir);
|
|
@@ -181311,9 +181671,8 @@ var configCmd = program2.command("config").description("Display effective merged
|
|
|
181311
181671
|
return;
|
|
181312
181672
|
}
|
|
181313
181673
|
try {
|
|
181314
|
-
|
|
181315
|
-
|
|
181316
|
-
await configCommand(config, {
|
|
181674
|
+
await configDisplayAction({
|
|
181675
|
+
dir: workdir,
|
|
181317
181676
|
explain: options.explain,
|
|
181318
181677
|
diff: options.diff,
|
|
181319
181678
|
profile: options.profile
|