@nathapp/nax 0.91.8-canary.2 → 0.91.8-canary.3
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 +1266 -568
- package/package.json +2 -2
package/dist/nax.js
CHANGED
|
@@ -3055,7 +3055,7 @@ function killProcessGroup(pid, signal, opts = {}) {
|
|
|
3055
3055
|
function memoryNoteKey(scope, slug) {
|
|
3056
3056
|
return `${scope}/${slug}`;
|
|
3057
3057
|
}
|
|
3058
|
-
var MEMORY_NOTE_TYPES, MEMORY_SCOPES, MEMORY_NOTE_STATUSES, MEMORY_DECISION_STATUSES, MEMORY_SLUG_RE, MEMORY_CLIENT_ID_RE, MEMORY_NOTE_BODY_MAX_BYTES = 8192, MEMORY_DESCRIPTION_MAX_CHARS = 200, MEMORY_SOURCE_MAX_CHARS = 64, MEMORY_FORGET_REASON_MAX_CHARS = 200, MEMORY_INDEX_MAX_BYTES = 24576, MEMORY_INDEX_MAX_LINES = 200, MEMORY_INDEX_MIN_LINES = 16, MEMORY_INDEX_MIN_BYTES = 512, MEMORY_PROBE_TIMEOUT_MS = 2000, MEMORY_OP_TIMEOUT_MS = 1e4, MEMORY_PULL_PAGE_SIZE = 200, MEMORY_PULL_MAX_PAGES = 50;
|
|
3058
|
+
var MEMORY_NOTE_TYPES, MEMORY_SCOPES, MEMORY_NOTE_STATUSES, MEMORY_DECISION_STATUSES, MEMORY_SLUG_RE, MEMORY_CLIENT_ID_RE, MEMORY_NOTE_BODY_MAX_BYTES = 8192, MEMORY_DESCRIPTION_MAX_CHARS = 200, MEMORY_SOURCE_MAX_CHARS = 64, MEMORY_FORGET_REASON_MAX_CHARS = 200, MEMORY_INDEX_MAX_BYTES = 24576, MEMORY_INDEX_MAX_LINES = 200, MEMORY_INDEX_MIN_LINES = 16, MEMORY_INDEX_MIN_BYTES = 512, MEMORY_PROBE_TIMEOUT_MS = 2000, MEMORY_OP_TIMEOUT_MS = 1e4, MEMORY_PULL_PAGE_SIZE = 200, MEMORY_PULL_MAX_PAGES = 50, MEMORY_PUSH_MAX_BAD_RESPONSES = 3;
|
|
3059
3059
|
var init_types2 = __esm(() => {
|
|
3060
3060
|
MEMORY_NOTE_TYPES = ["user", "feedback", "project", "reference"];
|
|
3061
3061
|
MEMORY_SCOPES = ["project", "user"];
|
|
@@ -9666,7 +9666,10 @@ ${note.body}`;
|
|
|
9666
9666
|
function isMemoryPushRejected(error) {
|
|
9667
9667
|
return error instanceof NaxError && error.code === "MEMORY_PUSH_REJECTED";
|
|
9668
9668
|
}
|
|
9669
|
-
|
|
9669
|
+
function isMemoryBadResponse(error) {
|
|
9670
|
+
return error instanceof NaxError && error.code.endsWith(BAD_RESPONSE_CODE_SUFFIX);
|
|
9671
|
+
}
|
|
9672
|
+
var ERROR_STAGE2 = "memory", FRONTMATTER_FENCE = "---", FENCE_LINE, BLANK_LINE, LINE_BREAK, NOTE_KEYS, NOTE_KEY_SET, NoteSchema, BAD_RESPONSE_CODE_SUFFIX = "_BAD_RESPONSE";
|
|
9670
9673
|
var init_note = __esm(() => {
|
|
9671
9674
|
init_zod();
|
|
9672
9675
|
init_nax_error();
|
|
@@ -10977,6 +10980,10 @@ function toRejected(entry, rejectionReason) {
|
|
|
10977
10980
|
reason: rejectionReason
|
|
10978
10981
|
};
|
|
10979
10982
|
}
|
|
10983
|
+
function toQueued(entry) {
|
|
10984
|
+
const { reason: _rejection, requestReason, badResponses: _count, lastError: _last, ...rest } = entry;
|
|
10985
|
+
return { ...rest, ...requestReason === undefined ? {} : { reason: requestReason }, state: "queued" };
|
|
10986
|
+
}
|
|
10980
10987
|
function createMemoryOutbox(input) {
|
|
10981
10988
|
const { dir } = input;
|
|
10982
10989
|
const now = input.now ?? (() => new Date);
|
|
@@ -11076,6 +11083,31 @@ function createMemoryOutbox(input) {
|
|
|
11076
11083
|
`);
|
|
11077
11084
|
}
|
|
11078
11085
|
}
|
|
11086
|
+
async function recordBadResponse(clientId, error) {
|
|
11087
|
+
let count = 0;
|
|
11088
|
+
for (const file of await filesFor(clientId)) {
|
|
11089
|
+
const entry = await readEntry(file);
|
|
11090
|
+
if (entry === null)
|
|
11091
|
+
continue;
|
|
11092
|
+
count = (entry.badResponses ?? 0) + 1;
|
|
11093
|
+
const counted = { ...entry, badResponses: count, lastError: error };
|
|
11094
|
+
await writeFileAtomic(join12(dir, file.name), `${JSON.stringify(counted)}
|
|
11095
|
+
`);
|
|
11096
|
+
}
|
|
11097
|
+
return count;
|
|
11098
|
+
}
|
|
11099
|
+
async function requeue(clientId) {
|
|
11100
|
+
let requeued = false;
|
|
11101
|
+
for (const file of await filesFor(clientId)) {
|
|
11102
|
+
const entry = await readEntry(file);
|
|
11103
|
+
if (entry === null || entry.state !== "rejected")
|
|
11104
|
+
continue;
|
|
11105
|
+
await writeFileAtomic(join12(dir, file.name), `${JSON.stringify(toQueued(entry))}
|
|
11106
|
+
`);
|
|
11107
|
+
requeued = true;
|
|
11108
|
+
}
|
|
11109
|
+
return requeued;
|
|
11110
|
+
}
|
|
11079
11111
|
async function heldKeys(kind) {
|
|
11080
11112
|
const keys = new Set;
|
|
11081
11113
|
for (const entry of (await scan()).entries) {
|
|
@@ -11087,7 +11119,7 @@ function createMemoryOutbox(input) {
|
|
|
11087
11119
|
}
|
|
11088
11120
|
return keys;
|
|
11089
11121
|
}
|
|
11090
|
-
return { enqueue, list, listInvalid, remove, markRejected, heldKeys };
|
|
11122
|
+
return { enqueue, list, listInvalid, remove, markRejected, recordBadResponse, requeue, heldKeys };
|
|
11091
11123
|
}
|
|
11092
11124
|
var ERROR_STAGE5 = "memory", ENTRY_FILE_RE, ENTRY_SEQ_DIGITS = 8, ENTRY_SUFFIX = ".json", READ_FLAGS2, EntrySchema;
|
|
11093
11125
|
var init_outbox = __esm(() => {
|
|
@@ -11109,6 +11141,8 @@ var init_outbox = __esm(() => {
|
|
|
11109
11141
|
note: unknown().optional(),
|
|
11110
11142
|
reason: string2().optional(),
|
|
11111
11143
|
requestReason: string2().optional(),
|
|
11144
|
+
badResponses: number2().int().positive().optional(),
|
|
11145
|
+
lastError: string2().optional(),
|
|
11112
11146
|
seq: number2().int().positive(),
|
|
11113
11147
|
enqueuedAt: string2().min(1),
|
|
11114
11148
|
state: _enum(["queued", "rejected"])
|
|
@@ -11457,27 +11491,7 @@ async function applyPushed(input, entry, answer) {
|
|
|
11457
11491
|
await input.store.writeNote({ ...base, id: answer.id, status: answer.status });
|
|
11458
11492
|
}
|
|
11459
11493
|
|
|
11460
|
-
// ../nax-agent/src/memory/sync.ts
|
|
11461
|
-
function noCounts() {
|
|
11462
|
-
return { pushed: 0, rejected: 0, pulled: 0, skipped: 0 };
|
|
11463
|
-
}
|
|
11464
|
-
function stopped(outcome, error) {
|
|
11465
|
-
return { outcome, ...noCounts(), ...error === undefined ? {} : { error } };
|
|
11466
|
-
}
|
|
11467
|
-
function clockOf2(input) {
|
|
11468
|
-
return input.now ?? (() => new Date);
|
|
11469
|
-
}
|
|
11470
|
-
async function takeLock(input) {
|
|
11471
|
-
return await acquireMirrorLocks(input, storeLockTargets(input.store));
|
|
11472
|
-
}
|
|
11473
|
-
async function recordUnreachable(input) {
|
|
11474
|
-
await recordLastError(input, UNREACHABLE);
|
|
11475
|
-
return stopped("unreachable");
|
|
11476
|
-
}
|
|
11477
|
-
async function recordLastError(input, message) {
|
|
11478
|
-
const state = await input.store.readSyncState();
|
|
11479
|
-
await input.store.writeSyncState({ ...state, lastError: message });
|
|
11480
|
-
}
|
|
11494
|
+
// ../nax-agent/src/memory/sync-drain.ts
|
|
11481
11495
|
function requestOf(entry) {
|
|
11482
11496
|
return {
|
|
11483
11497
|
kind: entry.kind,
|
|
@@ -11495,29 +11509,120 @@ async function pushEntry(input, entry, timers) {
|
|
|
11495
11509
|
return { kind: "pushed", result: await raceTimeout(pushed, MEMORY_OP_TIMEOUT_MS, timers) };
|
|
11496
11510
|
} catch (error) {
|
|
11497
11511
|
const reason = errorMessage(error);
|
|
11498
|
-
|
|
11512
|
+
if (isMemoryPushRejected(error))
|
|
11513
|
+
return { kind: "rejected", reason };
|
|
11514
|
+
return { kind: "failed", reason, badResponse: isMemoryBadResponse(error) };
|
|
11515
|
+
}
|
|
11516
|
+
}
|
|
11517
|
+
function entryKey(entry) {
|
|
11518
|
+
return `${entry.scope}/${entry.slug}`;
|
|
11519
|
+
}
|
|
11520
|
+
async function settle2(input, entry, outcome, tally) {
|
|
11521
|
+
if (outcome.kind === "rejected") {
|
|
11522
|
+
await input.outbox.markRejected(entry.clientId, outcome.reason);
|
|
11523
|
+
return { ...tally, rejected: tally.rejected + 1 };
|
|
11524
|
+
}
|
|
11525
|
+
await applyPushed(input, entry, outcome.result);
|
|
11526
|
+
await input.outbox.remove(entry.clientId);
|
|
11527
|
+
await dropSuperseded(input.outbox, entry);
|
|
11528
|
+
return { ...tally, pushed: tally.pushed + 1 };
|
|
11529
|
+
}
|
|
11530
|
+
async function dropSuperseded(outbox, delivered) {
|
|
11531
|
+
const key = entryKey(delivered);
|
|
11532
|
+
for (const entry of await outbox.list()) {
|
|
11533
|
+
if (entry.state === "rejected" && entryKey(entry) === key && entry.seq < delivered.seq) {
|
|
11534
|
+
await outbox.remove(entry.clientId);
|
|
11535
|
+
}
|
|
11499
11536
|
}
|
|
11500
11537
|
}
|
|
11538
|
+
async function rewindPullCursor(store, scope) {
|
|
11539
|
+
const state = await store.readSyncState();
|
|
11540
|
+
const cursor = scope === "user" ? { ...state.cursor, user: null } : { ...state.cursor, project: null };
|
|
11541
|
+
await store.writeSyncState({ ...state, cursor });
|
|
11542
|
+
}
|
|
11501
11543
|
async function drainOutbox(input) {
|
|
11502
11544
|
const timers = input.timers ?? GLOBAL_MEMORY_TIMERS;
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11545
|
+
const queue = (await input.outbox.list()).filter((entry) => entry.state === "queued");
|
|
11546
|
+
const proven = new Set;
|
|
11547
|
+
let tally = { pushed: 0, rejected: 0, parked: [] };
|
|
11548
|
+
for (const [index, entry] of queue.entries()) {
|
|
11549
|
+
if (proven.has(entry.clientId))
|
|
11507
11550
|
continue;
|
|
11508
11551
|
const outcome = await pushEntry(input, entry, timers);
|
|
11509
|
-
if (outcome.kind
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
}
|
|
11520
|
-
return
|
|
11552
|
+
if (outcome.kind !== "failed") {
|
|
11553
|
+
tally = await settle2(input, entry, outcome, tally);
|
|
11554
|
+
continue;
|
|
11555
|
+
}
|
|
11556
|
+
const candidate = { head: entry, rest: queue.slice(index + 1), proven, error: outcome.reason, timers };
|
|
11557
|
+
const proof = outcome.badResponse ? await proveAndPark(input, candidate, tally) : { kind: "stopped", answered: false };
|
|
11558
|
+
if (proof.kind === "stopped")
|
|
11559
|
+
return { ...tally, failure: outcome.reason, ...proof.answered ? { answered: true } : {} };
|
|
11560
|
+
proven.add(proof.clientId);
|
|
11561
|
+
tally = proof.tally;
|
|
11562
|
+
}
|
|
11563
|
+
return tally;
|
|
11564
|
+
}
|
|
11565
|
+
async function proveAndPark(input, candidate, tally) {
|
|
11566
|
+
const { head, rest, proven, error, timers } = candidate;
|
|
11567
|
+
const count = await input.outbox.recordBadResponse(head.clientId, error);
|
|
11568
|
+
if (count < MEMORY_PUSH_MAX_BAD_RESPONSES)
|
|
11569
|
+
return { kind: "stopped", answered: true };
|
|
11570
|
+
const proof = rest.find((entry) => !proven.has(entry.clientId) && entryKey(entry) !== entryKey(head));
|
|
11571
|
+
if (proof === undefined)
|
|
11572
|
+
return { kind: "stopped", answered: true };
|
|
11573
|
+
const outcome = await pushEntry(input, proof, timers);
|
|
11574
|
+
if (outcome.kind === "failed")
|
|
11575
|
+
return { kind: "stopped", answered: outcome.badResponse };
|
|
11576
|
+
const settled = await settle2(input, proof, outcome, tally);
|
|
11577
|
+
const parked = await park(input, head, `parked after ${count} bad responses: ${error}`);
|
|
11578
|
+
return {
|
|
11579
|
+
kind: "parked",
|
|
11580
|
+
clientId: proof.clientId,
|
|
11581
|
+
tally: { ...settled, rejected: settled.rejected + 1, parked: [...settled.parked, parked] }
|
|
11582
|
+
};
|
|
11583
|
+
}
|
|
11584
|
+
async function park(input, entry, reason) {
|
|
11585
|
+
await input.outbox.markRejected(entry.clientId, reason);
|
|
11586
|
+
await rewindPullCursor(input.store, entry.scope);
|
|
11587
|
+
const { clientId, kind, scope, slug } = entry;
|
|
11588
|
+
warnQuietly(input.logger, "memory sync parked an outbox entry the provider keeps answering badly", {
|
|
11589
|
+
clientId,
|
|
11590
|
+
kind,
|
|
11591
|
+
scope,
|
|
11592
|
+
slug,
|
|
11593
|
+
error: reason
|
|
11594
|
+
});
|
|
11595
|
+
return { clientId, kind, scope, slug, reason };
|
|
11596
|
+
}
|
|
11597
|
+
var init_sync_drain = __esm(() => {
|
|
11598
|
+
init_note();
|
|
11599
|
+
init_support();
|
|
11600
|
+
init_types2();
|
|
11601
|
+
});
|
|
11602
|
+
|
|
11603
|
+
// ../nax-agent/src/memory/sync.ts
|
|
11604
|
+
function noCounts() {
|
|
11605
|
+
return { pushed: 0, rejected: 0, pulled: 0, skipped: 0 };
|
|
11606
|
+
}
|
|
11607
|
+
function parkedField(parked) {
|
|
11608
|
+
return parked.length === 0 ? {} : { parked };
|
|
11609
|
+
}
|
|
11610
|
+
function stopped(outcome, error) {
|
|
11611
|
+
return { outcome, ...noCounts(), ...error === undefined ? {} : { error } };
|
|
11612
|
+
}
|
|
11613
|
+
function clockOf2(input) {
|
|
11614
|
+
return input.now ?? (() => new Date);
|
|
11615
|
+
}
|
|
11616
|
+
async function takeLock(input) {
|
|
11617
|
+
return await acquireMirrorLocks(input, storeLockTargets(input.store));
|
|
11618
|
+
}
|
|
11619
|
+
async function recordUnreachable(input) {
|
|
11620
|
+
await recordLastError(input, UNREACHABLE);
|
|
11621
|
+
return stopped("unreachable");
|
|
11622
|
+
}
|
|
11623
|
+
async function recordLastError(input, message) {
|
|
11624
|
+
const state = await input.store.readSyncState();
|
|
11625
|
+
await input.store.writeSyncState({ ...state, lastError: message });
|
|
11521
11626
|
}
|
|
11522
11627
|
function cursorWith(cursor, scope, next) {
|
|
11523
11628
|
return scope === "user" ? { ...cursor, user: next } : { ...cursor, project: next };
|
|
@@ -11612,14 +11717,19 @@ async function pullAll(input) {
|
|
|
11612
11717
|
}
|
|
11613
11718
|
return { pulled, skipped };
|
|
11614
11719
|
}
|
|
11615
|
-
async function failRun(input, counts, failure) {
|
|
11720
|
+
async function failRun(input, counts, parked, failure) {
|
|
11616
11721
|
await recordLastError(input, failure);
|
|
11617
|
-
return await finish(input, counts, failure);
|
|
11722
|
+
return await finish(input, counts, parked, failure);
|
|
11618
11723
|
}
|
|
11619
|
-
async function finish(input, counts, failure) {
|
|
11724
|
+
async function finish(input, counts, parked, failure) {
|
|
11620
11725
|
const heldForgets = await input.outbox.heldKeys("forget");
|
|
11621
11726
|
await refreshMemoryIndex(input.store, { heldForgets });
|
|
11622
|
-
|
|
11727
|
+
const outcome = failure === undefined ? { outcome: "synced" } : { outcome: "failed", error: failure };
|
|
11728
|
+
return { ...outcome, ...counts, ...parkedField(parked) };
|
|
11729
|
+
}
|
|
11730
|
+
function joinFailures(...failures) {
|
|
11731
|
+
const met = failures.filter((failure) => failure !== undefined);
|
|
11732
|
+
return met.length === 0 ? undefined : met.join("; ");
|
|
11623
11733
|
}
|
|
11624
11734
|
async function releaseQuietly(input, release) {
|
|
11625
11735
|
try {
|
|
@@ -11656,14 +11766,16 @@ async function syncMemory(input) {
|
|
|
11656
11766
|
return await recordUnreachable(input);
|
|
11657
11767
|
const drain = await drainOutbox(input);
|
|
11658
11768
|
const counts = { ...noCounts(), pushed: drain.pushed, rejected: drain.rejected };
|
|
11659
|
-
if (drain.failure !== undefined)
|
|
11660
|
-
return await failRun(input, counts, drain.failure);
|
|
11769
|
+
if (drain.failure !== undefined && drain.answered !== true) {
|
|
11770
|
+
return await failRun(input, counts, drain.parked, drain.failure);
|
|
11771
|
+
}
|
|
11661
11772
|
const pull = await pullAll(input);
|
|
11662
11773
|
counts.pulled = pull.pulled;
|
|
11663
11774
|
counts.skipped = pull.skipped;
|
|
11664
|
-
|
|
11665
|
-
|
|
11666
|
-
|
|
11775
|
+
const failure = joinFailures(drain.failure, pull.failure);
|
|
11776
|
+
if (failure !== undefined)
|
|
11777
|
+
return await failRun(input, counts, drain.parked, failure);
|
|
11778
|
+
return await finish(input, counts, drain.parked);
|
|
11667
11779
|
} catch (error) {
|
|
11668
11780
|
const message = errorMessage(error);
|
|
11669
11781
|
warnQuietly(input.logger, "memory sync failed", { path: lock, error: message });
|
|
@@ -11682,6 +11794,7 @@ var init_sync = __esm(() => {
|
|
|
11682
11794
|
init_mirror_lock();
|
|
11683
11795
|
init_note();
|
|
11684
11796
|
init_support();
|
|
11797
|
+
init_sync_drain();
|
|
11685
11798
|
init_sync_flight();
|
|
11686
11799
|
init_types2();
|
|
11687
11800
|
TOMBSTONES = new Set(["superseded", "rejected", "deleted"]);
|
|
@@ -15085,6 +15198,25 @@ var init_turn_compaction_step = __esm(() => {
|
|
|
15085
15198
|
});
|
|
15086
15199
|
|
|
15087
15200
|
// ../nax-agent/src/native/session/manual-compaction.ts
|
|
15201
|
+
function manualKeepTokens(messages, keepTurns) {
|
|
15202
|
+
let seen = 0;
|
|
15203
|
+
let start = 0;
|
|
15204
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
15205
|
+
const message = messages[i];
|
|
15206
|
+
if (message === undefined || message.role !== "user" || message.content.startsWith(COMPACTION_SUMMARY_PREFIX)) {
|
|
15207
|
+
continue;
|
|
15208
|
+
}
|
|
15209
|
+
seen++;
|
|
15210
|
+
if (seen === keepTurns) {
|
|
15211
|
+
start = i;
|
|
15212
|
+
break;
|
|
15213
|
+
}
|
|
15214
|
+
}
|
|
15215
|
+
let total = 0;
|
|
15216
|
+
for (const message of messages.slice(start))
|
|
15217
|
+
total += estimateTokens(message);
|
|
15218
|
+
return total;
|
|
15219
|
+
}
|
|
15088
15220
|
function applyManualCompaction(messages, plan, summary) {
|
|
15089
15221
|
return [summaryMessage(summary), ...messages.slice(plan.cutIndex)];
|
|
15090
15222
|
}
|
|
@@ -15100,9 +15232,8 @@ async function compactHistory(request) {
|
|
|
15100
15232
|
const messages = [...historyFromTranscript(await transcript.store.load(handle.id), identity, handle.id)];
|
|
15101
15233
|
const tokensBefore = estimateContextTokens(messages, undefined, undefined);
|
|
15102
15234
|
const resolution = await resolveSessionModel(client, state, handle);
|
|
15103
|
-
const
|
|
15104
|
-
|
|
15105
|
-
});
|
|
15235
|
+
const keep = Math.min(keepBudget(resolution.contextWindow, resolution.compaction), manualKeepTokens(messages, MANUAL_KEEP_TURNS));
|
|
15236
|
+
const plan = prepareCompaction(messages, keep, { pinFirstMessage: false });
|
|
15106
15237
|
if (plan === undefined) {
|
|
15107
15238
|
return { compacted: false, tokensBefore, tokensAfter: tokensBefore, usage: ZERO_USAGE, costUsd: 0 };
|
|
15108
15239
|
}
|
|
@@ -15122,7 +15253,7 @@ async function compactHistory(request) {
|
|
|
15122
15253
|
costUsd: applied.summary.costUsd
|
|
15123
15254
|
};
|
|
15124
15255
|
}
|
|
15125
|
-
var ZERO_USAGE;
|
|
15256
|
+
var MANUAL_KEEP_TURNS = 1, ZERO_USAGE;
|
|
15126
15257
|
var init_manual_compaction = __esm(() => {
|
|
15127
15258
|
init_infra();
|
|
15128
15259
|
init_compaction();
|
|
@@ -22698,11 +22829,25 @@ function registerBuiltinLoopHandlers(registry, deps) {
|
|
|
22698
22829
|
turnStateByRegistry.set(registry, state);
|
|
22699
22830
|
registry.register("before_tool", ({ call, tools }) => repairInvalidCall(state, call, tools));
|
|
22700
22831
|
registry.register("before_tool", ({ call }) => observeSpin(state, call));
|
|
22832
|
+
registry.register("before_turn_end", (payload) => unreadToolCallFollowUp(state, payload));
|
|
22701
22833
|
for (const entry of deps.loopHandlers ?? []) {
|
|
22702
22834
|
registry.register(entry.event, wrapExternalHandler(entry, () => contextFor(state), turnSignalView(state)));
|
|
22703
22835
|
}
|
|
22704
22836
|
registry.register("after_tool", (payload) => createTruncationHandler(state.current.sessionState, state.current.sessionName)(payload));
|
|
22705
22837
|
}
|
|
22838
|
+
function unreadToolCallFollowUp(state, payload) {
|
|
22839
|
+
const { unreadToolCall, toolNames } = state.current;
|
|
22840
|
+
if (payload.ended !== "completed" || payload.stopped || unreadToolCall.sent)
|
|
22841
|
+
return {};
|
|
22842
|
+
const last = payload.messages.at(-1);
|
|
22843
|
+
if (last?.role !== "assistant" || !last.content.includes(TOOL_CALL_MARKER))
|
|
22844
|
+
return {};
|
|
22845
|
+
unreadToolCall.sent = true;
|
|
22846
|
+
const names = toolNames();
|
|
22847
|
+
return {
|
|
22848
|
+
followUp: `Your reply contains a ${TOOL_CALL_MARKER} block that was not run: it did not read as a call of a declared tool. Call tools through the tool interface, using one of these exact names: ${names.length > 0 ? names.join(", ") : "(none)"}.`
|
|
22849
|
+
};
|
|
22850
|
+
}
|
|
22706
22851
|
function repairInvalidCall(state, call, tools) {
|
|
22707
22852
|
const invalid = state.current.budget.observe(call, tools);
|
|
22708
22853
|
if (invalid === undefined) {
|
|
@@ -22727,7 +22872,7 @@ function observeSpin(state, call) {
|
|
|
22727
22872
|
return { kind: "nudge", text: verdict.text };
|
|
22728
22873
|
return { kind: "allow" };
|
|
22729
22874
|
}
|
|
22730
|
-
var NEVER_ABORTED, turnStateByRegistry;
|
|
22875
|
+
var NEVER_ABORTED, turnStateByRegistry, TOOL_CALL_MARKER = "<tool_call>";
|
|
22731
22876
|
var init_loop_handlers = __esm(() => {
|
|
22732
22877
|
init_spin_breaker();
|
|
22733
22878
|
init_handle_invalid_tool_call();
|
|
@@ -23638,11 +23783,14 @@ async function runNativeTurn(handle, prompt, opts, deps) {
|
|
|
23638
23783
|
];
|
|
23639
23784
|
const spinFlags = { stopped: false, warned: false };
|
|
23640
23785
|
const invalidCallBudget = createInvalidCallBudget();
|
|
23786
|
+
const unreadToolCall = { sent: false };
|
|
23641
23787
|
const loopEvents = deps.loopEvents ?? createLoopEventRegistry();
|
|
23642
23788
|
registerBuiltinLoopHandlers(loopEvents, {
|
|
23643
23789
|
sessionName: handle.id,
|
|
23644
23790
|
sessionState: deps.sessionState,
|
|
23645
23791
|
budget: invalidCallBudget,
|
|
23792
|
+
unreadToolCall,
|
|
23793
|
+
toolNames: () => tools.map((tool) => tool.name),
|
|
23646
23794
|
...deps.spinBreaker !== undefined ? { spinBreaker: deps.spinBreaker } : {},
|
|
23647
23795
|
...deps.loopHandlers !== undefined ? { loopHandlers: deps.loopHandlers } : {},
|
|
23648
23796
|
...deps.loopHandlerContext !== undefined ? { loopHandlerContext: deps.loopHandlerContext } : {},
|
|
@@ -23794,16 +23942,25 @@ var init_turn_loop = __esm(() => {
|
|
|
23794
23942
|
import {
|
|
23795
23943
|
collectStream
|
|
23796
23944
|
} from "@nathapp/nax-ai";
|
|
23797
|
-
function deltaOf(event) {
|
|
23945
|
+
function deltaOf(event, seen) {
|
|
23798
23946
|
if (event.type === "text-delta")
|
|
23799
23947
|
return { type: "text_delta", text: event.text };
|
|
23800
23948
|
if (event.type === "thinking-delta")
|
|
23801
23949
|
return { type: "thinking_delta", text: event.text };
|
|
23950
|
+
if (event.type === "tool-call-partial") {
|
|
23951
|
+
const length = event.rawInput.length;
|
|
23952
|
+
const previous = seen.get(event.id) ?? 0;
|
|
23953
|
+
if (length <= previous)
|
|
23954
|
+
return;
|
|
23955
|
+
seen.set(event.id, length);
|
|
23956
|
+
return { type: "tool_input_delta", callId: event.id, name: event.name, chars: length - previous };
|
|
23957
|
+
}
|
|
23802
23958
|
return;
|
|
23803
23959
|
}
|
|
23804
23960
|
async function* tap(events, onDelta) {
|
|
23961
|
+
const seen = new Map;
|
|
23805
23962
|
for await (const event of events) {
|
|
23806
|
-
const delta = deltaOf(event);
|
|
23963
|
+
const delta = deltaOf(event, seen);
|
|
23807
23964
|
if (delta !== undefined) {
|
|
23808
23965
|
try {
|
|
23809
23966
|
onDelta(delta);
|
|
@@ -24297,10 +24454,23 @@ var init_agent_session_resume = __esm(() => {
|
|
|
24297
24454
|
|
|
24298
24455
|
// ../nax-agent/src/session/session-event-channel.ts
|
|
24299
24456
|
function isDelta(event) {
|
|
24300
|
-
return event !== undefined && (event.type === "text_delta" || event.type === "thinking_delta");
|
|
24457
|
+
return event !== undefined && (event.type === "text_delta" || event.type === "thinking_delta" || event.type === "tool_input_delta");
|
|
24301
24458
|
}
|
|
24302
24459
|
function canMergeInto(into, next) {
|
|
24303
|
-
|
|
24460
|
+
if (into.type !== next.type || into.round !== next.round)
|
|
24461
|
+
return false;
|
|
24462
|
+
if (into.type === "tool_input_delta" && next.type === "tool_input_delta")
|
|
24463
|
+
return into.callId === next.callId;
|
|
24464
|
+
return true;
|
|
24465
|
+
}
|
|
24466
|
+
function mergeDeltas(into, next) {
|
|
24467
|
+
if (into.type === "tool_input_delta" && next.type === "tool_input_delta") {
|
|
24468
|
+
return { ...into, chars: into.chars + next.chars };
|
|
24469
|
+
}
|
|
24470
|
+
if (into.type !== "tool_input_delta" && next.type !== "tool_input_delta") {
|
|
24471
|
+
return { ...into, text: into.text + next.text };
|
|
24472
|
+
}
|
|
24473
|
+
return into;
|
|
24304
24474
|
}
|
|
24305
24475
|
function createSessionEventChannel(options) {
|
|
24306
24476
|
let queue = [];
|
|
@@ -24329,7 +24499,7 @@ function createSessionEventChannel(options) {
|
|
|
24329
24499
|
function enqueue(event) {
|
|
24330
24500
|
if (isDelta(event)) {
|
|
24331
24501
|
if (tail !== undefined && canMergeInto(tail, event)) {
|
|
24332
|
-
tail =
|
|
24502
|
+
tail = mergeDeltas(tail, event);
|
|
24333
24503
|
return;
|
|
24334
24504
|
}
|
|
24335
24505
|
if (tail !== undefined)
|
|
@@ -28709,6 +28879,7 @@ var init_internal = __esm(() => {
|
|
|
28709
28879
|
init_git_exec();
|
|
28710
28880
|
init_note();
|
|
28711
28881
|
init_store();
|
|
28882
|
+
init_sync_drain();
|
|
28712
28883
|
init_compaction_settings();
|
|
28713
28884
|
init_instruction_file_name();
|
|
28714
28885
|
init_repository_instructions();
|
|
@@ -32659,12 +32830,17 @@ var init_schemas_execution = __esm(() => {
|
|
|
32659
32830
|
});
|
|
32660
32831
|
|
|
32661
32832
|
// src/config/schemas-model-alias.ts
|
|
32662
|
-
|
|
32833
|
+
function isAliasTarget(value) {
|
|
32834
|
+
return value.startsWith(ACP_PREFIX) ? ACP_ALIAS_TARGET.test(value) : MODEL_ALIAS_TARGET.test(value);
|
|
32835
|
+
}
|
|
32836
|
+
var ACP_PREFIX = "acp:", MODEL_ALIAS_TARGET, ACP_ALIAS_TARGET, ALIAS_TARGET_MESSAGE = 'agent.modelAliases values must be "provider/model" or "acp:<agent>[/<model>]" (agent: claude, codex, cursor), each with an optional [effort] suffix and no whitespace', ModelAliasTargetSchema, ModelAliasesSchema, AcpSubagentsConfigSchema;
|
|
32663
32837
|
var init_schemas_model_alias = __esm(() => {
|
|
32664
32838
|
init_zod();
|
|
32665
32839
|
MODEL_ALIAS_TARGET = /^[^\s/[\]]+\/[^\s[\]]+(\[[^\s[\]]+\])?$/;
|
|
32666
|
-
|
|
32840
|
+
ACP_ALIAS_TARGET = /^acp:(claude|codex|cursor)(\/[^\s[\]]+)?(\[[^\s[\]]+\])?$/;
|
|
32841
|
+
ModelAliasTargetSchema = string2().refine(isAliasTarget, { message: ALIAS_TARGET_MESSAGE });
|
|
32667
32842
|
ModelAliasesSchema = record2(string2().trim().min(1, "agent.modelAliases keys must be non-empty"), ModelAliasTargetSchema);
|
|
32843
|
+
AcpSubagentsConfigSchema = object({ profile: _enum(["review", "read", "ask", "full"]).optional() }).strict();
|
|
32668
32844
|
});
|
|
32669
32845
|
|
|
32670
32846
|
// src/config/schemas-router.ts
|
|
@@ -32932,6 +33108,7 @@ var init_schemas_infra = __esm(() => {
|
|
|
32932
33108
|
default: string2().trim().min(1, "agent.default must be non-empty").default(DEFAULT_AGENT_NAME),
|
|
32933
33109
|
maxInteractionTurns: number2().int().min(1).max(100).default(20),
|
|
32934
33110
|
modelAliases: ModelAliasesSchema.default({}),
|
|
33111
|
+
acpSubagents: AcpSubagentsConfigSchema.optional(),
|
|
32935
33112
|
promptAudit: PromptAuditConfigSchema.default({ enabled: false }),
|
|
32936
33113
|
usageAudit: UsageAuditConfigSchema.default({ enabled: false }),
|
|
32937
33114
|
transcriptAudit: TranscriptAuditConfigSchema.default({ enabled: false, maxRetained: 200 }),
|
|
@@ -45334,7 +45511,8 @@ var MAX_SKILLS_INDEX_ENTRIES = 150, MAX_SKILL_DESCRIPTION_LENGTH = 200;
|
|
|
45334
45511
|
// src/prompts/builders/agents-builder.ts
|
|
45335
45512
|
function buildAgentsInstructions(entries) {
|
|
45336
45513
|
const lines = [
|
|
45337
|
-
"When a task suits one of these agents, call nax-agents__run with the agent name and a self-contained task."
|
|
45514
|
+
"When a task suits one of these agents, call nax-agents__run with the agent name and a self-contained task.",
|
|
45515
|
+
"Pass model to run an agent on another model: provider/model for the nax native agent (openai-codex/gpt-6-luna is native), acp:<agent> for an installed ACP agent."
|
|
45338
45516
|
];
|
|
45339
45517
|
for (const entry of entries.slice(0, MAX_AGENTS_INDEX_ENTRIES)) {
|
|
45340
45518
|
lines.push(`- ${entry.qualifiedName}: ${cleanIndexDescription(entry.description)}`);
|
|
@@ -45345,6 +45523,20 @@ function buildAgentsInstructions(entries) {
|
|
|
45345
45523
|
return lines.join(`
|
|
45346
45524
|
`);
|
|
45347
45525
|
}
|
|
45526
|
+
function buildAcpSubagentInstructions(input) {
|
|
45527
|
+
const sections = [
|
|
45528
|
+
`You are ${input.agentLabel}, running as the nax chat subagent ${input.agent.qualifiedName}. Use your own tools for the work. Answer with your final result as text; the chat that called you reads only that.`
|
|
45529
|
+
];
|
|
45530
|
+
if (input.toolInstructions !== undefined && input.toolInstructions !== "")
|
|
45531
|
+
sections.push(input.toolInstructions);
|
|
45532
|
+
const memory = memorySectionOf(input.memoryIndex);
|
|
45533
|
+
if (memory !== undefined)
|
|
45534
|
+
sections.push(memory);
|
|
45535
|
+
sections.push(input.agent.prompt);
|
|
45536
|
+
return sections.join(`
|
|
45537
|
+
|
|
45538
|
+
`);
|
|
45539
|
+
}
|
|
45348
45540
|
function buildSubagentInstructions(input) {
|
|
45349
45541
|
const sections = [chatPermissionParagraph(input.mode)];
|
|
45350
45542
|
const rules = buildRulesIndexSection({ entries: input.rulesIndex, shownAutomatically: true });
|
|
@@ -57163,7 +57355,7 @@ var package_default;
|
|
|
57163
57355
|
var init_package = __esm(() => {
|
|
57164
57356
|
package_default = {
|
|
57165
57357
|
name: "@nathapp/nax",
|
|
57166
|
-
version: "0.91.8-canary.
|
|
57358
|
+
version: "0.91.8-canary.3",
|
|
57167
57359
|
description: "AI Coding Agent Orchestrator \u2014 loops until done",
|
|
57168
57360
|
type: "module",
|
|
57169
57361
|
bin: {
|
|
@@ -57249,7 +57441,7 @@ var init_package = __esm(() => {
|
|
|
57249
57441
|
"@agentclientprotocol/sdk": "~1.7.0",
|
|
57250
57442
|
"@anthropic-ai/sandbox-runtime": "0.0.77",
|
|
57251
57443
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
57252
|
-
"@nathapp/nax-ai": "0.91.8-canary.
|
|
57444
|
+
"@nathapp/nax-ai": "0.91.8-canary.3",
|
|
57253
57445
|
chalk: "^5.6.2",
|
|
57254
57446
|
commander: "^13.1.0",
|
|
57255
57447
|
"highlight.js": "^11.12.0",
|
|
@@ -80096,6 +80288,7 @@ function activityOf(event, toolNames) {
|
|
|
80096
80288
|
return usageActivity(event);
|
|
80097
80289
|
case "stream_reset":
|
|
80098
80290
|
case "compaction":
|
|
80291
|
+
case "tool_input_delta":
|
|
80099
80292
|
return;
|
|
80100
80293
|
}
|
|
80101
80294
|
}
|
|
@@ -82904,8 +83097,8 @@ var init_version = __esm(() => {
|
|
|
82904
83097
|
NAX_AI_VERSION = CATALOG_VERSION;
|
|
82905
83098
|
NAX_COMMIT = (() => {
|
|
82906
83099
|
try {
|
|
82907
|
-
if (/^[0-9a-f]{6,10}$/.test("
|
|
82908
|
-
return "
|
|
83100
|
+
if (/^[0-9a-f]{6,10}$/.test("41fd6ed"))
|
|
83101
|
+
return "41fd6ed";
|
|
82909
83102
|
} catch {}
|
|
82910
83103
|
try {
|
|
82911
83104
|
const result = Bun.spawnSync(["git", "rev-parse", "--short", "HEAD"], {
|
|
@@ -94772,7 +94965,8 @@ function buildWorkflowInstructions() {
|
|
|
94772
94965
|
"Call `nax-workflow__state` before proposing any workflow step, and call it again after any workflow step ends, so what you propose matches the feature's real state.",
|
|
94773
94966
|
"The nax loop runs in this order: brainstorm \u2192 spec-writing \u2192 spec-review (at most two fix rounds) \u2192 `nax plan` \u2192 PRD fidelity check (spec-review `--prd`) \u2192 commit the spec and PRD \u2192 `nax run` \u2192 `nax bot review` / `nax bot fix` \u2192 the user merges \u2192 the user releases.",
|
|
94774
94967
|
"`nax plan`, `nax run`, `nax bot review` and `nax bot fix` are billed: never start one without the user's explicit approval of that launch.",
|
|
94775
|
-
"nax never merges a PR and never releases; the user merges the PR and the user releases."
|
|
94968
|
+
"nax never merges a PR and never releases; the user merges the PR and the user releases.",
|
|
94969
|
+
"When the nax project is in a folder inside this chat's folder (for example repos/nax), pass repo with that folder's path; the chat stays where it is."
|
|
94776
94970
|
].join(`
|
|
94777
94971
|
`);
|
|
94778
94972
|
}
|
|
@@ -94800,6 +94994,7 @@ function buildJobsInstructions(options) {
|
|
|
94800
94994
|
"Jobs run in the background; a [nax-jobs] notice arrives when one ends.",
|
|
94801
94995
|
"Write, Edit, Delete and GitCommit are refused in this checkout while a run or plan job runs.",
|
|
94802
94996
|
"Start one step at a time: after a job ends, report the outcome to the user and propose the single next step.",
|
|
94997
|
+
"When the nax project is in a folder inside this chat's folder (for example repos/nax), pass repo with that folder's path; the chat stays where it is.",
|
|
94803
94998
|
'`nax-jobs__chain` proposes a full run: an ordered list of billed steps on one approval card. Only the user\'s yes on that card approves it; a chat message such as "go ahead" does not.',
|
|
94804
94999
|
"While a chain is active, call each step's launch tool with exactly the approved arguments, one step at a time, after the previous step succeeded; a different call stops the chain and shows a normal card.",
|
|
94805
95000
|
"Before a step that names a check, run that check yourself and record its verdict with `nax-jobs__chain_check`; stop the chain with `nax-jobs__chain_stop` when the user asks."
|
|
@@ -109765,6 +109960,13 @@ async function consumeTokenFile(path) {
|
|
|
109765
109960
|
}
|
|
109766
109961
|
return raw === undefined ? { readFailed: true } : { readFailed: false, token: raw.trim() };
|
|
109767
109962
|
}
|
|
109963
|
+
function parseUserId(userId) {
|
|
109964
|
+
const id = Number(userId);
|
|
109965
|
+
if (!USER_ID_PATTERN.test(userId) || id > Number.MAX_SAFE_INTEGER) {
|
|
109966
|
+
throw invalid3(`${FORGE_IDENTITY_ENV.userId} must be a positive integer`);
|
|
109967
|
+
}
|
|
109968
|
+
return id;
|
|
109969
|
+
}
|
|
109768
109970
|
function validateAccount(tokenFile, login, userId) {
|
|
109769
109971
|
if (tokenFile === undefined) {
|
|
109770
109972
|
if (login !== undefined) {
|
|
@@ -109779,11 +109981,20 @@ function validateAccount(tokenFile, login, userId) {
|
|
|
109779
109981
|
}
|
|
109780
109982
|
if (userId === undefined)
|
|
109781
109983
|
return;
|
|
109782
|
-
|
|
109783
|
-
|
|
109784
|
-
|
|
109984
|
+
return parseUserId(userId);
|
|
109985
|
+
}
|
|
109986
|
+
function loginOnlyIdentity(mode, tokenFile, login, userId) {
|
|
109987
|
+
if (mode !== LOGIN_ONLY_MODE) {
|
|
109988
|
+
throw invalid3(`${FORGE_IDENTITY_ENV.mode} must be ${LOGIN_ONLY_MODE}`);
|
|
109785
109989
|
}
|
|
109786
|
-
|
|
109990
|
+
if (tokenFile !== undefined) {
|
|
109991
|
+
throw invalid3(`${FORGE_IDENTITY_ENV.mode}=${LOGIN_ONLY_MODE} does not take ${FORGE_IDENTITY_ENV.tokenFile}`);
|
|
109992
|
+
}
|
|
109993
|
+
if (login === undefined) {
|
|
109994
|
+
throw invalid3(`${FORGE_IDENTITY_ENV.mode}=${LOGIN_ONLY_MODE} requires ${FORGE_IDENTITY_ENV.login}`);
|
|
109995
|
+
}
|
|
109996
|
+
const id = userId === undefined ? undefined : parseUserId(userId);
|
|
109997
|
+
return { login, ...id === undefined ? {} : { id } };
|
|
109787
109998
|
}
|
|
109788
109999
|
function tokenFrom(contents) {
|
|
109789
110000
|
if (contents === undefined || contents.readFailed) {
|
|
@@ -109798,10 +110009,16 @@ async function captureForgeIdentity(env) {
|
|
|
109798
110009
|
const tokenFile = present2(env[FORGE_IDENTITY_ENV.tokenFile]);
|
|
109799
110010
|
const login = present2(env[FORGE_IDENTITY_ENV.login]);
|
|
109800
110011
|
const userId = present2(env[FORGE_IDENTITY_ENV.userId]);
|
|
110012
|
+
const mode = present2(env[FORGE_IDENTITY_ENV.mode]);
|
|
109801
110013
|
const contents = tokenFile === undefined ? undefined : await consumeTokenFile(tokenFile);
|
|
109802
110014
|
if (present2(env[FORGE_IDENTITY_ENV.rejectedToken]) !== undefined) {
|
|
109803
110015
|
throw invalid3(`${FORGE_IDENTITY_ENV.rejectedToken} is not supported; pass the token through ${FORGE_IDENTITY_ENV.tokenFile}`);
|
|
109804
110016
|
}
|
|
110017
|
+
if (mode !== undefined) {
|
|
110018
|
+
const identity = loginOnlyIdentity(mode, tokenFile, login, userId);
|
|
110019
|
+
_forgeIdentity.current = identity;
|
|
110020
|
+
return identity;
|
|
110021
|
+
}
|
|
109805
110022
|
if (tokenFile === undefined && login === undefined && userId === undefined)
|
|
109806
110023
|
return;
|
|
109807
110024
|
const id = validateAccount(tokenFile, login, userId);
|
|
@@ -109813,7 +110030,7 @@ async function captureForgeIdentity(env) {
|
|
|
109813
110030
|
_forgeIdentity.current = identity;
|
|
109814
110031
|
return identity;
|
|
109815
110032
|
}
|
|
109816
|
-
var FORGE_IDENTITY_INVALID = "FORGE_IDENTITY_INVALID", USER_ID_PATTERN, FORGE_IDENTITY_ENV, _forgeIdentity, _forgeIdentityDeps;
|
|
110033
|
+
var FORGE_IDENTITY_INVALID = "FORGE_IDENTITY_INVALID", USER_ID_PATTERN, LOGIN_ONLY_MODE = "login-only", FORGE_IDENTITY_ENV, _forgeIdentity, _forgeIdentityDeps;
|
|
109817
110034
|
var init_identity = __esm(() => {
|
|
109818
110035
|
init_errors4();
|
|
109819
110036
|
USER_ID_PATTERN = /^[1-9][0-9]*$/;
|
|
@@ -109821,6 +110038,7 @@ var init_identity = __esm(() => {
|
|
|
109821
110038
|
tokenFile: "NAX_FORGE_TOKEN_FILE",
|
|
109822
110039
|
login: "NAX_FORGE_LOGIN",
|
|
109823
110040
|
userId: "NAX_FORGE_USER_ID",
|
|
110041
|
+
mode: "NAX_FORGE_IDENTITY",
|
|
109824
110042
|
rejectedToken: "NAX_FORGE_TOKEN"
|
|
109825
110043
|
};
|
|
109826
110044
|
_forgeIdentity = { current: undefined };
|
|
@@ -109846,9 +110064,10 @@ function forgeProgram(cmd) {
|
|
|
109846
110064
|
function tokenEnv(cmd) {
|
|
109847
110065
|
const identity = injectedForgeIdentity();
|
|
109848
110066
|
const program = forgeProgram(cmd);
|
|
109849
|
-
|
|
110067
|
+
const token = identity?.token;
|
|
110068
|
+
if (token === undefined || program === undefined)
|
|
109850
110069
|
return;
|
|
109851
|
-
return Object.fromEntries(FORGE_TOKEN_ENV[program].map((name) => [name,
|
|
110070
|
+
return Object.fromEntries(FORGE_TOKEN_ENV[program].map((name) => [name, token]));
|
|
109852
110071
|
}
|
|
109853
110072
|
async function defaultRun(cmd, opts) {
|
|
109854
110073
|
const proc = Bun.spawn(cmd[0] === "git" ? hardenedGitArgv(cmd) : cmd, {
|
|
@@ -110554,11 +110773,17 @@ var init_forge = __esm(() => {
|
|
|
110554
110773
|
});
|
|
110555
110774
|
|
|
110556
110775
|
// src/bot/git.ts
|
|
110776
|
+
function envOverlayFor(identity, networkVerb) {
|
|
110777
|
+
if (identity === undefined || !networkVerb)
|
|
110778
|
+
return;
|
|
110779
|
+
return identity.token === undefined ? { ...NO_TERMINAL_PROMPT } : { ...NO_TERMINAL_PROMPT, [BOT_GIT_TOKEN_ENV]: identity.token };
|
|
110780
|
+
}
|
|
110557
110781
|
function botGit(args, workdir, timeoutMs, maxBytes) {
|
|
110558
110782
|
const identity = injectedForgeIdentity();
|
|
110559
|
-
const
|
|
110783
|
+
const networkVerb = BOT_GIT_NETWORK_VERBS.has(args[0] ?? "");
|
|
110784
|
+
const authenticated = identity?.token !== undefined && networkVerb;
|
|
110560
110785
|
const prefix = authenticated ? [...BOT_GIT_HOOKS_OFF, ...BOT_GIT_CREDENTIAL_ARGV] : [...BOT_GIT_HOOKS_OFF];
|
|
110561
|
-
const envOverlay =
|
|
110786
|
+
const envOverlay = envOverlayFor(identity, networkVerb);
|
|
110562
110787
|
return gitWithTimeout(args, workdir, timeoutMs, maxBytes, ["git", ...prefix, ...args], envOverlay);
|
|
110563
110788
|
}
|
|
110564
110789
|
var BOT_GIT_HOOKS_OFF, NAX_BOT_CREDENTIAL_HELPER = `!f() { [ "$1" = get ] || return 0; proto=; while IFS= read -r line; do case $line in protocol=https) proto=1 ;; esac; done; [ -n "$proto" ] || return 0; printf '%s\\n' "username=x-access-token" "password=$NAX_FORGE_GIT_TOKEN"; }; f`, BOT_GIT_NETWORK_VERBS, BOT_GIT_TOKEN_ENV = "NAX_FORGE_GIT_TOKEN", NO_TERMINAL_PROMPT, BOT_GIT_CREDENTIAL_ARGV;
|
|
@@ -114237,7 +114462,7 @@ var init_merge_findings = __esm(() => {
|
|
|
114237
114462
|
});
|
|
114238
114463
|
|
|
114239
114464
|
// src/finish/review-round.ts
|
|
114240
|
-
function
|
|
114465
|
+
function settle3(lens, r) {
|
|
114241
114466
|
if (r.status === "fulfilled")
|
|
114242
114467
|
return r.value;
|
|
114243
114468
|
getSafeLogger2()?.warn("finish", "Finish review lens failed", { storyId: "_run", lens, error: String(r.reason) });
|
|
@@ -114245,8 +114470,8 @@ function settle2(lens, r) {
|
|
|
114245
114470
|
}
|
|
114246
114471
|
async function runReviewRound(run) {
|
|
114247
114472
|
const [s, q] = await Promise.allSettled([Promise.resolve().then(run.spec), Promise.resolve().then(run.quality)]);
|
|
114248
|
-
const spec =
|
|
114249
|
-
const quality =
|
|
114473
|
+
const spec = settle3("spec", s);
|
|
114474
|
+
const quality = settle3("quality", q);
|
|
114250
114475
|
const missing = [];
|
|
114251
114476
|
if (spec.missing)
|
|
114252
114477
|
missing.push("spec");
|
|
@@ -127932,12 +128157,13 @@ var init_rtk = __esm(() => {
|
|
|
127932
128157
|
function formatMemoryStatus(status, index) {
|
|
127933
128158
|
const lines = [
|
|
127934
128159
|
`provider: ${status.provider}`,
|
|
127935
|
-
`write mode: ${status.writeMode}`,
|
|
128160
|
+
`write mode: ${status.writeMode === "koda" ? "decided by koda" : status.writeMode}`,
|
|
127936
128161
|
`mirror: ${status.projectDir}`,
|
|
127937
128162
|
`user notes: ${status.userDir}`,
|
|
127938
128163
|
`last sync: ${status.lastPullAt ?? "never"}`,
|
|
127939
128164
|
...status.lastError === null ? [] : [`last error: ${status.lastError}`],
|
|
127940
128165
|
`outbox: ${status.queued} queued, ${status.rejected} rejected`,
|
|
128166
|
+
...status.rejectedEntries.map((entry) => `rejected: ${entryLabel(entry)} (${entry.reason})`),
|
|
127941
128167
|
`notes: ${status.notes.project} project, ${status.notes.user} user, ${status.notes.repo} repo`,
|
|
127942
128168
|
...status.repoSkipped > 0 ? [`repo notes skipped: ${status.repoSkipped}`] : []
|
|
127943
128169
|
];
|
|
@@ -127948,6 +128174,14 @@ function formatMemoryStatus(status, index) {
|
|
|
127948
128174
|
${index}`;
|
|
127949
128175
|
}
|
|
127950
128176
|
function formatMemorySyncResult(result) {
|
|
128177
|
+
const parked = (result.parked ?? []).map((entry) => `memory sync: parked ${entryLabel(entry)} (${entry.reason})`);
|
|
128178
|
+
return [syncOutcomeLine(result), ...parked].join(`
|
|
128179
|
+
`);
|
|
128180
|
+
}
|
|
128181
|
+
function entryLabel(entry) {
|
|
128182
|
+
return `${entry.kind} ${entry.scope}/${entry.slug}`;
|
|
128183
|
+
}
|
|
128184
|
+
function syncOutcomeLine(result) {
|
|
127951
128185
|
switch (result.outcome) {
|
|
127952
128186
|
case "synced":
|
|
127953
128187
|
return `memory sync: synced (pushed ${result.pushed}, rejected ${result.rejected}, pulled ${result.pulled}, skipped ${result.skipped})`;
|
|
@@ -128055,11 +128289,36 @@ function createHostWrites(input) {
|
|
|
128055
128289
|
return {
|
|
128056
128290
|
save: (write) => save(input, write),
|
|
128057
128291
|
forget: (request) => forget(input, request),
|
|
128058
|
-
approve: (request) => approve2(input, request)
|
|
128292
|
+
approve: (request) => approve2(input, request),
|
|
128293
|
+
requeue: (target) => requeue(input.outbox, target),
|
|
128294
|
+
discard: (target) => discard2(input, target)
|
|
128059
128295
|
};
|
|
128060
128296
|
}
|
|
128297
|
+
function rejectedMatches(entry, target) {
|
|
128298
|
+
if (entry.state !== "rejected")
|
|
128299
|
+
return false;
|
|
128300
|
+
return target === "all" || entry.scope === target.scope && entry.slug === target.slug;
|
|
128301
|
+
}
|
|
128302
|
+
async function requeue(outbox, target) {
|
|
128303
|
+
const matches = (await outbox.list()).filter((entry) => rejectedMatches(entry, target));
|
|
128304
|
+
let requeued = 0;
|
|
128305
|
+
for (const entry of matches) {
|
|
128306
|
+
if (await outbox.requeue(entry.clientId))
|
|
128307
|
+
requeued += 1;
|
|
128308
|
+
}
|
|
128309
|
+
return requeued;
|
|
128310
|
+
}
|
|
128311
|
+
async function discard2(input, target) {
|
|
128312
|
+
const matches = (await input.outbox.list()).filter((entry) => rejectedMatches(entry, target));
|
|
128313
|
+
for (const entry of matches)
|
|
128314
|
+
await input.outbox.remove(entry.clientId);
|
|
128315
|
+
for (const scope of new Set(matches.map((entry) => entry.scope)))
|
|
128316
|
+
await rewindPullCursor(input.store, scope);
|
|
128317
|
+
return matches.length;
|
|
128318
|
+
}
|
|
128061
128319
|
var LOG_STAGE = "memory", REPO_NOTE_DIR_LABEL;
|
|
128062
128320
|
var init_host_writes = __esm(() => {
|
|
128321
|
+
init_internal();
|
|
128063
128322
|
init_config();
|
|
128064
128323
|
init_errors4();
|
|
128065
128324
|
REPO_NOTE_DIR_LABEL = `${PROJECT_NAX_DIR}/memory`;
|
|
@@ -128386,6 +128645,12 @@ function parseKodaItems(value) {
|
|
|
128386
128645
|
}
|
|
128387
128646
|
return value.filter(isKodaRow);
|
|
128388
128647
|
}
|
|
128648
|
+
function parseKodaRecords(value) {
|
|
128649
|
+
if (!Array.isArray(value)) {
|
|
128650
|
+
throw new NaxError(`[memory] koda answered a list page whose records are not an array (got ${valueKindOf(value)})`, "MEMORY_KODA_BAD_RESPONSE", { stage: STAGE10, received: valueKindOf(value) });
|
|
128651
|
+
}
|
|
128652
|
+
return value.filter(isKodaRow);
|
|
128653
|
+
}
|
|
128389
128654
|
function stringField(item, field) {
|
|
128390
128655
|
const value = item[field];
|
|
128391
128656
|
return typeof value === "string" ? value : undefined;
|
|
@@ -128606,8 +128871,8 @@ var init_koda_mapping = __esm(() => {
|
|
|
128606
128871
|
function isRecord17(value) {
|
|
128607
128872
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
128608
128873
|
}
|
|
128609
|
-
function
|
|
128610
|
-
return
|
|
128874
|
+
function recordsOf(data) {
|
|
128875
|
+
return parseKodaRecords(isRecord17(data) ? data.records : undefined);
|
|
128611
128876
|
}
|
|
128612
128877
|
function badResponse2(input, detail) {
|
|
128613
128878
|
return new NaxError(`[memory] koda ${detail} for project "${input.project}"`, "MEMORY_KODA_BAD_RESPONSE", {
|
|
@@ -128656,7 +128921,7 @@ async function findActiveKodaNote(input) {
|
|
|
128656
128921
|
size: LOOKUP_PAGE_SIZE,
|
|
128657
128922
|
current: page
|
|
128658
128923
|
});
|
|
128659
|
-
const match = matchOf(
|
|
128924
|
+
const match = matchOf(recordsOf(answer.data), input);
|
|
128660
128925
|
if (match !== undefined)
|
|
128661
128926
|
return match;
|
|
128662
128927
|
if (!hasNextPage(answer.data, input))
|
|
@@ -129010,7 +129275,7 @@ function createKodaMemoryProvider(input) {
|
|
|
129010
129275
|
text,
|
|
129011
129276
|
size: Math.min(input.limit, SEARCH_SIZE_MAX)
|
|
129012
129277
|
});
|
|
129013
|
-
const records =
|
|
129278
|
+
const records = parseKodaRecords(isRecord19(answer.data) ? answer.data.records : undefined);
|
|
129014
129279
|
return hitsOf(records, input.limit);
|
|
129015
129280
|
}
|
|
129016
129281
|
return {
|
|
@@ -129705,6 +129970,9 @@ async function readIndex(reads, input) {
|
|
|
129705
129970
|
]);
|
|
129706
129971
|
return renderMemoryIndex({ projectNotes, userNotes, decisions, heldForgets, maxBytes: input.config.indexBytes });
|
|
129707
129972
|
}
|
|
129973
|
+
function rejectedEntries(entries) {
|
|
129974
|
+
return entries.filter((entry) => entry.state === "rejected").map(({ kind, scope, slug, reason }) => ({ kind, scope, slug, reason: reason ?? "no reason recorded" }));
|
|
129975
|
+
}
|
|
129708
129976
|
function countState(entries, state) {
|
|
129709
129977
|
return entries.filter((entry) => entry.state === state).length;
|
|
129710
129978
|
}
|
|
@@ -129712,6 +129980,9 @@ function syncParts(input) {
|
|
|
129712
129980
|
const { store, outbox, provider } = input.parts;
|
|
129713
129981
|
return _memoryHostDeps.syncMemory({ store, outbox, provider, logger: input.logger });
|
|
129714
129982
|
}
|
|
129983
|
+
function statusWriteMode(input) {
|
|
129984
|
+
return input.parts.provider.id.startsWith(MEMORY_KODA_PROVIDER_PREFIX) ? "koda" : input.config.writeMode;
|
|
129985
|
+
}
|
|
129715
129986
|
async function readStatus(reads, input) {
|
|
129716
129987
|
const [project, user, entries, sync] = await Promise.all([
|
|
129717
129988
|
reads.projectScope(),
|
|
@@ -129722,13 +129993,14 @@ async function readStatus(reads, input) {
|
|
|
129722
129993
|
return {
|
|
129723
129994
|
enabled: true,
|
|
129724
129995
|
provider: input.parts.provider.id,
|
|
129725
|
-
writeMode: input
|
|
129996
|
+
writeMode: statusWriteMode(input),
|
|
129726
129997
|
projectDir: input.parts.dirs.projectDir,
|
|
129727
129998
|
userDir: input.parts.dirs.userDir,
|
|
129728
129999
|
lastPullAt: sync.lastPullAt,
|
|
129729
130000
|
lastError: sync.lastError,
|
|
129730
130001
|
queued: countState(entries, "queued"),
|
|
129731
130002
|
rejected: countState(entries, "rejected"),
|
|
130003
|
+
rejectedEntries: rejectedEntries(entries),
|
|
129732
130004
|
notes: { project: project.mirror.length, user: user.length, repo: project.unshadowed.length },
|
|
129733
130005
|
repoSkipped: project.skipped
|
|
129734
130006
|
};
|
|
@@ -129763,6 +130035,8 @@ async function createMemoryHost(input) {
|
|
|
129763
130035
|
save: writes.save,
|
|
129764
130036
|
forget: writes.forget,
|
|
129765
130037
|
approve: writes.approve,
|
|
130038
|
+
requeue: writes.requeue,
|
|
130039
|
+
discard: writes.discard,
|
|
129766
130040
|
forgetPendingKeys: () => readForgetPendingKeys(parts),
|
|
129767
130041
|
close: closeOnce(parts.pool)
|
|
129768
130042
|
};
|
|
@@ -151538,7 +151812,7 @@ async function newestSidecar(runDir) {
|
|
|
151538
151812
|
const path = join184(runDir, newest);
|
|
151539
151813
|
return { path, sidecar: await readSidecar(path) };
|
|
151540
151814
|
}
|
|
151541
|
-
async function
|
|
151815
|
+
async function discard3(path) {
|
|
151542
151816
|
try {
|
|
151543
151817
|
await _sidecarDeps.unlink(path);
|
|
151544
151818
|
} catch {}
|
|
@@ -151551,7 +151825,7 @@ async function writeSidecar(path, sidecar) {
|
|
|
151551
151825
|
`);
|
|
151552
151826
|
await _sidecarDeps.rename(tmp, path);
|
|
151553
151827
|
} catch (err) {
|
|
151554
|
-
await
|
|
151828
|
+
await discard3(tmp);
|
|
151555
151829
|
throw err;
|
|
151556
151830
|
}
|
|
151557
151831
|
}
|
|
@@ -154667,7 +154941,7 @@ var init_chat_effort = __esm(() => {
|
|
|
154667
154941
|
|
|
154668
154942
|
// src/chat/acp/acp-model.ts
|
|
154669
154943
|
function isChatAcpModel(model) {
|
|
154670
|
-
return model.startsWith(
|
|
154944
|
+
return model.startsWith(ACP_PREFIX2);
|
|
154671
154945
|
}
|
|
154672
154946
|
function isAcpChatAgent(text) {
|
|
154673
154947
|
return ACP_CHAT_AGENTS.some((agent) => agent === text);
|
|
@@ -154684,7 +154958,7 @@ function invalid5(model, reason) {
|
|
|
154684
154958
|
function parseChatAcpModel(model) {
|
|
154685
154959
|
if (!isChatAcpModel(model))
|
|
154686
154960
|
return;
|
|
154687
|
-
const { model: body, effort } = parseModelSpec(model.slice(
|
|
154961
|
+
const { model: body, effort } = parseModelSpec(model.slice(ACP_PREFIX2.length));
|
|
154688
154962
|
const slash = body.indexOf("/");
|
|
154689
154963
|
const agent = slash === -1 ? body : body.slice(0, slash);
|
|
154690
154964
|
if (!isAcpChatAgent(agent)) {
|
|
@@ -154732,12 +155006,12 @@ function cursorBareNames(offered) {
|
|
|
154732
155006
|
}
|
|
154733
155007
|
function acpModelRows(agent, offeredModels) {
|
|
154734
155008
|
const names = agent === "cursor" ? cursorBareNames(offeredModels) : distinct(offeredModels).filter((id) => id !== "" && !hasBracket(id));
|
|
154735
|
-
return names.map((name) => `${
|
|
155009
|
+
return names.map((name) => `${ACP_PREFIX2}${agent}/${name}`);
|
|
154736
155010
|
}
|
|
154737
155011
|
function acpEffortLevels(offeredEfforts) {
|
|
154738
155012
|
return EFFORT_LEVELS.filter((level) => level === "default" || offeredEfforts.includes(level));
|
|
154739
155013
|
}
|
|
154740
|
-
var ACP_CHAT_AGENTS, ACP_RUN_COMMAND_UNSUPPORTED = "! commands run on nax's own models only; the agent runs commands with its own tools",
|
|
155014
|
+
var ACP_CHAT_AGENTS, ACP_RUN_COMMAND_UNSUPPORTED = "! commands run on nax's own models only; the agent runs commands with its own tools", ACP_PREFIX2 = "acp:", AGENT_LABELS, TRAILING_GROUP;
|
|
154741
155015
|
var init_acp_model = __esm(() => {
|
|
154742
155016
|
init_src();
|
|
154743
155017
|
init_errors4();
|
|
@@ -155712,6 +155986,100 @@ var init_acp_session_options = __esm(() => {
|
|
|
155712
155986
|
]);
|
|
155713
155987
|
});
|
|
155714
155988
|
|
|
155989
|
+
// src/chat/acp/acp-subagent-profile.ts
|
|
155990
|
+
function bareName(entry) {
|
|
155991
|
+
const open = entry.indexOf("(");
|
|
155992
|
+
return open > 0 && entry.endsWith(")") ? entry.slice(0, open) : entry;
|
|
155993
|
+
}
|
|
155994
|
+
function namesWriteTool(tools) {
|
|
155995
|
+
return tools.some((entry) => ACP_SUBAGENT_WRITE_TOOLS.includes(bareName(entry)));
|
|
155996
|
+
}
|
|
155997
|
+
function chatOwnProfile(mode) {
|
|
155998
|
+
return mode === "full" ? "full" : "ask";
|
|
155999
|
+
}
|
|
156000
|
+
function acpSubagentProfile(input) {
|
|
156001
|
+
if (input.override !== undefined)
|
|
156002
|
+
return input.override;
|
|
156003
|
+
if (input.tools === undefined || namesWriteTool(input.tools))
|
|
156004
|
+
return chatOwnProfile(input.mode);
|
|
156005
|
+
return "review";
|
|
156006
|
+
}
|
|
156007
|
+
function isReadOnlyAcpProfile(profile) {
|
|
156008
|
+
return READ_ONLY_PROFILES.has(profile);
|
|
156009
|
+
}
|
|
156010
|
+
function acpReadOnlyEnforced(agent) {
|
|
156011
|
+
const readOnly = registryEntry(agent)?.readOnly;
|
|
156012
|
+
return readOnly !== undefined && readOnly.policy === undefined;
|
|
156013
|
+
}
|
|
156014
|
+
var ACP_SUBAGENT_WRITE_TOOLS, READ_ONLY_PROFILES;
|
|
156015
|
+
var init_acp_subagent_profile = __esm(() => {
|
|
156016
|
+
init_client2();
|
|
156017
|
+
ACP_SUBAGENT_WRITE_TOOLS = Object.freeze([
|
|
156018
|
+
"Write",
|
|
156019
|
+
"Edit",
|
|
156020
|
+
"MultiEdit",
|
|
156021
|
+
"NotebookEdit",
|
|
156022
|
+
"Delete",
|
|
156023
|
+
"GitCommit"
|
|
156024
|
+
]);
|
|
156025
|
+
READ_ONLY_PROFILES = new Set(["review", "read"]);
|
|
156026
|
+
});
|
|
156027
|
+
|
|
156028
|
+
// src/chat/acp/acp-subagent-session.ts
|
|
156029
|
+
function namedByAllowedTools(allowedTools, providerId) {
|
|
156030
|
+
if (allowedTools === undefined)
|
|
156031
|
+
return true;
|
|
156032
|
+
return allowedTools.some((entry) => entry.startsWith(`${providerId}__`));
|
|
156033
|
+
}
|
|
156034
|
+
function deliveredProviders(input) {
|
|
156035
|
+
return input.toolProviders.filter((provider) => ACP_SUBAGENT_PROVIDER_IDS.includes(provider.id) && namedByAllowedTools(input.allowedTools, provider.id));
|
|
156036
|
+
}
|
|
156037
|
+
function subagentTools(tools, profile) {
|
|
156038
|
+
if (!isReadOnlyAcpProfile(profile))
|
|
156039
|
+
return tools;
|
|
156040
|
+
return tools.filter((tool) => !READ_ONLY_WITHHELD_TOOL_NAMES.has(tool.name));
|
|
156041
|
+
}
|
|
156042
|
+
async function acpSubagentSessionOptions(input, createTranscriptStore) {
|
|
156043
|
+
const { acp } = input;
|
|
156044
|
+
const resolved = await _acpSubagentDeps.chatAcpTools(deliveredProviders(input), input.cwd);
|
|
156045
|
+
return {
|
|
156046
|
+
backend: _acpSubagentDeps.acpBackend({
|
|
156047
|
+
agent: acp.agent,
|
|
156048
|
+
allowUnsandboxed: true,
|
|
156049
|
+
inheritEnv: true,
|
|
156050
|
+
...acp.model !== undefined ? { model: acp.model } : {},
|
|
156051
|
+
...acp.effort !== undefined ? { effort: acp.effort } : {}
|
|
156052
|
+
}),
|
|
156053
|
+
profile: input.profile,
|
|
156054
|
+
workdir: input.cwd,
|
|
156055
|
+
tools: subagentTools(resolved.tools, input.profile),
|
|
156056
|
+
instructions: buildAcpSubagentInstructions({
|
|
156057
|
+
agentLabel: acpAgentLabel(acp.agent),
|
|
156058
|
+
agent: input.agent,
|
|
156059
|
+
...resolved.instructions !== undefined ? { toolInstructions: resolved.instructions } : {},
|
|
156060
|
+
...input.memoryIndex !== undefined ? { memoryIndex: input.memoryIndex } : {}
|
|
156061
|
+
}),
|
|
156062
|
+
transcriptStore: createTranscriptStore(),
|
|
156063
|
+
metadata: { parentSessionId: input.parentSessionId, subagent: input.agent.qualifiedName },
|
|
156064
|
+
approvalTimeoutMs: input.config.execution.approvalTimeout
|
|
156065
|
+
};
|
|
156066
|
+
}
|
|
156067
|
+
var _acpSubagentDeps, ACP_SUBAGENT_PROVIDER_IDS, READ_ONLY_WITHHELD_TOOL_NAMES;
|
|
156068
|
+
var init_acp_subagent_session = __esm(() => {
|
|
156069
|
+
init_client2();
|
|
156070
|
+
init_memory2();
|
|
156071
|
+
init_prompts();
|
|
156072
|
+
init_acp_model();
|
|
156073
|
+
init_acp_subagent_profile();
|
|
156074
|
+
init_acp_tools();
|
|
156075
|
+
_acpSubagentDeps = { acpBackend, chatAcpTools };
|
|
156076
|
+
ACP_SUBAGENT_PROVIDER_IDS = ["nax-workflow", "nax-memory"];
|
|
156077
|
+
READ_ONLY_WITHHELD_TOOL_NAMES = new Set([
|
|
156078
|
+
`${MEMORY_TOOL_PROVIDER_ID}__save`,
|
|
156079
|
+
`${MEMORY_TOOL_PROVIDER_ID}__forget`
|
|
156080
|
+
]);
|
|
156081
|
+
});
|
|
156082
|
+
|
|
155715
156083
|
// src/chat/acp/acp-switch.ts
|
|
155716
156084
|
function parsedAcp(model) {
|
|
155717
156085
|
try {
|
|
@@ -155742,11 +156110,69 @@ var init_acp_switch = __esm(() => {
|
|
|
155742
156110
|
init_acp_model();
|
|
155743
156111
|
});
|
|
155744
156112
|
|
|
156113
|
+
// src/chat/target-repo.ts
|
|
156114
|
+
import { realpathSync as realpathSync6, statSync as statSync15 } from "fs";
|
|
156115
|
+
import { join as join195, resolve as resolve54, sep as sep27 } from "path";
|
|
156116
|
+
function isWithinRoot(path, root) {
|
|
156117
|
+
return path === root || path.startsWith(root.endsWith(sep27) ? root : root + sep27);
|
|
156118
|
+
}
|
|
156119
|
+
function isWithinRootCanonical(path, root) {
|
|
156120
|
+
const canon = (p) => {
|
|
156121
|
+
try {
|
|
156122
|
+
return realpathSync6(p);
|
|
156123
|
+
} catch {
|
|
156124
|
+
return p;
|
|
156125
|
+
}
|
|
156126
|
+
};
|
|
156127
|
+
return isWithinRoot(canon(path), canon(root));
|
|
156128
|
+
}
|
|
156129
|
+
function realOrNull(path) {
|
|
156130
|
+
try {
|
|
156131
|
+
return realpathSync6(path);
|
|
156132
|
+
} catch {
|
|
156133
|
+
return null;
|
|
156134
|
+
}
|
|
156135
|
+
}
|
|
156136
|
+
function isDirectory(path) {
|
|
156137
|
+
try {
|
|
156138
|
+
return statSync15(path).isDirectory();
|
|
156139
|
+
} catch {
|
|
156140
|
+
return false;
|
|
156141
|
+
}
|
|
156142
|
+
}
|
|
156143
|
+
async function resolveTargetRepo(chatRoot, repo) {
|
|
156144
|
+
if (repo === undefined)
|
|
156145
|
+
return { root: chatRoot };
|
|
156146
|
+
if (typeof repo !== "string" || !repo.trim())
|
|
156147
|
+
return { error: "[chat] repo must be a non-empty string" };
|
|
156148
|
+
const real = realOrNull(resolve54(chatRoot, repo));
|
|
156149
|
+
if (real === null)
|
|
156150
|
+
return { error: `[chat] repo ${repo} does not exist` };
|
|
156151
|
+
const realChat = realOrNull(chatRoot) ?? chatRoot;
|
|
156152
|
+
if (!isWithinRoot(real, realChat))
|
|
156153
|
+
return { error: `[chat] repo ${repo} is outside ${chatRoot}` };
|
|
156154
|
+
if (real === realChat)
|
|
156155
|
+
return { root: chatRoot };
|
|
156156
|
+
if (!isDirectory(join195(real, ".nax")))
|
|
156157
|
+
return { error: `[chat] repo ${repo} is not a nax project: no .nax directory` };
|
|
156158
|
+
return { root: real };
|
|
156159
|
+
}
|
|
156160
|
+
async function targetOutputDir(root) {
|
|
156161
|
+
const config = await _targetRepoDeps.loadConfig(join195(root, ".nax"));
|
|
156162
|
+
return projectOutputDir(getProjectKey(config, root), config.outputDir);
|
|
156163
|
+
}
|
|
156164
|
+
var _targetRepoDeps;
|
|
156165
|
+
var init_target_repo = __esm(() => {
|
|
156166
|
+
init_config();
|
|
156167
|
+
init_runtime3();
|
|
156168
|
+
_targetRepoDeps = { loadConfig };
|
|
156169
|
+
});
|
|
156170
|
+
|
|
155745
156171
|
// src/chat/acp/acp-write-guard.ts
|
|
155746
156172
|
function acpWriteRefusal(jobs, repoRoot, event) {
|
|
155747
156173
|
if (!ACP_WRITE_KINDS.includes(event.tool))
|
|
155748
156174
|
return;
|
|
155749
|
-
const job = jobs.running().filter((job) => job.cwd
|
|
156175
|
+
const job = jobs.running().filter((job) => isWithinRootCanonical(job.cwd, repoRoot) && (job.kind === "plan" || job.kind === "run")).sort((a, b) => Date.parse(b.startedAt) - Date.parse(a.startedAt))[0];
|
|
155750
156176
|
if (!job)
|
|
155751
156177
|
return;
|
|
155752
156178
|
return `[nax-jobs] ${event.tool} refused: nax ${job.kind} job ${job.id} is running in this checkout; wait for it to end or cancel it`;
|
|
@@ -155761,6 +156187,7 @@ function acpRefusal(input) {
|
|
|
155761
156187
|
}
|
|
155762
156188
|
var ACP_WRITE_KINDS;
|
|
155763
156189
|
var init_acp_write_guard = __esm(() => {
|
|
156190
|
+
init_target_repo();
|
|
155764
156191
|
init_acp_model();
|
|
155765
156192
|
ACP_WRITE_KINDS = Object.freeze(["edit", "delete", "move"]);
|
|
155766
156193
|
});
|
|
@@ -155775,6 +156202,8 @@ var init_acp3 = __esm(() => {
|
|
|
155775
156202
|
init_acp_model();
|
|
155776
156203
|
init_acp_recorder();
|
|
155777
156204
|
init_acp_session_options();
|
|
156205
|
+
init_acp_subagent_profile();
|
|
156206
|
+
init_acp_subagent_session();
|
|
155778
156207
|
init_acp_switch();
|
|
155779
156208
|
init_acp_transcript_append();
|
|
155780
156209
|
init_acp_write_guard();
|
|
@@ -155791,24 +156220,26 @@ function createAgentsProvider(options) {
|
|
|
155791
156220
|
const { catalog } = options;
|
|
155792
156221
|
const tool = {
|
|
155793
156222
|
localName: "run",
|
|
155794
|
-
description: "Run a named catalog agent on a self-contained task and return its final answer.",
|
|
156223
|
+
description: "Run a named catalog agent on a self-contained task and return its final answer. Optional model overrides the agent's model: provider/model (for example openai-codex/gpt-6-luna) runs it on the nax native agent with that provider's model; acp:<agent> (for example acp:codex) runs it on an installed ACP agent. A provider name such as openai-codex is a native provider, not the Codex ACP agent.",
|
|
155795
156224
|
inputSchema: {
|
|
155796
156225
|
type: "object",
|
|
155797
|
-
properties: { agent: { type: "string" }, task: { type: "string" } },
|
|
156226
|
+
properties: { agent: { type: "string" }, task: { type: "string" }, model: { type: "string" } },
|
|
155798
156227
|
required: ["agent", "task"],
|
|
155799
156228
|
additionalProperties: false
|
|
155800
156229
|
},
|
|
155801
156230
|
async run(input, ctx) {
|
|
155802
|
-
const { agent: name, task } = input;
|
|
156231
|
+
const { agent: name, task, model } = input;
|
|
155803
156232
|
if (!nonEmptyString2(name) || !nonEmptyString2(task)) {
|
|
155804
156233
|
return failure7("[chat] run requires agent: string and task: string");
|
|
155805
156234
|
}
|
|
156235
|
+
if (model !== undefined && !nonEmptyString2(model))
|
|
156236
|
+
return failure7("[chat] run model must be a non-empty string");
|
|
155806
156237
|
const agent = catalog.findAgent(name);
|
|
155807
156238
|
if (!agent) {
|
|
155808
156239
|
const available = catalog.agents.slice(0, MAX_AVAILABLE_AGENTS).map((entry) => entry.qualifiedName).join(", ");
|
|
155809
156240
|
return failure7(`unknown agent ${name}; available: ${available}`);
|
|
155810
156241
|
}
|
|
155811
|
-
return options.run(agent, task, ctx.signal);
|
|
156242
|
+
return model === undefined ? options.run(agent, task, ctx.signal) : options.run(agent, task, ctx.signal, model);
|
|
155812
156243
|
}
|
|
155813
156244
|
};
|
|
155814
156245
|
return {
|
|
@@ -156186,12 +156617,13 @@ function resolveSubagentModel(options) {
|
|
|
156186
156617
|
const tier = tierModel(requested, tiers);
|
|
156187
156618
|
if (tier !== undefined)
|
|
156188
156619
|
return { model: tier, source: "tier" };
|
|
156189
|
-
if (requested.includes("/"))
|
|
156620
|
+
if (isChatAcpModel(requested) || requested.includes("/"))
|
|
156190
156621
|
return { model: requested, source: "model" };
|
|
156191
156622
|
return { model: parentModel, source: "fallback" };
|
|
156192
156623
|
}
|
|
156193
156624
|
var INHERIT = "inherit", FAMILY_TIERS;
|
|
156194
156625
|
var init_subagent_model = __esm(() => {
|
|
156626
|
+
init_acp3();
|
|
156195
156627
|
FAMILY_TIERS = {
|
|
156196
156628
|
haiku: "fast",
|
|
156197
156629
|
sonnet: "balanced",
|
|
@@ -156200,7 +156632,7 @@ var init_subagent_model = __esm(() => {
|
|
|
156200
156632
|
});
|
|
156201
156633
|
|
|
156202
156634
|
// src/chat/subagent-tools.ts
|
|
156203
|
-
function
|
|
156635
|
+
function bareName2(entry) {
|
|
156204
156636
|
const open = entry.indexOf("(");
|
|
156205
156637
|
return open > 0 && entry.endsWith(")") ? entry.slice(0, open) : entry;
|
|
156206
156638
|
}
|
|
@@ -156211,7 +156643,7 @@ function mapMcp(name) {
|
|
|
156211
156643
|
return rest.includes(MCP_SEPARATOR) ? rest : `${rest}${MCP_SEPARATOR}*`;
|
|
156212
156644
|
}
|
|
156213
156645
|
function mapEntry(entry) {
|
|
156214
|
-
const name =
|
|
156646
|
+
const name = bareName2(entry);
|
|
156215
156647
|
if (NESTING_TOOLS.has(name))
|
|
156216
156648
|
return { reason: REASON_NESTED };
|
|
156217
156649
|
const direct = DIRECT_TOOLS.get(name);
|
|
@@ -156298,6 +156730,29 @@ var init_chat_agents_listing = __esm(() => {
|
|
|
156298
156730
|
init_subagent_tools();
|
|
156299
156731
|
});
|
|
156300
156732
|
|
|
156733
|
+
// src/chat/agent-call-model.ts
|
|
156734
|
+
function agentInput(input) {
|
|
156735
|
+
if (typeof input !== "object" || input === null)
|
|
156736
|
+
return;
|
|
156737
|
+
const agent = Reflect.get(input, "agent");
|
|
156738
|
+
if (typeof agent !== "string")
|
|
156739
|
+
return;
|
|
156740
|
+
const model = Reflect.get(input, "model");
|
|
156741
|
+
return typeof model === "string" ? { agent, model } : { agent };
|
|
156742
|
+
}
|
|
156743
|
+
function withAgentCallModel(onEvent, modelFor) {
|
|
156744
|
+
return (event) => {
|
|
156745
|
+
if (event.type !== "tool_call" || event.name !== AGENT_RUN_TOOL)
|
|
156746
|
+
return onEvent(event);
|
|
156747
|
+
const call = agentInput(event.input);
|
|
156748
|
+
const model = call === undefined ? undefined : modelFor(call.agent, call.model);
|
|
156749
|
+
if (model === undefined)
|
|
156750
|
+
return onEvent(event);
|
|
156751
|
+
onEvent({ ...event, metadata: { ...event.metadata, subagentModel: model } });
|
|
156752
|
+
};
|
|
156753
|
+
}
|
|
156754
|
+
var AGENT_RUN_TOOL = "nax-agents__run";
|
|
156755
|
+
|
|
156301
156756
|
// src/chat/background/task-types.ts
|
|
156302
156757
|
var TASK_ID_PATTERN;
|
|
156303
156758
|
var init_task_types = __esm(() => {
|
|
@@ -156306,7 +156761,7 @@ var init_task_types = __esm(() => {
|
|
|
156306
156761
|
|
|
156307
156762
|
// src/chat/background/task-registry.ts
|
|
156308
156763
|
import { appendFileSync as appendFileSync6, mkdirSync as mkdirSync10 } from "fs";
|
|
156309
|
-
import { join as
|
|
156764
|
+
import { join as join196 } from "path";
|
|
156310
156765
|
function terminalState(end) {
|
|
156311
156766
|
if (end.aborted)
|
|
156312
156767
|
return "stopped";
|
|
@@ -156411,7 +156866,7 @@ class BackgroundTasks {
|
|
|
156411
156866
|
origin: handle.origin,
|
|
156412
156867
|
startedAt: this.options.now().toISOString(),
|
|
156413
156868
|
state: "running",
|
|
156414
|
-
logPath:
|
|
156869
|
+
logPath: join196(this.options.outputDir, "chat-tasks", `${id}.log`)
|
|
156415
156870
|
},
|
|
156416
156871
|
handle,
|
|
156417
156872
|
pending: Promise.resolve(),
|
|
@@ -156421,7 +156876,7 @@ class BackgroundTasks {
|
|
|
156421
156876
|
logFailed: false
|
|
156422
156877
|
};
|
|
156423
156878
|
this.entries.set(id, entry);
|
|
156424
|
-
this.enqueue(entry, () => _backgroundTaskDeps.mkdir(
|
|
156879
|
+
this.enqueue(entry, () => _backgroundTaskDeps.mkdir(join196(this.options.outputDir, "chat-tasks")));
|
|
156425
156880
|
const completion = handle.ended.then((end) => {
|
|
156426
156881
|
this.finalize(entry, end);
|
|
156427
156882
|
this.completions.delete(completion);
|
|
@@ -156622,7 +157077,7 @@ var init_background = __esm(() => {
|
|
|
156622
157077
|
});
|
|
156623
157078
|
|
|
156624
157079
|
// src/chat/chat-ledger.ts
|
|
156625
|
-
import { join as
|
|
157080
|
+
import { join as join197 } from "path";
|
|
156626
157081
|
function createChatLedger(options) {
|
|
156627
157082
|
const aggregators = new Map;
|
|
156628
157083
|
return {
|
|
@@ -156630,7 +157085,7 @@ function createChatLedger(options) {
|
|
|
156630
157085
|
const runId = `chat-${event.sessionId}-${options.startedAt.getTime()}`;
|
|
156631
157086
|
let aggregator = aggregators.get(runId);
|
|
156632
157087
|
if (!aggregator) {
|
|
156633
|
-
aggregator = new CostAggregator(runId,
|
|
157088
|
+
aggregator = new CostAggregator(runId, join197(options.outputDir, "cost"));
|
|
156634
157089
|
aggregators.set(runId, aggregator);
|
|
156635
157090
|
}
|
|
156636
157091
|
const exact = event.costSource !== "unpriced";
|
|
@@ -156749,7 +157204,8 @@ function catalogModel(model) {
|
|
|
156749
157204
|
const split = model.indexOf("/");
|
|
156750
157205
|
if (split <= 0 || isChatAcpModel(model))
|
|
156751
157206
|
return;
|
|
156752
|
-
|
|
157207
|
+
const base = parseModelSpec(model).model;
|
|
157208
|
+
return { provider: base.slice(0, split), name: base.slice(split + 1) };
|
|
156753
157209
|
}
|
|
156754
157210
|
function createContextWindowCache(lookup) {
|
|
156755
157211
|
const windows = new Map;
|
|
@@ -156772,6 +157228,7 @@ function createContextWindowCache(lookup) {
|
|
|
156772
157228
|
};
|
|
156773
157229
|
}
|
|
156774
157230
|
var init_context_window_cache = __esm(() => {
|
|
157231
|
+
init_src();
|
|
156775
157232
|
init_acp3();
|
|
156776
157233
|
});
|
|
156777
157234
|
|
|
@@ -156854,9 +157311,9 @@ function createHostQueue() {
|
|
|
156854
157311
|
|
|
156855
157312
|
// src/chat/recent-models.ts
|
|
156856
157313
|
import { mkdirSync as mkdirSync11, renameSync as renameSync5, unlinkSync as unlinkSync4 } from "fs";
|
|
156857
|
-
import { dirname as dirname52, join as
|
|
157314
|
+
import { dirname as dirname52, join as join198 } from "path";
|
|
156858
157315
|
function recentModelsPath(sessionsDir) {
|
|
156859
|
-
return
|
|
157316
|
+
return join198(sessionsDir, RECENT_MODELS_FILE);
|
|
156860
157317
|
}
|
|
156861
157318
|
function baseOf(model) {
|
|
156862
157319
|
return parseModelSpec(model).model;
|
|
@@ -157235,6 +157692,14 @@ function parseBot(kind, raw, profiles) {
|
|
|
157235
157692
|
};
|
|
157236
157693
|
}
|
|
157237
157694
|
function parseJobInput(kind, raw) {
|
|
157695
|
+
const parsed = parseJobBody(kind, raw);
|
|
157696
|
+
if ("error" in parsed || raw.repo === undefined)
|
|
157697
|
+
return parsed;
|
|
157698
|
+
if (typeof raw.repo !== "string")
|
|
157699
|
+
return { error: "[chat] repo must be a non-empty string" };
|
|
157700
|
+
return { ...parsed, repo: raw.repo };
|
|
157701
|
+
}
|
|
157702
|
+
function parseJobBody(kind, raw) {
|
|
157238
157703
|
if (kind === "plan" || kind === "run") {
|
|
157239
157704
|
if (typeof raw.feature !== "string")
|
|
157240
157705
|
return { error: "[chat] feature must be a string" };
|
|
@@ -157332,18 +157797,18 @@ var init_chain_argv = __esm(() => {
|
|
|
157332
157797
|
init_chain_types();
|
|
157333
157798
|
init_job_argv();
|
|
157334
157799
|
CHAIN_STEP_FIELDS = {
|
|
157335
|
-
plan: ["feature", "spec", "profiles"],
|
|
157336
|
-
run: ["feature", "profiles", "maxIterations", "maxCost"],
|
|
157337
|
-
bot_review: ["pr", "profiles", "model", "decisions"],
|
|
157338
|
-
bot_fix: ["pr", "profiles", "model", "trust", "noRereview"]
|
|
157800
|
+
plan: ["feature", "spec", "profiles", "repo"],
|
|
157801
|
+
run: ["feature", "profiles", "maxIterations", "maxCost", "repo"],
|
|
157802
|
+
bot_review: ["pr", "profiles", "model", "decisions", "repo"],
|
|
157803
|
+
bot_fix: ["pr", "profiles", "model", "trust", "noRereview", "repo"]
|
|
157339
157804
|
};
|
|
157340
157805
|
});
|
|
157341
157806
|
|
|
157342
157807
|
// src/chat/jobs/chain-store.ts
|
|
157343
157808
|
import { linkSync as linkSync2, mkdirSync as mkdirSync12, renameSync as renameSync6, unlinkSync as unlinkSync5 } from "fs";
|
|
157344
|
-
import { join as
|
|
157809
|
+
import { join as join199 } from "path";
|
|
157345
157810
|
function chainsDir(outputDir) {
|
|
157346
|
-
return
|
|
157811
|
+
return join199(outputDir, CHAT_CHAINS_DIR);
|
|
157347
157812
|
}
|
|
157348
157813
|
function newChainId() {
|
|
157349
157814
|
return `chain-${_chainStoreDeps.randomHex()}`;
|
|
@@ -157359,11 +157824,11 @@ async function publishRecord(outputDir, chain, exclusive) {
|
|
|
157359
157824
|
throw new NaxError(`[chat] Invalid chain id: ${chain.id}`, "CHAT_CHAIN_INVALID_ID", { stage: "chat" });
|
|
157360
157825
|
}
|
|
157361
157826
|
const dir = chainsDir(outputDir);
|
|
157362
|
-
const temp =
|
|
157827
|
+
const temp = join199(dir, `${chain.id}.${_chainStoreDeps.randomUUID()}.tmp`);
|
|
157363
157828
|
try {
|
|
157364
157829
|
_chainStoreDeps.mkdir(dir, { recursive: true });
|
|
157365
157830
|
await _chainStoreDeps.write(temp, JSON.stringify(chain, null, 2));
|
|
157366
|
-
const destination =
|
|
157831
|
+
const destination = join199(dir, `${chain.id}.json`);
|
|
157367
157832
|
const published = publishTemp(temp, destination, exclusive);
|
|
157368
157833
|
if (exclusive) {
|
|
157369
157834
|
const cleanupCause = removeTemp(temp);
|
|
@@ -157659,7 +158124,7 @@ var init_chain_controller = __esm(() => {
|
|
|
157659
158124
|
});
|
|
157660
158125
|
|
|
157661
158126
|
// src/execution/status-file-read.ts
|
|
157662
|
-
import { join as
|
|
158127
|
+
import { join as join200 } from "path";
|
|
157663
158128
|
async function readStatusFileAt(path) {
|
|
157664
158129
|
try {
|
|
157665
158130
|
const raw = await _statusFileReadDeps.file(path).json();
|
|
@@ -157669,7 +158134,7 @@ async function readStatusFileAt(path) {
|
|
|
157669
158134
|
}
|
|
157670
158135
|
}
|
|
157671
158136
|
function readStatusFile(featureDir) {
|
|
157672
|
-
return readStatusFileAt(
|
|
158137
|
+
return readStatusFileAt(join200(featureDir, "status.json"));
|
|
157673
158138
|
}
|
|
157674
158139
|
function isUsableStatusFile(value) {
|
|
157675
158140
|
if (typeof value !== "object" || value === null)
|
|
@@ -157708,7 +158173,7 @@ var init_status_file_read = __esm(() => {
|
|
|
157708
158173
|
});
|
|
157709
158174
|
|
|
157710
158175
|
// src/chat/jobs/job-outcome.ts
|
|
157711
|
-
import { join as
|
|
158176
|
+
import { join as join201 } from "path";
|
|
157712
158177
|
function projectProgress(status) {
|
|
157713
158178
|
return {
|
|
157714
158179
|
cost: status.cost.spent,
|
|
@@ -157743,7 +158208,7 @@ function runOutcome(status, job, exitCode) {
|
|
|
157743
158208
|
}
|
|
157744
158209
|
async function planOutcome(job, repoRoot) {
|
|
157745
158210
|
try {
|
|
157746
|
-
const record = await _jobOutcomeDeps.stat(
|
|
158211
|
+
const record = await _jobOutcomeDeps.stat(join201(featureDir(repoRoot, job.target), "prd.json"));
|
|
157747
158212
|
if (record.mtimeMs >= Date.parse(job.startedAt))
|
|
157748
158213
|
return { state: "succeeded" };
|
|
157749
158214
|
} catch (error) {
|
|
@@ -157783,15 +158248,15 @@ var init_job_types = __esm(() => {
|
|
|
157783
158248
|
|
|
157784
158249
|
// src/chat/jobs/job-store.ts
|
|
157785
158250
|
import { mkdirSync as mkdirSync13, readdirSync as readdirSync6, renameSync as renameSync7, unlinkSync as unlinkSync6 } from "fs";
|
|
157786
|
-
import { join as
|
|
158251
|
+
import { join as join202 } from "path";
|
|
157787
158252
|
function jobsDir(outputDir) {
|
|
157788
|
-
return
|
|
158253
|
+
return join202(outputDir, CHAT_JOBS_DIR);
|
|
157789
158254
|
}
|
|
157790
158255
|
function jobLogPath(outputDir, id) {
|
|
157791
|
-
return
|
|
158256
|
+
return join202(jobsDir(outputDir), `${id}.log`);
|
|
157792
158257
|
}
|
|
157793
158258
|
function jobAsksDir(outputDir, jobId) {
|
|
157794
|
-
return
|
|
158259
|
+
return join202(jobsDir(outputDir), `${jobId}.asks`);
|
|
157795
158260
|
}
|
|
157796
158261
|
function newJobId(kind) {
|
|
157797
158262
|
return `${kind}-${_jobStoreDeps.randomHex()}`;
|
|
@@ -157801,11 +158266,11 @@ async function writeJobRecord(outputDir, job) {
|
|
|
157801
158266
|
throw new NaxError(`[chat-jobs] Invalid job id: ${job.id}`, "CHAT_JOB_INVALID_ID", { stage: "chat-jobs" });
|
|
157802
158267
|
}
|
|
157803
158268
|
const dir = jobsDir(outputDir);
|
|
157804
|
-
const temp =
|
|
158269
|
+
const temp = join202(dir, `${job.id}.${_jobStoreDeps.randomUUID()}.tmp`);
|
|
157805
158270
|
try {
|
|
157806
158271
|
_jobStoreDeps.mkdir(dir, { recursive: true });
|
|
157807
158272
|
await _jobStoreDeps.write(temp, JSON.stringify(job, null, 2));
|
|
157808
|
-
_jobStoreDeps.rename(temp,
|
|
158273
|
+
_jobStoreDeps.rename(temp, join202(dir, `${job.id}.json`));
|
|
157809
158274
|
} catch (cause) {
|
|
157810
158275
|
const cleanupCause = removeTemp2(temp);
|
|
157811
158276
|
throw new NaxError(`[chat-jobs] Failed to write job ${job.id}`, "CHAT_JOB_WRITE_FAILED", {
|
|
@@ -157854,7 +158319,7 @@ async function readJobRecords(outputDir) {
|
|
|
157854
158319
|
return [];
|
|
157855
158320
|
throw err;
|
|
157856
158321
|
}
|
|
157857
|
-
const records = await Promise.all(names.filter((name) => name.endsWith(".json")).map((name) => readRecord(
|
|
158322
|
+
const records = await Promise.all(names.filter((name) => name.endsWith(".json")).map((name) => readRecord(join202(dir, name))));
|
|
157858
158323
|
return records.filter((record) => record !== null).sort((a, b) => b.startedAt.localeCompare(a.startedAt));
|
|
157859
158324
|
}
|
|
157860
158325
|
var CHAT_JOBS_DIR = "chat-jobs", RANDOM_HEX_LENGTH3 = 8, JOB_KINDS, JOB_STATES, _jobStoreDeps;
|
|
@@ -157876,7 +158341,7 @@ var init_job_store = __esm(() => {
|
|
|
157876
158341
|
});
|
|
157877
158342
|
|
|
157878
158343
|
// src/chat/jobs/job-runner.ts
|
|
157879
|
-
import { closeSync, mkdirSync as mkdirSync14, openSync } from "fs";
|
|
158344
|
+
import { closeSync, mkdirSync as mkdirSync14, openSync, realpathSync as realpathSync7 } from "fs";
|
|
157880
158345
|
|
|
157881
158346
|
class DetachedJobs {
|
|
157882
158347
|
options;
|
|
@@ -157915,7 +158380,7 @@ class DetachedJobs {
|
|
|
157915
158380
|
const fd = _jobRunnerDeps.openLog(logPath);
|
|
157916
158381
|
try {
|
|
157917
158382
|
return _jobRunnerDeps.spawn(request.argv, {
|
|
157918
|
-
cwd: this.options.repoRoot,
|
|
158383
|
+
cwd: request.cwd ?? this.options.repoRoot,
|
|
157919
158384
|
detached: true,
|
|
157920
158385
|
stdin: secret ? "pipe" : "ignore",
|
|
157921
158386
|
stdout: fd,
|
|
@@ -157958,7 +158423,7 @@ class DetachedJobs {
|
|
|
157958
158423
|
schemaVersion: 1,
|
|
157959
158424
|
id,
|
|
157960
158425
|
logPath,
|
|
157961
|
-
cwd: this.options.repoRoot,
|
|
158426
|
+
cwd: request.cwd ?? this.options.repoRoot,
|
|
157962
158427
|
pid: child.pid,
|
|
157963
158428
|
startedAt: this.options.now().toISOString(),
|
|
157964
158429
|
state: "running"
|
|
@@ -158046,7 +158511,7 @@ class DetachedJobs {
|
|
|
158046
158511
|
const disk = (await readJobRecords(this.options.outputDir)).find((record) => record.id === job.id && record.cwd === job.cwd && record.pid === job.pid);
|
|
158047
158512
|
const current = this.records.get(job.id) ?? job;
|
|
158048
158513
|
const merged = disk?.cancelRequested ? { ...current, cancelRequested: true } : current;
|
|
158049
|
-
const outcome = await resolveJobOutcome(merged, { exitCode },
|
|
158514
|
+
const outcome = await resolveJobOutcome(merged, { exitCode }, job.cwd);
|
|
158050
158515
|
const terminal = {
|
|
158051
158516
|
...this.records.get(job.id) ?? merged,
|
|
158052
158517
|
...merged.cancelRequested ? { cancelRequested: true } : {},
|
|
@@ -158105,7 +158570,7 @@ class DetachedJobs {
|
|
|
158105
158570
|
stage: "chat"
|
|
158106
158571
|
});
|
|
158107
158572
|
}
|
|
158108
|
-
if (this.ownedIds.has(id) || await readRunProgress(job,
|
|
158573
|
+
if (this.ownedIds.has(id) || await readRunProgress(job, job.cwd))
|
|
158109
158574
|
return null;
|
|
158110
158575
|
return new NaxError(`job ${id} was started by another chat and its pid cannot be verified; stop it from that chat or by hand`, "CHAT_JOB_UNVERIFIED", { stage: "chat" });
|
|
158111
158576
|
}
|
|
@@ -158169,10 +158634,17 @@ class DetachedJobs {
|
|
|
158169
158634
|
this.attachment ??= this.loadRecords();
|
|
158170
158635
|
return this.attachment;
|
|
158171
158636
|
}
|
|
158637
|
+
ownsCwd(cwd) {
|
|
158638
|
+
try {
|
|
158639
|
+
return isWithinRoot(realpathSync7(cwd), realpathSync7(this.options.repoRoot));
|
|
158640
|
+
} catch {
|
|
158641
|
+
return false;
|
|
158642
|
+
}
|
|
158643
|
+
}
|
|
158172
158644
|
async loadRecords() {
|
|
158173
158645
|
const records = await readJobRecords(this.options.outputDir);
|
|
158174
158646
|
for (const job of records) {
|
|
158175
|
-
if (job.cwd
|
|
158647
|
+
if (!this.ownsCwd(job.cwd) || this.records.has(job.id))
|
|
158176
158648
|
continue;
|
|
158177
158649
|
this.records.set(job.id, job);
|
|
158178
158650
|
if (job.state === "running" && !_jobRunnerDeps.isProcessAlive(job.pid)) {
|
|
@@ -158184,11 +158656,11 @@ class DetachedJobs {
|
|
|
158184
158656
|
}
|
|
158185
158657
|
async finalizeAttached(job, notify) {
|
|
158186
158658
|
this.clearGrace(job.id);
|
|
158187
|
-
const disk = (await readJobRecords(this.options.outputDir)).find((record) => record.id === job.id && record.cwd ===
|
|
158659
|
+
const disk = (await readJobRecords(this.options.outputDir)).find((record) => record.id === job.id && record.cwd === job.cwd);
|
|
158188
158660
|
if (disk && disk.state !== "running") {
|
|
158189
158661
|
this.records.set(job.id, disk);
|
|
158190
158662
|
} else {
|
|
158191
|
-
const outcome = await resolveJobOutcome(job, {},
|
|
158663
|
+
const outcome = await resolveJobOutcome(job, {}, job.cwd);
|
|
158192
158664
|
const terminal = { ...job, ...outcome, endedAt: this.options.now().toISOString() };
|
|
158193
158665
|
await writeJobRecord(this.options.outputDir, terminal);
|
|
158194
158666
|
this.records.set(job.id, terminal);
|
|
@@ -158245,7 +158717,7 @@ class DetachedJobs {
|
|
|
158245
158717
|
}
|
|
158246
158718
|
}
|
|
158247
158719
|
async refreshProgress(job) {
|
|
158248
|
-
const metrics = await readRunProgress(job,
|
|
158720
|
+
const metrics = await readRunProgress(job, job.cwd);
|
|
158249
158721
|
const current = this.records.get(job.id);
|
|
158250
158722
|
if (this.disposed || current?.state !== "running" || !metrics)
|
|
158251
158723
|
return;
|
|
@@ -158285,6 +158757,7 @@ var init_job_runner = __esm(() => {
|
|
|
158285
158757
|
init_interaction3();
|
|
158286
158758
|
init_logger2();
|
|
158287
158759
|
init_prompts();
|
|
158760
|
+
init_target_repo();
|
|
158288
158761
|
init_job_outcome();
|
|
158289
158762
|
init_job_store();
|
|
158290
158763
|
_jobRunnerDeps = {
|
|
@@ -158320,7 +158793,7 @@ function createJobWriteGuard(jobs, repoRoot) {
|
|
|
158320
158793
|
handler: (payload) => {
|
|
158321
158794
|
if (!("call" in payload) || !GUARDED_WRITE_TOOLS.includes(payload.call.name))
|
|
158322
158795
|
return { kind: "allow" };
|
|
158323
|
-
const job = jobs.running().filter((job) => job.cwd
|
|
158796
|
+
const job = jobs.running().filter((job) => isWithinRootCanonical(job.cwd, repoRoot) && (job.kind === "plan" || job.kind === "run")).sort((a, b) => Date.parse(b.startedAt) - Date.parse(a.startedAt))[0];
|
|
158324
158797
|
if (!job)
|
|
158325
158798
|
return { kind: "allow" };
|
|
158326
158799
|
return {
|
|
@@ -158334,14 +158807,15 @@ function createJobWriteGuard(jobs, repoRoot) {
|
|
|
158334
158807
|
}
|
|
158335
158808
|
var GUARDED_WRITE_TOOLS;
|
|
158336
158809
|
var init_job_write_guard = __esm(() => {
|
|
158810
|
+
init_target_repo();
|
|
158337
158811
|
GUARDED_WRITE_TOOLS = Object.freeze(["Write", "Edit", "Delete", "GitCommit"]);
|
|
158338
158812
|
});
|
|
158339
158813
|
|
|
158340
158814
|
// src/chat/jobs/jobs-launch.ts
|
|
158341
|
-
import { join as
|
|
158815
|
+
import { join as join203, relative as relative50 } from "path";
|
|
158342
158816
|
async function lockHolder(repoRoot) {
|
|
158343
158817
|
try {
|
|
158344
|
-
const raw = await _jobsLaunchDeps.readLock(
|
|
158818
|
+
const raw = await _jobsLaunchDeps.readLock(join203(repoRoot, "nax.lock"));
|
|
158345
158819
|
if (typeof raw !== "object" || raw === null || !("pid" in raw))
|
|
158346
158820
|
return null;
|
|
158347
158821
|
const { pid } = raw;
|
|
@@ -158395,6 +158869,7 @@ async function startApproved(input, launch, options) {
|
|
|
158395
158869
|
kind: input.kind,
|
|
158396
158870
|
target: "feature" in input ? input.feature : String(input.pr),
|
|
158397
158871
|
argv,
|
|
158872
|
+
cwd: options.repoRoot,
|
|
158398
158873
|
sessionId: options.sessionId(),
|
|
158399
158874
|
approvedAt: auto ? auto.approvedAt : options.now().toISOString(),
|
|
158400
158875
|
...auto ? { chainId: auto.chainId, chainStep: auto.step } : {}
|
|
@@ -158421,7 +158896,7 @@ async function preparePlan(input, options) {
|
|
|
158421
158896
|
}
|
|
158422
158897
|
async function resolvePlanSpec(feature, requestedSpec, options) {
|
|
158423
158898
|
const dir = featureDir(options.repoRoot, feature);
|
|
158424
|
-
const candidates = requestedSpec === undefined ? [
|
|
158899
|
+
const candidates = requestedSpec === undefined ? [join203(dir, "spec.md"), join203(options.repoRoot, ".nax", "specs", `${feature}.md`)] : [join203(options.repoRoot, requestedSpec)];
|
|
158425
158900
|
let spec;
|
|
158426
158901
|
for (const path of candidates) {
|
|
158427
158902
|
if (await _jobsLaunchDeps.exists(path)) {
|
|
@@ -158434,10 +158909,10 @@ async function resolvePlanSpec(feature, requestedSpec, options) {
|
|
|
158434
158909
|
error: `[chat] no spec for ${feature}; looked for ${candidates.map((p) => relative50(options.repoRoot, p)).join(", ")}`
|
|
158435
158910
|
};
|
|
158436
158911
|
}
|
|
158437
|
-
return { spec, prdExists: await _jobsLaunchDeps.exists(
|
|
158912
|
+
return { spec, prdExists: await _jobsLaunchDeps.exists(join203(dir, "prd.json")) };
|
|
158438
158913
|
}
|
|
158439
158914
|
async function prepareRun(input, options) {
|
|
158440
|
-
const path =
|
|
158915
|
+
const path = join203(featureDir(options.repoRoot, input.feature), "prd.json");
|
|
158441
158916
|
if (!await _jobsLaunchDeps.exists(path)) {
|
|
158442
158917
|
return { error: `[chat] no prd.json for ${input.feature}; run nax plan first` };
|
|
158443
158918
|
}
|
|
@@ -158471,7 +158946,7 @@ async function prepareTarget(input, options) {
|
|
|
158471
158946
|
return preparePlan(input, options);
|
|
158472
158947
|
if (input.kind === "run")
|
|
158473
158948
|
return prepareRun(input, options);
|
|
158474
|
-
if (input.kind === "bot_review" && input.decisions !== undefined && !await _jobsLaunchDeps.exists(
|
|
158949
|
+
if (input.kind === "bot_review" && input.decisions !== undefined && !await _jobsLaunchDeps.exists(join203(options.repoRoot, input.decisions))) {
|
|
158475
158950
|
return { error: `[chat] decisions file ${input.decisions} not found` };
|
|
158476
158951
|
}
|
|
158477
158952
|
return { input, details: [] };
|
|
@@ -158486,7 +158961,11 @@ async function launchReason(prepared, options) {
|
|
|
158486
158961
|
].join(`
|
|
158487
158962
|
`);
|
|
158488
158963
|
}
|
|
158489
|
-
async function launchJob(request,
|
|
158964
|
+
async function launchJob(request, chatOptions) {
|
|
158965
|
+
const target = await resolveTargetRepo(chatOptions.repoRoot, request.raw.repo);
|
|
158966
|
+
if ("error" in target)
|
|
158967
|
+
return { isError: true, content: target.error };
|
|
158968
|
+
const options = { ...chatOptions, repoRoot: target.root };
|
|
158490
158969
|
const parsed = parseJobInput(request.kind, request.raw);
|
|
158491
158970
|
if ("error" in parsed)
|
|
158492
158971
|
return { isError: true, content: parsed.error };
|
|
@@ -158546,6 +159025,7 @@ var init_jobs_launch = __esm(() => {
|
|
|
158546
159025
|
init_config();
|
|
158547
159026
|
init_prd();
|
|
158548
159027
|
init_git2();
|
|
159028
|
+
init_target_repo();
|
|
158549
159029
|
init_job_argv();
|
|
158550
159030
|
_jobsLaunchDeps = {
|
|
158551
159031
|
git: gitWithTimeout,
|
|
@@ -158584,20 +159064,30 @@ function parseStep(raw, step) {
|
|
|
158584
159064
|
}
|
|
158585
159065
|
return { input, ...checkBefore === undefined ? {} : { checkBefore } };
|
|
158586
159066
|
}
|
|
159067
|
+
async function resolveStepTarget(entry, step, options) {
|
|
159068
|
+
const { input } = entry;
|
|
159069
|
+
const target = await resolveTargetRepo(options.repoRoot, input.repo);
|
|
159070
|
+
if ("error" in target)
|
|
159071
|
+
return stepError(step, target.error);
|
|
159072
|
+
const stepOptions = { ...options, repoRoot: target.root };
|
|
159073
|
+
if (input.kind !== "plan")
|
|
159074
|
+
return { input, options: stepOptions, prdExists: false };
|
|
159075
|
+
const resolved = await resolvePlanSpec(input.feature, input.spec, stepOptions);
|
|
159076
|
+
if ("error" in resolved)
|
|
159077
|
+
return stepError(step, resolved.error);
|
|
159078
|
+
return { input: { ...input, spec: resolved.spec }, options: stepOptions, prdExists: resolved.prdExists };
|
|
159079
|
+
}
|
|
158587
159080
|
async function resolveSteps(parsed, options) {
|
|
158588
159081
|
const steps = [];
|
|
158589
159082
|
const existingPlanPrds = [];
|
|
158590
159083
|
for (const [index, entry] of parsed.entries()) {
|
|
158591
|
-
|
|
158592
|
-
if (
|
|
158593
|
-
|
|
158594
|
-
|
|
158595
|
-
|
|
158596
|
-
|
|
158597
|
-
|
|
158598
|
-
input = { ...input, spec: resolved.spec };
|
|
158599
|
-
}
|
|
158600
|
-
const argv = buildChainStepArgv(input, options);
|
|
159084
|
+
const resolved = await resolveStepTarget(entry, index + 1, options);
|
|
159085
|
+
if ("error" in resolved)
|
|
159086
|
+
return resolved;
|
|
159087
|
+
const { input, options: stepOptions } = resolved;
|
|
159088
|
+
if (resolved.prdExists && input.kind === "plan")
|
|
159089
|
+
existingPlanPrds.push({ step: index + 1, feature: input.feature });
|
|
159090
|
+
const argv = buildChainStepArgv(input, stepOptions);
|
|
158601
159091
|
const prless = (input.kind === "bot_review" || input.kind === "bot_fix") && input.pr === undefined;
|
|
158602
159092
|
steps.push({
|
|
158603
159093
|
kind: input.kind,
|
|
@@ -158749,6 +159239,7 @@ function createChainTools(options) {
|
|
|
158749
159239
|
var BOT_PR_OFFSET2 = 2;
|
|
158750
159240
|
var init_chain_tools = __esm(() => {
|
|
158751
159241
|
init_internal();
|
|
159242
|
+
init_target_repo();
|
|
158752
159243
|
init_chain_argv();
|
|
158753
159244
|
init_chain_types();
|
|
158754
159245
|
init_jobs_launch();
|
|
@@ -158853,7 +159344,7 @@ function createJobsProvider(options) {
|
|
|
158853
159344
|
]
|
|
158854
159345
|
};
|
|
158855
159346
|
}
|
|
158856
|
-
var JOBS_LIST_LIMIT = 20, profiles, schemas4, LAUNCH_KINDS;
|
|
159347
|
+
var JOBS_LIST_LIMIT = 20, profiles, repo, schemas4, LAUNCH_KINDS;
|
|
158857
159348
|
var init_jobs_provider = __esm(() => {
|
|
158858
159349
|
init_prompts();
|
|
158859
159350
|
init_chain_tools();
|
|
@@ -158861,11 +159352,19 @@ var init_jobs_provider = __esm(() => {
|
|
|
158861
159352
|
init_job_types();
|
|
158862
159353
|
init_jobs_launch();
|
|
158863
159354
|
profiles = { type: "array", items: { type: "string" } };
|
|
159355
|
+
repo = { type: "string" };
|
|
158864
159356
|
schemas4 = {
|
|
158865
|
-
plan: { feature: { type: "string" }, spec: { type: "string" }, profiles },
|
|
158866
|
-
run: {
|
|
158867
|
-
|
|
159357
|
+
plan: { feature: { type: "string" }, spec: { type: "string" }, profiles, repo },
|
|
159358
|
+
run: {
|
|
159359
|
+
feature: { type: "string" },
|
|
159360
|
+
profiles,
|
|
159361
|
+
maxIterations: { type: "integer" },
|
|
159362
|
+
maxCost: { type: "number" },
|
|
159363
|
+
repo
|
|
159364
|
+
},
|
|
159365
|
+
bot_review: { pr: { type: "integer" }, profiles, model: { type: "string" }, decisions: { type: "string" }, repo },
|
|
158868
159366
|
bot_fix: {
|
|
159367
|
+
repo,
|
|
158869
159368
|
pr: { type: "integer" },
|
|
158870
159369
|
profiles,
|
|
158871
159370
|
model: { type: "string" },
|
|
@@ -159874,9 +160373,46 @@ async function runOnSession(session, input) {
|
|
|
159874
160373
|
await closeQuietly(session, input);
|
|
159875
160374
|
}
|
|
159876
160375
|
}
|
|
160376
|
+
function subagentProfile(input) {
|
|
160377
|
+
return acpSubagentProfile({
|
|
160378
|
+
tools: input.agent.tools,
|
|
160379
|
+
mode: input.mode,
|
|
160380
|
+
...input.config.agent?.acpSubagents?.profile !== undefined ? { override: input.config.agent.acpSubagents.profile } : {}
|
|
160381
|
+
});
|
|
160382
|
+
}
|
|
160383
|
+
function readOnlyRefusal(input, acp, profile) {
|
|
160384
|
+
if (!isReadOnlyAcpProfile(profile) || acpReadOnlyEnforced(acp.agent))
|
|
160385
|
+
return;
|
|
160386
|
+
return {
|
|
160387
|
+
isError: true,
|
|
160388
|
+
content: `[chat] subagent ${input.agent.qualifiedName} could not start read-only: ${acpAgentLabel(acp.agent)} has no read-only enforcement of its own`
|
|
160389
|
+
};
|
|
160390
|
+
}
|
|
160391
|
+
async function runAcpSubagent(input, acp, deps) {
|
|
160392
|
+
const profile = subagentProfile(input);
|
|
160393
|
+
const refusal = readOnlyRefusal(input, acp, profile);
|
|
160394
|
+
if (refusal !== undefined)
|
|
160395
|
+
return refusal;
|
|
160396
|
+
let session;
|
|
160397
|
+
try {
|
|
160398
|
+
const options = await acpSubagentSessionOptions({ ...input, acp, profile }, () => deps.createMemoryTranscriptStore());
|
|
160399
|
+
session = await deps.createAgentSession(options);
|
|
160400
|
+
} catch (err) {
|
|
160401
|
+
return failedResult2(input, err);
|
|
160402
|
+
}
|
|
160403
|
+
return runOnSession(session, input);
|
|
160404
|
+
}
|
|
159877
160405
|
async function runSubagent(input, deps = _subagentSessionDeps) {
|
|
159878
160406
|
if (input.signal?.aborted)
|
|
159879
160407
|
return cancelledResult2(input);
|
|
160408
|
+
let acp;
|
|
160409
|
+
try {
|
|
160410
|
+
acp = parseChatAcpModel(input.model);
|
|
160411
|
+
} catch (err) {
|
|
160412
|
+
return failedResult2(input, err);
|
|
160413
|
+
}
|
|
160414
|
+
if (acp !== undefined)
|
|
160415
|
+
return runAcpSubagent(input, acp, deps);
|
|
159880
160416
|
const posture = input.mode === "guarded" ? deps.resolveTuiPermissions(input.config) : undefined;
|
|
159881
160417
|
const options = await subagentSessionOptions(input, posture, deps);
|
|
159882
160418
|
let session;
|
|
@@ -159896,6 +160432,7 @@ var init_subagent_session = __esm(() => {
|
|
|
159896
160432
|
init_errors4();
|
|
159897
160433
|
init_logger2();
|
|
159898
160434
|
init_prompts();
|
|
160435
|
+
init_acp3();
|
|
159899
160436
|
init_chat_mode();
|
|
159900
160437
|
_subagentSessionDeps = {
|
|
159901
160438
|
createAgentSession,
|
|
@@ -159925,6 +160462,15 @@ function createSubagentRuns(deps) {
|
|
|
159925
160462
|
const active = new Set;
|
|
159926
160463
|
const inFlight = new Map;
|
|
159927
160464
|
let spentUsd = 0;
|
|
160465
|
+
function resolveFor(agent, current, override) {
|
|
160466
|
+
const requested = override ?? agent.model;
|
|
160467
|
+
return resolveSubagentModel({
|
|
160468
|
+
...requested !== undefined ? { requested } : {},
|
|
160469
|
+
parentModel: current.model,
|
|
160470
|
+
aliases: deps.config.agent?.modelAliases ?? {},
|
|
160471
|
+
tiers: deps.config.models.native
|
|
160472
|
+
});
|
|
160473
|
+
}
|
|
159928
160474
|
function release(session) {
|
|
159929
160475
|
active.delete(session);
|
|
159930
160476
|
for (const [requestId, owner] of [...owners]) {
|
|
@@ -159966,36 +160512,37 @@ function createSubagentRuns(deps) {
|
|
|
159966
160512
|
else if (event.type === "tool_call" || event.type === "tool_result")
|
|
159967
160513
|
listener?.(event);
|
|
159968
160514
|
}
|
|
159969
|
-
function run(agent, task, signal) {
|
|
160515
|
+
function run(agent, task, signal, model) {
|
|
159970
160516
|
const entry = { controller: new AbortController };
|
|
159971
160517
|
const onParentAbort = () => entry.controller.abort();
|
|
159972
160518
|
if (signal?.aborted)
|
|
159973
160519
|
onParentAbort();
|
|
159974
160520
|
else
|
|
159975
160521
|
signal?.addEventListener("abort", onParentAbort, { once: true });
|
|
159976
|
-
const promise = runNested(agent, task, entry).finally(() => {
|
|
160522
|
+
const promise = runNested(agent, task, entry, model).finally(() => {
|
|
159977
160523
|
signal?.removeEventListener("abort", onParentAbort);
|
|
159978
160524
|
inFlight.delete(promise);
|
|
159979
160525
|
});
|
|
159980
160526
|
inFlight.set(promise, entry);
|
|
159981
160527
|
return promise;
|
|
159982
160528
|
}
|
|
159983
|
-
async function runNested(agent, task, entry) {
|
|
160529
|
+
async function runNested(agent, task, entry, override) {
|
|
159984
160530
|
const current = deps.current();
|
|
159985
160531
|
const listener = deps.turnListener();
|
|
159986
160532
|
const forward = listener === undefined ? undefined : (event) => listener(taggedActivity(event, agent, task));
|
|
159987
|
-
const { model } =
|
|
159988
|
-
|
|
159989
|
-
|
|
159990
|
-
|
|
159991
|
-
|
|
159992
|
-
|
|
160533
|
+
const { model, source } = resolveFor(agent, current, override);
|
|
160534
|
+
if (override !== undefined && source === "fallback") {
|
|
160535
|
+
return {
|
|
160536
|
+
isError: true,
|
|
160537
|
+
content: `[chat] unknown model ${override}; pass provider/model (a nax native model such as openai-codex/gpt-6-luna), acp:<agent>, or a configured alias`
|
|
160538
|
+
};
|
|
160539
|
+
}
|
|
159993
160540
|
const { allowedTools } = mapSubagentTools(agent.tools);
|
|
159994
160541
|
const memoryIndex = deps.memoryIndex?.();
|
|
159995
160542
|
let nested;
|
|
159996
160543
|
const usage = {};
|
|
159997
160544
|
try {
|
|
159998
|
-
return await runSubagent({
|
|
160545
|
+
return await _subagentRunsDeps.runSubagent({
|
|
159999
160546
|
agent,
|
|
160000
160547
|
task,
|
|
160001
160548
|
mode: current.mode,
|
|
@@ -160027,6 +160574,13 @@ function createSubagentRuns(deps) {
|
|
|
160027
160574
|
}
|
|
160028
160575
|
const runs = {
|
|
160029
160576
|
run,
|
|
160577
|
+
modelFor(agentName, override) {
|
|
160578
|
+
const agent = deps.catalog.findAgent(agentName);
|
|
160579
|
+
if (agent === undefined)
|
|
160580
|
+
return;
|
|
160581
|
+
const { model, source } = resolveFor(agent, deps.current(), override);
|
|
160582
|
+
return override !== undefined && source === "fallback" ? undefined : model;
|
|
160583
|
+
},
|
|
160030
160584
|
sessionFor: (requestId) => owners.get(requestId),
|
|
160031
160585
|
takeCost() {
|
|
160032
160586
|
const taken = spentUsd;
|
|
@@ -160051,10 +160605,12 @@ function createSubagentRuns(deps) {
|
|
|
160051
160605
|
};
|
|
160052
160606
|
return runs;
|
|
160053
160607
|
}
|
|
160608
|
+
var _subagentRunsDeps;
|
|
160054
160609
|
var init_subagent_runs = __esm(() => {
|
|
160055
160610
|
init_subagent_model();
|
|
160056
160611
|
init_subagent_session();
|
|
160057
160612
|
init_subagent_tools();
|
|
160613
|
+
_subagentRunsDeps = { runSubagent };
|
|
160058
160614
|
});
|
|
160059
160615
|
|
|
160060
160616
|
// src/chat/turn-runner.ts
|
|
@@ -160470,7 +161026,7 @@ class NativeChatHost {
|
|
|
160470
161026
|
images: options?.images,
|
|
160471
161027
|
asks: this.asks,
|
|
160472
161028
|
ledger,
|
|
160473
|
-
onEvent,
|
|
161029
|
+
onEvent: runs ? withAgentCallModel(onEvent, runs.modelFor) : onEvent,
|
|
160474
161030
|
now: this.deps.now().toISOString(),
|
|
160475
161031
|
...runs ? { extraCostUsd: () => runs.takeCost(), settleNested: () => runs.settle() } : {}
|
|
160476
161032
|
});
|
|
@@ -160853,7 +161409,7 @@ var init_types18 = __esm(() => {
|
|
|
160853
161409
|
|
|
160854
161410
|
// src/chat/mentions/mention-expand.ts
|
|
160855
161411
|
import { readdir as readdir17, realpath as realpath10, stat as stat20 } from "fs/promises";
|
|
160856
|
-
import { relative as relative51, resolve as
|
|
161412
|
+
import { relative as relative51, resolve as resolve55, sep as sep28 } from "path";
|
|
160857
161413
|
async function expandChatMentions(text, where) {
|
|
160858
161414
|
const ctx = {
|
|
160859
161415
|
cwd: where.cwd,
|
|
@@ -160890,7 +161446,7 @@ async function expandToken(token, ctx) {
|
|
|
160890
161446
|
}
|
|
160891
161447
|
}
|
|
160892
161448
|
async function locate(token, cwd) {
|
|
160893
|
-
const direct = await realPathOrUndefined(
|
|
161449
|
+
const direct = await realPathOrUndefined(resolve55(cwd, token.path));
|
|
160894
161450
|
if (direct !== undefined)
|
|
160895
161451
|
return { path: token.path, realPath: direct };
|
|
160896
161452
|
if (token.quoted)
|
|
@@ -160898,18 +161454,18 @@ async function locate(token, cwd) {
|
|
|
160898
161454
|
const stripped = token.path.replace(TRAILING_PUNCTUATION2, "");
|
|
160899
161455
|
if (stripped === "" || stripped === token.path)
|
|
160900
161456
|
return;
|
|
160901
|
-
const retried = await realPathOrUndefined(
|
|
161457
|
+
const retried = await realPathOrUndefined(resolve55(cwd, stripped));
|
|
160902
161458
|
return retried === undefined ? undefined : { path: stripped, realPath: retried };
|
|
160903
161459
|
}
|
|
160904
161460
|
function boundaryRefusal(realPath, realRoot) {
|
|
160905
161461
|
if (realRoot === undefined)
|
|
160906
161462
|
return OUTSIDE_REPO;
|
|
160907
|
-
const prefix = realRoot.endsWith(
|
|
161463
|
+
const prefix = realRoot.endsWith(sep28) ? realRoot : `${realRoot}${sep28}`;
|
|
160908
161464
|
if (realPath === realRoot)
|
|
160909
161465
|
return;
|
|
160910
161466
|
if (!realPath.startsWith(prefix))
|
|
160911
161467
|
return OUTSIDE_REPO;
|
|
160912
|
-
const segments = realPath.slice(prefix.length).split(
|
|
161468
|
+
const segments = realPath.slice(prefix.length).split(sep28);
|
|
160913
161469
|
return segments.some((segment) => segment.toLowerCase() === GIT_DIR_SEGMENT) ? INSIDE_GIT_DIR : undefined;
|
|
160914
161470
|
}
|
|
160915
161471
|
async function ignoredRefusal(path, cwd) {
|
|
@@ -160962,7 +161518,7 @@ async function folderEntries(located, cwd) {
|
|
|
160962
161518
|
return entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
160963
161519
|
}
|
|
160964
161520
|
function folderPathspec(cwd, path) {
|
|
160965
|
-
const rel = relative51(cwd,
|
|
161521
|
+
const rel = relative51(cwd, resolve55(cwd, path)).split(sep28).join(PATH_SEPARATOR).replace(/\/+$/, "");
|
|
160966
161522
|
return rel === "" || rel === ROOT_PATHSPEC ? ROOT_PATHSPEC : `${rel}${FOLDER_SUFFIX}`;
|
|
160967
161523
|
}
|
|
160968
161524
|
function parseListedPaths(stdout, pathspec) {
|
|
@@ -161295,13 +161851,13 @@ var init_run_verdict = __esm(() => {
|
|
|
161295
161851
|
|
|
161296
161852
|
// src/chat/workflow/feature-state.ts
|
|
161297
161853
|
import { readdirSync as readdirSync7 } from "fs";
|
|
161298
|
-
import { join as
|
|
161854
|
+
import { join as join204, relative as relative52 } from "path";
|
|
161299
161855
|
async function readFeatureState(name, options) {
|
|
161300
161856
|
const dir = featureDir(options.repoRoot, name);
|
|
161301
161857
|
const warnings = [];
|
|
161302
161858
|
const [spec, prd, status] = await Promise.all([
|
|
161303
161859
|
readSpec(name, options.repoRoot),
|
|
161304
|
-
readPrd(
|
|
161860
|
+
readPrd(join204(dir, "prd.json"), warnings),
|
|
161305
161861
|
readStatusFile(dir)
|
|
161306
161862
|
]);
|
|
161307
161863
|
if (prd && options.maxIterations !== undefined && prd.pending > options.maxIterations) {
|
|
@@ -161364,7 +161920,7 @@ function isMissingFile(err) {
|
|
|
161364
161920
|
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
161365
161921
|
}
|
|
161366
161922
|
function readLastRunLog(name, outputDir) {
|
|
161367
|
-
const names = directoryEntries(
|
|
161923
|
+
const names = directoryEntries(join204(outputDir, "features", name, "runs")).filter((e) => e.isFile() && e.name.endsWith(".jsonl") && e.name !== "latest.jsonl").map((e) => e.name).sort().reverse();
|
|
161368
161924
|
return names[0]?.slice(0, -".jsonl".length) ?? null;
|
|
161369
161925
|
}
|
|
161370
161926
|
async function readWorkflowStateList(options) {
|
|
@@ -161386,7 +161942,7 @@ async function readWorkflowStateList(options) {
|
|
|
161386
161942
|
async function featureRecency(dir) {
|
|
161387
161943
|
const times = await Promise.all(["spec.md", "prd.json", "status.json"].map(async (name) => {
|
|
161388
161944
|
try {
|
|
161389
|
-
return (await _featureStateDeps.file(
|
|
161945
|
+
return (await _featureStateDeps.file(join204(dir, name)).stat()).mtimeMs;
|
|
161390
161946
|
} catch (err) {
|
|
161391
161947
|
if (isMissingFile(err))
|
|
161392
161948
|
return 0;
|
|
@@ -161396,10 +161952,10 @@ async function featureRecency(dir) {
|
|
|
161396
161952
|
return Math.max(0, ...times);
|
|
161397
161953
|
}
|
|
161398
161954
|
async function readSpec(name, repoRoot) {
|
|
161399
|
-
const preferred =
|
|
161955
|
+
const preferred = join204(featureDir(repoRoot, name), "spec.md");
|
|
161400
161956
|
if (await _featureStateDeps.file(preferred).exists())
|
|
161401
161957
|
return relative52(repoRoot, preferred);
|
|
161402
|
-
const legacy =
|
|
161958
|
+
const legacy = join204(repoRoot, ".nax", "specs", `${name}.md`);
|
|
161403
161959
|
return await _featureStateDeps.file(legacy).exists() ? relative52(repoRoot, legacy) : null;
|
|
161404
161960
|
}
|
|
161405
161961
|
async function readPrd(path, warnings) {
|
|
@@ -161455,8 +162011,8 @@ var init_feature_state = __esm(() => {
|
|
|
161455
162011
|
});
|
|
161456
162012
|
|
|
161457
162013
|
// src/chat/workflow/workflow-provider.ts
|
|
161458
|
-
import { readdirSync as readdirSync8, statSync as
|
|
161459
|
-
import { join as
|
|
162014
|
+
import { readdirSync as readdirSync8, statSync as statSync16 } from "fs";
|
|
162015
|
+
import { join as join205 } from "path";
|
|
161460
162016
|
function failure9(content) {
|
|
161461
162017
|
return { content, isError: true };
|
|
161462
162018
|
}
|
|
@@ -161490,7 +162046,11 @@ function exists3(path, kind) {
|
|
|
161490
162046
|
throw err;
|
|
161491
162047
|
}
|
|
161492
162048
|
}
|
|
161493
|
-
async function readState(input,
|
|
162049
|
+
async function readState(input, base) {
|
|
162050
|
+
const target = await resolveTargetRepo(base.repoRoot, input.repo);
|
|
162051
|
+
if ("error" in target)
|
|
162052
|
+
return failure9(target.error);
|
|
162053
|
+
const options = target.root === base.repoRoot ? base : { ...base, repoRoot: target.root, outputDir: await targetOutputDir(target.root) };
|
|
161494
162054
|
const { feature } = input;
|
|
161495
162055
|
if (!("feature" in input) || feature === null || typeof feature === "string" && !feature.trim()) {
|
|
161496
162056
|
return { content: JSON.stringify(await readWorkflowStateList(options), null, 2) };
|
|
@@ -161504,7 +162064,7 @@ async function readState(input, options) {
|
|
|
161504
162064
|
} catch (err) {
|
|
161505
162065
|
return failure9(errorMessage(err));
|
|
161506
162066
|
}
|
|
161507
|
-
if (exists3(dir, "directory") || exists3(
|
|
162067
|
+
if (exists3(dir, "directory") || exists3(join205(options.repoRoot, ".nax", "specs", `${feature}.md`), "file")) {
|
|
161508
162068
|
return { content: JSON.stringify(await readFeatureState(feature, options), null, 2) };
|
|
161509
162069
|
}
|
|
161510
162070
|
const names = knownDirectories(options.repoRoot);
|
|
@@ -161518,7 +162078,7 @@ function createWorkflowProvider(options) {
|
|
|
161518
162078
|
description: "Read where a nax feature stands (spec, PRD, last run, workflow verdict, branch). Omit feature to list recently active features. Read-only; call it before proposing any nax plan/run/bot step.",
|
|
161519
162079
|
inputSchema: {
|
|
161520
162080
|
type: "object",
|
|
161521
|
-
properties: { feature: { type: "string" } },
|
|
162081
|
+
properties: { feature: { type: "string" }, repo: { type: "string" } },
|
|
161522
162082
|
additionalProperties: false
|
|
161523
162083
|
},
|
|
161524
162084
|
run: async (input) => readState(input, options)
|
|
@@ -161537,8 +162097,9 @@ var init_workflow_provider = __esm(() => {
|
|
|
161537
162097
|
init_config();
|
|
161538
162098
|
init_prompts();
|
|
161539
162099
|
init_feature_name();
|
|
162100
|
+
init_target_repo();
|
|
161540
162101
|
init_feature_state();
|
|
161541
|
-
_workflowProviderDeps = { stat:
|
|
162102
|
+
_workflowProviderDeps = { stat: statSync16, readdir: readdirSync8 };
|
|
161542
162103
|
});
|
|
161543
162104
|
|
|
161544
162105
|
// src/chat/workflow/index.ts
|
|
@@ -181565,12 +182126,12 @@ function grepArg(input) {
|
|
|
181565
182126
|
const path = stringField3(input, "path");
|
|
181566
182127
|
return path === undefined ? `"${pattern}"` : `"${pattern}", ${path}`;
|
|
181567
182128
|
}
|
|
181568
|
-
function agentArg(input) {
|
|
182129
|
+
function agentArg(input, model) {
|
|
181569
182130
|
const agent = stringField3(input, "agent");
|
|
181570
182131
|
const task = stringField3(input, "task");
|
|
181571
|
-
return agent === undefined || task === undefined ? undefined : `${agent}: ${task}`;
|
|
182132
|
+
return agent === undefined || task === undefined ? undefined : `${agent}${model === undefined ? "" : ` [${model}]`}: ${task}`;
|
|
181572
182133
|
}
|
|
181573
|
-
function rawArg(name, input) {
|
|
182134
|
+
function rawArg(name, input, model) {
|
|
181574
182135
|
if (PATH_TOOLS.has(name))
|
|
181575
182136
|
return stringField3(input, "path");
|
|
181576
182137
|
if (name === "Bash")
|
|
@@ -181581,14 +182142,14 @@ function rawArg(name, input) {
|
|
|
181581
182142
|
return stringField3(input, "pattern");
|
|
181582
182143
|
if (name === "Git")
|
|
181583
182144
|
return stringField3(input, "subcommand");
|
|
181584
|
-
if (name ===
|
|
181585
|
-
return agentArg(input);
|
|
182145
|
+
if (name === AGENT_RUN_TOOL2)
|
|
182146
|
+
return agentArg(input, model);
|
|
181586
182147
|
if (name === SKILL_LOAD_TOOL)
|
|
181587
182148
|
return stringField3(input, "name");
|
|
181588
182149
|
return;
|
|
181589
182150
|
}
|
|
181590
|
-
function toolArg(name, input) {
|
|
181591
|
-
const value = rawArg(name, input);
|
|
182151
|
+
function toolArg(name, input, model) {
|
|
182152
|
+
const value = rawArg(name, input, model);
|
|
181592
182153
|
if (value === undefined)
|
|
181593
182154
|
return;
|
|
181594
182155
|
const flat = oneLine5(value);
|
|
@@ -181628,7 +182189,7 @@ function firstNonEmptyLine(text) {
|
|
|
181628
182189
|
function nonResultSummary(entry, tone) {
|
|
181629
182190
|
if (tone === "danger")
|
|
181630
182191
|
return [danger(firstNonEmptyLine(entry.preview) ?? FAILED2)];
|
|
181631
|
-
if (tone === "running" && entry.name ===
|
|
182192
|
+
if (tone === "running" && entry.name === AGENT_RUN_TOOL2)
|
|
181632
182193
|
return childSummary(entry.children);
|
|
181633
182194
|
return [];
|
|
181634
182195
|
}
|
|
@@ -181699,7 +182260,7 @@ function okSummary(entry, expanded) {
|
|
|
181699
182260
|
return readSummary(entry);
|
|
181700
182261
|
case "Bash":
|
|
181701
182262
|
return bashSummary(entry, expanded);
|
|
181702
|
-
case
|
|
182263
|
+
case AGENT_RUN_TOOL2:
|
|
181703
182264
|
return agentSummary(entry, expanded);
|
|
181704
182265
|
default:
|
|
181705
182266
|
return textSummary(entry);
|
|
@@ -181746,7 +182307,7 @@ function diffLines(oldText, newText) {
|
|
|
181746
182307
|
];
|
|
181747
182308
|
}
|
|
181748
182309
|
function toolCardModel(entry, options) {
|
|
181749
|
-
const arg = toolArg(entry.name, entry.input);
|
|
182310
|
+
const arg = toolArg(entry.name, entry.input, entry.model);
|
|
181750
182311
|
const tone = toolTone(entry.status);
|
|
181751
182312
|
const succeeded = tone === "success";
|
|
181752
182313
|
const summary = succeeded ? okSummary(entry, options.expanded) : { shown: nonResultSummary(entry, tone), hidden: 0 };
|
|
@@ -181760,12 +182321,12 @@ function toolCardModel(entry, options) {
|
|
|
181760
182321
|
hiddenLines: summary.hidden + diff.hidden
|
|
181761
182322
|
};
|
|
181762
182323
|
}
|
|
181763
|
-
var TOOL_ARG_LIMIT = 60, BASH_PREVIEW_LINES = 3, DIFF_PREVIEW_LINES = 12, CHILD_PREVIEW_LINES = 3, ELLIPSIS2 = "\u2026",
|
|
182324
|
+
var TOOL_ARG_LIMIT = 60, BASH_PREVIEW_LINES = 3, DIFF_PREVIEW_LINES = 12, CHILD_PREVIEW_LINES = 3, ELLIPSIS2 = "\u2026", AGENT_RUN_TOOL2 = "nax-agents__run", SKILL_LOAD_TOOL = "nax-skills__load", PATH_TOOLS, TITLES, FAILED2 = "failed", DONE2 = "Done", NOTHING3;
|
|
181764
182325
|
var init_tool_card = __esm(() => {
|
|
181765
182326
|
init_src();
|
|
181766
182327
|
PATH_TOOLS = new Set(["Read", "Write", "Edit", "Delete"]);
|
|
181767
182328
|
TITLES = new Map([
|
|
181768
|
-
[
|
|
182329
|
+
[AGENT_RUN_TOOL2, "Agent"],
|
|
181769
182330
|
[SKILL_LOAD_TOOL, "Skill"]
|
|
181770
182331
|
]);
|
|
181771
182332
|
NOTHING3 = { shown: [], hidden: 0 };
|
|
@@ -182497,6 +183058,45 @@ var init_bottom_region = __esm(async () => {
|
|
|
182497
183058
|
INPUT_MIN_ROWS = INPUT_RULE_ROWS + 1;
|
|
182498
183059
|
});
|
|
182499
183060
|
|
|
183061
|
+
// src/tui/chat/context-span.ts
|
|
183062
|
+
function formatTokens(n) {
|
|
183063
|
+
const rounded = Math.round(n);
|
|
183064
|
+
if (rounded < TOKEN_UNIT)
|
|
183065
|
+
return `${rounded}`;
|
|
183066
|
+
return `${(rounded / TOKEN_UNIT).toFixed(TOKEN_DECIMALS)}${TOKEN_SUFFIX}`;
|
|
183067
|
+
}
|
|
183068
|
+
function formatWindow(n) {
|
|
183069
|
+
if (n >= WINDOW_MILLION_FROM) {
|
|
183070
|
+
return `${Math.round(n / MILLION * WINDOW_DECIMALS) / WINDOW_DECIMALS}${WINDOW_MILLION_SUFFIX}`;
|
|
183071
|
+
}
|
|
183072
|
+
if (n >= TOKEN_UNIT)
|
|
183073
|
+
return `${Math.round(n / TOKEN_UNIT)}${TOKEN_SUFFIX}`;
|
|
183074
|
+
return `${n}`;
|
|
183075
|
+
}
|
|
183076
|
+
function contextPercent(state, status) {
|
|
183077
|
+
const { contextWindow } = state;
|
|
183078
|
+
if (contextWindow === undefined || contextWindow <= 0 || status.contextTokens === undefined)
|
|
183079
|
+
return;
|
|
183080
|
+
return Math.round(status.contextTokens / contextWindow * PERCENT);
|
|
183081
|
+
}
|
|
183082
|
+
function percentColor(percent) {
|
|
183083
|
+
if (percent > CONTEXT_DANGER_ABOVE)
|
|
183084
|
+
return "danger";
|
|
183085
|
+
return percent > CONTEXT_WARNING_ABOVE ? "warning" : "muted";
|
|
183086
|
+
}
|
|
183087
|
+
function contextSpan(state, status) {
|
|
183088
|
+
const tokens = status.contextTokens;
|
|
183089
|
+
if (tokens === undefined)
|
|
183090
|
+
return;
|
|
183091
|
+
const percent = contextPercent(state, status);
|
|
183092
|
+
if (percent === undefined || state.contextWindow === undefined) {
|
|
183093
|
+
return { text: `${SEPARATOR}${formatTokens(tokens)} ctx`, color: "muted" };
|
|
183094
|
+
}
|
|
183095
|
+
const text = `${formatTokens(tokens)}/${formatWindow(state.contextWindow)} ctx (${percent}%)`;
|
|
183096
|
+
return { text: `${SEPARATOR}${text}`, color: percentColor(percent) };
|
|
183097
|
+
}
|
|
183098
|
+
var TOKEN_UNIT = 1000, TOKEN_DECIMALS = 1, TOKEN_SUFFIX = "k", MILLION = 1e6, WINDOW_MILLION_FROM = 999500, WINDOW_DECIMALS = 100, WINDOW_MILLION_SUFFIX = "M", SEPARATOR = " \xB7 ", CONTEXT_WARNING_ABOVE = 70, CONTEXT_DANGER_ABOVE = 90, PERCENT = 100;
|
|
183099
|
+
|
|
182500
183100
|
// src/tui/chat/theme.ts
|
|
182501
183101
|
function isSet2(value) {
|
|
182502
183102
|
return value !== undefined && value !== "";
|
|
@@ -182726,6 +183326,8 @@ function reduceTurnStatus(status, event) {
|
|
|
182726
183326
|
return { ...inPhase(status, THINKING), streamedChars: status.streamedChars + event.text.length };
|
|
182727
183327
|
case "text_delta":
|
|
182728
183328
|
return { ...inPhase(status, WRITING), streamedChars: status.streamedChars + event.text.length };
|
|
183329
|
+
case "tool_input_delta":
|
|
183330
|
+
return { ...inPhase(status, WRITING), streamedChars: status.streamedChars + event.chars };
|
|
182729
183331
|
case "tool_call":
|
|
182730
183332
|
return inPhase(status, TOOL, event.name);
|
|
182731
183333
|
case "tool_result":
|
|
@@ -182746,12 +183348,6 @@ function reduceTurnStatus(status, event) {
|
|
|
182746
183348
|
return status;
|
|
182747
183349
|
}
|
|
182748
183350
|
}
|
|
182749
|
-
function formatTokens(n) {
|
|
182750
|
-
const rounded = Math.round(n);
|
|
182751
|
-
if (rounded < TOKEN_UNIT)
|
|
182752
|
-
return `${rounded}`;
|
|
182753
|
-
return `${(rounded / TOKEN_UNIT).toFixed(TOKEN_DECIMALS)}${TOKEN_SUFFIX}`;
|
|
182754
|
-
}
|
|
182755
183351
|
function modelParts(raw) {
|
|
182756
183352
|
if (isChatAcpModel(raw)) {
|
|
182757
183353
|
const { model: name, effort } = parseModelSpec(acpModelLabel(raw));
|
|
@@ -182788,9 +183384,9 @@ function sandboxSpan(sandbox) {
|
|
|
182788
183384
|
if (sandbox?.kind === "available")
|
|
182789
183385
|
return;
|
|
182790
183386
|
if (sandbox?.kind === "unavailable") {
|
|
182791
|
-
return { text: `${
|
|
183387
|
+
return { text: `${SEPARATOR2}${SANDBOX_UNAVAILABLE}`, color: "warning" };
|
|
182792
183388
|
}
|
|
182793
|
-
return { text: `${
|
|
183389
|
+
return { text: `${SEPARATOR2}${SANDBOX_OFF}`, color: "muted" };
|
|
182794
183390
|
}
|
|
182795
183391
|
function leftLine(input) {
|
|
182796
183392
|
const { state, hint, glyphs, copiedChars, layerHint } = input;
|
|
@@ -182798,29 +183394,12 @@ function leftLine(input) {
|
|
|
182798
183394
|
return [hintSpan(hint)];
|
|
182799
183395
|
const sandbox = sandboxSpan(state.sandbox);
|
|
182800
183396
|
const gesture = hintSpan(hint, copiedChars, layerHint);
|
|
182801
|
-
const spans = [modeSpan(state, glyphs), { text:
|
|
183397
|
+
const spans = [modeSpan(state, glyphs), { text: SEPARATOR2, color: "muted" }, gesture];
|
|
182802
183398
|
return sandbox === undefined ? spans : [...spans, sandbox];
|
|
182803
183399
|
}
|
|
182804
|
-
function contextPercent(state, status) {
|
|
182805
|
-
const { contextWindow } = state;
|
|
182806
|
-
if (contextWindow === undefined || contextWindow <= 0 || status.contextTokens === undefined)
|
|
182807
|
-
return;
|
|
182808
|
-
return Math.round(status.contextTokens / contextWindow * PERCENT);
|
|
182809
|
-
}
|
|
182810
|
-
function percentColor(percent) {
|
|
182811
|
-
if (percent > CONTEXT_DANGER_ABOVE)
|
|
182812
|
-
return "danger";
|
|
182813
|
-
return percent > CONTEXT_WARNING_ABOVE ? "warning" : "muted";
|
|
182814
|
-
}
|
|
182815
|
-
function contextSpan(state, status) {
|
|
182816
|
-
const percent = contextPercent(state, status);
|
|
182817
|
-
if (percent === undefined)
|
|
182818
|
-
return;
|
|
182819
|
-
return { text: `${SEPARATOR}${percent}% ctx`, color: percentColor(percent) };
|
|
182820
|
-
}
|
|
182821
183400
|
function costSpan(state) {
|
|
182822
183401
|
const cost = (state.meta.costUsd ?? 0).toFixed(COST_DECIMALS);
|
|
182823
|
-
return { text: `${
|
|
183402
|
+
return { text: `${SEPARATOR2}${COST_PREFIX}${cost}`, color: "muted" };
|
|
182824
183403
|
}
|
|
182825
183404
|
function jobPart(job) {
|
|
182826
183405
|
const target = singleRow(job.target);
|
|
@@ -182844,7 +183423,7 @@ function formatJobStrip(jobs, tasks = []) {
|
|
|
182844
183423
|
const shown = [...jobs.slice(0, JOB_STRIP_LIMIT).map(jobPart)];
|
|
182845
183424
|
for (const task of tasks.slice(0, Math.max(0, JOB_STRIP_LIMIT - jobs.length)))
|
|
182846
183425
|
shown.push(taskPart(task));
|
|
182847
|
-
const strip = shown.join(
|
|
183426
|
+
const strip = shown.join(SEPARATOR2);
|
|
182848
183427
|
return total > JOB_STRIP_LIMIT ? `${strip} +${total - JOB_STRIP_LIMIT}` : strip;
|
|
182849
183428
|
}
|
|
182850
183429
|
function rightLine(state, status) {
|
|
@@ -182857,7 +183436,7 @@ function footerModel(input) {
|
|
|
182857
183436
|
return {
|
|
182858
183437
|
left: leftLine({ ...input, glyphs: input.glyphs ?? GLYPHS }),
|
|
182859
183438
|
right: [
|
|
182860
|
-
...strip === "" ? [] : [{ text: strip }, { text:
|
|
183439
|
+
...strip === "" ? [] : [{ text: strip }, { text: SEPARATOR2, color: "muted" }],
|
|
182861
183440
|
...rightLine(input.state, input.status)
|
|
182862
183441
|
],
|
|
182863
183442
|
stripWidth: displayWidth(strip)
|
|
@@ -182905,7 +183484,7 @@ function workingTokens(status) {
|
|
|
182905
183484
|
}
|
|
182906
183485
|
function workingDetail(status, elapsed, escHint) {
|
|
182907
183486
|
const seconds = Math.floor(elapsed / MILLIS_PER_SECOND);
|
|
182908
|
-
return ` (${seconds}s${
|
|
183487
|
+
return ` (${seconds}s${SEPARATOR2}${workingTokens(status)}${SEPARATOR2}${escHint})`;
|
|
182909
183488
|
}
|
|
182910
183489
|
function workingLine(status, nowMs, glyphs, escHint = ESC_INTERRUPT) {
|
|
182911
183490
|
if (!status.running)
|
|
@@ -182980,13 +183559,13 @@ function headerModel(raw, columns, ellipsis) {
|
|
|
182980
183559
|
}
|
|
182981
183560
|
function headerTitleLine(state, version, width, glyphs) {
|
|
182982
183561
|
const title = { text: `${glyphs.thinking} ${HEADER_TITLE}`, color: "accent", bold: true };
|
|
182983
|
-
const beforeModel = ` v${singleRow(version)}${
|
|
182984
|
-
const afterModel = `${
|
|
183562
|
+
const beforeModel = ` v${singleRow(version)}${SEPARATOR2}`;
|
|
183563
|
+
const afterModel = `${SEPARATOR2}${modeLabel(state.mode)}`;
|
|
182985
183564
|
const modelRoom = width - displayWidth(`${title.text}${beforeModel}${afterModel}`);
|
|
182986
183565
|
const model = headerModel(singleRow(state.model), modelRoom, glyphs.ellipsis);
|
|
182987
183566
|
const facts = `${beforeModel}${model}${afterModel}`;
|
|
182988
|
-
const room = width - displayWidth(`${title.text}${facts}${
|
|
182989
|
-
const sessionTitle = state.meta.title !== null && room >= MIN_TITLE_COLUMNS ? `${
|
|
183567
|
+
const room = width - displayWidth(`${title.text}${facts}${SEPARATOR2}`);
|
|
183568
|
+
const sessionTitle = state.meta.title !== null && room >= MIN_TITLE_COLUMNS ? `${SEPARATOR2}${elideEnd(singleRow(sessionTitleText(state.meta.title, state.sessionId)), room, glyphs.ellipsis)}` : "";
|
|
182990
183569
|
return [title, { text: `${facts}${sessionTitle}`, color: "muted" }];
|
|
182991
183570
|
}
|
|
182992
183571
|
function headerPathLine(state, cwd, home, width, glyphs) {
|
|
@@ -182995,7 +183574,7 @@ function headerPathLine(state, cwd, home, width, glyphs) {
|
|
|
182995
183574
|
const shown = elideMiddle(path, budget, glyphs.ellipsis);
|
|
182996
183575
|
return [
|
|
182997
183576
|
{ text: `${HEADER_INDENT}${shown}` },
|
|
182998
|
-
{ text: `${
|
|
183577
|
+
{ text: `${SEPARATOR2}${headerSandbox(state.sandbox)}`, color: "muted" }
|
|
182999
183578
|
];
|
|
183000
183579
|
}
|
|
183001
183580
|
function headerRuleLine(width, glyphs) {
|
|
@@ -183010,7 +183589,7 @@ function headerLines(input) {
|
|
|
183010
183589
|
headerRuleLine(width, glyphs)
|
|
183011
183590
|
];
|
|
183012
183591
|
}
|
|
183013
|
-
var IDLE_STATUS, THINKING = "thinking", WRITING = "writing", TOOL = "tool", APPROVAL = "approval", COMPACTING = "compacting", RETRYING = "retrying",
|
|
183592
|
+
var IDLE_STATUS, THINKING = "thinking", WRITING = "writing", TOOL = "tool", APPROVAL = "approval", COMPACTING = "compacting", RETRYING = "retrying", CHARS_PER_ESTIMATED_TOKEN = 4, SHORT_MODEL_MAX = 24, ELLIPSIS3 = "\u2026", PATH_SEPARATOR3 = "/", HINT_TEXT, SEPARATOR2 = " \xB7 ", SANDBOX_OFF = "sandbox off", SANDBOX_UNAVAILABLE = "sandbox unavailable", COST_DECIMALS = 2, COST_PREFIX = "$", GLYPHS, JOB_TARGET_LIMIT = 16, JOB_STRIP_LIMIT = 2, WORKING_TICK_MS = 250, SPINNER_FRAME_MS = 120, MILLIS_PER_SECOND = 1000, UP_ARROW = "\u2191", DOWN_ARROW = "\u2193", ESC_INTERRUPT, HEADER_TITLE = "nax chat", HEADER_CWD_RESERVE = 20, HEADER_INDENT = " ", HOME = "~", SANDBOX_ON = "sandbox on", MIN_TITLE_COLUMNS = 8;
|
|
183014
183593
|
var init_chat_status = __esm(async () => {
|
|
183015
183594
|
init_src();
|
|
183016
183595
|
init_chat2();
|
|
@@ -191956,7 +192535,7 @@ var init_message_queue = __esm(async () => {
|
|
|
191956
192535
|
});
|
|
191957
192536
|
|
|
191958
192537
|
// src/tui/chat/slash-commands.ts
|
|
191959
|
-
import { join as
|
|
192538
|
+
import { join as join207 } from "path";
|
|
191960
192539
|
function parseSlashCommand(text) {
|
|
191961
192540
|
if (!text.startsWith("/"))
|
|
191962
192541
|
return null;
|
|
@@ -191971,12 +192550,12 @@ async function featureMessage(command, host, show) {
|
|
|
191971
192550
|
return;
|
|
191972
192551
|
}
|
|
191973
192552
|
const dir = featureDir(host.repoRoot, feature);
|
|
191974
|
-
const spec = await _slashCommandDeps.readText(
|
|
192553
|
+
const spec = await _slashCommandDeps.readText(join207(dir, "spec.md"));
|
|
191975
192554
|
if (spec === undefined) {
|
|
191976
192555
|
show(`no feature ${feature} (looked in ${dir})`);
|
|
191977
192556
|
return;
|
|
191978
192557
|
}
|
|
191979
|
-
const prd = await _slashCommandDeps.readText(
|
|
192558
|
+
const prd = await _slashCommandDeps.readText(join207(dir, "prd.json"));
|
|
191980
192559
|
const message = command.rest.replace(/^\s*\S+\s?/, "");
|
|
191981
192560
|
return buildChatFeatureMessage({ feature, spec, prd, message });
|
|
191982
192561
|
}
|
|
@@ -192595,7 +193174,7 @@ function maxOffset(total, height) {
|
|
|
192595
193174
|
function clampOffset(offset, total, height) {
|
|
192596
193175
|
return Math.min(Math.max(offset, 0), maxOffset(total, height));
|
|
192597
193176
|
}
|
|
192598
|
-
function
|
|
193177
|
+
function settle4(offset, total, height, unseen) {
|
|
192599
193178
|
const clamped = clampOffset(offset, total, height);
|
|
192600
193179
|
return clamped === 0 ? INITIAL_VIEWPORT : { offset: clamped, follow: false, unseen };
|
|
192601
193180
|
}
|
|
@@ -192603,10 +193182,10 @@ function afterContent(state, action, total) {
|
|
|
192603
193182
|
const growth = Math.max(0, action.total - total);
|
|
192604
193183
|
const offset = state.follow ? 0 : state.offset + growth;
|
|
192605
193184
|
const unseen = state.follow ? state.unseen : state.unseen + growth;
|
|
192606
|
-
return
|
|
193185
|
+
return settle4(offset, action.total, action.height, unseen);
|
|
192607
193186
|
}
|
|
192608
193187
|
function afterMove(state, delta, total, height) {
|
|
192609
|
-
return
|
|
193188
|
+
return settle4(state.offset + delta, total, height, state.unseen);
|
|
192610
193189
|
}
|
|
192611
193190
|
function reduceViewport(state, action, total, height) {
|
|
192612
193191
|
switch (action.type) {
|
|
@@ -192625,7 +193204,7 @@ function reduceViewport(state, action, total, height) {
|
|
|
192625
193204
|
case "wheelDown":
|
|
192626
193205
|
return afterMove(state, -WHEEL_LINES, total, height);
|
|
192627
193206
|
case "home":
|
|
192628
|
-
return
|
|
193207
|
+
return settle4(maxOffset(total, height), total, height, state.unseen);
|
|
192629
193208
|
case "end":
|
|
192630
193209
|
return INITIAL_VIEWPORT;
|
|
192631
193210
|
}
|
|
@@ -193003,7 +193582,7 @@ function subagentTask(event) {
|
|
|
193003
193582
|
}
|
|
193004
193583
|
function findAgentParent(entries, task) {
|
|
193005
193584
|
return findTool(entries, (entry) => {
|
|
193006
|
-
if (entry.name !==
|
|
193585
|
+
if (entry.name !== AGENT_RUN_TOOL3 || entry.status !== "running")
|
|
193007
193586
|
return false;
|
|
193008
193587
|
return stringField6(entry.input, "task") === task;
|
|
193009
193588
|
});
|
|
@@ -193035,6 +193614,7 @@ function applyToolCall(entries, event) {
|
|
|
193035
193614
|
const child = { callId: event.callId, name: event.name, input: event.input, status: "running" };
|
|
193036
193615
|
return replaceIn(ended, parent.index, { ...parent.entry, children: [...parent.entry.children, child] });
|
|
193037
193616
|
}
|
|
193617
|
+
const model = stringField6(event.metadata, "subagentModel");
|
|
193038
193618
|
return [
|
|
193039
193619
|
...ended,
|
|
193040
193620
|
{
|
|
@@ -193045,6 +193625,7 @@ function applyToolCall(entries, event) {
|
|
|
193045
193625
|
input: event.input,
|
|
193046
193626
|
startedAt: event.at,
|
|
193047
193627
|
status: "running",
|
|
193628
|
+
...model === undefined ? {} : { model },
|
|
193048
193629
|
children: []
|
|
193049
193630
|
}
|
|
193050
193631
|
];
|
|
@@ -193056,7 +193637,7 @@ function findChildParent(entries, event) {
|
|
|
193056
193637
|
return false;
|
|
193057
193638
|
if (task === undefined)
|
|
193058
193639
|
return true;
|
|
193059
|
-
return entry.name ===
|
|
193640
|
+
return entry.name === AGENT_RUN_TOOL3 && stringField6(entry.input, "task") === task;
|
|
193060
193641
|
});
|
|
193061
193642
|
}
|
|
193062
193643
|
function applyToolResult(entries, event) {
|
|
@@ -193100,7 +193681,7 @@ function reduceTranscript(entries, event) {
|
|
|
193100
193681
|
return entries;
|
|
193101
193682
|
}
|
|
193102
193683
|
}
|
|
193103
|
-
var
|
|
193684
|
+
var AGENT_RUN_TOOL3 = "nax-agents__run", COMPACTION_NOTICE = "conversation compacted";
|
|
193104
193685
|
|
|
193105
193686
|
// src/tui/chat/turn-stats.ts
|
|
193106
193687
|
function timeOf(at) {
|
|
@@ -193132,7 +193713,7 @@ function decodeRate(events) {
|
|
|
193132
193713
|
for (const event of events) {
|
|
193133
193714
|
if (isSubagentEvent(event))
|
|
193134
193715
|
continue;
|
|
193135
|
-
if (event.type === "text_delta" || event.type === "thinking_delta") {
|
|
193716
|
+
if (event.type === "text_delta" || event.type === "thinking_delta" || event.type === "tool_input_delta") {
|
|
193136
193717
|
openWindow(windows, event);
|
|
193137
193718
|
} else if (event.type === "stream_reset") {
|
|
193138
193719
|
windows.delete(event.round);
|
|
@@ -193153,10 +193734,10 @@ function wholeSeconds(elapsedMs) {
|
|
|
193153
193734
|
}
|
|
193154
193735
|
function turnStatsText(input) {
|
|
193155
193736
|
const output = formatTokens(input.outputTokens);
|
|
193156
|
-
const spent = `${output}${OUT_UNIT}${
|
|
193737
|
+
const spent = `${output}${OUT_UNIT}${SEPARATOR3}${wholeSeconds(input.elapsedMs)}${SECONDS_SUFFIX2}`;
|
|
193157
193738
|
if (input.rate === undefined)
|
|
193158
193739
|
return spent;
|
|
193159
|
-
return `${input.rate.toFixed(RATE_DECIMALS)}${RATE_UNIT}${
|
|
193740
|
+
return `${input.rate.toFixed(RATE_DECIMALS)}${RATE_UNIT}${SEPARATOR3}${spent}`;
|
|
193160
193741
|
}
|
|
193161
193742
|
function turnElapsedMs(events, end) {
|
|
193162
193743
|
const start = events.find((event) => event.type === "turn_start" && !isSubagentEvent(event));
|
|
@@ -193178,7 +193759,7 @@ function turnStatsEntry(events, end) {
|
|
|
193178
193759
|
})
|
|
193179
193760
|
};
|
|
193180
193761
|
}
|
|
193181
|
-
var
|
|
193762
|
+
var SEPARATOR3 = " \xB7 ", MILLIS_PER_SECOND2 = 1000, RATE_SCALE = 10, RATE_DECIMALS = 1, RATE_UNIT = " tok/s", OUT_UNIT = " out", SECONDS_SUFFIX2 = "s";
|
|
193182
193763
|
var init_turn_stats = __esm(async () => {
|
|
193183
193764
|
await init_chat_status();
|
|
193184
193765
|
});
|
|
@@ -193329,7 +193910,7 @@ var init_clipboard_image = __esm(() => {
|
|
|
193329
193910
|
});
|
|
193330
193911
|
|
|
193331
193912
|
// src/tui/chat/pasted-path.ts
|
|
193332
|
-
import { resolve as
|
|
193913
|
+
import { resolve as resolve56 } from "path";
|
|
193333
193914
|
function unquote2(text) {
|
|
193334
193915
|
if (text.length < 2)
|
|
193335
193916
|
return text;
|
|
@@ -193351,7 +193932,7 @@ function pastedImagePath(chunk, cwd) {
|
|
|
193351
193932
|
const path = text.startsWith(FILE_URL_PREFIX) ? fileUrlPath(text) : text.replace(BACKSLASH_ESCAPE, "$1");
|
|
193352
193933
|
if (path === undefined || !IMAGE_EXTENSION.test(path))
|
|
193353
193934
|
return;
|
|
193354
|
-
return
|
|
193935
|
+
return resolve56(cwd, path);
|
|
193355
193936
|
}
|
|
193356
193937
|
var IMAGE_EXTENSION, FILE_URL_PREFIX = "file://", QUOTES, NEWLINE4, BACKSLASH_ESCAPE;
|
|
193357
193938
|
var init_pasted_path = __esm(() => {
|
|
@@ -193362,7 +193943,7 @@ var init_pasted_path = __esm(() => {
|
|
|
193362
193943
|
});
|
|
193363
193944
|
|
|
193364
193945
|
// src/tui/chat/use-image-attach.ts
|
|
193365
|
-
import { resolve as
|
|
193946
|
+
import { resolve as resolve57 } from "path";
|
|
193366
193947
|
async function readImageFile(path) {
|
|
193367
193948
|
try {
|
|
193368
193949
|
const file = Bun.file(path);
|
|
@@ -193454,7 +194035,7 @@ function useImageAttach(options) {
|
|
|
193454
194035
|
return Promise.resolve();
|
|
193455
194036
|
if (path === undefined)
|
|
193456
194037
|
return run(fromClipboard);
|
|
193457
|
-
return run(() => fromFile({ path:
|
|
194038
|
+
return run(() => fromFile({ path: resolve57(options.cwd, path), label: path }));
|
|
193458
194039
|
}
|
|
193459
194040
|
function onPaste(chunk) {
|
|
193460
194041
|
const path = pastedImagePath(chunk, options.cwd);
|
|
@@ -195054,7 +195635,13 @@ function chatTitle(project, busy, glyphs) {
|
|
|
195054
195635
|
const title = `${APP_NAME}${TITLE_SEPARATOR2}${withoutControls(project)}`;
|
|
195055
195636
|
return busy ? `${glyphs.busy}${BUSY_SEPARATOR}${title}` : title;
|
|
195056
195637
|
}
|
|
195057
|
-
|
|
195638
|
+
function titleFrames(glyphs) {
|
|
195639
|
+
return glyphs.spinner.length >= 2 ? glyphs.spinner : [glyphs.busy];
|
|
195640
|
+
}
|
|
195641
|
+
function chatTitleFrame(project, frame) {
|
|
195642
|
+
return `${frame}${BUSY_SEPARATOR}${APP_NAME}${TITLE_SEPARATOR2}${withoutControls(project)}`;
|
|
195643
|
+
}
|
|
195644
|
+
var PUSH_TITLE = "\x1B[22;0t", POP_TITLE = "\x1B[23;0t", OSC_TITLE = "\x1B]0;", BEL = "\x07", APP_NAME = "nax", TITLE_SEPARATOR2 = " \xB7 ", BUSY_SEPARATOR = " ", CONTROL_CHARACTERS, TITLE_FRAME_MS = 400;
|
|
195058
195645
|
var init_terminal_title = __esm(() => {
|
|
195059
195646
|
CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
195060
195647
|
});
|
|
@@ -195063,10 +195650,10 @@ var init_terminal_title = __esm(() => {
|
|
|
195063
195650
|
function formatChatExitSummary(state) {
|
|
195064
195651
|
const cost = (state.meta.costUsd ?? 0).toFixed(COST_DECIMALS2);
|
|
195065
195652
|
const resume = `nax chat --resume ${state.sessionId}`;
|
|
195066
|
-
return `${BULLET} nax chat session ${state.sessionId}${
|
|
195653
|
+
return `${BULLET} nax chat session ${state.sessionId}${SEPARATOR4}${COST_PREFIX2}${cost}
|
|
195067
195654
|
${INDENT}resume with: ${resume}`;
|
|
195068
195655
|
}
|
|
195069
|
-
var COST_DECIMALS2 = 2, COST_PREFIX2 = "$", BULLET = "\u273B",
|
|
195656
|
+
var COST_DECIMALS2 = 2, COST_PREFIX2 = "$", BULLET = "\u273B", SEPARATOR4 = " \xB7 ", INDENT = " ";
|
|
195070
195657
|
|
|
195071
195658
|
// src/tui/chat/index.ts
|
|
195072
195659
|
import { basename as basename37 } from "path";
|
|
@@ -195088,10 +195675,46 @@ function renderChat(props) {
|
|
|
195088
195675
|
return;
|
|
195089
195676
|
_renderChatDeps.write(setTitleSequence(chatTitle(project, busy, glyphs)));
|
|
195090
195677
|
};
|
|
195678
|
+
const frames = titleFrames(glyphs);
|
|
195679
|
+
let timer;
|
|
195680
|
+
let armed = 0;
|
|
195681
|
+
let frameIndex = 0;
|
|
195682
|
+
const stopFrames = () => {
|
|
195683
|
+
if (timer === undefined)
|
|
195684
|
+
return;
|
|
195685
|
+
_renderChatDeps.clearTimeout(timer);
|
|
195686
|
+
timer = undefined;
|
|
195687
|
+
armed += 1;
|
|
195688
|
+
};
|
|
195689
|
+
const armFrame = () => {
|
|
195690
|
+
armed += 1;
|
|
195691
|
+
const mine = armed;
|
|
195692
|
+
timer = _renderChatDeps.setTimeout(() => {
|
|
195693
|
+
if (restored || mine !== armed || timer === undefined)
|
|
195694
|
+
return;
|
|
195695
|
+
timer = undefined;
|
|
195696
|
+
const frame = frames[frameIndex % frames.length];
|
|
195697
|
+
frameIndex += 1;
|
|
195698
|
+
_renderChatDeps.write(setTitleSequence(chatTitleFrame(project, frame)));
|
|
195699
|
+
armFrame();
|
|
195700
|
+
}, TITLE_FRAME_MS);
|
|
195701
|
+
};
|
|
195702
|
+
const onBusy = (busy) => {
|
|
195703
|
+
if (!isTTY || restored)
|
|
195704
|
+
return;
|
|
195705
|
+
showTitle(busy);
|
|
195706
|
+
if (!busy) {
|
|
195707
|
+
stopFrames();
|
|
195708
|
+
} else if (timer === undefined) {
|
|
195709
|
+
frameIndex = 0;
|
|
195710
|
+
armFrame();
|
|
195711
|
+
}
|
|
195712
|
+
};
|
|
195091
195713
|
const restore = () => {
|
|
195092
195714
|
if (restored)
|
|
195093
195715
|
return;
|
|
195094
195716
|
restored = true;
|
|
195717
|
+
stopFrames();
|
|
195095
195718
|
removeExit?.();
|
|
195096
195719
|
if (isTTY)
|
|
195097
195720
|
_renderChatDeps.write(DISABLE_MOUSE);
|
|
@@ -195101,7 +195724,7 @@ function renderChat(props) {
|
|
|
195101
195724
|
mouse.dispose();
|
|
195102
195725
|
};
|
|
195103
195726
|
try {
|
|
195104
|
-
const instance = _renderChatDeps.render(import_react45.createElement(ChatApp, { ...props, mouse: mouse.events, ...isTTY ? { onBusyChange:
|
|
195727
|
+
const instance = _renderChatDeps.render(import_react45.createElement(ChatApp, { ...props, mouse: mouse.events, ...isTTY ? { onBusyChange: onBusy } : {} }), {
|
|
195105
195728
|
exitOnCtrlC: false,
|
|
195106
195729
|
incrementalRendering: true,
|
|
195107
195730
|
stdin: mouse.stdin
|
|
@@ -195144,6 +195767,8 @@ var init_chat3 = __esm(async () => {
|
|
|
195144
195767
|
render: render_default,
|
|
195145
195768
|
stdin: () => process.stdin,
|
|
195146
195769
|
createMouseInput,
|
|
195770
|
+
setTimeout: (handler, ms) => setTimeout(handler, ms),
|
|
195771
|
+
clearTimeout: (handle) => clearTimeout(handle),
|
|
195147
195772
|
write: (text) => {
|
|
195148
195773
|
process.stdout.write(text);
|
|
195149
195774
|
},
|
|
@@ -195159,7 +195784,7 @@ var init_chat3 = __esm(async () => {
|
|
|
195159
195784
|
|
|
195160
195785
|
// src/cli/chat.ts
|
|
195161
195786
|
import { homedir as homedir11 } from "os";
|
|
195162
|
-
import { dirname as dirname53, join as
|
|
195787
|
+
import { dirname as dirname53, join as join208, resolve as resolve58 } from "path";
|
|
195163
195788
|
async function interactionChain(config, deps) {
|
|
195164
195789
|
try {
|
|
195165
195790
|
return await deps.initInteractionChain(config, true);
|
|
@@ -195262,7 +195887,7 @@ async function chatMemory(input, deps) {
|
|
|
195262
195887
|
async function chatResources(repoRoot, config, deps, logger) {
|
|
195263
195888
|
let registry;
|
|
195264
195889
|
try {
|
|
195265
|
-
registry = await deps.loadPlugins(
|
|
195890
|
+
registry = await deps.loadPlugins(join208(globalConfigDir(), "plugins"), join208(repoRoot, ".nax", "plugins"), config.plugins ?? [], repoRoot, config.disabledPlugins);
|
|
195266
195891
|
} catch (error) {
|
|
195267
195892
|
deps.writeErr(`nax plugins unavailable: ${errorMessage(error)}`);
|
|
195268
195893
|
registry = new PluginRegistry([]);
|
|
@@ -195400,7 +196025,7 @@ async function chatCommand(options, deps = _chatCommandDeps) {
|
|
|
195400
196025
|
deps.setExitCode(1);
|
|
195401
196026
|
return;
|
|
195402
196027
|
}
|
|
195403
|
-
const cwd =
|
|
196028
|
+
const cwd = resolve58(options.dir ?? process.cwd());
|
|
195404
196029
|
try {
|
|
195405
196030
|
await deps.ensureTrusted(cwd);
|
|
195406
196031
|
} catch (error) {
|
|
@@ -195793,7 +196418,9 @@ var init_config_descriptions = __esm(() => {
|
|
|
195793
196418
|
"prompts.overrides.verifier": 'Path to custom verifier prompt (e.g., ".nax/prompts/verifier.md")',
|
|
195794
196419
|
agent: "Agent protocol configuration (ACP-003)",
|
|
195795
196420
|
"agent.protocol": "Protocol for agent communication: 'acp' (default) | 'native' | 'hybrid'",
|
|
195796
|
-
"agent.modelAliases": 'Map of a Claude Code model name to a nax model id, e.g. { sonnet: "anthropic/claude-sonnet-5-5",
|
|
196421
|
+
"agent.modelAliases": 'Map of a Claude Code model name to a nax model id or an ACP agent target, e.g. { sonnet: "anthropic/claude-sonnet-5-5", reviewer: "acp:codex/gpt-6.1-terra[high]" }. Each value is either "provider/model" or "acp:<agent>[/<model>]" (agent: claude, codex, cursor), with an optional [effort] suffix. An alias always wins over the models.native tier step. Default: {}.',
|
|
196422
|
+
"agent.acpSubagents": 'Settings for the ACP subagents a chat session may run, e.g. { profile: "review" }. Omit for the per-agent default; an alias pointing at an acp:<agent> target is what selects the subagent.',
|
|
196423
|
+
"agent.acpSubagents.profile": "Permissions profile for ACP subagents: 'review' | 'read' | 'ask' | 'full'. Omit to use the profile derived per agent file ('review' and 'read' are read-only).",
|
|
195797
196424
|
"agent.acp": "ACP agent transport settings (claude, codex, cursor, opencode, gemini, pi)",
|
|
195798
196425
|
"agent.native.instructionFileName": "Repository instruction filename (default: AGENTS.md). Custom Markdown basenames load without AGENTS/CLAUDE fallbacks.",
|
|
195799
196426
|
"agent.native.catalogOverrides": "Native only. Explicit catalog entries for model ids newer than the bundled pi-ai snapshot, plus optional provider-wide baseUrl/headers.",
|
|
@@ -195863,7 +196490,7 @@ var init_config_descriptions = __esm(() => {
|
|
|
195863
196490
|
|
|
195864
196491
|
// src/cli/config-get.ts
|
|
195865
196492
|
import { existsSync as existsSync26 } from "fs";
|
|
195866
|
-
import { join as
|
|
196493
|
+
import { join as join209 } from "path";
|
|
195867
196494
|
async function loadConfigFile(path) {
|
|
195868
196495
|
if (!existsSync26(path))
|
|
195869
196496
|
return null;
|
|
@@ -195885,7 +196512,7 @@ async function loadProjectConfig() {
|
|
|
195885
196512
|
const projectDir = findProjectDir(process.cwd());
|
|
195886
196513
|
if (!projectDir)
|
|
195887
196514
|
return null;
|
|
195888
|
-
const projectPath =
|
|
196515
|
+
const projectPath = join209(projectDir, "config.json");
|
|
195889
196516
|
return await loadConfigFile(projectPath);
|
|
195890
196517
|
}
|
|
195891
196518
|
var init_config_get = __esm(() => {
|
|
@@ -195897,10 +196524,10 @@ var init_config_get = __esm(() => {
|
|
|
195897
196524
|
|
|
195898
196525
|
// src/cli/config-profile.ts
|
|
195899
196526
|
import { mkdirSync as mkdirSync15, readdirSync as readdirSync9 } from "fs";
|
|
195900
|
-
import { join as
|
|
196527
|
+
import { join as join210 } from "path";
|
|
195901
196528
|
async function profileListCommand(startDir) {
|
|
195902
|
-
const globalProfilesDir =
|
|
195903
|
-
const projectProfilesDir =
|
|
196529
|
+
const globalProfilesDir = join210(globalConfigDir(), "profiles");
|
|
196530
|
+
const projectProfilesDir = join210(projectConfigDir(startDir), "profiles");
|
|
195904
196531
|
const globalProfiles = scanProfileDir(globalProfilesDir);
|
|
195905
196532
|
const projectProfiles = scanProfileDir(projectProfilesDir);
|
|
195906
196533
|
const activeProfile = await resolveProfileName({}, _profileCLIDeps.env, startDir);
|
|
@@ -195977,7 +196604,7 @@ function maskProfileValue(value) {
|
|
|
195977
196604
|
return value;
|
|
195978
196605
|
}
|
|
195979
196606
|
async function profileUseCommand(profileName, startDir) {
|
|
195980
|
-
const configPath =
|
|
196607
|
+
const configPath = join210(projectConfigDir(startDir), "config.json");
|
|
195981
196608
|
const configFile = Bun.file(configPath);
|
|
195982
196609
|
let existing = {};
|
|
195983
196610
|
if (await configFile.exists()) {
|
|
@@ -195998,8 +196625,8 @@ async function profileCurrentCommand(startDir) {
|
|
|
195998
196625
|
}
|
|
195999
196626
|
async function profileCreateCommand(profileName, startDir) {
|
|
196000
196627
|
validateProfileName(profileName);
|
|
196001
|
-
const profilesDir =
|
|
196002
|
-
const profilePath =
|
|
196628
|
+
const profilesDir = join210(projectConfigDir(startDir), "profiles");
|
|
196629
|
+
const profilePath = join210(profilesDir, `${profileName}.json`);
|
|
196003
196630
|
const profileFile = Bun.file(profilePath);
|
|
196004
196631
|
if (await profileFile.exists()) {
|
|
196005
196632
|
throw new NaxError(`Profile "${profileName}" already exists at ${profilePath}`, "PROFILE_ALREADY_EXISTS", {
|
|
@@ -196037,7 +196664,7 @@ var init_config_profile = __esm(() => {
|
|
|
196037
196664
|
|
|
196038
196665
|
// src/cli/config-display.ts
|
|
196039
196666
|
import { existsSync as existsSync27 } from "fs";
|
|
196040
|
-
import { join as
|
|
196667
|
+
import { join as join211 } from "path";
|
|
196041
196668
|
function rejectDiffProfileConflict(options) {
|
|
196042
196669
|
if (options.diff && (options.profile?.length ?? 0) > 0) {
|
|
196043
196670
|
console.error("Error: --diff cannot be combined with --profile");
|
|
@@ -196104,7 +196731,7 @@ async function configCommand(config, options = {}) {
|
|
|
196104
196731
|
function determineConfigSources(startDir) {
|
|
196105
196732
|
const globalPath = globalConfigPath();
|
|
196106
196733
|
const projectDir = findProjectDir(startDir ?? process.cwd());
|
|
196107
|
-
const projectPath = projectDir ?
|
|
196734
|
+
const projectPath = projectDir ? join211(projectDir, "config.json") : null;
|
|
196108
196735
|
return {
|
|
196109
196736
|
global: fileExists(globalPath) ? globalPath : null,
|
|
196110
196737
|
project: projectPath && fileExists(projectPath) ? projectPath : null
|
|
@@ -196681,7 +197308,7 @@ var init_context5 = __esm(() => {
|
|
|
196681
197308
|
|
|
196682
197309
|
// src/cli/context-fragments.ts
|
|
196683
197310
|
import { existsSync as existsSync29 } from "fs";
|
|
196684
|
-
import { join as
|
|
197311
|
+
import { join as join212 } from "path";
|
|
196685
197312
|
function listDependentStoryIds(prd, startId) {
|
|
196686
197313
|
const forward = new Map;
|
|
196687
197314
|
for (const story of prd.userStories) {
|
|
@@ -196766,7 +197393,7 @@ function resolveProjectDir(dir) {
|
|
|
196766
197393
|
return dir ?? process.cwd();
|
|
196767
197394
|
}
|
|
196768
197395
|
function featurePrdPath2(projectDir, featureId) {
|
|
196769
|
-
return
|
|
197396
|
+
return join212(featureDir(projectDir, featureId), "prd.json");
|
|
196770
197397
|
}
|
|
196771
197398
|
async function fragmentsInspectCommand(options) {
|
|
196772
197399
|
const projectDir = _contextFragmentsDeps.projectDirFor(resolveProjectDir(options.dir));
|
|
@@ -196852,7 +197479,7 @@ var init_context_fragments = __esm(() => {
|
|
|
196852
197479
|
|
|
196853
197480
|
// src/cli/cost-ledger-query.ts
|
|
196854
197481
|
import { readdir as readdir18, stat as stat21 } from "fs/promises";
|
|
196855
|
-
import { basename as basename38, dirname as dirname54, join as
|
|
197482
|
+
import { basename as basename38, dirname as dirname54, join as join213 } from "path";
|
|
196856
197483
|
function errorCode3(err) {
|
|
196857
197484
|
return typeof err === "object" && err !== null ? Reflect.get(err, "code") : undefined;
|
|
196858
197485
|
}
|
|
@@ -196873,7 +197500,7 @@ async function readEntries(dir) {
|
|
|
196873
197500
|
throw err;
|
|
196874
197501
|
}
|
|
196875
197502
|
}
|
|
196876
|
-
async function
|
|
197503
|
+
async function isDirectory2(path) {
|
|
196877
197504
|
try {
|
|
196878
197505
|
return (await stat21(path)).isDirectory();
|
|
196879
197506
|
} catch (err) {
|
|
@@ -196890,11 +197517,11 @@ function compareStrings(a, b) {
|
|
|
196890
197517
|
async function listCostLedgerFiles(roots) {
|
|
196891
197518
|
const found = new Set;
|
|
196892
197519
|
for (const root of roots) {
|
|
196893
|
-
const dir =
|
|
197520
|
+
const dir = join213(root, COST_DIR);
|
|
196894
197521
|
for (const entry of await readEntries(dir)) {
|
|
196895
197522
|
if (entry.isDir || !entry.name.endsWith(LEDGER_SUFFIX))
|
|
196896
197523
|
continue;
|
|
196897
|
-
found.add(
|
|
197524
|
+
found.add(join213(dir, entry.name));
|
|
196898
197525
|
}
|
|
196899
197526
|
}
|
|
196900
197527
|
return [...found].sort(compareStrings);
|
|
@@ -196902,10 +197529,10 @@ async function listCostLedgerFiles(roots) {
|
|
|
196902
197529
|
async function listProjectOutputDirs(globalDir) {
|
|
196903
197530
|
const found = [];
|
|
196904
197531
|
for (const entry of await readEntries(globalDir)) {
|
|
196905
|
-
const child =
|
|
196906
|
-
if (!await
|
|
197532
|
+
const child = join213(globalDir, entry.name);
|
|
197533
|
+
if (!await isDirectory2(child))
|
|
196907
197534
|
continue;
|
|
196908
|
-
if (!await
|
|
197535
|
+
if (!await isDirectory2(join213(child, COST_DIR)))
|
|
196909
197536
|
continue;
|
|
196910
197537
|
found.push(child);
|
|
196911
197538
|
}
|
|
@@ -197256,7 +197883,7 @@ var init_cost4 = __esm(() => {
|
|
|
197256
197883
|
});
|
|
197257
197884
|
|
|
197258
197885
|
// src/cli/gates.ts
|
|
197259
|
-
import { dirname as dirname55, join as
|
|
197886
|
+
import { dirname as dirname55, join as join214 } from "path";
|
|
197260
197887
|
async function projectRootOf(dir) {
|
|
197261
197888
|
const naxDir = findProjectDir(dir);
|
|
197262
197889
|
if (naxDir === null || realOrRaw(naxDir) === realOrRaw(globalConfigDir())) {
|
|
@@ -197374,7 +198001,7 @@ async function gatesRunCommand(opts, deps = _gatesCliDeps) {
|
|
|
197374
198001
|
if (opts.json)
|
|
197375
198002
|
deps.log(JSON.stringify(empty));
|
|
197376
198003
|
else
|
|
197377
|
-
deps.log(`no quality.commands configured in ${
|
|
198004
|
+
deps.log(`no quality.commands configured in ${join214(projectDir, PROJECT_NAX_DIR, "config.json")}; nothing was verified`);
|
|
197378
198005
|
return 2;
|
|
197379
198006
|
}
|
|
197380
198007
|
const records = [];
|
|
@@ -197440,9 +198067,9 @@ var init_gates2 = __esm(() => {
|
|
|
197440
198067
|
|
|
197441
198068
|
// src/context/injector.ts
|
|
197442
198069
|
import { existsSync as existsSync30 } from "fs";
|
|
197443
|
-
import { join as
|
|
198070
|
+
import { join as join215 } from "path";
|
|
197444
198071
|
async function detectNode(workdir) {
|
|
197445
|
-
const pkgPath =
|
|
198072
|
+
const pkgPath = join215(workdir, "package.json");
|
|
197446
198073
|
if (!existsSync30(pkgPath))
|
|
197447
198074
|
return null;
|
|
197448
198075
|
try {
|
|
@@ -197459,7 +198086,7 @@ async function detectNode(workdir) {
|
|
|
197459
198086
|
}
|
|
197460
198087
|
}
|
|
197461
198088
|
async function detectGo(workdir) {
|
|
197462
|
-
const goMod =
|
|
198089
|
+
const goMod = join215(workdir, "go.mod");
|
|
197463
198090
|
if (!existsSync30(goMod))
|
|
197464
198091
|
return null;
|
|
197465
198092
|
try {
|
|
@@ -197483,7 +198110,7 @@ async function detectGo(workdir) {
|
|
|
197483
198110
|
}
|
|
197484
198111
|
}
|
|
197485
198112
|
async function detectRust(workdir) {
|
|
197486
|
-
const cargoPath =
|
|
198113
|
+
const cargoPath = join215(workdir, "Cargo.toml");
|
|
197487
198114
|
if (!existsSync30(cargoPath))
|
|
197488
198115
|
return null;
|
|
197489
198116
|
try {
|
|
@@ -197499,8 +198126,8 @@ async function detectRust(workdir) {
|
|
|
197499
198126
|
}
|
|
197500
198127
|
}
|
|
197501
198128
|
async function detectPython(workdir) {
|
|
197502
|
-
const pyproject =
|
|
197503
|
-
const requirements =
|
|
198129
|
+
const pyproject = join215(workdir, "pyproject.toml");
|
|
198130
|
+
const requirements = join215(workdir, "requirements.txt");
|
|
197504
198131
|
if (!existsSync30(pyproject) && !existsSync30(requirements))
|
|
197505
198132
|
return null;
|
|
197506
198133
|
try {
|
|
@@ -197519,7 +198146,7 @@ async function detectPython(workdir) {
|
|
|
197519
198146
|
}
|
|
197520
198147
|
}
|
|
197521
198148
|
async function detectPhp(workdir) {
|
|
197522
|
-
const composerPath =
|
|
198149
|
+
const composerPath = join215(workdir, "composer.json");
|
|
197523
198150
|
if (!existsSync30(composerPath))
|
|
197524
198151
|
return null;
|
|
197525
198152
|
try {
|
|
@@ -197532,7 +198159,7 @@ async function detectPhp(workdir) {
|
|
|
197532
198159
|
}
|
|
197533
198160
|
}
|
|
197534
198161
|
async function detectRuby(workdir) {
|
|
197535
|
-
const gemfile =
|
|
198162
|
+
const gemfile = join215(workdir, "Gemfile");
|
|
197536
198163
|
if (!existsSync30(gemfile))
|
|
197537
198164
|
return null;
|
|
197538
198165
|
try {
|
|
@@ -197544,9 +198171,9 @@ async function detectRuby(workdir) {
|
|
|
197544
198171
|
}
|
|
197545
198172
|
}
|
|
197546
198173
|
async function detectJvm(workdir) {
|
|
197547
|
-
const pom =
|
|
197548
|
-
const gradle =
|
|
197549
|
-
const gradleKts =
|
|
198174
|
+
const pom = join215(workdir, "pom.xml");
|
|
198175
|
+
const gradle = join215(workdir, "build.gradle");
|
|
198176
|
+
const gradleKts = join215(workdir, "build.gradle.kts");
|
|
197550
198177
|
if (!existsSync30(pom) && !existsSync30(gradle) && !existsSync30(gradleKts))
|
|
197551
198178
|
return null;
|
|
197552
198179
|
try {
|
|
@@ -197554,7 +198181,7 @@ async function detectJvm(workdir) {
|
|
|
197554
198181
|
const content = await Bun.file(pom).text();
|
|
197555
198182
|
const nameMatch = content.match(/<artifactId>([^<]+)<\/artifactId>/);
|
|
197556
198183
|
const deps = [...content.matchAll(/<artifactId>([^<]+)<\/artifactId>/g)].map((m) => m[1]).filter((d) => d !== nameMatch?.[1]).slice(0, 10);
|
|
197557
|
-
const lang = existsSync30(
|
|
198184
|
+
const lang = existsSync30(join215(workdir, "src/main/kotlin")) ? "Kotlin" : "Java";
|
|
197558
198185
|
return { name: nameMatch?.[1], lang, dependencies: deps };
|
|
197559
198186
|
}
|
|
197560
198187
|
const gradleFile = existsSync30(gradleKts) ? gradleKts : gradle;
|
|
@@ -197809,7 +198436,7 @@ var init_windsurf = __esm(() => {
|
|
|
197809
198436
|
|
|
197810
198437
|
// src/context/generator/index.ts
|
|
197811
198438
|
import { existsSync as existsSync31 } from "fs";
|
|
197812
|
-
import { join as
|
|
198439
|
+
import { join as join216, relative as relative53 } from "path";
|
|
197813
198440
|
async function loadContextContent(options, config) {
|
|
197814
198441
|
if (!_generatorDeps.existsSync(options.contextPath)) {
|
|
197815
198442
|
throw new NaxError(`Context file not found: ${options.contextPath}`, "CONTEXT_FILE_NOT_FOUND", {
|
|
@@ -197830,7 +198457,7 @@ async function generateFor(agent, options, config) {
|
|
|
197830
198457
|
try {
|
|
197831
198458
|
const context = await loadContextContent(options, config);
|
|
197832
198459
|
const content = generator.generate(context);
|
|
197833
|
-
const outputPath =
|
|
198460
|
+
const outputPath = join216(options.outputDir, generator.outputFile);
|
|
197834
198461
|
validateFilePath(outputPath, options.outputDir);
|
|
197835
198462
|
if (!options.dryRun) {
|
|
197836
198463
|
await _generatorDeps.writeFile(outputPath, content);
|
|
@@ -197848,7 +198475,7 @@ async function generateAll(options, config, agentFilter) {
|
|
|
197848
198475
|
for (const [agentKey, generator] of entries) {
|
|
197849
198476
|
try {
|
|
197850
198477
|
const content = generator.generate(context);
|
|
197851
|
-
const outputPath =
|
|
198478
|
+
const outputPath = join216(options.outputDir, generator.outputFile);
|
|
197852
198479
|
validateFilePath(outputPath, options.outputDir);
|
|
197853
198480
|
if (!options.dryRun) {
|
|
197854
198481
|
await _generatorDeps.writeFile(outputPath, content);
|
|
@@ -197868,7 +198495,7 @@ async function discoverPackages(repoRoot) {
|
|
|
197868
198495
|
const glob = new Bun.Glob(pattern);
|
|
197869
198496
|
for await (const match of glob.scan({ cwd: repoRoot, dot: true })) {
|
|
197870
198497
|
const pkgRelative = match.replace(/^\.nax\/mono\//, "").replace(/\/context\.md$/, "");
|
|
197871
|
-
const pkgAbsolute =
|
|
198498
|
+
const pkgAbsolute = join216(repoRoot, pkgRelative);
|
|
197872
198499
|
if (!seen.has(pkgAbsolute)) {
|
|
197873
198500
|
seen.add(pkgAbsolute);
|
|
197874
198501
|
packages.push(pkgAbsolute);
|
|
@@ -197900,14 +198527,14 @@ async function discoverWorkspacePackages2(repoRoot) {
|
|
|
197900
198527
|
}
|
|
197901
198528
|
}
|
|
197902
198529
|
}
|
|
197903
|
-
const turboPath =
|
|
198530
|
+
const turboPath = join216(repoRoot, "turbo.json");
|
|
197904
198531
|
try {
|
|
197905
198532
|
const turbo = JSON.parse(await _generatorDeps.readTextFile(turboPath));
|
|
197906
198533
|
if (Array.isArray(turbo.packages)) {
|
|
197907
198534
|
await resolveGlobs(turbo.packages);
|
|
197908
198535
|
}
|
|
197909
198536
|
} catch {}
|
|
197910
|
-
const pkgPath =
|
|
198537
|
+
const pkgPath = join216(repoRoot, "package.json");
|
|
197911
198538
|
try {
|
|
197912
198539
|
const pkg = JSON.parse(await _generatorDeps.readTextFile(pkgPath));
|
|
197913
198540
|
const ws = pkg.workspaces;
|
|
@@ -197915,7 +198542,7 @@ async function discoverWorkspacePackages2(repoRoot) {
|
|
|
197915
198542
|
if (patterns.length > 0)
|
|
197916
198543
|
await resolveGlobs(patterns);
|
|
197917
198544
|
} catch {}
|
|
197918
|
-
const pnpmPath =
|
|
198545
|
+
const pnpmPath = join216(repoRoot, "pnpm-workspace.yaml");
|
|
197919
198546
|
try {
|
|
197920
198547
|
const raw = await _generatorDeps.readTextFile(pnpmPath);
|
|
197921
198548
|
const lines = raw.split(`
|
|
@@ -197941,7 +198568,7 @@ async function discoverWorkspacePackages2(repoRoot) {
|
|
|
197941
198568
|
async function generateForPackage(packageDir, config, dryRun = false, repoRoot) {
|
|
197942
198569
|
const resolvedRepoRoot = repoRoot ?? packageDir;
|
|
197943
198570
|
const relativePkgPath = relative53(resolvedRepoRoot, packageDir);
|
|
197944
|
-
const contextPath =
|
|
198571
|
+
const contextPath = join216(resolvedRepoRoot, ".nax", "mono", relativePkgPath, "context.md");
|
|
197945
198572
|
if (!_generatorDeps.existsSync(contextPath)) {
|
|
197946
198573
|
return [
|
|
197947
198574
|
{
|
|
@@ -198012,7 +198639,7 @@ var init_generator2 = __esm(() => {
|
|
|
198012
198639
|
|
|
198013
198640
|
// src/cli/generate.ts
|
|
198014
198641
|
import { existsSync as existsSync32 } from "fs";
|
|
198015
|
-
import { join as
|
|
198642
|
+
import { join as join217 } from "path";
|
|
198016
198643
|
async function loadCommandConfig(workdir) {
|
|
198017
198644
|
try {
|
|
198018
198645
|
return await loadConfig(workdir);
|
|
@@ -198063,7 +198690,7 @@ async function runSinglePackage(frame, pkg) {
|
|
|
198063
198690
|
if (!isRelativeAndSafe(pkg)) {
|
|
198064
198691
|
throw new NaxError(`generateCommand: package "${pkg}" is not a safe relative path (must be non-empty, relative, and free of ".." segments)`, "INVALID_PACKAGE_PATH", { stage: "generate", package: pkg });
|
|
198065
198692
|
}
|
|
198066
|
-
const packageDir =
|
|
198693
|
+
const packageDir = join217(frame.workdir, pkg);
|
|
198067
198694
|
printDryRunNotice(frame.dryRun);
|
|
198068
198695
|
console.log(source_default.blue(`\u2192 Generating agent files for package: ${pkg}`));
|
|
198069
198696
|
const pkgResults = await generateForPackage(packageDir, frame.config, frame.dryRun, frame.workdir);
|
|
@@ -198162,8 +198789,8 @@ async function generateFromConfig(frame, genOptions) {
|
|
|
198162
198789
|
await generateDiscoveredPackages(frame);
|
|
198163
198790
|
}
|
|
198164
198791
|
async function runRootGeneration(frame, options) {
|
|
198165
|
-
const contextPath = options.context ?
|
|
198166
|
-
const outputDir = options.output ?
|
|
198792
|
+
const contextPath = options.context ? join217(frame.workdir, options.context) : join217(frame.workdir, ".nax/context.md");
|
|
198793
|
+
const outputDir = options.output ? join217(frame.workdir, options.output) : frame.workdir;
|
|
198167
198794
|
const autoInject = !options.noAutoInject;
|
|
198168
198795
|
validateRootInputs(contextPath, options.agent);
|
|
198169
198796
|
printDryRunNotice(frame.dryRun);
|
|
@@ -198224,7 +198851,7 @@ var init_generate = __esm(() => {
|
|
|
198224
198851
|
|
|
198225
198852
|
// src/cli/init-context.ts
|
|
198226
198853
|
import { mkdir as mkdir55, readdir as readdir19 } from "fs/promises";
|
|
198227
|
-
import { basename as basename40, join as
|
|
198854
|
+
import { basename as basename40, join as join218, relative as relative54, sep as sep29 } from "path";
|
|
198228
198855
|
async function bunFileExists(path) {
|
|
198229
198856
|
return Bun.file(path).exists();
|
|
198230
198857
|
}
|
|
@@ -198249,14 +198876,14 @@ async function walkDir(root, current, out, maxFiles) {
|
|
|
198249
198876
|
if (entry.isDirectory()) {
|
|
198250
198877
|
if (EXCLUDED_DIR_NAMES.has(entry.name))
|
|
198251
198878
|
continue;
|
|
198252
|
-
await walkDir(root,
|
|
198879
|
+
await walkDir(root, join218(current, entry.name), out, maxFiles);
|
|
198253
198880
|
} else if (entry.isFile()) {
|
|
198254
|
-
out.push(relative54(root,
|
|
198881
|
+
out.push(relative54(root, join218(current, entry.name)).replaceAll(sep29, "/"));
|
|
198255
198882
|
}
|
|
198256
198883
|
}
|
|
198257
198884
|
}
|
|
198258
198885
|
async function readPackageManifest(projectRoot) {
|
|
198259
|
-
const packageJsonPath =
|
|
198886
|
+
const packageJsonPath = join218(projectRoot, "package.json");
|
|
198260
198887
|
if (!await bunFileExists(packageJsonPath)) {
|
|
198261
198888
|
return null;
|
|
198262
198889
|
}
|
|
@@ -198274,7 +198901,7 @@ async function readPackageManifest(projectRoot) {
|
|
|
198274
198901
|
}
|
|
198275
198902
|
}
|
|
198276
198903
|
async function readReadmeSnippet(projectRoot) {
|
|
198277
|
-
const readmePath =
|
|
198904
|
+
const readmePath = join218(projectRoot, "README.md");
|
|
198278
198905
|
if (!await bunFileExists(readmePath)) {
|
|
198279
198906
|
return null;
|
|
198280
198907
|
}
|
|
@@ -198292,7 +198919,7 @@ async function detectEntryPoints(projectRoot) {
|
|
|
198292
198919
|
const candidates = ["src/index.ts", "src/main.ts", "main.go", "src/lib.rs"];
|
|
198293
198920
|
const found = [];
|
|
198294
198921
|
for (const candidate of candidates) {
|
|
198295
|
-
const path =
|
|
198922
|
+
const path = join218(projectRoot, candidate);
|
|
198296
198923
|
if (await bunFileExists(path)) {
|
|
198297
198924
|
found.push(candidate);
|
|
198298
198925
|
}
|
|
@@ -198303,7 +198930,7 @@ async function detectConfigFiles(projectRoot) {
|
|
|
198303
198930
|
const candidates = ["tsconfig.json", "biome.json", "turbo.json", ".env.example"];
|
|
198304
198931
|
const found = [];
|
|
198305
198932
|
for (const candidate of candidates) {
|
|
198306
|
-
const path =
|
|
198933
|
+
const path = join218(projectRoot, candidate);
|
|
198307
198934
|
if (await bunFileExists(path)) {
|
|
198308
198935
|
found.push(candidate);
|
|
198309
198936
|
}
|
|
@@ -198434,8 +199061,8 @@ async function initPackage(repoRoot, packagePath, force = false) {
|
|
|
198434
199061
|
throw new NaxError(`initPackage: packagePath "${packagePath}" is not a safe relative path (must be non-empty, relative, and free of ".." segments)`, "INVALID_PACKAGE_PATH", { stage: "init-context", packagePath });
|
|
198435
199062
|
}
|
|
198436
199063
|
const logger = getLogger2();
|
|
198437
|
-
const naxDir =
|
|
198438
|
-
const contextPath =
|
|
199064
|
+
const naxDir = join218(repoRoot, ".nax", "mono", packagePath);
|
|
199065
|
+
const contextPath = join218(naxDir, "context.md");
|
|
198439
199066
|
if (await bunFileExists(contextPath) && !force) {
|
|
198440
199067
|
logger.info("init", "Package context.md already exists (use --force to overwrite)", {
|
|
198441
199068
|
storyId: "init-context",
|
|
@@ -198458,8 +199085,8 @@ async function initPackage(repoRoot, packagePath, force = false) {
|
|
|
198458
199085
|
}
|
|
198459
199086
|
async function initContext(projectRoot, options = {}) {
|
|
198460
199087
|
const logger = getLogger2();
|
|
198461
|
-
const naxDir =
|
|
198462
|
-
const contextPath =
|
|
199088
|
+
const naxDir = join218(projectRoot, ".nax");
|
|
199089
|
+
const contextPath = join218(naxDir, "context.md");
|
|
198463
199090
|
if (await bunFileExists(contextPath) && !options.force) {
|
|
198464
199091
|
logger.info("init", "context.md already exists, skipping (use --force to overwrite)", {
|
|
198465
199092
|
storyId: "init-context",
|
|
@@ -198494,9 +199121,9 @@ var init_init_context = __esm(() => {
|
|
|
198494
199121
|
|
|
198495
199122
|
// src/cli/init-detect.ts
|
|
198496
199123
|
import { existsSync as existsSync33, readFileSync as readFileSync4 } from "fs";
|
|
198497
|
-
import { join as
|
|
199124
|
+
import { join as join219 } from "path";
|
|
198498
199125
|
function readPackageJson(projectRoot) {
|
|
198499
|
-
const pkgPath =
|
|
199126
|
+
const pkgPath = join219(projectRoot, "package.json");
|
|
198500
199127
|
if (!existsSync33(pkgPath))
|
|
198501
199128
|
return;
|
|
198502
199129
|
try {
|
|
@@ -198539,41 +199166,41 @@ function detectStack(projectRoot) {
|
|
|
198539
199166
|
};
|
|
198540
199167
|
}
|
|
198541
199168
|
function detectRuntime(projectRoot) {
|
|
198542
|
-
if (existsSync33(
|
|
199169
|
+
if (existsSync33(join219(projectRoot, "bun.lockb")) || existsSync33(join219(projectRoot, "bunfig.toml"))) {
|
|
198543
199170
|
return "bun";
|
|
198544
199171
|
}
|
|
198545
|
-
if (existsSync33(
|
|
199172
|
+
if (existsSync33(join219(projectRoot, "package-lock.json")) || existsSync33(join219(projectRoot, "yarn.lock")) || existsSync33(join219(projectRoot, "pnpm-lock.yaml"))) {
|
|
198546
199173
|
return "node";
|
|
198547
199174
|
}
|
|
198548
199175
|
return "unknown";
|
|
198549
199176
|
}
|
|
198550
199177
|
function detectLanguage2(projectRoot) {
|
|
198551
|
-
if (existsSync33(
|
|
199178
|
+
if (existsSync33(join219(projectRoot, "tsconfig.json")))
|
|
198552
199179
|
return "typescript";
|
|
198553
|
-
if (existsSync33(
|
|
199180
|
+
if (existsSync33(join219(projectRoot, "pyproject.toml")) || existsSync33(join219(projectRoot, "setup.py"))) {
|
|
198554
199181
|
return "python";
|
|
198555
199182
|
}
|
|
198556
|
-
if (existsSync33(
|
|
199183
|
+
if (existsSync33(join219(projectRoot, "Cargo.toml")))
|
|
198557
199184
|
return "rust";
|
|
198558
|
-
if (existsSync33(
|
|
199185
|
+
if (existsSync33(join219(projectRoot, "go.mod")))
|
|
198559
199186
|
return "go";
|
|
198560
199187
|
return "unknown";
|
|
198561
199188
|
}
|
|
198562
199189
|
function detectLinter(projectRoot) {
|
|
198563
|
-
if (existsSync33(
|
|
199190
|
+
if (existsSync33(join219(projectRoot, "biome.json")) || existsSync33(join219(projectRoot, "biome.jsonc"))) {
|
|
198564
199191
|
return "biome";
|
|
198565
199192
|
}
|
|
198566
|
-
if (existsSync33(
|
|
199193
|
+
if (existsSync33(join219(projectRoot, ".eslintrc.json")) || existsSync33(join219(projectRoot, ".eslintrc.js")) || existsSync33(join219(projectRoot, "eslint.config.js"))) {
|
|
198567
199194
|
return "eslint";
|
|
198568
199195
|
}
|
|
198569
199196
|
return "unknown";
|
|
198570
199197
|
}
|
|
198571
199198
|
function detectMonorepo(projectRoot) {
|
|
198572
|
-
if (existsSync33(
|
|
199199
|
+
if (existsSync33(join219(projectRoot, "turbo.json")))
|
|
198573
199200
|
return "turborepo";
|
|
198574
|
-
if (existsSync33(
|
|
199201
|
+
if (existsSync33(join219(projectRoot, "nx.json")))
|
|
198575
199202
|
return "nx";
|
|
198576
|
-
if (existsSync33(
|
|
199203
|
+
if (existsSync33(join219(projectRoot, "pnpm-workspace.yaml")))
|
|
198577
199204
|
return "pnpm-workspaces";
|
|
198578
199205
|
const pkg = readPackageJson(projectRoot);
|
|
198579
199206
|
if (pkg?.workspaces)
|
|
@@ -198709,7 +199336,7 @@ var init_init_detect = () => {};
|
|
|
198709
199336
|
// src/cli/init.ts
|
|
198710
199337
|
import { existsSync as existsSync34 } from "fs";
|
|
198711
199338
|
import { mkdir as mkdir56 } from "fs/promises";
|
|
198712
|
-
import { join as
|
|
199339
|
+
import { join as join220 } from "path";
|
|
198713
199340
|
function validateProjectName(name) {
|
|
198714
199341
|
if (!name)
|
|
198715
199342
|
return { valid: false, error: "name must be non-empty" };
|
|
@@ -198745,7 +199372,7 @@ async function checkInitCollision(name, currentWorkdir, currentRemote) {
|
|
|
198745
199372
|
}
|
|
198746
199373
|
async function updateGitignore(projectRoot) {
|
|
198747
199374
|
const logger = getLogger2();
|
|
198748
|
-
const gitignorePath =
|
|
199375
|
+
const gitignorePath = join220(projectRoot, ".gitignore");
|
|
198749
199376
|
const result = await patchIgnoreFile(gitignorePath, NAX_GITIGNORE_ENTRIES);
|
|
198750
199377
|
if (result.added.length === 0) {
|
|
198751
199378
|
logger.info("init", ".gitignore already has nax entries", { path: gitignorePath });
|
|
@@ -198759,7 +199386,7 @@ async function updateGitignore(projectRoot) {
|
|
|
198759
199386
|
}
|
|
198760
199387
|
async function updateNaxignore(projectRoot) {
|
|
198761
199388
|
const logger = getLogger2();
|
|
198762
|
-
const naxignorePath =
|
|
199389
|
+
const naxignorePath = join220(projectRoot, ".naxignore");
|
|
198763
199390
|
const result = await patchIgnoreFile(naxignorePath, NAX_NAXIGNORE_ENTRIES, {
|
|
198764
199391
|
header: NAX_NAXIGNORE_HEADER,
|
|
198765
199392
|
footer: NAX_NAXIGNORE_SUGGESTIONS,
|
|
@@ -198845,7 +199472,7 @@ async function initGlobal() {
|
|
|
198845
199472
|
await mkdir56(globalDir, { recursive: true });
|
|
198846
199473
|
logger.info("init", "Created global config directory", { path: globalDir });
|
|
198847
199474
|
}
|
|
198848
|
-
const configPath =
|
|
199475
|
+
const configPath = join220(globalDir, "config.json");
|
|
198849
199476
|
if (!existsSync34(configPath)) {
|
|
198850
199477
|
await Bun.write(configPath, `${JSON.stringify(MINIMAL_GLOBAL_CONFIG, null, 2)}
|
|
198851
199478
|
`);
|
|
@@ -198853,14 +199480,14 @@ async function initGlobal() {
|
|
|
198853
199480
|
} else {
|
|
198854
199481
|
logger.info("init", "Global config already exists", { path: configPath });
|
|
198855
199482
|
}
|
|
198856
|
-
const constitutionPath =
|
|
199483
|
+
const constitutionPath = join220(globalDir, "constitution.md");
|
|
198857
199484
|
if (!existsSync34(constitutionPath)) {
|
|
198858
199485
|
await Bun.write(constitutionPath, buildConstitution({ runtime: "unknown", language: "unknown", linter: "unknown", monorepo: "none" }));
|
|
198859
199486
|
logger.info("init", "Created global constitution", { path: constitutionPath });
|
|
198860
199487
|
} else {
|
|
198861
199488
|
logger.info("init", "Global constitution already exists", { path: constitutionPath });
|
|
198862
199489
|
}
|
|
198863
|
-
const hooksDir =
|
|
199490
|
+
const hooksDir = join220(globalDir, "hooks");
|
|
198864
199491
|
if (!existsSync34(hooksDir)) {
|
|
198865
199492
|
await mkdir56(hooksDir, { recursive: true });
|
|
198866
199493
|
logger.info("init", "Created global hooks directory", { path: hooksDir });
|
|
@@ -198893,7 +199520,7 @@ async function initProject(projectRoot, options) {
|
|
|
198893
199520
|
if (detectedName && !options?.force) {
|
|
198894
199521
|
const collision = await checkInitCollision(detectedName, projectRoot, currentRemote);
|
|
198895
199522
|
if (collision.collision && collision.existing) {
|
|
198896
|
-
const configPath =
|
|
199523
|
+
const configPath = join220(projectDir, "config.json");
|
|
198897
199524
|
throw new NaxError([
|
|
198898
199525
|
`Project name collision: "${detectedName}"`,
|
|
198899
199526
|
` This project: ${projectRoot}`,
|
|
@@ -198921,7 +199548,7 @@ async function initProject(projectRoot, options) {
|
|
|
198921
199548
|
linter: stack.linter,
|
|
198922
199549
|
monorepo: stack.monorepo
|
|
198923
199550
|
});
|
|
198924
|
-
const configPath =
|
|
199551
|
+
const configPath = join220(projectDir, "config.json");
|
|
198925
199552
|
if (!existsSync34(configPath)) {
|
|
198926
199553
|
await Bun.write(configPath, `${JSON.stringify(projectConfig, null, 2)}
|
|
198927
199554
|
`);
|
|
@@ -198930,7 +199557,7 @@ async function initProject(projectRoot, options) {
|
|
|
198930
199557
|
logger.info("init", "Project config already exists", { path: configPath });
|
|
198931
199558
|
}
|
|
198932
199559
|
await initContext(projectRoot, { force: options?.force });
|
|
198933
|
-
const constitutionPath =
|
|
199560
|
+
const constitutionPath = join220(projectDir, "constitution.md");
|
|
198934
199561
|
if (!existsSync34(constitutionPath) || options?.force) {
|
|
198935
199562
|
await Bun.write(constitutionPath, buildConstitution(stack));
|
|
198936
199563
|
logger.info("init", "Created project constitution", { path: constitutionPath });
|
|
@@ -198938,7 +199565,7 @@ async function initProject(projectRoot, options) {
|
|
|
198938
199565
|
logger.info("init", "Project constitution already exists", { path: constitutionPath });
|
|
198939
199566
|
}
|
|
198940
199567
|
for (const [label, dir] of [
|
|
198941
|
-
["hooks",
|
|
199568
|
+
["hooks", join220(projectDir, "hooks")],
|
|
198942
199569
|
["features", featuresDir(projectRoot)]
|
|
198943
199570
|
]) {
|
|
198944
199571
|
if (!existsSync34(dir)) {
|
|
@@ -199049,7 +199676,7 @@ var init_memory_admin_deps = __esm(() => {
|
|
|
199049
199676
|
});
|
|
199050
199677
|
|
|
199051
199678
|
// src/cli/memory-admin-config.ts
|
|
199052
|
-
import { join as
|
|
199679
|
+
import { join as join221 } from "path";
|
|
199053
199680
|
function isRecord24(value) {
|
|
199054
199681
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
199055
199682
|
}
|
|
@@ -199060,7 +199687,7 @@ function stringField8(value, key) {
|
|
|
199060
199687
|
return typeof field === "string" && field !== "" ? field : undefined;
|
|
199061
199688
|
}
|
|
199062
199689
|
function projectConfigPath(repoRoot) {
|
|
199063
|
-
return
|
|
199690
|
+
return join221(repoRoot, PROJECT_NAX_DIR, "config.json");
|
|
199064
199691
|
}
|
|
199065
199692
|
function projectOf2(raw) {
|
|
199066
199693
|
const memory = raw.memory;
|
|
@@ -199123,9 +199750,9 @@ var init_memory_admin_config = __esm(() => {
|
|
|
199123
199750
|
});
|
|
199124
199751
|
|
|
199125
199752
|
// src/cli/memory-admin-relink.ts
|
|
199126
|
-
import { basename as basename41, dirname as dirname57, join as
|
|
199753
|
+
import { basename as basename41, dirname as dirname57, join as join222 } from "path";
|
|
199127
199754
|
function pendingRelinkPath(dirs) {
|
|
199128
|
-
return
|
|
199755
|
+
return join222(dirs.root, RELINK_DIR_NAME, `${basename41(dirs.projectDir)}.json`);
|
|
199129
199756
|
}
|
|
199130
199757
|
function relinkQuarantinePath(dirs) {
|
|
199131
199758
|
return `${pendingRelinkPath(dirs)}.mirror`;
|
|
@@ -199349,7 +199976,7 @@ var init_memory_cli_deps = __esm(() => {
|
|
|
199349
199976
|
});
|
|
199350
199977
|
|
|
199351
199978
|
// src/cli/memory-admin.ts
|
|
199352
|
-
import { dirname as dirname59, join as
|
|
199979
|
+
import { dirname as dirname59, join as join223 } from "path";
|
|
199353
199980
|
function assertKodaSlug(slug) {
|
|
199354
199981
|
if (KODA_PROJECT_SLUG_RE.test(slug))
|
|
199355
199982
|
return;
|
|
@@ -199369,14 +199996,16 @@ function relinkFrom(raw, slug, force) {
|
|
|
199369
199996
|
throw linkRefusal(`already linked to koda project "${existing}"; pass --force to relink (the project mirror is rebuilt)`, { project: existing });
|
|
199370
199997
|
}
|
|
199371
199998
|
async function undeliveredWrites(host) {
|
|
199372
|
-
const
|
|
199373
|
-
|
|
199999
|
+
const { queued, rejected } = await host.status();
|
|
200000
|
+
const steps = rejected > 0 ? "run nax memory requeue --all then nax memory sync, or nax memory discard --all," : "run nax memory sync";
|
|
200001
|
+
const total = queued + rejected;
|
|
200002
|
+
return { total, advice: `${total} writes are not delivered (${queued} queued, ${rejected} rejected); ${steps}` };
|
|
199374
200003
|
}
|
|
199375
200004
|
async function assertNothingUndelivered(host) {
|
|
199376
200005
|
const undelivered = await undeliveredWrites(host);
|
|
199377
|
-
if (undelivered === 0)
|
|
200006
|
+
if (undelivered.total === 0)
|
|
199378
200007
|
return;
|
|
199379
|
-
throw linkRefusal(`${undelivered}
|
|
200008
|
+
throw linkRefusal(`${undelivered.advice} before relinking`, { undelivered: undelivered.total });
|
|
199380
200009
|
}
|
|
199381
200010
|
function linkWriteModeOf(mode) {
|
|
199382
200011
|
return LINK_WRITE_MODES.find((known) => known === mode);
|
|
@@ -199479,15 +200108,15 @@ function assertKodaMirror(providerId) {
|
|
|
199479
200108
|
}
|
|
199480
200109
|
async function assertNothingUndeliveredBeforeReset(host) {
|
|
199481
200110
|
const undelivered = await undeliveredWrites(host);
|
|
199482
|
-
if (undelivered === 0)
|
|
200111
|
+
if (undelivered.total === 0)
|
|
199483
200112
|
return;
|
|
199484
|
-
throw resetRefusal2(`${undelivered}
|
|
200113
|
+
throw resetRefusal2(`${undelivered.advice} before reset`, { undelivered: undelivered.total });
|
|
199485
200114
|
}
|
|
199486
200115
|
async function clearProjectMirror(projectDir) {
|
|
199487
200116
|
for (const entry of await _memoryAdminDeps.listDir(projectDir)) {
|
|
199488
200117
|
if (entry === KODA_APPROVALS_FILE)
|
|
199489
200118
|
continue;
|
|
199490
|
-
await _memoryAdminDeps.removePath(
|
|
200119
|
+
await _memoryAdminDeps.removePath(join223(projectDir, entry));
|
|
199491
200120
|
}
|
|
199492
200121
|
}
|
|
199493
200122
|
async function runReset(opts, deps) {
|
|
@@ -199570,6 +200199,73 @@ var init_memory_read = __esm(() => {
|
|
|
199570
200199
|
init_memory_cli_deps();
|
|
199571
200200
|
});
|
|
199572
200201
|
|
|
200202
|
+
// src/cli/memory-rejected.ts
|
|
200203
|
+
function rejectedUsageError(message) {
|
|
200204
|
+
return new NaxError(`[memory] ${message}`, "MEMORY_CLI_USAGE", { stage: "memory" });
|
|
200205
|
+
}
|
|
200206
|
+
function rejectedTargetOf(op, slug, opts) {
|
|
200207
|
+
const all = opts.all === true;
|
|
200208
|
+
if (slug === undefined && !all)
|
|
200209
|
+
throw rejectedUsageError(`${op} needs a slug or --all`);
|
|
200210
|
+
if (slug !== undefined && all)
|
|
200211
|
+
throw rejectedUsageError(`${op} takes a slug or --all, not both`);
|
|
200212
|
+
if (all && opts.scope !== undefined)
|
|
200213
|
+
throw rejectedUsageError("--scope names one note's scope; --all takes every scope");
|
|
200214
|
+
if (slug === undefined)
|
|
200215
|
+
return "all";
|
|
200216
|
+
return { scope: parseNoteScope(opts.scope) ?? DEFAULT_REJECTED_SCOPE, slug };
|
|
200217
|
+
}
|
|
200218
|
+
function countedWrites(verb, count) {
|
|
200219
|
+
return count === 1 ? `${verb} 1 rejected write` : `${verb} ${count} rejected writes`;
|
|
200220
|
+
}
|
|
200221
|
+
function formatRejectedLine(op, count) {
|
|
200222
|
+
if (count === 0)
|
|
200223
|
+
return `no rejected writes to ${op}`;
|
|
200224
|
+
if (op === "discard") {
|
|
200225
|
+
const tail = "a discarded forget leaves its note on the provider, and the next sync brings it back";
|
|
200226
|
+
return `${countedWrites("discarded", count)}; ${tail}`;
|
|
200227
|
+
}
|
|
200228
|
+
const deliver = count === 1 ? "deliver it" : "deliver them";
|
|
200229
|
+
return `${countedWrites("requeued", count)}; run nax memory sync to ${deliver}`;
|
|
200230
|
+
}
|
|
200231
|
+
async function memoryRejectedCommand(op, slug, opts, deps) {
|
|
200232
|
+
return withMemoryErrors(async () => {
|
|
200233
|
+
const target = rejectedTargetOf(op, slug, opts);
|
|
200234
|
+
return withMemoryHost(await memoryContext(opts.dir, deps), deps, async (host) => {
|
|
200235
|
+
const run = host === null ? undefined : host[op];
|
|
200236
|
+
if (run === undefined)
|
|
200237
|
+
throw memoryDisabledError();
|
|
200238
|
+
const count = await run(target);
|
|
200239
|
+
const key = op === "requeue" ? "requeued" : "discarded";
|
|
200240
|
+
deps.log(opts.json === true ? JSON.stringify({ [key]: count }) : formatRejectedLine(op, count));
|
|
200241
|
+
return 0;
|
|
200242
|
+
});
|
|
200243
|
+
}, deps);
|
|
200244
|
+
}
|
|
200245
|
+
async function memoryRequeueCommand(slug, opts, deps = _memoryCliDeps) {
|
|
200246
|
+
return memoryRejectedCommand("requeue", slug, opts, deps);
|
|
200247
|
+
}
|
|
200248
|
+
async function memoryDiscardCommand(slug, opts, deps = _memoryCliDeps) {
|
|
200249
|
+
return memoryRejectedCommand("discard", slug, opts, deps);
|
|
200250
|
+
}
|
|
200251
|
+
function withRejectedFlags(command, allHelp) {
|
|
200252
|
+
return command.argument("[slug]", "The note whose rejected writes to act on").option("--all", allHelp, false).option("--scope <scope>", `The scope the note is in: ${NOTE_SCOPES.join(", ")} (default ${DEFAULT_REJECTED_SCOPE})`).option("-d, --dir <path>", "Project directory", memoryDefaultDir()).option("--json", "Emit one machine-readable document", false);
|
|
200253
|
+
}
|
|
200254
|
+
function registerMemoryRejectedCommands(memory, deps = _memoryCliDeps) {
|
|
200255
|
+
withRejectedFlags(memory.command("requeue").description("Put rejected memory writes back in the queue for the next sync"), "Requeue every rejected write").action(async (slug, opts) => {
|
|
200256
|
+
deps.exit(await memoryRequeueCommand(slug, opts, deps));
|
|
200257
|
+
});
|
|
200258
|
+
withRejectedFlags(memory.command("discard").description("Drop rejected memory writes for good"), "Discard every rejected write").action(async (slug, opts) => {
|
|
200259
|
+
deps.exit(await memoryDiscardCommand(slug, opts, deps));
|
|
200260
|
+
});
|
|
200261
|
+
return memory;
|
|
200262
|
+
}
|
|
200263
|
+
var DEFAULT_REJECTED_SCOPE = "project";
|
|
200264
|
+
var init_memory_rejected = __esm(() => {
|
|
200265
|
+
init_errors4();
|
|
200266
|
+
init_memory_cli_deps();
|
|
200267
|
+
});
|
|
200268
|
+
|
|
199573
200269
|
// src/cli/memory-write.ts
|
|
199574
200270
|
function bodyInputError() {
|
|
199575
200271
|
return new NaxError("give exactly one of --body or --body-file", "MEMORY_CLI_USAGE", { stage: "memory" });
|
|
@@ -199766,6 +200462,7 @@ function registerMemoryCommand(program, deps = _memoryCliDeps) {
|
|
|
199766
200462
|
registerMemoryReadCommands(memory, deps);
|
|
199767
200463
|
registerMemoryWriteCommands(memory, deps);
|
|
199768
200464
|
registerMemoryAdminCommands(memory, deps);
|
|
200465
|
+
registerMemoryRejectedCommands(memory, deps);
|
|
199769
200466
|
return memory;
|
|
199770
200467
|
}
|
|
199771
200468
|
var SCOPE_ORDER3, FORGET_PENDING_SUFFIX = " (forget pending)", NO_NOTES_LINE = "no memory notes", NO_MATCHED_NOTES_LINE = "no memory notes match", NO_PENDING_FORGETS;
|
|
@@ -199775,6 +200472,7 @@ var init_memory3 = __esm(() => {
|
|
|
199775
200472
|
init_memory_admin();
|
|
199776
200473
|
init_memory_cli_deps();
|
|
199777
200474
|
init_memory_read();
|
|
200475
|
+
init_memory_rejected();
|
|
199778
200476
|
init_memory_write();
|
|
199779
200477
|
SCOPE_ORDER3 = NOTE_SCOPES;
|
|
199780
200478
|
NO_PENDING_FORGETS = new Set;
|
|
@@ -199849,7 +200547,7 @@ var init_plan_helpers = __esm(() => {
|
|
|
199849
200547
|
});
|
|
199850
200548
|
|
|
199851
200549
|
// src/analyze/scanner.ts
|
|
199852
|
-
import { join as
|
|
200550
|
+
import { join as join224 } from "path";
|
|
199853
200551
|
function resolveFrameworkAndRunner(language, pkg) {
|
|
199854
200552
|
if (language === "go")
|
|
199855
200553
|
return { framework: "", testRunner: "go-test" };
|
|
@@ -199871,7 +200569,7 @@ async function scanSourceRoots(workdir) {
|
|
|
199871
200569
|
});
|
|
199872
200570
|
try {
|
|
199873
200571
|
const language = await deps.detectLanguage(workdir);
|
|
199874
|
-
const pkg = await deps.readPackageJson(
|
|
200572
|
+
const pkg = await deps.readPackageJson(join224(workdir, "package.json"));
|
|
199875
200573
|
const { framework, testRunner } = resolveFrameworkAndRunner(language, pkg);
|
|
199876
200574
|
return [{ path: ".", language, framework, testRunner }];
|
|
199877
200575
|
} catch {
|
|
@@ -199889,9 +200587,9 @@ async function scanSourceRoots(workdir) {
|
|
|
199889
200587
|
packages = packages.slice(0, MAX_SOURCE_ROOTS);
|
|
199890
200588
|
}
|
|
199891
200589
|
return Promise.all(packages.map(async (pkgPath) => {
|
|
199892
|
-
const pkgDir = pkgPath === "." ? workdir :
|
|
200590
|
+
const pkgDir = pkgPath === "." ? workdir : join224(workdir, pkgPath);
|
|
199893
200591
|
const language = await deps.detectLanguage(pkgDir);
|
|
199894
|
-
const pkg = await deps.readPackageJson(
|
|
200592
|
+
const pkg = await deps.readPackageJson(join224(pkgDir, "package.json"));
|
|
199895
200593
|
const { framework, testRunner } = resolveFrameworkAndRunner(language, pkg);
|
|
199896
200594
|
return { path: pkgPath, language, framework, testRunner };
|
|
199897
200595
|
}));
|
|
@@ -199983,7 +200681,7 @@ var init_decompose_mapper = __esm(() => {
|
|
|
199983
200681
|
});
|
|
199984
200682
|
|
|
199985
200683
|
// src/cli/plan-decompose.ts
|
|
199986
|
-
import { join as
|
|
200684
|
+
import { join as join225 } from "path";
|
|
199987
200685
|
function validateDecomposedStoryIds(stories, existingIds) {
|
|
199988
200686
|
const generatedIds = new Set;
|
|
199989
200687
|
for (const story of stories) {
|
|
@@ -199997,7 +200695,7 @@ function validateDecomposedStoryIds(stories, existingIds) {
|
|
|
199997
200695
|
}
|
|
199998
200696
|
}
|
|
199999
200697
|
async function planDecomposeCommand(workdir, config, options) {
|
|
200000
|
-
const prdPath =
|
|
200698
|
+
const prdPath = join225(featureDir(workdir, options.feature), "prd.json");
|
|
200001
200699
|
if (!_planDeps.existsSync(prdPath)) {
|
|
200002
200700
|
throw new NaxError(`PRD not found: ${prdPath}`, "PRD_NOT_FOUND", {
|
|
200003
200701
|
stage: "decompose",
|
|
@@ -200152,7 +200850,7 @@ var init_plan_decompose = __esm(() => {
|
|
|
200152
200850
|
|
|
200153
200851
|
// src/cli/plan-runtime/index.ts
|
|
200154
200852
|
import { existsSync as existsSync35 } from "fs";
|
|
200155
|
-
import { join as
|
|
200853
|
+
import { join as join226 } from "path";
|
|
200156
200854
|
function createPlanRuntime(config, workdir, featureName) {
|
|
200157
200855
|
return _planDeps.createRuntime(config, workdir, featureName);
|
|
200158
200856
|
}
|
|
@@ -200204,7 +200902,7 @@ var init_plan_runtime = __esm(() => {
|
|
|
200204
200902
|
scanSourceRoots: (workdir) => scanSourceRoots(workdir),
|
|
200205
200903
|
createRuntime: (cfg, wd, featureName) => createRuntime(cfg, wd, { featureName }),
|
|
200206
200904
|
claimProjectIdentity,
|
|
200207
|
-
readPackageJson: (workdir) => Bun.file(
|
|
200905
|
+
readPackageJson: (workdir) => Bun.file(join226(workdir, "package.json")).json().catch(() => null),
|
|
200208
200906
|
spawnSync: (cmd, opts) => {
|
|
200209
200907
|
const result = Bun.spawnSync(cmd, opts ? { cwd: opts.cwd, ...opts.env ? { env: opts.env } : {} } : {});
|
|
200210
200908
|
return { stdout: result.stdout, exitCode: result.exitCode };
|
|
@@ -200227,13 +200925,13 @@ var init_plan_runtime = __esm(() => {
|
|
|
200227
200925
|
|
|
200228
200926
|
// src/plan/spec-lint-gate.ts
|
|
200229
200927
|
import { existsSync as existsSync36 } from "fs";
|
|
200230
|
-
import { join as
|
|
200928
|
+
import { join as join227 } from "path";
|
|
200231
200929
|
function assertSpecLintClean(specContent, options) {
|
|
200232
200930
|
if (options.skip === true)
|
|
200233
200931
|
return [];
|
|
200234
200932
|
const findings = lintSpecContent(specContent, {
|
|
200235
200933
|
maxAcCount: options.maxAcCount,
|
|
200236
|
-
fileExists: (path) => existsSync36(
|
|
200934
|
+
fileExists: (path) => existsSync36(join227(options.workdir, path))
|
|
200237
200935
|
});
|
|
200238
200936
|
const blocking = findings.filter((finding) => BLOCKING_SPEC_LINT_CODES.has(finding.code));
|
|
200239
200937
|
if (blocking.length > 0) {
|
|
@@ -200256,9 +200954,9 @@ var init_spec_lint_gate = __esm(() => {
|
|
|
200256
200954
|
});
|
|
200257
200955
|
|
|
200258
200956
|
// src/plan/strategies/context-builder.ts
|
|
200259
|
-
import { join as
|
|
200957
|
+
import { join as join228 } from "path";
|
|
200260
200958
|
async function buildPlanModeContext(workdir, fullConfig, options, deps) {
|
|
200261
|
-
const naxDir =
|
|
200959
|
+
const naxDir = join228(workdir, ".nax");
|
|
200262
200960
|
if (!deps.existsSync(naxDir)) {
|
|
200263
200961
|
throw new NaxError(`.nax directory not found. Run 'nax init' first in ${workdir}`, "PLAN_CONTEXT_NO_NAX_DIR", {
|
|
200264
200962
|
stage: "plan",
|
|
@@ -200266,8 +200964,8 @@ async function buildPlanModeContext(workdir, fullConfig, options, deps) {
|
|
|
200266
200964
|
});
|
|
200267
200965
|
}
|
|
200268
200966
|
validateFeatureName(options.feature);
|
|
200269
|
-
const outputDir =
|
|
200270
|
-
const outputPath =
|
|
200967
|
+
const outputDir = join228(naxDir, "features", options.feature);
|
|
200968
|
+
const outputPath = join228(outputDir, "prd.json");
|
|
200271
200969
|
const [specContent, sourceRoots, pkg] = await Promise.all([
|
|
200272
200970
|
deps.readFile(options.from),
|
|
200273
200971
|
deps.scanSourceRoots(workdir),
|
|
@@ -200296,7 +200994,7 @@ async function buildPlanModeContext(workdir, fullConfig, options, deps) {
|
|
|
200296
200994
|
...new Set(sourceRoots.map((root) => root.path).filter((path) => path !== ".").map((path) => path.startsWith("/") ? path.replace(`${workdir}/`, "") : path))
|
|
200297
200995
|
];
|
|
200298
200996
|
const packageDetails = relativePackages.length === 0 ? [] : await Promise.all(relativePackages.map(async (relativePath) => {
|
|
200299
|
-
const packageJson = await deps.readPackageJsonAt(
|
|
200997
|
+
const packageJson = await deps.readPackageJsonAt(join228(workdir, relativePath, "package.json"));
|
|
200300
200998
|
return buildPackageSummary(relativePath, packageJson);
|
|
200301
200999
|
}));
|
|
200302
201000
|
const projectName = detectProjectName(workdir, pkg);
|
|
@@ -200386,12 +201084,12 @@ var init_finalize_routing = __esm(() => {
|
|
|
200386
201084
|
|
|
200387
201085
|
// src/plan/strategies/persist-prd.ts
|
|
200388
201086
|
import { existsSync as defaultExistsSync, renameSync as defaultRenameSync } from "fs";
|
|
200389
|
-
import { dirname as dirname60, join as
|
|
201087
|
+
import { dirname as dirname60, join as join229 } from "path";
|
|
200390
201088
|
function unverifiedStampedStoryIds(prd) {
|
|
200391
201089
|
return prd.userStories.filter((story) => story.workdirSource !== undefined && (story.contextFiles?.length ?? 0) + (story.expectedFiles?.length ?? 0) + (story.modifiedFiles?.length ?? 0) > 0).map((story) => story.id);
|
|
200392
201090
|
}
|
|
200393
201091
|
function moveDraftAside(outputPath) {
|
|
200394
|
-
const rejectedPath =
|
|
201092
|
+
const rejectedPath = join229(dirname60(outputPath), "prd.rejected.json");
|
|
200395
201093
|
if (!_persistPrdDeps.existsSync(outputPath)) {
|
|
200396
201094
|
return { phrase: `no draft was on disk at ${outputPath}` };
|
|
200397
201095
|
}
|
|
@@ -200476,7 +201174,7 @@ async function finalizeAndWritePrd(args) {
|
|
|
200476
201174
|
respelled: result.respelled
|
|
200477
201175
|
});
|
|
200478
201176
|
}
|
|
200479
|
-
if (result.defaulted.length > 0 && _persistPrdDeps.existsSync(
|
|
201177
|
+
if (result.defaulted.length > 0 && _persistPrdDeps.existsSync(join229(args.repoRoot, ".nax", "mono"))) {
|
|
200480
201178
|
getLogger2().warn("plan", "stories have no resolved workdir in a monorepo: they will receive the WHOLE rule corpus and the ROOT quality.commands, not their package's", { storyIds: result.defaulted });
|
|
200481
201179
|
}
|
|
200482
201180
|
} catch (err) {
|
|
@@ -200887,12 +201585,12 @@ var init_prompts_export = __esm(() => {
|
|
|
200887
201585
|
|
|
200888
201586
|
// src/cli/prompts-init.ts
|
|
200889
201587
|
import { existsSync as existsSync37, mkdirSync as mkdirSync16 } from "fs";
|
|
200890
|
-
import { join as
|
|
201588
|
+
import { join as join231 } from "path";
|
|
200891
201589
|
async function promptsInitCommand(options) {
|
|
200892
201590
|
const { workdir, force = false, autoWireConfig = true } = options;
|
|
200893
|
-
const templatesDir =
|
|
201591
|
+
const templatesDir = join231(workdir, ".nax", "templates");
|
|
200894
201592
|
mkdirSync16(templatesDir, { recursive: true });
|
|
200895
|
-
const existingFiles = TEMPLATE_ROLES.map((t) => t.file).filter((f) => existsSync37(
|
|
201593
|
+
const existingFiles = TEMPLATE_ROLES.map((t) => t.file).filter((f) => existsSync37(join231(templatesDir, f)));
|
|
200896
201594
|
if (existingFiles.length > 0 && !force) {
|
|
200897
201595
|
_promptsInitDeps.warn(`[WARN] .nax/templates/ already contains files: ${existingFiles.join(", ")}. No files overwritten.
|
|
200898
201596
|
Pass --force to overwrite existing templates.`);
|
|
@@ -200900,7 +201598,7 @@ async function promptsInitCommand(options) {
|
|
|
200900
201598
|
}
|
|
200901
201599
|
const written = [];
|
|
200902
201600
|
for (const template of TEMPLATE_ROLES) {
|
|
200903
|
-
const filePath =
|
|
201601
|
+
const filePath = join231(templatesDir, template.file);
|
|
200904
201602
|
const roleBody = unwrapProtocolRegions(template.role === "implementer" ? buildRoleTaskSection(template.role, template.variant) : buildRoleTaskSection(template.role));
|
|
200905
201603
|
const content = TEMPLATE_HEADER + roleBody;
|
|
200906
201604
|
await Bun.write(filePath, content);
|
|
@@ -200916,7 +201614,7 @@ async function promptsInitCommand(options) {
|
|
|
200916
201614
|
return written;
|
|
200917
201615
|
}
|
|
200918
201616
|
async function autoWirePromptsConfig(workdir) {
|
|
200919
|
-
const configPath =
|
|
201617
|
+
const configPath = join231(projectConfigDir(workdir), "config.json");
|
|
200920
201618
|
if (!existsSync37(configPath)) {
|
|
200921
201619
|
const exampleConfig = JSON.stringify({
|
|
200922
201620
|
prompts: {
|
|
@@ -201046,7 +201744,7 @@ function buildFrontmatter(story, ctx, role) {
|
|
|
201046
201744
|
}
|
|
201047
201745
|
|
|
201048
201746
|
// src/cli/prompts-tdd.ts
|
|
201049
|
-
import { join as
|
|
201747
|
+
import { join as join232 } from "path";
|
|
201050
201748
|
async function handleThreeSessionTddPrompts(story, ctx, outputDir, logger) {
|
|
201051
201749
|
const scopedTestCommand = commandSpecIncludes(ctx.config.quality?.commands?.testScoped, "{{files}}") ? "testScoped" : undefined;
|
|
201052
201750
|
const [testWriterPrompt, implementerPrompt, verifierPrompt] = await Promise.all([
|
|
@@ -201066,7 +201764,7 @@ ${frontmatter}---
|
|
|
201066
201764
|
|
|
201067
201765
|
${session.prompt}`;
|
|
201068
201766
|
if (outputDir) {
|
|
201069
|
-
const promptFile =
|
|
201767
|
+
const promptFile = join232(outputDir, `${story.id}.${session.role}.md`);
|
|
201070
201768
|
await Bun.write(promptFile, fullOutput);
|
|
201071
201769
|
logger.info("cli", "Written TDD prompt file", {
|
|
201072
201770
|
storyId: story.id,
|
|
@@ -201082,7 +201780,7 @@ ${"=".repeat(80)}`);
|
|
|
201082
201780
|
}
|
|
201083
201781
|
}
|
|
201084
201782
|
if (outputDir && ctx.contextMarkdown) {
|
|
201085
|
-
const contextFile =
|
|
201783
|
+
const contextFile = join232(outputDir, `${story.id}.context.md`);
|
|
201086
201784
|
const frontmatter = buildFrontmatter(story, ctx);
|
|
201087
201785
|
const contextOutput = `---
|
|
201088
201786
|
${frontmatter}---
|
|
@@ -201098,19 +201796,19 @@ var init_prompts_tdd = __esm(() => {
|
|
|
201098
201796
|
|
|
201099
201797
|
// src/cli/prompts-main.ts
|
|
201100
201798
|
import { existsSync as existsSync38, mkdirSync as mkdirSync17 } from "fs";
|
|
201101
|
-
import { join as
|
|
201799
|
+
import { join as join233 } from "path";
|
|
201102
201800
|
async function promptsCommand(options) {
|
|
201103
201801
|
const logger = getLogger2();
|
|
201104
201802
|
const { feature, workdir, config, storyId, outputDir } = options;
|
|
201105
|
-
const naxDir =
|
|
201803
|
+
const naxDir = join233(workdir, ".nax");
|
|
201106
201804
|
if (!existsSync38(naxDir)) {
|
|
201107
201805
|
throw new NaxError(`.nax directory not found. Run 'nax init' first in ${workdir}`, "NAX_DIR_NOT_FOUND", {
|
|
201108
201806
|
stage: "cli",
|
|
201109
201807
|
workdir
|
|
201110
201808
|
});
|
|
201111
201809
|
}
|
|
201112
|
-
const featureDir =
|
|
201113
|
-
const prdPath =
|
|
201810
|
+
const featureDir = join233(naxDir, "features", feature);
|
|
201811
|
+
const prdPath = join233(featureDir, "prd.json");
|
|
201114
201812
|
if (!existsSync38(prdPath)) {
|
|
201115
201813
|
throw new NaxError(`Feature "${feature}" not found or missing prd.json`, "FEATURE_PRD_NOT_FOUND", {
|
|
201116
201814
|
stage: "cli",
|
|
@@ -201181,10 +201879,10 @@ ${frontmatter}---
|
|
|
201181
201879
|
|
|
201182
201880
|
${ctx.prompt}`;
|
|
201183
201881
|
if (outputDir) {
|
|
201184
|
-
const promptFile =
|
|
201882
|
+
const promptFile = join233(outputDir, `${story.id}.prompt.md`);
|
|
201185
201883
|
await Bun.write(promptFile, fullOutput);
|
|
201186
201884
|
if (ctx.contextMarkdown) {
|
|
201187
|
-
const contextFile =
|
|
201885
|
+
const contextFile = join233(outputDir, `${story.id}.context.md`);
|
|
201188
201886
|
const contextOutput = `---
|
|
201189
201887
|
${frontmatter}---
|
|
201190
201888
|
|
|
@@ -201234,7 +201932,7 @@ var init_prompts2 = __esm(() => {
|
|
|
201234
201932
|
|
|
201235
201933
|
// src/cli/routing-calibrate.ts
|
|
201236
201934
|
import { mkdirSync as mkdirSync18 } from "fs";
|
|
201237
|
-
import { basename as basename44, join as
|
|
201935
|
+
import { basename as basename44, join as join234 } from "path";
|
|
201238
201936
|
function resolveProjectConfigDir(workdir) {
|
|
201239
201937
|
return findProjectDir(workdir) ?? projectInputDir(workdir);
|
|
201240
201938
|
}
|
|
@@ -201366,7 +202064,7 @@ var init_routing_calibrate = __esm(() => {
|
|
|
201366
202064
|
loadRunMetrics: (outputDir) => loadRunMetrics(outputDir),
|
|
201367
202065
|
readConfig: (workdir) => loadConfig(workdir),
|
|
201368
202066
|
readProjectConfig: async (workdir) => {
|
|
201369
|
-
const filePath =
|
|
202067
|
+
const filePath = join234(resolveProjectConfigDir(workdir), "config.json");
|
|
201370
202068
|
const configFile = Bun.file(filePath);
|
|
201371
202069
|
if (!await configFile.exists())
|
|
201372
202070
|
return {};
|
|
@@ -201375,7 +202073,7 @@ var init_routing_calibrate = __esm(() => {
|
|
|
201375
202073
|
writeConfig: async (workdir, config) => {
|
|
201376
202074
|
const dir = resolveProjectConfigDir(workdir);
|
|
201377
202075
|
mkdirSync18(dir, { recursive: true });
|
|
201378
|
-
const filePath =
|
|
202076
|
+
const filePath = join234(dir, "config.json");
|
|
201379
202077
|
await saveJsonFile(filePath, config, "routing-calibrate");
|
|
201380
202078
|
},
|
|
201381
202079
|
stdout: (msg) => {
|
|
@@ -201390,8 +202088,8 @@ var init_routing_calibrate = __esm(() => {
|
|
|
201390
202088
|
});
|
|
201391
202089
|
|
|
201392
202090
|
// src/cli/rules-lint.ts
|
|
201393
|
-
import { statSync as
|
|
201394
|
-
import { join as
|
|
202091
|
+
import { statSync as statSync17 } from "fs";
|
|
202092
|
+
import { join as join235 } from "path";
|
|
201395
202093
|
function classifyPattern(normalizedPattern) {
|
|
201396
202094
|
const segments = normalizedPattern.split("/");
|
|
201397
202095
|
const literal = [];
|
|
@@ -201410,7 +202108,7 @@ function matchLiteralPath(literalPath, cwd) {
|
|
|
201410
202108
|
if (!isRelativeAndSafe(literalPath))
|
|
201411
202109
|
return "no-match";
|
|
201412
202110
|
try {
|
|
201413
|
-
return
|
|
202111
|
+
return statSync17(join235(cwd, literalPath)).isFile() ? "match" : "no-match";
|
|
201414
202112
|
} catch {
|
|
201415
202113
|
return "no-match";
|
|
201416
202114
|
}
|
|
@@ -201450,7 +202148,7 @@ function collectCanonicalRuleRoots(workdir, globCanonicalRuleFiles = _rulesLintD
|
|
|
201450
202148
|
const packageRel = normalized.slice(0, idx);
|
|
201451
202149
|
if (!packageRel)
|
|
201452
202150
|
continue;
|
|
201453
|
-
roots.add(
|
|
202151
|
+
roots.add(join235(workdir, packageRel));
|
|
201454
202152
|
}
|
|
201455
202153
|
return [...roots].sort();
|
|
201456
202154
|
}
|
|
@@ -201479,7 +202177,7 @@ function lintPackagePaths(rule, root, { packages, logger }) {
|
|
|
201479
202177
|
return 0;
|
|
201480
202178
|
let warningCount = 0;
|
|
201481
202179
|
for (const pattern of rule.paths ?? []) {
|
|
201482
|
-
if (packages.some((pkg) => ruleMatchesPackage([pattern], root,
|
|
202180
|
+
if (packages.some((pkg) => ruleMatchesPackage([pattern], root, join235(root, pkg), pkg)))
|
|
201483
202181
|
continue;
|
|
201484
202182
|
warningCount++;
|
|
201485
202183
|
logger.warn("rules-lint", "Canonical rule paths: glob matches no workspace package directory - paths: scopes packages; use appliesTo: for file globs", { file: rule.path ?? rule.fileName, pattern, code: "PATHS_MATCH_NO_PACKAGE", root });
|
|
@@ -201520,7 +202218,7 @@ function lintRulesForRoot(rules, root, isSinglePackageRepo, packages, deps, logg
|
|
|
201520
202218
|
if (isSinglePackageRepo && rule.paths && rule.paths.length > 0) {
|
|
201521
202219
|
warningCount++;
|
|
201522
202220
|
logger.warn("rules-lint", "Canonical rule declares paths: but the repository has no workspace packages \u2014 paths: is inert in single-package repos. Use appliesTo: for file globs.", {
|
|
201523
|
-
file:
|
|
202221
|
+
file: join235(root, CANONICAL_RULES_DIR, rule.path ?? rule.fileName),
|
|
201524
202222
|
code: "INERT_PATHS",
|
|
201525
202223
|
paths: rule.paths,
|
|
201526
202224
|
root,
|
|
@@ -201619,7 +202317,7 @@ var init_rules_lint = __esm(() => {
|
|
|
201619
202317
|
return matchLiteralPath(shape.path, cwd);
|
|
201620
202318
|
const regex = globToRegex3(normalizedPattern);
|
|
201621
202319
|
if (shape.kind === "prefixed")
|
|
201622
|
-
return scanTreeForMatch(
|
|
202320
|
+
return scanTreeForMatch(join235(cwd, shape.prefix), shape.prefix, regex);
|
|
201623
202321
|
return scanTreeForMatch(cwd, "", regex);
|
|
201624
202322
|
} catch {
|
|
201625
202323
|
return "no-match";
|
|
@@ -201633,7 +202331,7 @@ var init_rules_lint = __esm(() => {
|
|
|
201633
202331
|
|
|
201634
202332
|
// src/cli/rules-cli-deps.ts
|
|
201635
202333
|
import { mkdir as mkdir58 } from "fs/promises";
|
|
201636
|
-
import { join as
|
|
202334
|
+
import { join as join236 } from "path";
|
|
201637
202335
|
var _rulesCLIDeps;
|
|
201638
202336
|
var init_rules_cli_deps = __esm(() => {
|
|
201639
202337
|
init_canonical_loader();
|
|
@@ -201647,7 +202345,7 @@ var init_rules_cli_deps = __esm(() => {
|
|
|
201647
202345
|
fileExists: async (path) => Bun.file(path).exists(),
|
|
201648
202346
|
globInDir: (dir) => {
|
|
201649
202347
|
try {
|
|
201650
|
-
return [...new Bun.Glob("*.md").scanSync({ cwd: dir })].sort().map((f) =>
|
|
202348
|
+
return [...new Bun.Glob("*.md").scanSync({ cwd: dir })].sort().map((f) => join236(dir, f));
|
|
201651
202349
|
} catch {
|
|
201652
202350
|
return [];
|
|
201653
202351
|
}
|
|
@@ -201664,14 +202362,14 @@ var init_rules_cli_deps = __esm(() => {
|
|
|
201664
202362
|
});
|
|
201665
202363
|
|
|
201666
202364
|
// src/cli/rules-migrate-plan.ts
|
|
201667
|
-
import { resolve as
|
|
202365
|
+
import { resolve as resolve59, sep as sep30 } from "path";
|
|
201668
202366
|
async function planMigration(sources, options) {
|
|
201669
202367
|
const writes = [];
|
|
201670
202368
|
const skips = [];
|
|
201671
|
-
const resolvedTargetDir =
|
|
202369
|
+
const resolvedTargetDir = resolve59(options.targetDir);
|
|
201672
202370
|
for (const source of sources) {
|
|
201673
|
-
const resolvedTargetPath =
|
|
201674
|
-
if (!resolvedTargetPath.startsWith(`${resolvedTargetDir}${
|
|
202371
|
+
const resolvedTargetPath = resolve59(source.targetPath);
|
|
202372
|
+
if (!resolvedTargetPath.startsWith(`${resolvedTargetDir}${sep30}`) && resolvedTargetPath !== resolvedTargetDir) {
|
|
201675
202373
|
throw new NaxError(`Migration target escapes ${options.targetDir}: ${source.targetFileName} -> ${source.targetPath}`, "RULES_MIGRATE_TARGET_ESCAPE", { stage: "rules-migrate-plan", targetDir: options.targetDir, entry: source.targetPath });
|
|
201676
202374
|
}
|
|
201677
202375
|
const exists = await options.fileExists(source.targetPath);
|
|
@@ -201688,7 +202386,7 @@ var init_rules_migrate_plan = __esm(() => {
|
|
|
201688
202386
|
});
|
|
201689
202387
|
|
|
201690
202388
|
// src/cli/rules-migrate.ts
|
|
201691
|
-
import { basename as basename45, join as
|
|
202389
|
+
import { basename as basename45, join as join237 } from "path";
|
|
201692
202390
|
function neutralizeContent(content) {
|
|
201693
202391
|
let result = content;
|
|
201694
202392
|
let replacements = 0;
|
|
@@ -201737,7 +202435,7 @@ function withReviewNotice(content, replacements) {
|
|
|
201737
202435
|
}
|
|
201738
202436
|
async function collectMigrationSources(workdir) {
|
|
201739
202437
|
const sources = [];
|
|
201740
|
-
const rulesDir =
|
|
202438
|
+
const rulesDir = join237(workdir, ".claude", "rules");
|
|
201741
202439
|
const ruleFiles = _rulesCLIDeps.globInDir(rulesDir);
|
|
201742
202440
|
for (const filePath of ruleFiles) {
|
|
201743
202441
|
try {
|
|
@@ -201759,11 +202457,11 @@ async function rulesMigrateCommand(options) {
|
|
|
201759
202457
|
console.log("[WARN] Root CLAUDE.md is not a migration source. Move the rules you want migrated into .claude/rules/, or author .nax/rules/ directly.");
|
|
201760
202458
|
return { written: [], skipped: [] };
|
|
201761
202459
|
}
|
|
201762
|
-
const targetDir =
|
|
202460
|
+
const targetDir = join237(workdir, CANONICAL_RULES_DIR);
|
|
201763
202461
|
const planEntries = sources.map((source) => ({
|
|
201764
202462
|
sourcePath: source.sourcePath,
|
|
201765
202463
|
targetFileName: source.targetFileName,
|
|
201766
|
-
targetPath:
|
|
202464
|
+
targetPath: join237(targetDir, source.targetFileName),
|
|
201767
202465
|
content: source.content
|
|
201768
202466
|
}));
|
|
201769
202467
|
const plan = await planMigration(planEntries, {
|
|
@@ -201813,7 +202511,7 @@ var init_rules_migrate = __esm(() => {
|
|
|
201813
202511
|
});
|
|
201814
202512
|
|
|
201815
202513
|
// src/cli/rules.ts
|
|
201816
|
-
import { join as
|
|
202514
|
+
import { join as join238, resolve as resolve60, sep as sep31 } from "path";
|
|
201817
202515
|
async function rulesLintCommand2(options) {
|
|
201818
202516
|
return rulesLintCommand(options, {
|
|
201819
202517
|
globCanonicalRuleFiles: _rulesCLIDeps.globCanonicalRuleFiles,
|
|
@@ -201864,8 +202562,8 @@ async function exportRuleDirectory(input) {
|
|
|
201864
202562
|
const drifted = [];
|
|
201865
202563
|
for (const rule of rules) {
|
|
201866
202564
|
const rel = rule.path ?? rule.fileName;
|
|
201867
|
-
const target =
|
|
201868
|
-
if (!target.startsWith(`${
|
|
202565
|
+
const target = resolve60(workdir, ruleDir, rel);
|
|
202566
|
+
if (!target.startsWith(`${resolve60(workdir, ruleDir)}${sep31}`)) {
|
|
201869
202567
|
throw new NaxError(`Rule path escapes ${ruleDir}: ${rel}`, "RULES_EXPORT_PATH_ESCAPE", {
|
|
201870
202568
|
stage: "rules-export",
|
|
201871
202569
|
rule: rel
|
|
@@ -201885,9 +202583,9 @@ async function exportRuleDirectory(input) {
|
|
|
201885
202583
|
}
|
|
201886
202584
|
await _rulesCLIDeps.writeFile(target, content);
|
|
201887
202585
|
}
|
|
201888
|
-
const expected = new Set(rules.map((r) =>
|
|
201889
|
-
for (const existing of _rulesCLIDeps.globInDir(
|
|
201890
|
-
if (!expected.has(
|
|
202586
|
+
const expected = new Set(rules.map((r) => resolve60(workdir, ruleDir, r.path ?? r.fileName)));
|
|
202587
|
+
for (const existing of _rulesCLIDeps.globInDir(join238(workdir, ruleDir))) {
|
|
202588
|
+
if (!expected.has(resolve60(existing))) {
|
|
201891
202589
|
_rulesCLIDeps.getLogger().warn("rules-export", "Generated rules dir contains a file with no canonical source", {
|
|
201892
202590
|
file: existing,
|
|
201893
202591
|
hint: `Delete it, or add the rule to ${CANONICAL_RULES_DIR}/`
|
|
@@ -201942,7 +202640,7 @@ ${r.content}`).join(`
|
|
|
201942
202640
|
`);
|
|
201943
202641
|
const shimContent = `${header + body}
|
|
201944
202642
|
`;
|
|
201945
|
-
const shimPath =
|
|
202643
|
+
const shimPath = join238(workdir, shimFileName);
|
|
201946
202644
|
if (options.dryRun) {
|
|
201947
202645
|
console.log(`[dry-run] Would write ${shimPath} (${shimContent.length} bytes)`);
|
|
201948
202646
|
return;
|
|
@@ -201972,7 +202670,7 @@ var init_rules = __esm(() => {
|
|
|
201972
202670
|
|
|
201973
202671
|
// src/cli/runs.ts
|
|
201974
202672
|
import { existsSync as existsSync39, readdirSync as readdirSync10 } from "fs";
|
|
201975
|
-
import { basename as basename46, join as
|
|
202673
|
+
import { basename as basename46, join as join239 } from "path";
|
|
201976
202674
|
async function resolveOutputDir2(workdir, override) {
|
|
201977
202675
|
if (override)
|
|
201978
202676
|
return override;
|
|
@@ -202016,7 +202714,7 @@ async function runsListCommand(options) {
|
|
|
202016
202714
|
const logger = getLogger2();
|
|
202017
202715
|
const { feature, workdir } = options;
|
|
202018
202716
|
const outputDir = await resolveOutputDir2(workdir, options.outputDir);
|
|
202019
|
-
const runsDir =
|
|
202717
|
+
const runsDir = join239(outputDir, "features", feature, "runs");
|
|
202020
202718
|
if (!existsSync39(runsDir)) {
|
|
202021
202719
|
logger.info("cli", "No runs found for feature", { feature, hint: `Directory not found: ${runsDir}` });
|
|
202022
202720
|
return;
|
|
@@ -202028,7 +202726,7 @@ async function runsListCommand(options) {
|
|
|
202028
202726
|
}
|
|
202029
202727
|
logger.info("cli", `Runs for ${feature}`, { count: files.length });
|
|
202030
202728
|
for (const file of files.sort().reverse()) {
|
|
202031
|
-
const logPath =
|
|
202729
|
+
const logPath = join239(runsDir, file);
|
|
202032
202730
|
const entries = await parseRunLog(logPath);
|
|
202033
202731
|
const startEvent = findRunStart(entries);
|
|
202034
202732
|
const completeEvent = findRunSummary(entries);
|
|
@@ -202055,7 +202753,7 @@ async function runsShowCommand(options) {
|
|
|
202055
202753
|
const logger = getLogger2();
|
|
202056
202754
|
const { runId, feature, workdir } = options;
|
|
202057
202755
|
const outputDir = await resolveOutputDir2(workdir, options.outputDir);
|
|
202058
|
-
const logPath =
|
|
202756
|
+
const logPath = join239(outputDir, "features", feature, "runs", `${runId}.jsonl`);
|
|
202059
202757
|
if (!existsSync39(logPath)) {
|
|
202060
202758
|
logger.error("cli", "Run not found", { runId, feature, logPath });
|
|
202061
202759
|
throw new NaxError("Run not found", "RUN_NOT_FOUND", { runId, feature, logPath });
|
|
@@ -202226,36 +202924,36 @@ var init_sandbox_probe = __esm(() => {
|
|
|
202226
202924
|
});
|
|
202227
202925
|
|
|
202228
202926
|
// src/cli/setup-analyze.ts
|
|
202229
|
-
import { join as
|
|
202927
|
+
import { join as join240 } from "path";
|
|
202230
202928
|
async function detectPackageManager(workdir) {
|
|
202231
202929
|
const { fileExists } = _analyzeRepoDeps;
|
|
202232
|
-
if (await fileExists(
|
|
202930
|
+
if (await fileExists(join240(workdir, "bun.lock")))
|
|
202233
202931
|
return { pmRunPrefix: "bun run", pmDlx: "bunx" };
|
|
202234
|
-
if (await fileExists(
|
|
202932
|
+
if (await fileExists(join240(workdir, "bun.lockb")))
|
|
202235
202933
|
return { pmRunPrefix: "bun run", pmDlx: "bunx" };
|
|
202236
|
-
if (await fileExists(
|
|
202934
|
+
if (await fileExists(join240(workdir, "package-lock.json")))
|
|
202237
202935
|
return { pmRunPrefix: "npm run", pmDlx: "npx" };
|
|
202238
|
-
if (await fileExists(
|
|
202936
|
+
if (await fileExists(join240(workdir, "yarn.lock")))
|
|
202239
202937
|
return { pmRunPrefix: "yarn", pmDlx: "yarn dlx" };
|
|
202240
|
-
if (await fileExists(
|
|
202938
|
+
if (await fileExists(join240(workdir, "pnpm-lock.yaml")))
|
|
202241
202939
|
return { pmRunPrefix: "pnpm run", pmDlx: "pnpx" };
|
|
202242
202940
|
return { pmRunPrefix: "npm run", pmDlx: "npx" };
|
|
202243
202941
|
}
|
|
202244
202942
|
async function detectOrchestrator(workdir) {
|
|
202245
202943
|
const { fileExists } = _analyzeRepoDeps;
|
|
202246
|
-
if (await fileExists(
|
|
202944
|
+
if (await fileExists(join240(workdir, "turbo.json")))
|
|
202247
202945
|
return "turbo";
|
|
202248
|
-
if (await fileExists(
|
|
202946
|
+
if (await fileExists(join240(workdir, "nx.json")))
|
|
202249
202947
|
return "nx";
|
|
202250
202948
|
return "none";
|
|
202251
202949
|
}
|
|
202252
202950
|
async function getMissingScripts(packageDir) {
|
|
202253
|
-
const pkg = await _analyzeRepoDeps.readJson(
|
|
202951
|
+
const pkg = await _analyzeRepoDeps.readJson(join240(packageDir, "package.json"));
|
|
202254
202952
|
const scripts = pkg?.scripts ?? {};
|
|
202255
202953
|
return CANONICAL_SCRIPTS.filter((s) => !(s in scripts));
|
|
202256
202954
|
}
|
|
202257
202955
|
async function buildPackageFacts(workdir, relativeDir, testPatternMap) {
|
|
202258
|
-
const packageDir = relativeDir === "" ? workdir :
|
|
202956
|
+
const packageDir = relativeDir === "" ? workdir : join240(workdir, relativeDir);
|
|
202259
202957
|
const [profile, missingScripts] = await Promise.all([
|
|
202260
202958
|
_analyzeRepoDeps.detectProjectProfile(packageDir, {}),
|
|
202261
202959
|
getMissingScripts(packageDir)
|
|
@@ -202316,7 +203014,7 @@ var init_setup_analyze = __esm(() => {
|
|
|
202316
203014
|
});
|
|
202317
203015
|
|
|
202318
203016
|
// src/cli/setup-fill.ts
|
|
202319
|
-
import { join as
|
|
203017
|
+
import { join as join241 } from "path";
|
|
202320
203018
|
async function addScriptToPackageJson(pkgJsonPath, key, value) {
|
|
202321
203019
|
const pkg = await _fillScriptsDeps.readJson(pkgJsonPath) ?? {};
|
|
202322
203020
|
const scripts = pkg.scripts ?? {};
|
|
@@ -202339,18 +203037,18 @@ async function fillScripts(workdir, analysis) {
|
|
|
202339
203037
|
if (shape === "single") {
|
|
202340
203038
|
const rootPkg = packages[0];
|
|
202341
203039
|
if (rootPkg?.missingScripts.includes(TYPE_CHECK_KEY)) {
|
|
202342
|
-
await addScriptToPackageJson(
|
|
203040
|
+
await addScriptToPackageJson(join241(workdir, "package.json"), TYPE_CHECK_KEY, TYPE_CHECK_SCRIPT);
|
|
202343
203041
|
}
|
|
202344
203042
|
return;
|
|
202345
203043
|
}
|
|
202346
203044
|
for (const pkg of packages) {
|
|
202347
203045
|
if (!pkg.missingScripts.includes(TYPE_CHECK_KEY))
|
|
202348
203046
|
continue;
|
|
202349
|
-
await addScriptToPackageJson(
|
|
203047
|
+
await addScriptToPackageJson(join241(workdir, pkg.relativeDir, "package.json"), TYPE_CHECK_KEY, TYPE_CHECK_SCRIPT);
|
|
202350
203048
|
}
|
|
202351
203049
|
if (orchestrator === "turbo" && packages.some((p) => p.missingScripts.includes(TYPE_CHECK_KEY))) {
|
|
202352
|
-
await addTurboTask(
|
|
202353
|
-
await addScriptToPackageJson(
|
|
203050
|
+
await addTurboTask(join241(workdir, "turbo.json"), TYPE_CHECK_KEY);
|
|
203051
|
+
await addScriptToPackageJson(join241(workdir, "package.json"), TYPE_CHECK_KEY, TYPE_CHECK_TURBO_PASSTHROUGH);
|
|
202354
203052
|
}
|
|
202355
203053
|
}
|
|
202356
203054
|
var TYPE_CHECK_KEY = "type-check", TYPE_CHECK_SCRIPT = "tsc --noEmit -p tsconfig.json", TYPE_CHECK_TURBO_PASSTHROUGH = "turbo run type-check", _fillScriptsDeps;
|
|
@@ -202405,17 +203103,17 @@ var init_setup_verify = __esm(() => {
|
|
|
202405
203103
|
});
|
|
202406
203104
|
|
|
202407
203105
|
// src/cli/setup-write.ts
|
|
202408
|
-
import { join as
|
|
203106
|
+
import { join as join242 } from "path";
|
|
202409
203107
|
async function writeSetupConfig(workdir, config, monoConfigs, _opts, deps = _writeSetupDeps) {
|
|
202410
|
-
const naxDir =
|
|
202411
|
-
const naxConfigPath =
|
|
203108
|
+
const naxDir = join242(workdir, ".nax");
|
|
203109
|
+
const naxConfigPath = join242(naxDir, "config.json");
|
|
202412
203110
|
const written = [];
|
|
202413
203111
|
await deps.mkdir(naxDir);
|
|
202414
203112
|
await deps.writeFile(naxConfigPath, JSON.stringify(config, null, 2));
|
|
202415
203113
|
written.push(naxConfigPath);
|
|
202416
203114
|
for (const mc of monoConfigs) {
|
|
202417
|
-
const monoDir =
|
|
202418
|
-
const monoConfigPath =
|
|
203115
|
+
const monoDir = join242(naxDir, "mono", mc.relativeDir);
|
|
203116
|
+
const monoConfigPath = join242(monoDir, "config.json");
|
|
202419
203117
|
await deps.mkdir(monoDir);
|
|
202420
203118
|
await deps.writeFile(monoConfigPath, JSON.stringify(mc.config, null, 2));
|
|
202421
203119
|
written.push(monoConfigPath);
|
|
@@ -202434,11 +203132,11 @@ var init_setup_write = __esm(() => {
|
|
|
202434
203132
|
});
|
|
202435
203133
|
|
|
202436
203134
|
// src/cli/setup.ts
|
|
202437
|
-
import { join as
|
|
203135
|
+
import { join as join243 } from "path";
|
|
202438
203136
|
async function setupCommand(options = {}) {
|
|
202439
203137
|
const workdir = options.dir ?? process.cwd();
|
|
202440
|
-
const naxDir =
|
|
202441
|
-
const naxConfigPath =
|
|
203138
|
+
const naxDir = join243(workdir, ".nax");
|
|
203139
|
+
const naxConfigPath = join243(naxDir, "config.json");
|
|
202442
203140
|
const exists = await _setupDeps.fileExists(naxConfigPath);
|
|
202443
203141
|
if (exists && !options.force) {
|
|
202444
203142
|
_setupDeps.stderr("[setup] .nax/config.json already exists. Use --force to overwrite.");
|
|
@@ -202521,7 +203219,7 @@ var init_setup = __esm(() => {
|
|
|
202521
203219
|
|
|
202522
203220
|
// src/cli/spec-lint-command.ts
|
|
202523
203221
|
import { existsSync as existsSync40 } from "fs";
|
|
202524
|
-
import { join as
|
|
203222
|
+
import { join as join244 } from "path";
|
|
202525
203223
|
async function resolveSpecPaths(options, deps) {
|
|
202526
203224
|
const explicit = (options.paths ?? []).filter((path) => path.trim().length > 0);
|
|
202527
203225
|
if (explicit.length > 0)
|
|
@@ -202537,7 +203235,7 @@ async function resolveSpecPaths(options, deps) {
|
|
|
202537
203235
|
message: `${options.feature} resolved to ${resolved.specSource.path}; a prd.json has no spec sections to lint. Pass the markdown spec explicitly.`
|
|
202538
203236
|
};
|
|
202539
203237
|
}
|
|
202540
|
-
return [
|
|
203238
|
+
return [join244(options.dir, resolved.specSource.path)];
|
|
202541
203239
|
}
|
|
202542
203240
|
async function lintOne(specPath, options, deps) {
|
|
202543
203241
|
if (!deps.fileExists(specPath)) {
|
|
@@ -202551,7 +203249,7 @@ async function lintOne(specPath, options, deps) {
|
|
|
202551
203249
|
}
|
|
202552
203250
|
const findings = lintSpecContent(content, {
|
|
202553
203251
|
maxAcCount: options.maxAcCount,
|
|
202554
|
-
fileExists: (path) => deps.fileExists(
|
|
203252
|
+
fileExists: (path) => deps.fileExists(join244(options.dir, path))
|
|
202555
203253
|
});
|
|
202556
203254
|
return {
|
|
202557
203255
|
specPath,
|
|
@@ -202762,21 +203460,21 @@ var init_status_cost = __esm(() => {
|
|
|
202762
203460
|
});
|
|
202763
203461
|
|
|
202764
203462
|
// src/commands/common.ts
|
|
202765
|
-
import { existsSync as existsSync41, readdirSync as readdirSync11, realpathSync as
|
|
202766
|
-
import { join as
|
|
203463
|
+
import { existsSync as existsSync41, readdirSync as readdirSync11, realpathSync as realpathSync8 } from "fs";
|
|
203464
|
+
import { join as join245, resolve as resolve61 } from "path";
|
|
202767
203465
|
function resolveProject2(options = {}) {
|
|
202768
203466
|
const { dir, feature } = options;
|
|
202769
203467
|
let projectRoot;
|
|
202770
203468
|
let naxDir;
|
|
202771
203469
|
let configPath;
|
|
202772
203470
|
if (dir) {
|
|
202773
|
-
projectRoot =
|
|
202774
|
-
naxDir =
|
|
203471
|
+
projectRoot = realpathSync8(resolve61(dir));
|
|
203472
|
+
naxDir = join245(projectRoot, ".nax");
|
|
202775
203473
|
if (!existsSync41(naxDir)) {
|
|
202776
203474
|
throw new NaxError(`Directory does not contain a nax project: ${projectRoot}
|
|
202777
203475
|
Expected to find: ${naxDir}`, "NAX_DIR_NOT_FOUND", { projectRoot, naxDir });
|
|
202778
203476
|
}
|
|
202779
|
-
configPath =
|
|
203477
|
+
configPath = join245(naxDir, "config.json");
|
|
202780
203478
|
if (!existsSync41(configPath)) {
|
|
202781
203479
|
throw new NaxError(`.nax directory found but config.json is missing: ${naxDir}
|
|
202782
203480
|
Expected to find: ${configPath}`, "CONFIG_NOT_FOUND", { naxDir, configPath });
|
|
@@ -202784,17 +203482,17 @@ Expected to find: ${configPath}`, "CONFIG_NOT_FOUND", { naxDir, configPath });
|
|
|
202784
203482
|
} else {
|
|
202785
203483
|
const found = findProjectRoot(process.cwd());
|
|
202786
203484
|
if (!found) {
|
|
202787
|
-
const cwdNaxDir =
|
|
203485
|
+
const cwdNaxDir = join245(process.cwd(), ".nax");
|
|
202788
203486
|
if (existsSync41(cwdNaxDir)) {
|
|
202789
|
-
const cwdConfigPath =
|
|
203487
|
+
const cwdConfigPath = join245(cwdNaxDir, "config.json");
|
|
202790
203488
|
throw new NaxError(`.nax directory found but config.json is missing: ${cwdNaxDir}
|
|
202791
203489
|
Expected to find: ${cwdConfigPath}`, "CONFIG_NOT_FOUND", { naxDir: cwdNaxDir, configPath: cwdConfigPath });
|
|
202792
203490
|
}
|
|
202793
203491
|
throw new NaxError("No nax project found. Run this command from within a nax project directory, or use -d flag to specify the project path.", "PROJECT_NOT_FOUND", { cwd: process.cwd() });
|
|
202794
203492
|
}
|
|
202795
203493
|
projectRoot = found;
|
|
202796
|
-
naxDir =
|
|
202797
|
-
configPath =
|
|
203494
|
+
naxDir = join245(projectRoot, ".nax");
|
|
203495
|
+
configPath = join245(naxDir, "config.json");
|
|
202798
203496
|
}
|
|
202799
203497
|
let featureDir;
|
|
202800
203498
|
if (feature) {
|
|
@@ -202803,8 +203501,8 @@ Expected to find: ${cwdConfigPath}`, "CONFIG_NOT_FOUND", { naxDir: cwdNaxDir, co
|
|
|
202803
203501
|
} catch (error) {
|
|
202804
203502
|
throw new NaxError(error.message, "FEATURE_INVALID", { feature });
|
|
202805
203503
|
}
|
|
202806
|
-
const featuresDir =
|
|
202807
|
-
featureDir =
|
|
203504
|
+
const featuresDir = join245(naxDir, "features");
|
|
203505
|
+
featureDir = join245(featuresDir, feature);
|
|
202808
203506
|
if (!existsSync41(featureDir)) {
|
|
202809
203507
|
const availableFeatures = existsSync41(featuresDir) ? readdirSync11(featuresDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name) : [];
|
|
202810
203508
|
const availableMsg = availableFeatures.length > 0 ? `
|
|
@@ -202828,7 +203526,7 @@ No features found in this project.`;
|
|
|
202828
203526
|
};
|
|
202829
203527
|
}
|
|
202830
203528
|
function resolveSingleFeature(naxDir, remediationHint = "pass -f <name>") {
|
|
202831
|
-
const featuresDir =
|
|
203529
|
+
const featuresDir = join245(naxDir, "features");
|
|
202832
203530
|
const available = existsSync41(featuresDir) ? readdirSync11(featuresDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort() : [];
|
|
202833
203531
|
if (available.length === 1)
|
|
202834
203532
|
return available[0];
|
|
@@ -202848,12 +203546,12 @@ async function resolveProjectAsync(options = {}) {
|
|
|
202848
203546
|
if (!dir) {
|
|
202849
203547
|
return resolveProject2(options);
|
|
202850
203548
|
}
|
|
202851
|
-
if (existsSync41(
|
|
203549
|
+
if (existsSync41(resolve61(dir))) {
|
|
202852
203550
|
return resolveProject2(options);
|
|
202853
203551
|
}
|
|
202854
203552
|
const isPlainName = !dir.includes("/") && !dir.includes("\\");
|
|
202855
203553
|
if (isPlainName) {
|
|
202856
|
-
const registryIdentityPath =
|
|
203554
|
+
const registryIdentityPath = join245(globalConfigDir(), dir, ".identity");
|
|
202857
203555
|
const identityFile = Bun.file(registryIdentityPath);
|
|
202858
203556
|
if (await identityFile.exists()) {
|
|
202859
203557
|
try {
|
|
@@ -202864,17 +203562,17 @@ async function resolveProjectAsync(options = {}) {
|
|
|
202864
203562
|
} catch {}
|
|
202865
203563
|
}
|
|
202866
203564
|
throw new NaxError(`No project found for name or path: "${dir}"
|
|
202867
|
-
Checked filesystem path: ${
|
|
203565
|
+
Checked filesystem path: ${resolve61(dir)}
|
|
202868
203566
|
Checked identity registry: ${registryIdentityPath}
|
|
202869
|
-
Tip: use an absolute or relative path, or run "nax init" in your project directory first.`, "PROJECT_NOT_FOUND", { dir, resolvedPath:
|
|
203567
|
+
Tip: use an absolute or relative path, or run "nax init" in your project directory first.`, "PROJECT_NOT_FOUND", { dir, resolvedPath: resolve61(dir), registryIdentityPath });
|
|
202870
203568
|
}
|
|
202871
203569
|
try {
|
|
202872
203570
|
return resolveProject2(options);
|
|
202873
203571
|
} catch (err) {
|
|
202874
203572
|
if (err instanceof Error && "code" in err && err.code === "ENOENT") {
|
|
202875
|
-
throw new NaxError(`Path does not exist: ${
|
|
203573
|
+
throw new NaxError(`Path does not exist: ${resolve61(dir)}`, "PROJECT_NOT_FOUND", {
|
|
202876
203574
|
dir,
|
|
202877
|
-
resolvedPath:
|
|
203575
|
+
resolvedPath: resolve61(dir),
|
|
202878
203576
|
cause: err
|
|
202879
203577
|
});
|
|
202880
203578
|
}
|
|
@@ -202882,15 +203580,15 @@ Tip: use an absolute or relative path, or run "nax init" in your project directo
|
|
|
202882
203580
|
}
|
|
202883
203581
|
}
|
|
202884
203582
|
function findProjectRoot(startDir) {
|
|
202885
|
-
let current =
|
|
203583
|
+
let current = resolve61(startDir);
|
|
202886
203584
|
let depth = 0;
|
|
202887
203585
|
while (depth < MAX_DIRECTORY_DEPTH) {
|
|
202888
|
-
const naxDir =
|
|
202889
|
-
const configPath =
|
|
203586
|
+
const naxDir = join245(current, ".nax");
|
|
203587
|
+
const configPath = join245(naxDir, "config.json");
|
|
202890
203588
|
if (existsSync41(configPath)) {
|
|
202891
|
-
return
|
|
203589
|
+
return realpathSync8(current);
|
|
202892
203590
|
}
|
|
202893
|
-
const parent =
|
|
203591
|
+
const parent = join245(current, "..");
|
|
202894
203592
|
if (parent === current) {
|
|
202895
203593
|
break;
|
|
202896
203594
|
}
|
|
@@ -203025,15 +203723,15 @@ var init_status_features_details = __esm(() => {
|
|
|
203025
203723
|
|
|
203026
203724
|
// src/cli/status-features.ts
|
|
203027
203725
|
import { existsSync as existsSync42, readdirSync as readdirSync12 } from "fs";
|
|
203028
|
-
import { basename as basename48, join as
|
|
203726
|
+
import { basename as basename48, join as join246, resolve as resolve62 } from "path";
|
|
203029
203727
|
async function loadProjectStatusFile(projectDir) {
|
|
203030
203728
|
const config = await _statusFeaturesDeps.loadConfig(projectDir).catch(() => null);
|
|
203031
203729
|
const projectKey = config?.name?.trim() || basename48(projectDir);
|
|
203032
203730
|
const outputDir = _statusFeaturesDeps.projectOutputDir(projectKey, config?.outputDir);
|
|
203033
|
-
return readStatusFileAt(
|
|
203731
|
+
return readStatusFileAt(join246(outputDir, "status.json"));
|
|
203034
203732
|
}
|
|
203035
203733
|
async function getFeatureSummary(featureName, featureDir, runsDir) {
|
|
203036
|
-
const prdPath =
|
|
203734
|
+
const prdPath = join246(featureDir, "prd.json");
|
|
203037
203735
|
if (!existsSync42(prdPath)) {
|
|
203038
203736
|
return {
|
|
203039
203737
|
name: featureName,
|
|
@@ -203150,7 +203848,7 @@ async function displayAllFeatures(projectRoot) {
|
|
|
203150
203848
|
console.log();
|
|
203151
203849
|
}
|
|
203152
203850
|
}
|
|
203153
|
-
const summaries = await Promise.all(features.map((name) => getFeatureSummary(name, featureDir(projectRoot, name),
|
|
203851
|
+
const summaries = await Promise.all(features.map((name) => getFeatureSummary(name, featureDir(projectRoot, name), join246(outputDir, "features", name, "runs"))));
|
|
203154
203852
|
console.log(source_default.bold(`\uD83D\uDCCA Features
|
|
203155
203853
|
`));
|
|
203156
203854
|
const header = ` ${"Feature".padEnd(25)} ${"Done".padEnd(6)} ${"Failed".padEnd(8)} ${"Pending".padEnd(9)} ${"Last Run".padEnd(22)} ${"Cost".padEnd(10)} Status`;
|
|
@@ -203178,7 +203876,7 @@ async function displayAllFeatures(projectRoot) {
|
|
|
203178
203876
|
console.log();
|
|
203179
203877
|
}
|
|
203180
203878
|
async function displayFeatureDetails(featureName, featureDir) {
|
|
203181
|
-
const prdPath =
|
|
203879
|
+
const prdPath = join246(featureDir, "prd.json");
|
|
203182
203880
|
if (!existsSync42(prdPath)) {
|
|
203183
203881
|
displayNoPrdNotice(featureName);
|
|
203184
203882
|
return;
|
|
@@ -203200,9 +203898,9 @@ async function displayFeatureDetails(featureName, featureDir) {
|
|
|
203200
203898
|
}
|
|
203201
203899
|
}
|
|
203202
203900
|
function resolveRootFromDir(dir) {
|
|
203203
|
-
const resolved =
|
|
203901
|
+
const resolved = resolve62(dir);
|
|
203204
203902
|
const naxDir = _statusFeaturesDeps.findProjectDir(resolved);
|
|
203205
|
-
return naxDir ?
|
|
203903
|
+
return naxDir ? join246(naxDir, "..") : resolved;
|
|
203206
203904
|
}
|
|
203207
203905
|
async function displayFeatureStatus(options = {}) {
|
|
203208
203906
|
if (options.feature) {
|
|
@@ -203343,12 +204041,12 @@ var init_status_dispatch = __esm(() => {
|
|
|
203343
204041
|
|
|
203344
204042
|
// src/cli/trust.ts
|
|
203345
204043
|
import { homedir as osHomedir4 } from "os";
|
|
203346
|
-
import { resolve as
|
|
204044
|
+
import { resolve as resolve63 } from "path";
|
|
203347
204045
|
function unreadableStoreLine(reason) {
|
|
203348
204046
|
return trustStoreUnreadableError(trustStorePath(), reason).message;
|
|
203349
204047
|
}
|
|
203350
204048
|
function resolveAgainstCwd(path, deps) {
|
|
203351
|
-
return path === undefined ? deps.cwd() :
|
|
204049
|
+
return path === undefined ? deps.cwd() : resolve63(deps.cwd(), path);
|
|
203352
204050
|
}
|
|
203353
204051
|
function foldersOf(read) {
|
|
203354
204052
|
return read.state === "ok" ? read.file.folders : [];
|
|
@@ -203700,7 +204398,7 @@ var init_workflow_forge = __esm(() => {
|
|
|
203700
204398
|
});
|
|
203701
204399
|
|
|
203702
204400
|
// src/cli/workflow-promote.ts
|
|
203703
|
-
import { join as
|
|
204401
|
+
import { join as join247 } from "path";
|
|
203704
204402
|
function invalid6(message, context = {}) {
|
|
203705
204403
|
return new NaxError(message, PROMOTE_INVALID, { stage: "workflow", ...context });
|
|
203706
204404
|
}
|
|
@@ -203789,7 +204487,7 @@ function promotedSidecar(target, now) {
|
|
|
203789
204487
|
async function recordAction(target) {
|
|
203790
204488
|
const now = target.forgeDeps.now();
|
|
203791
204489
|
const found = target.found;
|
|
203792
|
-
const path = found?.path ??
|
|
204490
|
+
const path = found?.path ?? join247(target.loaded.runDir, sidecarFileName(now));
|
|
203793
204491
|
const sidecar = found ? { ...found.sidecar, decisions: target.entries, outcome: "promoted", url: target.url } : promotedSidecar(target, now);
|
|
203794
204492
|
await writeSidecar(path, sidecar);
|
|
203795
204493
|
return { name: "record", status: "done" };
|
|
@@ -203886,7 +204584,7 @@ var init_workflow_promote = __esm(() => {
|
|
|
203886
204584
|
});
|
|
203887
204585
|
|
|
203888
204586
|
// src/cli/workflow-record.ts
|
|
203889
|
-
import { join as
|
|
204587
|
+
import { join as join248, relative as relative55 } from "path";
|
|
203890
204588
|
function invalid7(message, context = {}) {
|
|
203891
204589
|
return new NaxError(message, RECORD_INVALID, { stage: "workflow", ...context });
|
|
203892
204590
|
}
|
|
@@ -203958,7 +204656,7 @@ async function writeRecorded(input) {
|
|
|
203958
204656
|
if (input.opts.decisions === undefined) {
|
|
203959
204657
|
throw invalid7(`no decisions sidecar for run ${input.loaded.runId}; pass --decisions`);
|
|
203960
204658
|
}
|
|
203961
|
-
const path =
|
|
204659
|
+
const path = join248(input.loaded.runDir, sidecarFileName(input.now));
|
|
203962
204660
|
const sidecar = newSidecar(input);
|
|
203963
204661
|
await writeSidecar(path, sidecar);
|
|
203964
204662
|
return { path, sidecar };
|
|
@@ -204335,7 +205033,7 @@ var init_worktree_id2 = __esm(() => {
|
|
|
204335
205033
|
});
|
|
204336
205034
|
|
|
204337
205035
|
// src/bakeoff/contestant.ts
|
|
204338
|
-
import { basename as basename53, join as
|
|
205036
|
+
import { basename as basename53, join as join260 } from "path";
|
|
204339
205037
|
function aggregateTotals(metrics) {
|
|
204340
205038
|
let costUsd = 0;
|
|
204341
205039
|
let wallTimeMs = 0;
|
|
@@ -204366,7 +205064,7 @@ async function runContestant(agent, options, deps) {
|
|
|
204366
205064
|
};
|
|
204367
205065
|
const worktree = storyWorktreePath(options.projectRoot, storyId);
|
|
204368
205066
|
const projectKey = options.config.name?.trim() || basename53(options.projectRoot);
|
|
204369
|
-
const outputDir =
|
|
205067
|
+
const outputDir = join260(projectOutputDir(projectKey, options.outputDir), "bakeoff", feature, agent);
|
|
204370
205068
|
const context = {
|
|
204371
205069
|
profile: agent,
|
|
204372
205070
|
config: { ...pinnedConfig, outputDir },
|
|
@@ -204423,7 +205121,7 @@ var init_contestant = __esm(() => {
|
|
|
204423
205121
|
});
|
|
204424
205122
|
|
|
204425
205123
|
// src/bakeoff/pipeline-adapter.ts
|
|
204426
|
-
import { join as
|
|
205124
|
+
import { join as join261 } from "path";
|
|
204427
205125
|
function toResults(runs, result) {
|
|
204428
205126
|
const latest = runs.at(-1);
|
|
204429
205127
|
if (latest && latest.stories.length > 0) {
|
|
@@ -204449,8 +205147,8 @@ async function pipeline2(ctx) {
|
|
|
204449
205147
|
validateFeatureName(ctx.feature);
|
|
204450
205148
|
const hooks = await _pipelineAdapterDeps.loadHooksConfig(ctx.worktree, globalConfigDir());
|
|
204451
205149
|
const contestantFeatureDir = featureDir(ctx.worktree, ctx.feature);
|
|
204452
|
-
const prdPath =
|
|
204453
|
-
const statusFile =
|
|
205150
|
+
const prdPath = join261(contestantFeatureDir, "prd.json");
|
|
205151
|
+
const statusFile = join261(ctx.outputDir, "status.json");
|
|
204454
205152
|
const result = await _pipelineAdapterDeps.run({
|
|
204455
205153
|
prdPath,
|
|
204456
205154
|
workdir: ctx.worktree,
|
|
@@ -204497,9 +205195,9 @@ var init_ranking = __esm(() => {
|
|
|
204497
205195
|
});
|
|
204498
205196
|
|
|
204499
205197
|
// src/bakeoff/coordinator.ts
|
|
204500
|
-
import { join as
|
|
205198
|
+
import { join as join262 } from "path";
|
|
204501
205199
|
async function persistBakeoffResult(result, outputDir) {
|
|
204502
|
-
const filePath =
|
|
205200
|
+
const filePath = join262(outputDir, "bakeoff", result.feature, "bakeoff.json");
|
|
204503
205201
|
await Bun.write(filePath, JSON.stringify(result, null, 2));
|
|
204504
205202
|
}
|
|
204505
205203
|
async function runBakeoff(options, deps = {}) {
|
|
@@ -204541,7 +205239,7 @@ async function handleRunAction(options, deps = _bakeoffCliDeps) {
|
|
|
204541
205239
|
if (compareList.length === 0) {
|
|
204542
205240
|
return deps.runSingleAgent(options);
|
|
204543
205241
|
}
|
|
204544
|
-
const prdPath =
|
|
205242
|
+
const prdPath = join262(featureDir(options.projectRoot, options.feature), "prd.json");
|
|
204545
205243
|
await deps.assertPrdCommitted(prdPath, options.projectRoot);
|
|
204546
205244
|
const agents = options.agents ?? compareList;
|
|
204547
205245
|
return deps.runBakeoff({
|
|
@@ -204825,7 +205523,7 @@ var init_mcp3 = __esm(() => {
|
|
|
204825
205523
|
// src/commands/curator.ts
|
|
204826
205524
|
import { readdirSync as readdirSync15 } from "fs";
|
|
204827
205525
|
import { unlink as unlink15 } from "fs/promises";
|
|
204828
|
-
import { join as
|
|
205526
|
+
import { join as join264, resolve as resolve64, sep as sep32 } from "path";
|
|
204829
205527
|
function openInEditor(filePath) {
|
|
204830
205528
|
const [editor, ...args] = parseCommandToArgv(process.env.EDITOR ?? process.env.VISUAL ?? "vi");
|
|
204831
205529
|
if (!editor)
|
|
@@ -204931,7 +205629,7 @@ async function curatorStatus(options) {
|
|
|
204931
205629
|
const config = await _curatorCmdDeps.loadConfig(resolved.projectDir);
|
|
204932
205630
|
const projectKey = getProjectKey(config, resolved.projectDir);
|
|
204933
205631
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
204934
|
-
const runsDir =
|
|
205632
|
+
const runsDir = join264(outputDir, "runs");
|
|
204935
205633
|
const runIds = listRunIds(runsDir);
|
|
204936
205634
|
let runId;
|
|
204937
205635
|
if (options.run) {
|
|
@@ -204948,8 +205646,8 @@ async function curatorStatus(options) {
|
|
|
204948
205646
|
runId = runIds[runIds.length - 1];
|
|
204949
205647
|
}
|
|
204950
205648
|
console.log(`Run: ${runId}`);
|
|
204951
|
-
const runDir =
|
|
204952
|
-
const observationsPath =
|
|
205649
|
+
const runDir = join264(runsDir, runId);
|
|
205650
|
+
const observationsPath = join264(runDir, "observations.jsonl");
|
|
204953
205651
|
const observations = await parseObservations(observationsPath);
|
|
204954
205652
|
const counts = new Map;
|
|
204955
205653
|
for (const obs of observations) {
|
|
@@ -204959,7 +205657,7 @@ async function curatorStatus(options) {
|
|
|
204959
205657
|
for (const [kind, count] of counts.entries()) {
|
|
204960
205658
|
console.log(` ${kind}: ${count}`);
|
|
204961
205659
|
}
|
|
204962
|
-
const proposalsPath =
|
|
205660
|
+
const proposalsPath = join264(runDir, "curator-proposals.md");
|
|
204963
205661
|
const proposalText = await _curatorCmdDeps.readFile(proposalsPath).catch(() => null);
|
|
204964
205662
|
if (proposalText !== null) {
|
|
204965
205663
|
console.log("");
|
|
@@ -204969,16 +205667,16 @@ async function curatorStatus(options) {
|
|
|
204969
205667
|
}
|
|
204970
205668
|
}
|
|
204971
205669
|
function resolveCanonicalTargetPath(projectDir, canonicalFile) {
|
|
204972
|
-
const target =
|
|
204973
|
-
const root =
|
|
204974
|
-
if (target !== root && !target.startsWith(root +
|
|
205670
|
+
const target = resolve64(projectDir, canonicalFile);
|
|
205671
|
+
const root = resolve64(projectDir);
|
|
205672
|
+
if (target !== root && !target.startsWith(root + sep32))
|
|
204975
205673
|
return null;
|
|
204976
|
-
const relative = target.slice(root.length + 1).replaceAll(
|
|
205674
|
+
const relative = target.slice(root.length + 1).replaceAll(sep32, "/");
|
|
204977
205675
|
return CURATOR_TARGET_SHAPES.some((shape) => shape.test(relative)) ? target : null;
|
|
204978
205676
|
}
|
|
204979
205677
|
function isWithinCanonicalRulesDir(projectDir, targetPath) {
|
|
204980
|
-
const rulesRoot =
|
|
204981
|
-
return targetPath === rulesRoot || targetPath.startsWith(rulesRoot +
|
|
205678
|
+
const rulesRoot = resolve64(projectDir, CANONICAL_RULES_DIR);
|
|
205679
|
+
return targetPath === rulesRoot || targetPath.startsWith(rulesRoot + sep32);
|
|
204982
205680
|
}
|
|
204983
205681
|
async function curatorCommit(options) {
|
|
204984
205682
|
if (!isRelativeAndSafe(options.runId)) {
|
|
@@ -204988,8 +205686,8 @@ async function curatorCommit(options) {
|
|
|
204988
205686
|
const config = await _curatorCmdDeps.loadConfig(resolved.projectDir);
|
|
204989
205687
|
const projectKey = getProjectKey(config, resolved.projectDir);
|
|
204990
205688
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
204991
|
-
const runDir =
|
|
204992
|
-
const proposalsPath =
|
|
205689
|
+
const runDir = join264(outputDir, "runs", options.runId);
|
|
205690
|
+
const proposalsPath = join264(runDir, "curator-proposals.md");
|
|
204993
205691
|
const proposalText = await _curatorCmdDeps.readFile(proposalsPath).catch(() => null);
|
|
204994
205692
|
if (proposalText === null) {
|
|
204995
205693
|
console.log(`curator-proposals.md not found for run ${options.runId}.`);
|
|
@@ -205119,7 +205817,7 @@ async function curatorDryrun(options) {
|
|
|
205119
205817
|
const config = await _curatorCmdDeps.loadConfig(resolved.projectDir);
|
|
205120
205818
|
const projectKey = getProjectKey(config, resolved.projectDir);
|
|
205121
205819
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
205122
|
-
const runsDir =
|
|
205820
|
+
const runsDir = join264(outputDir, "runs");
|
|
205123
205821
|
const runIds = listRunIds(runsDir);
|
|
205124
205822
|
if (runIds.length === 0) {
|
|
205125
205823
|
console.log("No runs found.");
|
|
@@ -205130,7 +205828,7 @@ async function curatorDryrun(options) {
|
|
|
205130
205828
|
console.log(`Run ${options.run} not found in ${runsDir}.`);
|
|
205131
205829
|
return;
|
|
205132
205830
|
}
|
|
205133
|
-
const observationsPath =
|
|
205831
|
+
const observationsPath = join264(runsDir, runId, "observations.jsonl");
|
|
205134
205832
|
const observations = await parseObservations(observationsPath);
|
|
205135
205833
|
const thresholds = getThresholds(config);
|
|
205136
205834
|
const proposals = runHeuristics(observations, thresholds);
|
|
@@ -205162,12 +205860,12 @@ async function curatorGc(options) {
|
|
|
205162
205860
|
dropUnattributed: sweep
|
|
205163
205861
|
});
|
|
205164
205862
|
const outputDir = _curatorCmdDeps.projectOutputDir(projectKey, config.outputDir);
|
|
205165
|
-
const perRunsDir =
|
|
205863
|
+
const perRunsDir = join264(outputDir, "runs");
|
|
205166
205864
|
for (const runId of uniqueRunIds) {
|
|
205167
205865
|
if (!keepSet.has(runId)) {
|
|
205168
|
-
const runDir =
|
|
205169
|
-
await _curatorCmdDeps.removeFile(
|
|
205170
|
-
await _curatorCmdDeps.removeFile(
|
|
205866
|
+
const runDir = join264(perRunsDir, runId);
|
|
205867
|
+
await _curatorCmdDeps.removeFile(join264(runDir, "observations.jsonl"));
|
|
205868
|
+
await _curatorCmdDeps.removeFile(join264(runDir, "curator-proposals.md"));
|
|
205171
205869
|
}
|
|
205172
205870
|
}
|
|
205173
205871
|
const droppedRuns = Math.max(0, uniqueRunIds.length - keepSet.size);
|
|
@@ -205284,7 +205982,7 @@ init_status_dispatch();
|
|
|
205284
205982
|
await init_cli2();
|
|
205285
205983
|
import { existsSync as existsSync50, mkdirSync as mkdirSync20, symlinkSync as symlinkSync4, unlinkSync as unlinkSync7 } from "fs";
|
|
205286
205984
|
import { homedir as homedir12 } from "os";
|
|
205287
|
-
import { join as
|
|
205985
|
+
import { join as join265 } from "path";
|
|
205288
205986
|
|
|
205289
205987
|
// src/commands/detect.ts
|
|
205290
205988
|
init_source();
|
|
@@ -205293,7 +205991,7 @@ init_config();
|
|
|
205293
205991
|
init_logger2();
|
|
205294
205992
|
init_detect();
|
|
205295
205993
|
init_common2();
|
|
205296
|
-
import { join as
|
|
205994
|
+
import { join as join249 } from "path";
|
|
205297
205995
|
function resolveEffective(detected, configPatterns) {
|
|
205298
205996
|
if (configPatterns !== undefined)
|
|
205299
205997
|
return "config";
|
|
@@ -205378,7 +206076,7 @@ async function detectCommand(options) {
|
|
|
205378
206076
|
const rootDetected = detectionMap[""] ?? { patterns: [], confidence: "empty", sources: [] };
|
|
205379
206077
|
const pkgEntries = await Promise.all(packageDirs.map(async (dir) => {
|
|
205380
206078
|
const det = detectionMap[dir] ?? { patterns: [], confidence: "empty", sources: [] };
|
|
205381
|
-
const pkgConfigPath =
|
|
206079
|
+
const pkgConfigPath = join249(workdir, ".nax", "mono", dir, "config.json");
|
|
205382
206080
|
const pkgRaw = await loadRawConfig(pkgConfigPath);
|
|
205383
206081
|
const pkgPatterns = deepGet(pkgRaw, TEST_PATTERNS_KEY);
|
|
205384
206082
|
const effective = Array.isArray(pkgPatterns) ? pkgPatterns : undefined;
|
|
@@ -205432,13 +206130,13 @@ async function detectCommand(options) {
|
|
|
205432
206130
|
if (rootDetected.confidence === "empty") {
|
|
205433
206131
|
console.log(source_default.yellow(" root: skipped (empty detection)"));
|
|
205434
206132
|
} else {
|
|
205435
|
-
const rootConfigPath =
|
|
206133
|
+
const rootConfigPath = join249(workdir, ".nax", "config.json");
|
|
205436
206134
|
try {
|
|
205437
206135
|
const status = await applyToConfig(rootConfigPath, rootDetected.patterns, options.force ?? false);
|
|
205438
206136
|
if (status === "skipped") {
|
|
205439
206137
|
console.log(source_default.dim(" root: skipped (testFilePatterns already set; use --force to overwrite)"));
|
|
205440
206138
|
} else {
|
|
205441
|
-
console.log(source_default.green(` root: ${status} \u2192 ${
|
|
206139
|
+
console.log(source_default.green(` root: ${status} \u2192 ${join249(".nax", "config.json")}`));
|
|
205442
206140
|
}
|
|
205443
206141
|
} catch (err) {
|
|
205444
206142
|
console.error(source_default.red(` root: write failed \u2014 ${err.message}`));
|
|
@@ -205451,13 +206149,13 @@ async function detectCommand(options) {
|
|
|
205451
206149
|
console.log(source_default.dim(` ${dir}: skipped (empty detection)`));
|
|
205452
206150
|
continue;
|
|
205453
206151
|
}
|
|
205454
|
-
const pkgConfigPath =
|
|
206152
|
+
const pkgConfigPath = join249(workdir, ".nax", "mono", dir, "config.json");
|
|
205455
206153
|
try {
|
|
205456
206154
|
const status = await applyToConfig(pkgConfigPath, det.patterns, options.force ?? false);
|
|
205457
206155
|
if (status === "skipped") {
|
|
205458
206156
|
console.log(source_default.dim(` ${dir}: skipped (already set)`));
|
|
205459
206157
|
} else {
|
|
205460
|
-
console.log(source_default.green(` ${dir}: ${status} \u2192 ${
|
|
206158
|
+
console.log(source_default.green(` ${dir}: ${status} \u2192 ${join249(".nax", "mono", dir, "config.json")}`));
|
|
205461
206159
|
}
|
|
205462
206160
|
} catch (err) {
|
|
205463
206161
|
console.error(source_default.red(` ${dir}: write failed \u2014 ${err.message}`));
|
|
@@ -205482,7 +206180,7 @@ init_prd();
|
|
|
205482
206180
|
init_precheck();
|
|
205483
206181
|
init_common2();
|
|
205484
206182
|
import { existsSync as existsSync43 } from "fs";
|
|
205485
|
-
import { join as
|
|
206183
|
+
import { join as join250 } from "path";
|
|
205486
206184
|
async function precheckCommand(options) {
|
|
205487
206185
|
const resolved = resolveProject2({
|
|
205488
206186
|
dir: options.dir,
|
|
@@ -205495,7 +206193,7 @@ async function precheckCommand(options) {
|
|
|
205495
206193
|
process.exit(result.passed ? EXIT_CODES.SUCCESS : EXIT_CODES.BLOCKER);
|
|
205496
206194
|
return;
|
|
205497
206195
|
}
|
|
205498
|
-
const naxDir =
|
|
206196
|
+
const naxDir = join250(resolved.projectDir, ".nax");
|
|
205499
206197
|
let featureName = options.feature;
|
|
205500
206198
|
if (!featureName) {
|
|
205501
206199
|
try {
|
|
@@ -205505,8 +206203,8 @@ async function precheckCommand(options) {
|
|
|
205505
206203
|
process.exit(1);
|
|
205506
206204
|
}
|
|
205507
206205
|
}
|
|
205508
|
-
const featureDir =
|
|
205509
|
-
const prdPath =
|
|
206206
|
+
const featureDir = join250(naxDir, "features", featureName);
|
|
206207
|
+
const prdPath = join250(featureDir, "prd.json");
|
|
205510
206208
|
if (!existsSync43(featureDir)) {
|
|
205511
206209
|
console.error(source_default.red(`Feature not found: ${featureName}`));
|
|
205512
206210
|
process.exit(1);
|
|
@@ -205536,7 +206234,7 @@ async function doctorCommand(options) {
|
|
|
205536
206234
|
init_errors4();
|
|
205537
206235
|
init_common2();
|
|
205538
206236
|
import { existsSync as existsSync45 } from "fs";
|
|
205539
|
-
import { join as
|
|
206237
|
+
import { join as join253 } from "path";
|
|
205540
206238
|
|
|
205541
206239
|
// src/commands/logs-formatter.ts
|
|
205542
206240
|
init_source();
|
|
@@ -205544,14 +206242,14 @@ init_formatter();
|
|
|
205544
206242
|
init_summary();
|
|
205545
206243
|
init_bun_deps();
|
|
205546
206244
|
import { readdirSync as readdirSync14 } from "fs";
|
|
205547
|
-
import { join as
|
|
206245
|
+
import { join as join252 } from "path";
|
|
205548
206246
|
|
|
205549
206247
|
// src/commands/logs-reader.ts
|
|
205550
206248
|
init_errors4();
|
|
205551
206249
|
init_paths4();
|
|
205552
206250
|
import { existsSync as existsSync44, readdirSync as readdirSync13 } from "fs";
|
|
205553
206251
|
import { readdir as readdir21 } from "fs/promises";
|
|
205554
|
-
import { join as
|
|
206252
|
+
import { join as join251 } from "path";
|
|
205555
206253
|
var _logsReaderDeps = {
|
|
205556
206254
|
getRunsDir
|
|
205557
206255
|
};
|
|
@@ -205566,7 +206264,7 @@ async function resolveRunFileFromRegistry(runId) {
|
|
|
205566
206264
|
let exactMatch = null;
|
|
205567
206265
|
const prefixMatches = [];
|
|
205568
206266
|
for (const entry of entries) {
|
|
205569
|
-
const metaPath =
|
|
206267
|
+
const metaPath = join251(runsDir, entry, "meta.json");
|
|
205570
206268
|
try {
|
|
205571
206269
|
const meta = await Bun.file(metaPath).json();
|
|
205572
206270
|
if (meta.runId === runId) {
|
|
@@ -205602,14 +206300,14 @@ async function resolveRunFileFromRegistry(runId) {
|
|
|
205602
206300
|
return null;
|
|
205603
206301
|
}
|
|
205604
206302
|
const specificFile = files.find((f) => f === `${matched.runId}.jsonl`);
|
|
205605
|
-
return
|
|
206303
|
+
return join251(matched.eventsDir, specificFile ?? files[0]);
|
|
205606
206304
|
}
|
|
205607
206305
|
async function selectRunFile(runsDir) {
|
|
205608
206306
|
const files = readdirSync13(runsDir).filter((f) => f.endsWith(".jsonl") && f !== "latest.jsonl").sort().reverse();
|
|
205609
206307
|
if (files.length === 0) {
|
|
205610
206308
|
return null;
|
|
205611
206309
|
}
|
|
205612
|
-
return
|
|
206310
|
+
return join251(runsDir, files[0]);
|
|
205613
206311
|
}
|
|
205614
206312
|
async function extractRunSummary(filePath) {
|
|
205615
206313
|
const file = Bun.file(filePath);
|
|
@@ -205695,7 +206393,7 @@ Runs:
|
|
|
205695
206393
|
console.log(source_default.gray(" Timestamp Stories Duration Cost Status"));
|
|
205696
206394
|
console.log(source_default.gray(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
205697
206395
|
for (const file of files) {
|
|
205698
|
-
const filePath =
|
|
206396
|
+
const filePath = join252(runsDir, file);
|
|
205699
206397
|
const summary = await extractRunSummary(filePath);
|
|
205700
206398
|
const timestamp = file.replace(".jsonl", "");
|
|
205701
206399
|
const stories = summary ? `${summary.passed}/${summary.total}` : "?/?";
|
|
@@ -205828,10 +206526,10 @@ async function logsCommand(options) {
|
|
|
205828
206526
|
return;
|
|
205829
206527
|
}
|
|
205830
206528
|
const resolved = resolveProject2({ dir: options.dir });
|
|
205831
|
-
const naxDir =
|
|
206529
|
+
const naxDir = join253(resolved.projectDir, ".nax");
|
|
205832
206530
|
const featureName = resolveSingleFeature(naxDir, "pass -r <runId> (see `nax runs list`)");
|
|
205833
|
-
const featureDir =
|
|
205834
|
-
const runsDir =
|
|
206531
|
+
const featureDir = join253(naxDir, "features", featureName);
|
|
206532
|
+
const runsDir = join253(featureDir, "runs");
|
|
205835
206533
|
if (!existsSync45(runsDir)) {
|
|
205836
206534
|
throw new NaxError(`No runs directory found for feature: ${featureName}`, "LOGS_RUNS_DIR_NOT_FOUND", {
|
|
205837
206535
|
stage: "logs",
|
|
@@ -205863,7 +206561,7 @@ import { dirname as dirname61 } from "path";
|
|
|
205863
206561
|
init_errors4();
|
|
205864
206562
|
init_paths4();
|
|
205865
206563
|
import { readdir as readdir22 } from "fs/promises";
|
|
205866
|
-
import { join as
|
|
206564
|
+
import { join as join254 } from "path";
|
|
205867
206565
|
var _discoveryDeps = {
|
|
205868
206566
|
getRunsDir
|
|
205869
206567
|
};
|
|
@@ -205877,7 +206575,7 @@ async function loadMetas(runsDir) {
|
|
|
205877
206575
|
const metas = [];
|
|
205878
206576
|
for (const entry of entries) {
|
|
205879
206577
|
try {
|
|
205880
|
-
const meta = await Bun.file(
|
|
206578
|
+
const meta = await Bun.file(join254(runsDir, entry, "meta.json")).json();
|
|
205881
206579
|
metas.push(meta);
|
|
205882
206580
|
} catch {}
|
|
205883
206581
|
}
|
|
@@ -205894,7 +206592,7 @@ async function discoverRun(query, depsArg = _discoveryDeps) {
|
|
|
205894
206592
|
throw new NaxError("No runs registered", "RUN_NOT_FOUND", { runsDir });
|
|
205895
206593
|
}
|
|
205896
206594
|
const latest = metas.reduce((acc, m) => m.runId > acc.runId ? m : acc);
|
|
205897
|
-
return { meta: latest, jsonlPath:
|
|
206595
|
+
return { meta: latest, jsonlPath: join254(latest.eventsDir, `${latest.runId}.jsonl`) };
|
|
205898
206596
|
}
|
|
205899
206597
|
const matched = metas.filter((m) => matches3(m, query));
|
|
205900
206598
|
if (matched.length === 0) {
|
|
@@ -205911,7 +206609,7 @@ async function discoverRun(query, depsArg = _discoveryDeps) {
|
|
|
205911
206609
|
});
|
|
205912
206610
|
}
|
|
205913
206611
|
const meta = matched[0];
|
|
205914
|
-
return { meta, jsonlPath:
|
|
206612
|
+
return { meta, jsonlPath: join254(meta.eventsDir, `${meta.runId}.jsonl`) };
|
|
205915
206613
|
}
|
|
205916
206614
|
|
|
205917
206615
|
// src/replay/json.ts
|
|
@@ -206254,11 +206952,11 @@ init_checkpoint2();
|
|
|
206254
206952
|
init_runtime3();
|
|
206255
206953
|
init_feature_name();
|
|
206256
206954
|
import { existsSync as existsSync47 } from "fs";
|
|
206257
|
-
import { basename as basename50, join as
|
|
206955
|
+
import { basename as basename50, join as join255 } from "path";
|
|
206258
206956
|
async function defaultCheckpointExists(featureDir) {
|
|
206259
206957
|
if (!featureDir || !existsSync47(featureDir))
|
|
206260
206958
|
return false;
|
|
206261
|
-
return existsSync47(
|
|
206959
|
+
return existsSync47(join255(featureDir, "checkpoint.jsonl"));
|
|
206262
206960
|
}
|
|
206263
206961
|
async function defaultLoadCheckpoints(featureDir) {
|
|
206264
206962
|
return loadCheckpoints(featureDir);
|
|
@@ -206336,12 +207034,12 @@ function registerResumeCommand(program) {
|
|
|
206336
207034
|
`);
|
|
206337
207035
|
process.exit(1);
|
|
206338
207036
|
}
|
|
206339
|
-
const featureDir =
|
|
207037
|
+
const featureDir = join255(naxDir, "features", cmdOpts.feature);
|
|
206340
207038
|
const deps = {
|
|
206341
207039
|
..._resumeCmdDeps,
|
|
206342
207040
|
runInvocation: async (feature, opts) => {
|
|
206343
207041
|
const config = await loadConfig(naxDir ?? undefined);
|
|
206344
|
-
const prdPath =
|
|
207042
|
+
const prdPath = join255(opts.featureDir ?? "", "prd.json");
|
|
206345
207043
|
if (!existsSync(prdPath)) {
|
|
206346
207044
|
process.stderr.write(`Feature "${feature}" not found or missing prd.json
|
|
206347
207045
|
`);
|
|
@@ -206353,11 +207051,11 @@ function registerResumeCommand(program) {
|
|
|
206353
207051
|
applyResumeModeDeps(opts.featureDir ?? "", "auto");
|
|
206354
207052
|
const projectKey = config.name?.trim() || basename50(dir);
|
|
206355
207053
|
const outputDir = projectOutputDir(projectKey, config.outputDir);
|
|
206356
|
-
const statusFilePath =
|
|
206357
|
-
const runsDir =
|
|
207054
|
+
const statusFilePath = join255(outputDir, "status.json");
|
|
207055
|
+
const runsDir = join255(outputDir, "features", feature, "runs");
|
|
206358
207056
|
mkdirSync(runsDir, { recursive: true });
|
|
206359
207057
|
const runId = buildRunId(dir, new Date);
|
|
206360
|
-
const logFilePath =
|
|
207058
|
+
const logFilePath = join255(runsDir, `${runId}.jsonl`);
|
|
206361
207059
|
initLogger({ level: "info", filePath: logFilePath, useChalk: true, headless: true, suppressConsole: false });
|
|
206362
207060
|
const result = await run({
|
|
206363
207061
|
prdPath,
|
|
@@ -206394,7 +207092,7 @@ function registerResumeCommand(program) {
|
|
|
206394
207092
|
init_source();
|
|
206395
207093
|
init_paths4();
|
|
206396
207094
|
import { readdir as readdir23 } from "fs/promises";
|
|
206397
|
-
import { join as
|
|
207095
|
+
import { join as join256 } from "path";
|
|
206398
207096
|
var DEFAULT_LIMIT = 20;
|
|
206399
207097
|
var _runsCmdDeps = {
|
|
206400
207098
|
getRunsDir
|
|
@@ -206451,7 +207149,7 @@ async function runsCommand(options = {}) {
|
|
|
206451
207149
|
}
|
|
206452
207150
|
const rows = [];
|
|
206453
207151
|
for (const entry of entries) {
|
|
206454
|
-
const metaPath =
|
|
207152
|
+
const metaPath = join256(runsDir, entry, "meta.json");
|
|
206455
207153
|
let meta;
|
|
206456
207154
|
try {
|
|
206457
207155
|
meta = await Bun.file(metaPath).json();
|
|
@@ -206533,7 +207231,7 @@ init_execution();
|
|
|
206533
207231
|
init_logger2();
|
|
206534
207232
|
init_runtime3();
|
|
206535
207233
|
import { mkdir as mkdir59, unlink as unlink14 } from "fs/promises";
|
|
206536
|
-
import { basename as basename51, join as
|
|
207234
|
+
import { basename as basename51, join as join257 } from "path";
|
|
206537
207235
|
var _unlockDeps = {
|
|
206538
207236
|
findProjectDir,
|
|
206539
207237
|
loadConfig,
|
|
@@ -206597,7 +207295,7 @@ async function tryRemoveFeatureLock(outputDir, feature, force) {
|
|
|
206597
207295
|
return "removed";
|
|
206598
207296
|
}
|
|
206599
207297
|
async function listFeatureLockFeatures(outputDir) {
|
|
206600
|
-
const featuresRoot =
|
|
207298
|
+
const featuresRoot = join257(outputDir, "features");
|
|
206601
207299
|
let paths;
|
|
206602
207300
|
try {
|
|
206603
207301
|
paths = await Array.fromAsync(new Bun.Glob("*/nax.lock").scan({ cwd: featuresRoot, onlyFiles: true }));
|
|
@@ -206614,7 +207312,7 @@ async function unlockCommand(options) {
|
|
|
206614
207312
|
const workdir = options.dir ?? process.cwd();
|
|
206615
207313
|
if (options.feature !== undefined && options.feature.length > 0) {
|
|
206616
207314
|
const { outputDir } = await resolveOutputDir3(workdir);
|
|
206617
|
-
await mkdir59(
|
|
207315
|
+
await mkdir59(join257(outputDir, "features"), { recursive: true });
|
|
206618
207316
|
const outcome = await tryRemoveFeatureLock(outputDir, options.feature, options.force ?? false);
|
|
206619
207317
|
if (outcome === "skipped" || outcome === "parse-error") {
|
|
206620
207318
|
process.exit(1);
|
|
@@ -206622,7 +207320,7 @@ async function unlockCommand(options) {
|
|
|
206622
207320
|
logUnlockInfo("Feature lock removed");
|
|
206623
207321
|
process.exit(0);
|
|
206624
207322
|
}
|
|
206625
|
-
const checkoutLockPath =
|
|
207323
|
+
const checkoutLockPath = join257(workdir, "nax.lock");
|
|
206626
207324
|
let checkoutAborted = false;
|
|
206627
207325
|
const lockFile = Bun.file(checkoutLockPath);
|
|
206628
207326
|
const exists = await lockFile.exists();
|
|
@@ -208354,12 +209052,12 @@ init_source();
|
|
|
208354
209052
|
init_run_chat_asks();
|
|
208355
209053
|
await init_cli2();
|
|
208356
209054
|
import { existsSync as existsSync48, mkdirSync as mkdirSync19 } from "fs";
|
|
208357
|
-
import { basename as basename52, join as
|
|
209055
|
+
import { basename as basename52, join as join259 } from "path";
|
|
208358
209056
|
|
|
208359
209057
|
// src/cli/run-context-overrides.ts
|
|
208360
|
-
import { isAbsolute as isAbsolute44, join as
|
|
209058
|
+
import { isAbsolute as isAbsolute44, join as join258 } from "path";
|
|
208361
209059
|
function resolveCliOverridePath(workdir, value) {
|
|
208362
|
-
return isAbsolute44(value) || value.startsWith("~/") ? value :
|
|
209060
|
+
return isAbsolute44(value) || value.startsWith("~/") ? value : join258(workdir, value);
|
|
208363
209061
|
}
|
|
208364
209062
|
function resolveContextCliOverrides(workdir, options) {
|
|
208365
209063
|
const overrides = {};
|
|
@@ -208671,7 +209369,7 @@ async function resolveRunProjectContext(workdir, options) {
|
|
|
208671
209369
|
const cliOverrides = {};
|
|
208672
209370
|
const cliProfiles = options.profile ?? [];
|
|
208673
209371
|
const profileOverride = naxDir ? await resolveRunProfileOverride({
|
|
208674
|
-
prdPath:
|
|
209372
|
+
prdPath: join259(naxDir, "features", options.feature, "prd.json"),
|
|
208675
209373
|
projectRoot: workdir,
|
|
208676
209374
|
cliProfile: cliProfiles,
|
|
208677
209375
|
envProfile: process.env.NAX_PROFILE
|
|
@@ -208718,10 +209416,10 @@ async function maybeRunPlanPhase(params) {
|
|
|
208718
209416
|
}
|
|
208719
209417
|
async function runPlanningPhase(params) {
|
|
208720
209418
|
const { options, from, config, workdir, projectRoot, featureDir } = params;
|
|
208721
|
-
const planLogDir =
|
|
209419
|
+
const planLogDir = join259(featureDir, "plan");
|
|
208722
209420
|
mkdirSync19(planLogDir, { recursive: true });
|
|
208723
209421
|
const planLogId = new Date().toISOString().replace(/:/g, "-").replace(/\..+/, "");
|
|
208724
|
-
const planLogPath =
|
|
209422
|
+
const planLogPath = join259(planLogDir, `${planLogId}.jsonl`);
|
|
208725
209423
|
initLogger({ level: "info", filePath: planLogPath, useChalk: false, headless: true });
|
|
208726
209424
|
console.log(source_default.dim(` [Plan log: ${planLogPath}]`));
|
|
208727
209425
|
console.log(source_default.dim(" [Planning phase: generating PRD from spec]"));
|
|
@@ -208765,10 +209463,10 @@ function initRunLogging(params) {
|
|
|
208765
209463
|
const { options, config, workdir, isTTY, logLevel, formatterMode } = params;
|
|
208766
209464
|
const projectKey = config.name?.trim() || basename52(workdir);
|
|
208767
209465
|
const outputDir = projectOutputDir(projectKey, config.outputDir);
|
|
208768
|
-
const runsDir =
|
|
209466
|
+
const runsDir = join259(outputDir, "features", options.feature, "runs");
|
|
208769
209467
|
mkdirSync19(runsDir, { recursive: true });
|
|
208770
209468
|
const runId = new Date().toISOString().replace(/:/g, "-").replace(/\..+/, "");
|
|
208771
|
-
const logFilePath =
|
|
209469
|
+
const logFilePath = join259(runsDir, `${runId}.jsonl`);
|
|
208772
209470
|
const headlessFlag = options.headless ?? false;
|
|
208773
209471
|
const headlessEnv = process.env.NAX_HEADLESS === "1";
|
|
208774
209472
|
const useHeadless = resolveUseHeadless({ isTTY, headlessFlag, headlessEnv, formatterMode });
|
|
@@ -208805,7 +209503,7 @@ function applyRunCliOverrides(config, options, maxIterationsFlag) {
|
|
|
208805
209503
|
// bin/run-action-execute.ts
|
|
208806
209504
|
init_source();
|
|
208807
209505
|
init_execution();
|
|
208808
|
-
import { join as
|
|
209506
|
+
import { join as join263 } from "path";
|
|
208809
209507
|
init_version();
|
|
208810
209508
|
function mountRunTui(params) {
|
|
208811
209509
|
const initialStories = params.prd.userStories.map((story) => ({
|
|
@@ -208820,7 +209518,7 @@ function mountRunTui(params) {
|
|
|
208820
209518
|
stories: initialStories,
|
|
208821
209519
|
events: params.eventEmitter,
|
|
208822
209520
|
agentStreamEvents: params.agentStreamEvents,
|
|
208823
|
-
queueFilePath:
|
|
209521
|
+
queueFilePath: join263(params.workdir, ".queue.txt")
|
|
208824
209522
|
});
|
|
208825
209523
|
}
|
|
208826
209524
|
async function waitForScheduledRun(params) {
|
|
@@ -208994,9 +209692,9 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
208994
209692
|
process.exit(1);
|
|
208995
209693
|
}
|
|
208996
209694
|
await runTrustGate(workdir);
|
|
208997
|
-
const projectRoot =
|
|
208998
|
-
const featureDir =
|
|
208999
|
-
const prdPath =
|
|
209695
|
+
const projectRoot = join265(naxDir, "..");
|
|
209696
|
+
const featureDir = join265(naxDir, "features", options.feature);
|
|
209697
|
+
const prdPath = join265(featureDir, "prd.json");
|
|
209000
209698
|
await maybeRunPlanPhase({ options, config, workdir, projectRoot, featureDir, prdPath });
|
|
209001
209699
|
if (!existsSync50(prdPath)) {
|
|
209002
209700
|
console.error(source_default.red(`Feature "${options.feature}" not found or missing prd.json`));
|
|
@@ -209015,7 +209713,7 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
209015
209713
|
});
|
|
209016
209714
|
const chatAskSecret = await readRunChatAskSecret(chatAsksDir);
|
|
209017
209715
|
config = applyRunCliOverrides(config, options, maxIterationsFlag);
|
|
209018
|
-
const globalNaxDir =
|
|
209716
|
+
const globalNaxDir = join265(homedir12(), ".nax");
|
|
209019
209717
|
const hooks = await loadHooksConfig(naxDir, globalNaxDir);
|
|
209020
209718
|
const eventEmitter = new PipelineEventEmitter;
|
|
209021
209719
|
const agentStreamEvents = useHeadless ? undefined : new AgentStreamEventBus;
|
|
@@ -209032,7 +209730,7 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
209032
209730
|
} else {
|
|
209033
209731
|
console.log(source_default.dim(" [Headless mode \u2014 pipe output]"));
|
|
209034
209732
|
}
|
|
209035
|
-
const statusFilePath =
|
|
209733
|
+
const statusFilePath = join265(outputDir, "status.json");
|
|
209036
209734
|
await waitForScheduledRun({ scheduleGate, feature: options.feature, formatterMode, isTTY, tuiInstance });
|
|
209037
209735
|
if (options.compare) {
|
|
209038
209736
|
await runBakeoffMode({ options, workdir, outputDir, config, tuiInstance });
|
|
@@ -209055,7 +209753,7 @@ program2.command("run").description("Run the orchestration loop for a feature").
|
|
|
209055
209753
|
agentStreamEvents,
|
|
209056
209754
|
tuiInstance
|
|
209057
209755
|
});
|
|
209058
|
-
const latestSymlink =
|
|
209756
|
+
const latestSymlink = join265(runsDir, "latest.jsonl");
|
|
209059
209757
|
try {
|
|
209060
209758
|
if (existsSync50(latestSymlink)) {
|
|
209061
209759
|
unlinkSync7(latestSymlink);
|
|
@@ -209149,9 +209847,9 @@ features.command("create <name>").description("Create a new feature").option("-d
|
|
|
209149
209847
|
console.error(source_default.red("nax not initialized. Run: nax init"));
|
|
209150
209848
|
process.exit(1);
|
|
209151
209849
|
}
|
|
209152
|
-
const featureDir =
|
|
209850
|
+
const featureDir = join265(naxDir, "features", name);
|
|
209153
209851
|
mkdirSync20(featureDir, { recursive: true });
|
|
209154
|
-
await Bun.write(
|
|
209852
|
+
await Bun.write(join265(featureDir, "spec.md"), `# Feature: ${name}
|
|
209155
209853
|
|
|
209156
209854
|
## Overview
|
|
209157
209855
|
|
|
@@ -209184,7 +209882,7 @@ features.command("create <name>").description("Create a new feature").option("-d
|
|
|
209184
209882
|
|
|
209185
209883
|
<!-- What this feature explicitly does NOT cover. -->
|
|
209186
209884
|
`);
|
|
209187
|
-
await Bun.write(
|
|
209885
|
+
await Bun.write(join265(featureDir, "progress.txt"), `# Progress: ${name}
|
|
209188
209886
|
|
|
209189
209887
|
Created: ${new Date().toISOString()}
|
|
209190
209888
|
|
|
@@ -209210,7 +209908,7 @@ features.command("list").description("List all features").option("-d, --dir <pat
|
|
|
209210
209908
|
console.error(source_default.red("nax not initialized."));
|
|
209211
209909
|
process.exit(1);
|
|
209212
209910
|
}
|
|
209213
|
-
const featuresDir =
|
|
209911
|
+
const featuresDir = join265(naxDir, "features");
|
|
209214
209912
|
if (!existsSync50(featuresDir)) {
|
|
209215
209913
|
console.log(source_default.dim("No features yet."));
|
|
209216
209914
|
return;
|
|
@@ -209225,7 +209923,7 @@ features.command("list").description("List all features").option("-d, --dir <pat
|
|
|
209225
209923
|
Features:
|
|
209226
209924
|
`));
|
|
209227
209925
|
for (const name of entries) {
|
|
209228
|
-
const prdPath =
|
|
209926
|
+
const prdPath = join265(featuresDir, name, "prd.json");
|
|
209229
209927
|
if (existsSync50(prdPath)) {
|
|
209230
209928
|
try {
|
|
209231
209929
|
const prd = await loadPRD(prdPath);
|
|
@@ -209297,17 +209995,17 @@ Use: nax plan -f <feature> --from <spec>`));
|
|
|
209297
209995
|
console.error(source_default.red("nax not initialized. Run: nax init"));
|
|
209298
209996
|
process.exit(1);
|
|
209299
209997
|
}
|
|
209300
|
-
const projectRoot =
|
|
209998
|
+
const projectRoot = join265(naxDir, "..");
|
|
209301
209999
|
const cliOverrides = {};
|
|
209302
210000
|
const cliProfiles = options.profile ?? [];
|
|
209303
210001
|
if (cliProfiles.length > 0) {
|
|
209304
210002
|
cliOverrides.profile = cliProfiles;
|
|
209305
210003
|
}
|
|
209306
210004
|
const config = await loadConfig(projectRoot, cliOverrides);
|
|
209307
|
-
const featureLogDir =
|
|
210005
|
+
const featureLogDir = join265(naxDir, "features", options.feature, "plan");
|
|
209308
210006
|
mkdirSync20(featureLogDir, { recursive: true });
|
|
209309
210007
|
const planLogId = new Date().toISOString().replace(/:/g, "-").replace(/\..+/, "");
|
|
209310
|
-
const planLogPath =
|
|
210008
|
+
const planLogPath = join265(featureLogDir, `${planLogId}.jsonl`);
|
|
209311
210009
|
initLogger({ level: "info", filePath: planLogPath, useChalk: false, headless: true });
|
|
209312
210010
|
console.log(source_default.dim(` [Plan log: ${planLogPath}]`));
|
|
209313
210011
|
try {
|
|
@@ -209837,7 +210535,7 @@ spec.command("lint [paths...]").description("Check a spec's machine-extracted se
|
|
|
209837
210535
|
return;
|
|
209838
210536
|
}
|
|
209839
210537
|
const naxDir = findProjectDir(workdir);
|
|
209840
|
-
const projectRoot = naxDir ?
|
|
210538
|
+
const projectRoot = naxDir ? join265(naxDir, "..") : workdir;
|
|
209841
210539
|
let maxAcCount;
|
|
209842
210540
|
if (naxDir) {
|
|
209843
210541
|
const config = await loadConfig(projectRoot);
|