nexrall-code 0.5.164 → 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.
Files changed (2) hide show
  1. package/dist/index.js +61 -10
  2. 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 = readEvents(id)) {
153266
- const session = loadSession(id);
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.
@@ -173609,9 +173654,15 @@ program2.command("sessions").description("List, export, import, or delete saved
173609
173654
  }
173610
173655
  if (opts.events) {
173611
173656
  const want = Number.parseInt(String(opts.last ?? "20"), 10);
173612
- const events = readEvents(opts.events, { last: Number.isFinite(want) && want > 0 ? want : 20 });
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 });
173613
173664
  if (!events.length) {
173614
- console.log(paint.dim(` No events recorded for ${opts.events.slice(0, 8)} (NEXRALL_EVENTS=off disables the stream).`));
173665
+ console.log(paint.dim(` No events recorded for ${hit.id.slice(0, 8)} (NEXRALL_EVENTS=off disables the stream).`));
173615
173666
  return;
173616
173667
  }
173617
173668
  if (opts.json) {
@@ -173620,11 +173671,11 @@ program2.command("sessions").description("List, export, import, or delete saved
173620
173671
  return;
173621
173672
  }
173622
173673
  console.log();
173623
- console.log(paint.bold(` Events for ${opts.events.slice(0, 8)} `) + paint.dim(`(last ${events.length})`));
173674
+ console.log(paint.bold(` Events for ${hit.id.slice(0, 8)} `) + paint.dim(`(last ${events.length})`));
173624
173675
  for (const ev of events)
173625
173676
  console.log(" " + paint.dim(summarizeEvent(ev)));
173626
173677
  console.log(paint.dim(`
173627
- Raw JSONL: ${eventsPath(opts.events)}`));
173678
+ Raw JSONL: ${eventsPath(hit.id)}`));
173628
173679
  console.log();
173629
173680
  return;
173630
173681
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexrall-code",
3
- "version": "0.5.164",
3
+ "version": "0.5.165",
4
4
  "description": "Nexrall Code — AI coding assistant for your terminal (headless agent for scripts, CI and automation)",
5
5
  "keywords": [
6
6
  "ai",