nexrall-code 0.5.163 → 0.5.165
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/index.js +99 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -108651,11 +108651,17 @@ Do NOT call any tools and do NOT continue the task. Reply with text only: a conc
|
|
|
108651
108651
|
if ((options._depth ?? 0) === 0) {
|
|
108652
108652
|
await runLifecycleHooks(loadHooks(options.workDir).PreCompact, "PreCompact", options.workDir, { trigger: "auto", session_id: options.sessionId ?? "", messages_to_summarize: cut }, "auto").catch(() => void 0);
|
|
108653
108653
|
}
|
|
108654
|
+
const beforeCompact = messages.length;
|
|
108655
|
+
const afterCompact = cut > 0 ? messages.length - cut + 1 : messages.length;
|
|
108654
108656
|
const toSummarize = messages.slice(0, cut);
|
|
108655
108657
|
const kept = messages.slice(cut);
|
|
108656
108658
|
const firePostCompact = async () => {
|
|
108657
108659
|
if ((options._depth ?? 0) !== 0)
|
|
108658
108660
|
return;
|
|
108661
|
+
try {
|
|
108662
|
+
options.onCompact?.({ trigger: "auto", before: beforeCompact, after: afterCompact });
|
|
108663
|
+
} catch {
|
|
108664
|
+
}
|
|
108659
108665
|
await runLifecycleHooks(loadHooks(options.workDir).PostCompact, "PostCompact", options.workDir, { trigger: "auto", session_id: options.sessionId ?? "", messages_summarized: cut }, "auto").catch(() => void 0);
|
|
108660
108666
|
};
|
|
108661
108667
|
const originalTask = originalTaskText(toSummarize);
|
|
@@ -153211,9 +153217,40 @@ function listSessions() {
|
|
|
153211
153217
|
return [];
|
|
153212
153218
|
}
|
|
153213
153219
|
}
|
|
153220
|
+
function knownSessionIds() {
|
|
153221
|
+
const ids = /* @__PURE__ */ new Set();
|
|
153222
|
+
const add = (dir, ext) => {
|
|
153223
|
+
try {
|
|
153224
|
+
for (const f3 of fs11.readdirSync(dir))
|
|
153225
|
+
if (f3.endsWith(ext))
|
|
153226
|
+
ids.add(f3.slice(0, -ext.length));
|
|
153227
|
+
} catch {
|
|
153228
|
+
}
|
|
153229
|
+
};
|
|
153230
|
+
add(SESSIONS_DIR, ".json");
|
|
153231
|
+
add(eventsDir(), ".jsonl");
|
|
153232
|
+
return [...ids];
|
|
153233
|
+
}
|
|
153234
|
+
function resolveSessionId(idOrPrefix) {
|
|
153235
|
+
const want = (idOrPrefix ?? "").trim().toLowerCase();
|
|
153236
|
+
if (!want)
|
|
153237
|
+
return { ok: false, error: "No session id given" };
|
|
153238
|
+
const known = knownSessionIds();
|
|
153239
|
+
if (known.includes(want))
|
|
153240
|
+
return { ok: true, id: want };
|
|
153241
|
+
const m2 = known.filter((id) => id.startsWith(want));
|
|
153242
|
+
if (m2.length === 1)
|
|
153243
|
+
return { ok: true, id: m2[0] };
|
|
153244
|
+
if (m2.length > 1)
|
|
153245
|
+
return { ok: false, error: `"${want}" matches ${m2.length} sessions \u2014 use more characters` };
|
|
153246
|
+
return { ok: false, error: `No such session "${want}". Run \`nex sessions\`.` };
|
|
153247
|
+
}
|
|
153214
153248
|
function loadSession(id) {
|
|
153249
|
+
const r2 = resolveSessionId(id);
|
|
153250
|
+
if (!r2.ok)
|
|
153251
|
+
return null;
|
|
153215
153252
|
try {
|
|
153216
|
-
return JSON.parse(fs11.readFileSync(sessionPath(id), "utf-8"));
|
|
153253
|
+
return JSON.parse(fs11.readFileSync(sessionPath(r2.id), "utf-8"));
|
|
153217
153254
|
} catch {
|
|
153218
153255
|
return null;
|
|
153219
153256
|
}
|
|
@@ -153234,13 +153271,16 @@ function forkTitle(parentTitle, requested) {
|
|
|
153234
153271
|
return base ? `${base.slice(0, 68)} (fork)` : "";
|
|
153235
153272
|
}
|
|
153236
153273
|
function deleteSession(id) {
|
|
153274
|
+
const r2 = resolveSessionId(id);
|
|
153275
|
+
if (!r2.ok)
|
|
153276
|
+
return false;
|
|
153237
153277
|
try {
|
|
153238
|
-
fs11.unlinkSync(sessionPath(id));
|
|
153278
|
+
fs11.unlinkSync(sessionPath(r2.id));
|
|
153239
153279
|
} catch {
|
|
153240
153280
|
return false;
|
|
153241
153281
|
}
|
|
153242
153282
|
try {
|
|
153243
|
-
fs11.unlinkSync(eventsPath(id));
|
|
153283
|
+
fs11.unlinkSync(eventsPath(r2.id));
|
|
153244
153284
|
} catch {
|
|
153245
153285
|
}
|
|
153246
153286
|
return true;
|
|
@@ -153262,11 +153302,14 @@ function sameDir(a, b) {
|
|
|
153262
153302
|
function lastSessionForDir(dir, sessions = listSessions()) {
|
|
153263
153303
|
return sessions.find((s2) => s2.workDir && s2.messages.length > 0 && sameDir(s2.workDir, dir)) ?? null;
|
|
153264
153304
|
}
|
|
153265
|
-
function exportSession(id, events
|
|
153266
|
-
const
|
|
153305
|
+
function exportSession(id, events) {
|
|
153306
|
+
const r2 = resolveSessionId(id);
|
|
153307
|
+
if (!r2.ok)
|
|
153308
|
+
return null;
|
|
153309
|
+
const session = loadSession(r2.id);
|
|
153267
153310
|
if (!session)
|
|
153268
153311
|
return null;
|
|
153269
|
-
const bundle = { format: "nexrall-session", version: 1, exportedAt: Date.now(), session, events };
|
|
153312
|
+
const bundle = { format: "nexrall-session", version: 1, exportedAt: Date.now(), session, events: events ?? readEvents(r2.id) };
|
|
153270
153313
|
return JSON.stringify(bundle, null, 2);
|
|
153271
153314
|
}
|
|
153272
153315
|
function parseSessionBundle(raw) {
|
|
@@ -169063,6 +169106,7 @@ async function runTurn(messages, modelAlias, workDir, abortSignal, env4, nexrall
|
|
|
169063
169106
|
backgroundAgents: cliBackgroundAgents,
|
|
169064
169107
|
disableHooks: noDiscovery,
|
|
169065
169108
|
_extraAgentTypes: _cliAgentTypes,
|
|
169109
|
+
onCompact: (info) => emitEvent("context.compacted", { where: "auto", before: info.before, after: info.after }),
|
|
169066
169110
|
// The backend streams a cumulative output-token count (routes/code.js's
|
|
169067
169111
|
// sendProgress, throttled to ≤5/s) covering thinking, visible text AND
|
|
169068
169112
|
// tool-argument JSON. This used to be stored in a variable and rendered only
|
|
@@ -169386,6 +169430,7 @@ async function runTurnHeadless(messages, modelAlias, workDir, _abortSignal, env4
|
|
|
169386
169430
|
backgroundAgents: cliBackgroundAgents,
|
|
169387
169431
|
disableHooks: noDiscovery,
|
|
169388
169432
|
_extraAgentTypes: _cliAgentTypes,
|
|
169433
|
+
onCompact: (info) => emitEvent("context.compacted", { where: "auto", before: info.before, after: info.after }),
|
|
169389
169434
|
effort,
|
|
169390
169435
|
abortSignal: _abortSignal,
|
|
169391
169436
|
// `--max-turns`: a hard round cap. autoContinue off, or the loop would extend it.
|
|
@@ -173092,6 +173137,17 @@ function killJob(job, dir = bgDir()) {
|
|
|
173092
173137
|
}
|
|
173093
173138
|
}
|
|
173094
173139
|
}
|
|
173140
|
+
function removeJob(job, dir = bgDir()) {
|
|
173141
|
+
if (job.state === "running")
|
|
173142
|
+
return { ok: false, error: `Job ${job.id} is still running \u2014 stop it first (nex kill ${job.id}).` };
|
|
173143
|
+
for (const suffix of [".json", ".log", ".code", ".killed"]) {
|
|
173144
|
+
try {
|
|
173145
|
+
fs25.rmSync(path25.join(dir, job.id + suffix), { force: true });
|
|
173146
|
+
} catch {
|
|
173147
|
+
}
|
|
173148
|
+
}
|
|
173149
|
+
return { ok: true };
|
|
173150
|
+
}
|
|
173095
173151
|
var ago = (t2) => {
|
|
173096
173152
|
const s2 = Math.max(0, Math.round((Date.now() - t2) / 1e3));
|
|
173097
173153
|
return s2 < 90 ? `${s2}s` : s2 < 5400 ? `${Math.round(s2 / 60)}m` : `${Math.round(s2 / 3600)}h`;
|
|
@@ -173467,6 +173523,33 @@ program2.command("attach <id>").description("Watch a background job live, readab
|
|
|
173467
173523
|
}
|
|
173468
173524
|
process.exit(await followLog(r2.job, true, void 0, void 0, true));
|
|
173469
173525
|
});
|
|
173526
|
+
program2.command("stop <id>").description("Stop a running background job (same as kill; matches Claude Code's name)").action((id) => {
|
|
173527
|
+
const r2 = resolveJob(id);
|
|
173528
|
+
if (!r2.ok) {
|
|
173529
|
+
console.error(r2.error);
|
|
173530
|
+
process.exit(1);
|
|
173531
|
+
}
|
|
173532
|
+
if (!killJob(r2.job)) {
|
|
173533
|
+
console.error(`Job ${r2.job.id} is not running (${r2.job.state}).`);
|
|
173534
|
+
process.exit(1);
|
|
173535
|
+
}
|
|
173536
|
+
console.log(`Stopped job ${r2.job.id}`);
|
|
173537
|
+
process.exit(0);
|
|
173538
|
+
});
|
|
173539
|
+
program2.command("rm <id>").description("Delete a finished background job's records (log included)").action((id) => {
|
|
173540
|
+
const r2 = resolveJob(id);
|
|
173541
|
+
if (!r2.ok) {
|
|
173542
|
+
console.error(r2.error);
|
|
173543
|
+
process.exit(1);
|
|
173544
|
+
}
|
|
173545
|
+
const res = removeJob(r2.job);
|
|
173546
|
+
if (!res.ok) {
|
|
173547
|
+
console.error(res.error);
|
|
173548
|
+
process.exit(1);
|
|
173549
|
+
}
|
|
173550
|
+
console.log(`Removed job ${r2.job.id}`);
|
|
173551
|
+
process.exit(0);
|
|
173552
|
+
});
|
|
173470
173553
|
program2.command("kill <id>").description("Stop a background job").action((id) => {
|
|
173471
173554
|
const r2 = resolveJob(id);
|
|
173472
173555
|
if (!r2.ok) {
|
|
@@ -173571,9 +173654,15 @@ program2.command("sessions").description("List, export, import, or delete saved
|
|
|
173571
173654
|
}
|
|
173572
173655
|
if (opts.events) {
|
|
173573
173656
|
const want = Number.parseInt(String(opts.last ?? "20"), 10);
|
|
173574
|
-
const
|
|
173657
|
+
const hit = resolveSessionId(opts.events);
|
|
173658
|
+
if (!hit.ok) {
|
|
173659
|
+
console.log(paint.red(` ${hit.error}`));
|
|
173660
|
+
process.exitCode = 1;
|
|
173661
|
+
return;
|
|
173662
|
+
}
|
|
173663
|
+
const events = readEvents(hit.id, { last: Number.isFinite(want) && want > 0 ? want : 20 });
|
|
173575
173664
|
if (!events.length) {
|
|
173576
|
-
console.log(paint.dim(` No events recorded for ${
|
|
173665
|
+
console.log(paint.dim(` No events recorded for ${hit.id.slice(0, 8)} (NEXRALL_EVENTS=off disables the stream).`));
|
|
173577
173666
|
return;
|
|
173578
173667
|
}
|
|
173579
173668
|
if (opts.json) {
|
|
@@ -173582,11 +173671,11 @@ program2.command("sessions").description("List, export, import, or delete saved
|
|
|
173582
173671
|
return;
|
|
173583
173672
|
}
|
|
173584
173673
|
console.log();
|
|
173585
|
-
console.log(paint.bold(` Events for ${
|
|
173674
|
+
console.log(paint.bold(` Events for ${hit.id.slice(0, 8)} `) + paint.dim(`(last ${events.length})`));
|
|
173586
173675
|
for (const ev of events)
|
|
173587
173676
|
console.log(" " + paint.dim(summarizeEvent(ev)));
|
|
173588
173677
|
console.log(paint.dim(`
|
|
173589
|
-
Raw JSONL: ${eventsPath(
|
|
173678
|
+
Raw JSONL: ${eventsPath(hit.id)}`));
|
|
173590
173679
|
console.log();
|
|
173591
173680
|
return;
|
|
173592
173681
|
}
|